Package org.apache.cxf.common.classloader.ClassLoaderUtils

Examples of org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder


     */
    public void onMessage(javax.jms.Message message) {
        onMessage(message, null);
    }
    public void onMessage(javax.jms.Message message, Session session) {
        ClassLoaderHolder origLoader = null;
        try {
            if (loader != null) {
                origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
            }
            getLogger().log(Level.FINE, "server received request: ", message);
             // Build CXF message from JMS message
            Message inMessage = new MessageImpl();           
            JMSUtils.populateIncomingContext(message, inMessage,
                                             JMSConstants.JMS_SERVER_REQUEST_HEADERS, jmsConfig);
           
            JMSUtils.retrieveAndSetPayload(inMessage, message, (String)inMessage.get(Message.ENCODING));
            inMessage.put(JMSConstants.JMS_SERVER_RESPONSE_HEADERS, new JMSMessageHeadersType());
            inMessage.put(JMSConstants.JMS_REQUEST_MESSAGE, message);
            ((MessageImpl)inMessage).setDestination(this);
            if (jmsConfig.getMaxSuspendedContinuations() != 0) {
                inMessage.put(ContinuationProvider.class.getName(),
                              new JMSContinuationProvider(bus,
                                                          inMessage,
                                                          incomingObserver,
                                                          continuations,
                                                          jmsListener,
                                                          jmsConfig));
            }
           
            BusFactory.setThreadDefaultBus(bus);

           
            Map<Class<?>, ?> mp = JCATransactionalMessageListenerContainer.ENDPOINT_LOCAL.get();
            if (mp != null) {
                for (Map.Entry<Class<?>, ?> ent : mp.entrySet()) {
                    inMessage.setContent(ent.getKey(), ent.getValue());
                }
                JCATransactionalMessageListenerContainer.ENDPOINT_LOCAL.remove();
            }

            // handle the incoming message
            incomingObserver.onMessage(inMessage);
           
            if (inMessage.getExchange() != null
                && inMessage.getExchange().getInMessage() != null) {
                inMessage = inMessage.getExchange().getInMessage();
            }
            //need to propagate any exceptions back to Spring container
            //so transactions can occur
            if (inMessage.getContent(Exception.class) != null && session != null) {
                PlatformTransactionManager m = jmsConfig.getTransactionManager();
                if (m != null) {
                    TransactionStatus status = m.getTransaction(null);
                    JmsResourceHolder resourceHolder =
                        (JmsResourceHolder) TransactionSynchronizationManager
                            .getResource(jmsConfig.getConnectionFactory());
                    boolean trans = resourceHolder == null
                        || !resourceHolder.containsSession(session);
                    if (status != null && !status.isCompleted() && trans) {
                        Exception ex = inMessage.getContent(Exception.class);
                        if (ex.getCause() instanceof RuntimeException) {
                            throw (RuntimeException)ex.getCause();
                        } else {
                            throw new RuntimeException(ex);
                        }
                    }
                }
            }
           
        } catch (SuspendedInvocationException ex) {
            getLogger().log(Level.FINE, "Request message has been suspended");
        } catch (UnsupportedEncodingException ex) {
            getLogger().log(Level.WARNING, "can't get the right encoding information. " + ex);
        } finally {
            BusFactory.setThreadDefaultBus(null);
            if (origLoader != null) {
                origLoader.reset();
            }
        }
    }
View Full Code Here


        this.bus = bus;
    }

    @Override
    protected void invoke(HttpServletRequest request, HttpServletResponse response) throws ServletException {
        ClassLoaderHolder origLoader = null;
        try {
            if (loader != null) {
                origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
            }
            if (bus != null) {
                BusFactory.setThreadDefaultBus(bus);
            }
            controller.invoke(request, response);
        } finally {
            BusFactory.setThreadDefaultBus(null);
            if (origLoader != null) {
                origLoader.reset();
            }
        }
    }
View Full Code Here

        //on the thread the runnable actually runs on.
       
        final ClassLoader loader = Thread.currentThread().getContextClassLoader();
        Runnable r = new Runnable() {
            public void run() {
                ClassLoaderHolder orig = ClassLoaderUtils.setThreadContextClassloader(loader);
                try {
                    command.run();
                } finally {
                    if (orig != null) {
                        orig.reset();
                    }
                }
            }
        };
        //The ThreadPoolExecutor in the JDK doesn't expand the number
View Full Code Here

    }

    public void onMessage(Message m) {
        Bus origBus = BusFactory.getThreadDefaultBus(false);
        BusFactory.setThreadDefaultBus(bus);
        ClassLoaderHolder origLoader = null;
        try {
            if (loader != null) {
                origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
            }
            InterceptorChain phaseChain = null;
           
            if (m.getInterceptorChain() != null) {
                phaseChain = m.getInterceptorChain();
                // To make sure the phase chain is run by one thread once
                synchronized (phaseChain) {
                    if (phaseChain.getState() == InterceptorChain.State.PAUSED
                        || phaseChain.getState() == InterceptorChain.State.SUSPENDED) {
                        phaseChain.resume();
                        return;
                    }
                }
            }
           
            Message message = getBinding().createMessage(m);
            Exchange exchange = message.getExchange();
            if (exchange == null) {
                exchange = new ExchangeImpl();
                m.setExchange(exchange);
            }
            exchange.setInMessage(message);
            setExchangeProperties(exchange, message);
   
            InterceptorProvider dbp = null;
            if (endpoint.getService().getDataBinding() instanceof InterceptorProvider) {
                dbp = (InterceptorProvider)endpoint.getService().getDataBinding();
            }
            // setup chain
            if (dbp == null) {
                phaseChain = chainCache.get(bus.getExtension(PhaseManager.class).getInPhases(),
                                                             bus.getInInterceptors(),
                                                             endpoint.getService().getInInterceptors(),
                                                             endpoint.getInInterceptors(),
                                                             getBinding().getInInterceptors());
            } else {
                phaseChain = chainCache.get(bus.getExtension(PhaseManager.class).getInPhases(),
                                            bus.getInInterceptors(),
                                            endpoint.getService().getInInterceptors(),
                                            endpoint.getInInterceptors(),
                                            getBinding().getInInterceptors(),
                                            dbp.getInInterceptors());
            }
       
           
           
            message.setInterceptorChain(phaseChain);
           
            phaseChain.setFaultObserver(endpoint.getOutFaultObserver());
          
            addToChain(phaseChain, message);
           
            phaseChain.doIntercept(message);
           
        } finally {
            BusFactory.setThreadDefaultBus(origBus);
            if (origLoader != null) {
                origLoader.reset();
            }
        }
    }
View Full Code Here

        checkPublishPermission();
        checkPublishable();
       
        ServerImpl serv = null;
       
        ClassLoaderHolder loader = null;
        try {
            if (bus != null) {
                ClassLoader newLoader = bus.getExtension(ClassLoader.class);
                if (newLoader != null) {
                    loader = ClassLoaderUtils.setThreadContextClassloader(newLoader);
                }
            }
            serv = getServer(addr);
            if (addr != null) {           
                EndpointInfo endpointInfo = serv.getEndpoint().getEndpointInfo();
                if (!endpointInfo.getAddress().contains(addr)) {
                    endpointInfo.setAddress(addr);
                }
                if (publishedEndpointUrl != null) {
                    // TODO is there a good place to put this key-string as a constant?
                    endpointInfo.setProperty("publishedEndpointUrl", publishedEndpointUrl);
                }

                if (null != properties) {
                    for (Entry<String, Object> entry : properties.entrySet()) {
                        endpointInfo.setProperty(entry.getKey(), entry.getValue());
                    }
                }

                this.address = endpointInfo.getAddress();
            }
            serv.start();
            publishable = false;
        } catch (Exception ex) {
            try {
                stop();
            } catch (Exception e) {
                // Nothing we can do.
            }
           
            throw new WebServiceException(ex);
        } finally {
            if (loader != null) {
                loader.reset();
            }
        }
    }
View Full Code Here

   
    public synchronized ServerImpl getServer(String addr) {
        if (server == null) {
            checkProperties();

            ClassLoaderHolder loader = null;
            try {
                if (bus != null) {
                    ClassLoader newLoader = bus.getExtension(ClassLoader.class);
                    if (newLoader != null) {
                        loader = ClassLoaderUtils.setThreadContextClassloader(newLoader);
                    }
                }
   
                // Initialize the endpointName so we can do configureObject
                QName origEpn = endpointName;
                if (endpointName == null) {
                    JaxWsImplementorInfo implInfo = new JaxWsImplementorInfo(getImplementorClass());
                    endpointName = implInfo.getEndpointName();
                }
               
                if (serviceFactory != null) {
                    serverFactory.setServiceFactory(serviceFactory);
                }
   
                /*if (serviceName != null) {
                    serverFactory.getServiceFactory().setServiceName(serviceName);
                }*/
   
                configureObject(this);
                endpointName = origEpn;
               
                // Set up the server factory
                serverFactory.setAddress(addr);
                serverFactory.setStart(false);
                serverFactory.setEndpointName(endpointName);
                serverFactory.setServiceBean(implementor);
                serverFactory.setBus(bus);
                serverFactory.setFeatures(getFeatures());
                serverFactory.setInvoker(invoker);
                serverFactory.setSchemaLocations(schemaLocations);
                if (serverFactory.getProperties() != null) {
                    serverFactory.getProperties().putAll(properties);
                } else {
                    serverFactory.setProperties(properties);
                }
               
                // Be careful not to override any serverfactory settings as a user might
                // have supplied their own.
                if (getWsdlLocation() != null) {
                    serverFactory.setWsdlURL(getWsdlLocation());
                }
               
                if (bindingUri != null) {
                    serverFactory.setBindingId(bindingUri);
                }
   
                if (serviceName != null) {
                    serverFactory.getServiceFactory().setServiceName(serviceName);
                }
               
                if (implementorClass != null) {
                    serverFactory.setServiceClass(implementorClass);
                }
               
                if (executor != null) {
                    serverFactory.getServiceFactory().setExecutor(executor);
                }
                if (handlers.size() > 0) {
                    serverFactory.addHandlers(handlers);
                }
   
                configureObject(serverFactory);
               
                server = serverFactory.create();
               
                org.apache.cxf.endpoint.Endpoint endpoint = getEndpoint();
                if (in != null) {
                    endpoint.getInInterceptors().addAll(in);
                }
                if (out != null) {
                    endpoint.getOutInterceptors().addAll(out);
                }
                if (inFault != null) {
                    endpoint.getInFaultInterceptors().addAll(inFault);
                }
                if (outFault != null) {
                    endpoint.getOutFaultInterceptors().addAll(outFault);
                }
               
                if (properties != null) {
                    endpoint.putAll(properties);
                }
               
                configureObject(endpoint.getService());
                configureObject(endpoint);
                this.service = endpoint.getService();
               
                if (getWsdlLocation() == null) {
                    //hold onto the wsdl location so cache won't clear till we go away
                    setWsdlLocation(serverFactory.getWsdlURL());
                }
               
                if (serviceName == null) {
                    setServiceName(serverFactory.getServiceFactory().getServiceQName());
                }
                if (endpointName == null) {
                    endpointName = endpoint.getEndpointInfo().getName();
                }
            } finally {
                if (loader != null) {
                    loader.reset();
                }
            }
        }
        return (ServerImpl) server;
    }
View Full Code Here

                }
            }
        }

        // REVISIT: service on executor if associated with endpoint
        ClassLoaderHolder origLoader = null;
        try {
            if (loader != null) {
                origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
            }
            BusFactory.setThreadDefaultBus(bus);
            serviceRequest(context, req, resp);
        } finally {
            BusFactory.setThreadDefaultBus(null);
            if (origLoader != null) {
                origLoader.reset();
            }
        }   
    }
View Full Code Here

     */
    public void onMessage(javax.jms.Message message) {
        onMessage(message, null);
    }
    public void onMessage(javax.jms.Message message, Session session) {
        ClassLoaderHolder origLoader = null;
        Bus origBus = null;
        try {
            if (loader != null) {
                origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
            }
            getLogger().log(Level.FINE, "server received request: ", message);
             // Build CXF message from JMS message
            Message inMessage = new MessageImpl();           
            JMSUtils.populateIncomingContext(message, inMessage,
                                             JMSConstants.JMS_SERVER_REQUEST_HEADERS, jmsConfig);
           
            JMSUtils.retrieveAndSetPayload(inMessage, message, (String)inMessage.get(Message.ENCODING));
            inMessage.put(JMSConstants.JMS_SERVER_RESPONSE_HEADERS, new JMSMessageHeadersType());
            inMessage.put(JMSConstants.JMS_REQUEST_MESSAGE, message);
            ((MessageImpl)inMessage).setDestination(this);
            if (jmsConfig.getMaxSuspendedContinuations() != 0) {
                inMessage.put(ContinuationProvider.class.getName(),
                              new JMSContinuationProvider(bus,
                                                          inMessage,
                                                          incomingObserver,
                                                          continuations,
                                                          jmsListener,
                                                          jmsConfig));
            }
           
            origBus = BusFactory.getAndSetThreadDefaultBus(bus);

           
            Map<Class<?>, ?> mp = JCATransactionalMessageListenerContainer.ENDPOINT_LOCAL.get();
            if (mp != null) {
                for (Map.Entry<Class<?>, ?> ent : mp.entrySet()) {
                    inMessage.setContent(ent.getKey(), ent.getValue());
                }
                JCATransactionalMessageListenerContainer.ENDPOINT_LOCAL.remove();
            }

            // handle the incoming message
            incomingObserver.onMessage(inMessage);
           
            if (inMessage.getExchange() != null
                && inMessage.getExchange().getInMessage() != null) {
                inMessage = inMessage.getExchange().getInMessage();
            }
            //need to propagate any exceptions back to Spring container
            //so transactions can occur
            if (inMessage.getContent(Exception.class) != null && session != null) {
                PlatformTransactionManager m = jmsConfig.getTransactionManager();
                if (m != null) {
                    TransactionStatus status = m.getTransaction(null);
                    JmsResourceHolder resourceHolder =
                        (JmsResourceHolder) TransactionSynchronizationManager
                            .getResource(jmsConfig.getConnectionFactory());
                    boolean trans = resourceHolder == null
                        || !resourceHolder.containsSession(session);
                    if (status != null && !status.isCompleted() && trans) {
                        Exception ex = inMessage.getContent(Exception.class);
                        if (ex.getCause() instanceof RuntimeException) {
                            throw (RuntimeException)ex.getCause();
                        } else {
                            throw new RuntimeException(ex);
                        }
                    }
                }
            }
           
        } catch (SuspendedInvocationException ex) {
            getLogger().log(Level.FINE, "Request message has been suspended");
        } catch (UnsupportedEncodingException ex) {
            getLogger().log(Level.WARNING, "can't get the right encoding information. " + ex);
        } finally {
            if (origBus != bus) {
                BusFactory.setThreadDefaultBus(origBus);
            }
            if (origLoader != null) {
                origLoader.reset();
            }
        }
    }
View Full Code Here

        checkPublishPermission();
        checkPublishable();
       
        ServerImpl serv = null;
       
        ClassLoaderHolder loader = null;
        try {
            if (bus != null) {
                ClassLoader newLoader = bus.getExtension(ClassLoader.class);
                if (newLoader != null) {
                    loader = ClassLoaderUtils.setThreadContextClassloader(newLoader);
                }
            }
            serv = getServer(addr);
            if (addr != null) {           
                EndpointInfo endpointInfo = serv.getEndpoint().getEndpointInfo();
                if (!endpointInfo.getAddress().contains(addr)) {
                    endpointInfo.setAddress(addr);
                }
                if (publishedEndpointUrl != null) {
                    endpointInfo.setProperty(WSDLGetUtils.PUBLISHED_ENDPOINT_URL, publishedEndpointUrl);
                }
                if (publishedEndpointUrl != null && wsdlLocation != null) {
                    //early update the publishedEndpointUrl so that endpoints in the same app sharing the same wsdl
                    //do not require all of them to be queried for wsdl before the wsdl is finally fully updated
                    Definition def = endpointInfo.getService()
                        .getProperty(WSDLServiceBuilder.WSDL_DEFINITION, Definition.class);
                    if (def == null) {
                        def = bus.getExtension(WSDLManager.class).getDefinition(wsdlLocation);
                    }
                    new WSDLGetUtils().updateWSDLPublishedEndpointAddress(def, endpointInfo);
                }

                if (null != properties) {
                    for (Entry<String, Object> entry : properties.entrySet()) {
                        endpointInfo.setProperty(entry.getKey(), entry.getValue());
                    }
                }

                this.address = endpointInfo.getAddress();
            }
            serv.start();
            publishable = false;
        } catch (Exception ex) {
            try {
                stop();
            } catch (Exception e) {
                // Nothing we can do.
            }
           
            throw new WebServiceException(ex);
        } finally {
            if (loader != null) {
                loader.reset();
            }
        }
    }
View Full Code Here

   
    public synchronized ServerImpl getServer(String addr) {
        if (server == null) {
            checkProperties();

            ClassLoaderHolder loader = null;
            try {
                if (bus != null) {
                    ClassLoader newLoader = bus.getExtension(ClassLoader.class);
                    if (newLoader != null) {
                        loader = ClassLoaderUtils.setThreadContextClassloader(newLoader);
                    }
                }
   
                // Initialize the endpointName so we can do configureObject
                QName origEpn = endpointName;
                if (endpointName == null) {
                    JaxWsImplementorInfo implInfo = new JaxWsImplementorInfo(getImplementorClass());
                    endpointName = implInfo.getEndpointName();
                }
               
                if (serviceFactory != null) {
                    serverFactory.setServiceFactory(serviceFactory);
                }
   
                /*if (serviceName != null) {
                    serverFactory.getServiceFactory().setServiceName(serviceName);
                }*/
   
                configureObject(this);
                endpointName = origEpn;
               
                // Set up the server factory
                serverFactory.setAddress(addr);
                serverFactory.setStart(false);
                serverFactory.setEndpointName(endpointName);
                serverFactory.setServiceBean(implementor);
                serverFactory.setBus(bus);
                serverFactory.setFeatures(getFeatures());
                serverFactory.setInvoker(invoker);
                serverFactory.setSchemaLocations(schemaLocations);
                if (serverFactory.getProperties() != null) {
                    serverFactory.getProperties().putAll(properties);
                } else {
                    serverFactory.setProperties(properties);
                }
               
                // Be careful not to override any serverfactory settings as a user might
                // have supplied their own.
                if (getWsdlLocation() != null) {
                    serverFactory.setWsdlURL(getWsdlLocation());
                }
               
                if (bindingUri != null) {
                    serverFactory.setBindingId(bindingUri);
                }
   
                if (serviceName != null) {
                    serverFactory.getServiceFactory().setServiceName(serviceName);
                }
               
                if (implementorClass != null) {
                    serverFactory.setServiceClass(implementorClass);
                }
               
                if (executor != null) {
                    serverFactory.getServiceFactory().setExecutor(executor);
                }
                if (handlers.size() > 0) {
                    serverFactory.addHandlers(handlers);
                }
   
                configureObject(serverFactory);
               
                server = serverFactory.create();
               
                org.apache.cxf.endpoint.Endpoint endpoint = getEndpoint();
                if (in != null) {
                    endpoint.getInInterceptors().addAll(in);
                }
                if (out != null) {
                    endpoint.getOutInterceptors().addAll(out);
                }
                if (inFault != null) {
                    endpoint.getInFaultInterceptors().addAll(inFault);
                }
                if (outFault != null) {
                    endpoint.getOutFaultInterceptors().addAll(outFault);
                }
               
                if (properties != null) {
                    endpoint.putAll(properties);
                }
               
                configureObject(endpoint.getService());
                configureObject(endpoint);
                this.service = endpoint.getService();
               
                if (getWsdlLocation() == null) {
                    //hold onto the wsdl location so cache won't clear till we go away
                    setWsdlLocation(serverFactory.getWsdlURL());
                }
               
                if (serviceName == null) {
                    setServiceName(serverFactory.getServiceFactory().getServiceQName());
                }
                if (endpointName == null) {
                    endpointName = endpoint.getEndpointInfo().getName();
                }
            } finally {
                if (loader != null) {
                    loader.reset();
                }
            }
        }
        return (ServerImpl) server;
    }
View Full Code Here

TOP

Related Classes of org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.