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

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


        return bindingInfo;
    }
   
    public Server create() {
        ClassLoaderHolder orig = null;
        try {
            if (bus != null) {
                ClassLoader loader = bus.getExtension(ClassLoader.class);
                if (loader != null) {
                    orig = ClassLoaderUtils.setThreadContextClassloader(loader);
                }
            }

            Server server = super.create();
            initializeResourcesAndHandlerChain();
            checkPrivateEndpoint(server.getEndpoint());
           
            return server;
        } finally {
            if (orig != null) {
                orig.reset();
            }
        }
    }
View Full Code Here


     
        assert null != message;
       
        Bus origBus = BusFactory.getThreadDefaultBus(false);
        BusFactory.setThreadDefaultBus(bus);
        ClassLoaderHolder origLoader = null;
        try {
            if (loader != null) {
                origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
            }
           
            Exchange exchange = message.getExchange();
   
            Message faultMessage = null;
   
            // now that we have switched over to the fault chain,
            // prevent any further operations on the in/out message
   
            if (isOutboundObserver()) {
                Exception ex = message.getContent(Exception.class);
                if (!(ex instanceof Fault)) {
                    ex = new Fault(ex);
                }
                FaultMode mode = (FaultMode)message.get(FaultMode.class);
               
                faultMessage = exchange.getOutMessage();
                if (null == faultMessage) {
                    faultMessage = new MessageImpl();
                    faultMessage.setExchange(exchange);
                    faultMessage = exchange.get(Endpoint.class).getBinding().createMessage(faultMessage);
                }
                faultMessage.setContent(Exception.class, ex);
                if (null != mode) {
                    faultMessage.put(FaultMode.class, mode);
                }
                exchange.setOutMessage(null);
                exchange.setOutFaultMessage(faultMessage);
                if (message.get(BindingFaultInfo.class) != null) {
                    faultMessage.put(BindingFaultInfo.class, message.get(BindingFaultInfo.class));
                }
            } else {
                faultMessage = message;
                exchange.setInMessage(null);
                exchange.setInFaultMessage(faultMessage);
            }         
            
          
            // setup chain
            PhaseInterceptorChain chain = new PhaseInterceptorChain(getPhases());
            initializeInterceptors(faultMessage.getExchange(), chain);
           
            faultMessage.setInterceptorChain(chain);
            try {
                chain.doIntercept(faultMessage);
            } catch (Exception exc) {
                LOG.log(Level.SEVERE, "Error occurred during error handling, give up!", exc);
                throw new RuntimeException(exc);
            }
        } finally {
            BusFactory.setThreadDefaultBus(origBus);
            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

                              BindingOperationInfo oi,
                              Object[] params,
                              Map<String, Object> context,
                              Exchange exchange) throws Exception {
        Bus origBus = BusFactory.getThreadDefaultBus(false);
        ClassLoaderHolder origLoader = null;
        try {
            BusFactory.setThreadDefaultBus(bus);
            ClassLoader loader = bus.getExtension(ClassLoader.class);
            if (loader != null) {
                origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
            }
            if (exchange == null) {
                exchange = new ExchangeImpl();
            }
            exchange.setSynchronous(callback == null);
            Endpoint endpoint = getEndpoint();
            if (LOG.isLoggable(Level.FINE)) {
                LOG.fine("Invoke, operation info: " + oi + ", params: " + Arrays.toString(params));
            }
            Message message = endpoint.getBinding().createMessage();
           
            // Make sure INVOCATION CONTEXT, REQUEST_CONTEXT and RESPONSE_CONTEXT are present
            // on message
            Map<String, Object> reqContext = null;
            Map<String, Object> resContext = null;
            if (context == null) {
                context = new HashMap<String, Object>();
            }
            reqContext = CastUtils.cast((Map)context.get(REQUEST_CONTEXT));
            resContext = CastUtils.cast((Map)context.get(RESPONSE_CONTEXT));
            if (reqContext == null) {
                reqContext = new HashMap<String, Object>(getRequestContext());
                context.put(REQUEST_CONTEXT, reqContext);
            }
            if (resContext == null) {
                resContext = new HashMap<String, Object>();
                context.put(RESPONSE_CONTEXT, resContext);
            }
           
            message.put(Message.INVOCATION_CONTEXT, context);
            setContext(reqContext, message);
            if (null != reqContext) {
                exchange.putAll(reqContext);
            }
           
            setParameters(params, message);

            if (null != oi) {
                exchange.setOneWay(oi.getOutput() == null);
            }

            exchange.setOutMessage(message);
            exchange.put(ClientCallback.class, callback);
           
            setOutMessageProperties(message, oi);
            setExchangeProperties(exchange, endpoint, oi);

            PhaseInterceptorChain chain = setupInterceptorChain(endpoint);
            message.setInterceptorChain(chain);
            chain.setFaultObserver(outFaultObserver);
            prepareConduitSelector(message);

            // add additional interceptors and such
            modifyChain(chain, message, false);
            try {
                chain.doIntercept(message);
            } catch (Fault fault) {
                enrichFault(fault);
                throw fault;
            }
           
            if (callback != null) {
                return null;
            } else {
                return processResult(message, exchange, oi, resContext);
            }
        } finally {
            if (origLoader != null) {
                origLoader.reset();
            }
            BusFactory.setThreadDefaultBus(origBus);
        }
    }
View Full Code Here

     * Creates a proxy object that can be used to make remote invocations.
     *
     * @return the proxy. You must cast the returned object to the appropriate class before using it.
     */
    public synchronized Object create() {
        ClassLoaderHolder orig = null;
        try {
            if (getBus() != null) {
                ClassLoader loader = getBus().getExtension(ClassLoader.class);
                if (loader != null) {
                    orig = ClassLoaderUtils.setThreadContextClassloader(loader);
                }
            }
            configureObject();
           
            if (properties == null) {
                properties = new HashMap<String, Object>();
            }
   
            if (username != null) {
                AuthorizationPolicy authPolicy = new AuthorizationPolicy();
                authPolicy.setUserName(username);
                authPolicy.setPassword(password);
                properties.put(AuthorizationPolicy.class.getName(), authPolicy);
            }
   
            initFeatures();
            clientFactoryBean.setProperties(properties);
   
            if (bus != null) {
                clientFactoryBean.setBus(bus);
            }
   
            if (dataBinding != null) {
                clientFactoryBean.setDataBinding(dataBinding);
            }
   
            Client c = clientFactoryBean.create();
            if (getInInterceptors() != null) {
                c.getInInterceptors().addAll(getInInterceptors());
            }
            if (getOutInterceptors() != null) {
                c.getOutInterceptors().addAll(getOutInterceptors());
            }
            if (getInFaultInterceptors() != null) {
                c.getInFaultInterceptors().addAll(getInFaultInterceptors());
            }
            if (getOutFaultInterceptors() != null) {
                c.getOutFaultInterceptors().addAll(getOutFaultInterceptors());
            }
   
            ClientProxy handler = clientClientProxy(c);
   
            Class classes[] = getImplementingClasses();
           
            Object obj = Proxy.newProxyInstance(clientFactoryBean.getServiceClass().getClassLoader(),
                                                classes,
                                                handler);
   
            this.getServiceFactory().sendEvent(FactoryBeanListener.Event.PROXY_CREATED,
                                               classes, handler, obj);
            return obj;
        } finally {
            if (orig != null) {
                orig.reset();
            }
        }
    }
View Full Code Here

        } else if (request != null) {
            params = new MessageContentsList(request);
        }

        Object result = null;
        ClassLoaderHolder contextLoader = null;
        try {
            if (setServiceLoaderAsContextLoader(inMessage)) {
                contextLoader = ClassLoaderUtils
                    .setThreadContextClassloader(resourceObject.getClass().getClassLoader());
            }
            AsyncResponseImpl asyncResponse = null;
            if (!ori.isSubResourceLocator()) {
                asyncResponse = (AsyncResponseImpl)inMessage.get(AsyncResponse.class);
            }
            result = invoke(exchange, resourceObject, methodToInvoke, params);
            if (asyncResponse != null) {
                if (!asyncResponse.isSuspended() && !asyncResponse.isResumedByApplication()) {
                    asyncResponse.suspendContinuation();
                } else {
                    result = handleAsyncResponse(exchange, asyncResponse.getResponseObject());
                }
            }
        } catch (Fault ex) {
            return handleFault(ex, inMessage, cri, methodToInvoke);
        } finally {
            exchange.put(LAST_SERVICE_OBJECT, resourceObject);
            if (contextLoader != null) {
                contextLoader.reset();
            }
        }
        ClassResourceInfo subCri = null;
        if (ori.isSubResourceLocator()) {
            try {
View Full Code Here

                }
            }
        }

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

    /**
     * Creates the JAX-RS Server instance
     * @return the server
     */
    public Server create() {
        ClassLoaderHolder origLoader = null;
        try {
            Bus bus = getBus();
            ClassLoader loader = bus.getExtension(ClassLoader.class);
            if (loader != null) {
                origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
            }
            serviceFactory.setBus(bus);
            checkResources(true);
            if (serviceFactory.getService() == null) {
                serviceFactory.create();
                updateClassResourceProviders();
            }
           
            Endpoint ep = createEndpoint();
            server = new ServerImpl(getBus(),
                                    ep,
                                    getDestinationFactory(),
                                    getBindingFactory());

            Invoker invoker = serviceFactory.getInvoker();
            if (invoker == null) {
                ep.getService().setInvoker(createInvoker());
            } else {
                ep.getService().setInvoker(invoker);
            }
           
            ProviderFactory factory = setupFactory(ep);
            ep.put(Application.class.getName(), appProvider);
            factory.setApplicationProvider(appProvider);
            factory.setRequestPreprocessor(
                new RequestPreprocessor(languageMappings, extensionMappings));
            ep.put(Bus.class.getName(), getBus());
            if (documentLocation != null) {
                ep.put(JAXRSUtils.DOC_LOCATION, documentLocation);
            }
            if (rc != null) {
                ep.put("org.apache.cxf.jaxrs.comparator", rc);
            }
            checkPrivateEndpoint(ep);
           
            getServiceFactory().sendEvent(FactoryBeanListener.Event.SERVER_CREATED,
                                          server,
                                          null,
                                          null);
           
            applyFeatures();
           
            if (start) {
                server.start();
            }
        } catch (EndpointException e) {
            throw new ServiceConstructionException(e);
        } catch (BusException e) {
            throw new ServiceConstructionException(e);
        } catch (IOException e) {
            throw new ServiceConstructionException(e);
        } catch (Exception e) {
            throw new ServiceConstructionException(e);
        } finally {
            if (origLoader != null) {
                origLoader.reset();
            }
        }

        return server;
    }
View Full Code Here

        } else if (request != null) {
            params = new MessageContentsList(request);
        }

        Object result = null;
        ClassLoaderHolder contextLoader = null;
        try {
            if (setServiceLoaderAsContextLoader(inMessage)) {
                contextLoader = ClassLoaderUtils
                    .setThreadContextClassloader(resourceObject.getClass().getClassLoader());
            }
            AsyncResponse asyncResponse = inMessage.get(AsyncResponse.class);
            if (asyncResponse != null) {
                inMessage.put(AsyncResponse.class, null);
                AsyncResponseImpl asyncImpl = (AsyncResponseImpl)asyncResponse;
                asyncImpl.suspend();
            }
            result = invoke(exchange, resourceObject, methodToInvoke, params);
        } catch (Fault ex) {
            return handleFault(ex, inMessage, cri, methodToInvoke);
        } finally {
            exchange.put(LAST_SERVICE_OBJECT, resourceObject);
            if (contextLoader != null) {
                contextLoader.reset();
            }
        }
        ClassResourceInfo subCri = null;
        if (ori.isSubResourceLocator()) {
            try {
View Full Code Here

                    }
                }
            } else {
                EndpointInfo ei = d.getEndpointInfo();
                Bus bus = d.getBus();
                ClassLoaderHolder orig = null;
                try {
                    ResourceManager manager = bus.getExtension(ResourceManager.class);
                    if (manager != null) {
                        ClassLoader loader = manager.resolveResource("", ClassLoader.class);
                        if (loader != null) {
                            //need to set the context classloader to the loader of the bundle
                            orig = ClassLoaderUtils.setThreadContextClassloader(loader);
                        }
                    }
                    QueryHandlerRegistry queryHandlerRegistry = bus.getExtension(QueryHandlerRegistry.class);

                    if (!StringUtils.isEmpty(request.getQueryString()) && queryHandlerRegistry != null) {
                       
                        // update the EndPoint Address with request url
                        if ("GET".equals(request.getMethod())) {
                            updateDestination(request, d);
                        }
                       
                        String ctxUri = request.getPathInfo();
                        String baseUri = request.getRequestURL().toString()
                            + "?" + request.getQueryString();

                        QueryHandler selectedHandler =
                            findQueryHandler(queryHandlerRegistry, ei, ctxUri, baseUri);
                       
                        if (selectedHandler != null) {
                            respondUsingQueryHandler(selectedHandler, res, ei, ctxUri, baseUri);
                            return true;
                        }
                    } else {
                        updateDestination(request, d);
                    }
                    invokeDestination(request, res, d);
                } finally {
                    if (orig != null) {
                        orig.reset();
                    }
                }
            }
        } catch (IOException e) {
            throw new ServletException(e);
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.