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

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


        } 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();
                    providerFactory.clearThreadLocalProxies();
                } 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


            for (Element referenceParameter : referenceParameters) {
                builder.referenceParameter(referenceParameter);
            }
        }
       
        ClassLoaderHolder orig = null;
        try {
            orig = ClassLoaderUtils.setThreadContextClassloader(EndpointReferenceBuilder.class.getClassLoader());
            return builder.build();
        } finally {
            if (orig != null) {
                orig.reset();
            }
        }
    }
View Full Code Here

        doResume();
    }
   
    protected void doResume() {
        updateContinuations(true);
        ClassLoaderHolder origLoader = null;
        Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus);
        try {
            if (loader != null) {
                origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
            }
            incomingObserver.onMessage(inMessage);
        } finally {
            isPending = false;
            if (origBus != bus) {
                BusFactory.setThreadDefaultBus(origBus);
            }
            if (origLoader != null) {
                origLoader.reset();
            }
        }
    }
View Full Code Here

     * @return the proxy. You must cast the returned object to the approriate class
     * before making remote calls
     */
    @Override
    public synchronized Object create() {
        ClassLoaderHolder orig = null;
        try {
            if (getBus() != null) {
                ClassLoader loader = getBus().getExtension(ClassLoader.class);
                if (loader != null) {
                    orig = ClassLoaderUtils.setThreadContextClassloader(loader);
                }
            }
           
            Object obj = super.create();
            Service service = getServiceFactory().getService();
            if (needWrapperClassInterceptor(service.getServiceInfos().get(0))) {
                List<Interceptor<? extends Message>> in = super.getInInterceptors();
                List<Interceptor<? extends Message>> out = super.getOutInterceptors();
                in.add(new WrapperClassInInterceptor());
                in.add(new HolderInInterceptor());
                out.add(new WrapperClassOutInterceptor());
                out.add(new HolderOutInterceptor());
            }
            return obj;
        } finally {
            if (orig != null) {
                orig.reset();
            }
        }
    }
View Full Code Here

    }
   
    protected Crypto loadCryptoFromPropertiesFile(
        SoapMessage soapMessage, String propFilename, WSSSecurityProperties securityProperties
    ) throws WSSecurityException {
        ClassLoaderHolder orig = null;
        try {
            try {
                URL url = ClassLoaderUtils.getResource(propFilename, this.getClass());
                if (url == null) {
                    ResourceManager manager = soapMessage.getExchange()
                            .getBus().getExtension(ResourceManager.class);
                    ClassLoader loader = manager.resolveResource("", ClassLoader.class);
                    if (loader != null) {
                        orig = ClassLoaderUtils.setThreadContextClassloader(loader);
                    }
                    url = manager.resolveResource(propFilename, URL.class);
                }
                if (url != null) {
                    Properties props = new Properties();
                    InputStream in = url.openStream();
                    props.load(in);
                    in.close();
                    return CryptoFactory.getInstance(props, getClassLoader(),
                                                     getPasswordEncryptor(soapMessage, securityProperties));
                }
            } catch (Exception e) {
                //ignore
            }
            return CryptoFactory.getInstance(propFilename, getClassLoader());
        } finally {
            if (orig != null) {
                orig.reset();
            }
        }
    }
View Full Code Here

   
    public static void doHacks() {
        try {
            // Use the system classloader as the victim for all this
            // ClassLoader pinning we're about to do.
            ClassLoaderHolder orig = ClassLoaderUtils
                .setThreadContextClassloader(ClassLoader.getSystemClassLoader());
            try {
               
                try {
                    //Trigger a call to sun.awt.AppContext.getAppContext()
                    ImageIO.getCacheDirectory();
                } catch (Throwable t) {
                    //ignore
                }
                try {
                    // Several components end up opening JarURLConnections without first
                    // disabling caching. This effectively locks the file.
                    // JAXB does this and thus affects us pretty badly.
                    // Doesn't matter that this JAR doesn't exist - just as long as
                    // the URL is well-formed
                    URL url = new URL("jar:file://dummy.jar!/");
                    URLConnection uConn = new URLConnection(url) {
                        @Override
                        public void connect() throws IOException {
                            // NOOP
                        }
                    };
                    uConn.setDefaultUseCaches(false);
                } catch (Throwable e) {
                    //ignore
                }
                try {
                    //DocumentBuilderFactory seems to SOMETIMES pin the classloader
                    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                    factory.newDocumentBuilder();
                } catch (Throwable e) {
                    //ignore
                }
                // Several components end up calling:
                // sun.misc.GC.requestLatency(long)
                //
                // Those libraries / components known to trigger memory leaks due to
                // eventual calls to requestLatency(long) are:
                // - javax.management.remote.rmi.RMIConnectorServer.start()
                try {
                    Class<?> clazz = Class.forName("sun.misc.GC");
                    Method method = clazz.getDeclaredMethod("requestLatency",
                            new Class[] {Long.TYPE});
                    method.invoke(null, Long.valueOf(3600000));
                } catch (Throwable e) {
                    //ignore
                }
               
                // Calling getPolicy retains a static reference to the context
                // class loader.
                try {
                    // Policy.getPolicy();
                    Class<?> policyClass = Class
                        .forName("javax.security.auth.Policy");
                    Method method = policyClass.getMethod("getPolicy");
                    method.invoke(null);
                } catch (Throwable e) {
                    // ignore
                }
                try {
                    // Initializing javax.security.auth.login.Configuration retains a static reference
                    // to the context class loader.
                    Class.forName("javax.security.auth.login.Configuration", true,
                                  ClassLoader.getSystemClassLoader());
                } catch (Throwable e) {
                    // Ignore
                }
                // Creating a MessageDigest during web application startup
                // initializes the Java Cryptography Architecture. Under certain
                // conditions this starts a Token poller thread with TCCL equal
                // to the web application class loader.
                java.security.Security.getProviders();
            } finally {
                if (orig != null) {
                    orig.reset();
                }
            }
        } catch (Throwable t) {
            //ignore
        }
View Full Code Here

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

        Object result = null;
        ClassLoaderHolder contextLoader = null;
        try {
            if (setServiceLoaderAsContextLoader(exchange.getInMessage())) {
                contextLoader = ClassLoaderUtils
                    .setThreadContextClassloader(resourceObject.getClass().getClassLoader());
            }
            result = invoke(exchange, resourceObject, methodToInvoke, params);
        } catch (Fault ex) {
            String errorMessage = ex.getCause().getMessage();
            if (errorMessage != null
                && errorMessage.contains(PROXY_INVOCATION_ERROR_FRAGMENT)) {
                org.apache.cxf.common.i18n.Message errorM =
                    new org.apache.cxf.common.i18n.Message("PROXY_INVOCATION_FAILURE",
                                                           BUNDLE,
                                                           methodToInvoke,
                                                           cri.getServiceClass().getName());
                LOG.severe(errorM.toString());
            }
            Response excResponse = JAXRSUtils.convertFaultToResponse(ex.getCause(),
                                                                     exchange.getInMessage());
            if (excResponse == null) {
                ProviderFactory.getInstance(exchange.getInMessage()).clearThreadLocalProxies();
                ClassResourceInfo criRoot =
                    (ClassResourceInfo)exchange.get(JAXRSUtils.ROOT_RESOURCE_CLASS);
                if (criRoot != null) {
                    criRoot.clearThreadLocalProxies();
                }
                exchange.put(Message.PROPOGATE_EXCEPTION,
                             JAXRSUtils.propogateException(exchange.getInMessage()));
                throw ex;
            }
            return new MessageContentsList(excResponse);
        } finally {
            exchange.put(LAST_SERVICE_OBJECT, resourceObject);
            if (contextLoader != null) {
                contextLoader.reset();
            }
        }
        ClassResourceInfo subCri = null;
        if (ori.isSubResourceLocator()) {
            try {
View Full Code Here

     * @return the proxy. You must cast the returned object to the approriate class
     * before making remote calls
     */
    @Override
    public synchronized Object create() {
        ClassLoaderHolder orig = null;
        try {
            if (getBus() != null) {
                ClassLoader loader = getBus().getExtension(ClassLoader.class);
                if (loader != null) {
                    orig = ClassLoaderUtils.setThreadContextClassloader(loader);
                }
            }
           
            Object obj = super.create();
            Service service = getServiceFactory().getService();
            if (needWrapperClassInterceptor(service.getServiceInfos().get(0))) {
                List<Interceptor<? extends Message>> in = super.getInInterceptors();
                List<Interceptor<? extends Message>> out = super.getOutInterceptors();
                in.add(new WrapperClassInInterceptor());
                in.add(new HolderInInterceptor());
                out.add(new WrapperClassOutInterceptor());
                out.add(new HolderOutInterceptor());
            }
            return obj;
        } finally {
            if (orig != null) {
                orig.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

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.