Search in sources :

Example 6 with ClassLoaderHolder

use of org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder in project cxf by apache.

the class SecurityUtils method loadResource.

public static URL loadResource(ResourceManager manager, Object o) {
    if (o instanceof String) {
        URL url = ClassLoaderUtils.getResource((String) o, SecurityUtils.class);
        if (url != null) {
            return url;
        }
        ClassLoaderHolder orig = null;
        try {
            if (manager != null) {
                ClassLoader loader = manager.resolveResource((String) o, ClassLoader.class);
                if (loader != null) {
                    orig = ClassLoaderUtils.setThreadContextClassloader(loader);
                }
                url = manager.resolveResource((String) o, URL.class);
            }
            if (url == null) {
                try {
                    url = new URL((String) o);
                } catch (IOException e) {
                // Do nothing
                }
            }
            if (url == null) {
                try {
                    URI propResourceUri = URI.create((String) o);
                    if (propResourceUri.getScheme() != null) {
                        url = propResourceUri.toURL();
                    } else {
                        File f = new File(propResourceUri.toString());
                        if (f.exists()) {
                            url = f.toURI().toURL();
                        }
                    }
                } catch (IOException ex) {
                // Do nothing
                }
            }
            return url;
        } finally {
            if (orig != null) {
                orig.reset();
            }
        }
    } else if (o instanceof URL) {
        return (URL) o;
    }
    return null;
}
Also used : ClassLoaderHolder(org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder) IOException(java.io.IOException) URI(java.net.URI) File(java.io.File) URL(java.net.URL)

Example 7 with ClassLoaderHolder

use of org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder in project cxf by apache.

the class JettyHTTPDestination method doService.

protected void doService(ServletContext context, HttpServletRequest req, HttpServletResponse resp) throws IOException {
    if (context == null) {
        context = servletContext;
    }
    Request baseRequest = (req instanceof Request) ? (Request) req : getCurrentRequest();
    HTTPServerPolicy sp = getServer();
    if (sp.isSetRedirectURL()) {
        resp.sendRedirect(sp.getRedirectURL());
        resp.flushBuffer();
        baseRequest.setHandled(true);
        return;
    }
    // REVISIT: service on executor if associated with endpoint
    ClassLoaderHolder origLoader = null;
    Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus);
    try {
        if (loader != null) {
            origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
        }
        invoke(null, context, req, resp);
    } finally {
        if (origBus != bus) {
            BusFactory.setThreadDefaultBus(origBus);
        }
        if (origLoader != null) {
            origLoader.reset();
        }
    }
}
Also used : Bus(org.apache.cxf.Bus) HTTPServerPolicy(org.apache.cxf.transports.http.configuration.HTTPServerPolicy) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) ClassLoaderHolder(org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder)

Example 8 with ClassLoaderHolder

use of org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder in project cxf by apache.

the class EndpointImpl method getServer.

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);
            }
            // 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.isEmpty()) {
                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;
}
Also used : JaxWsImplementorInfo(org.apache.cxf.jaxws.support.JaxWsImplementorInfo) ServerImpl(org.apache.cxf.endpoint.ServerImpl) QName(javax.xml.namespace.QName) ClassLoaderHolder(org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder)

Example 9 with ClassLoaderHolder

use of org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder in project cxf by apache.

the class JaxWsServerFactoryBean method create.

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(server);
        checkPrivateEndpoint(server.getEndpoint());
        return server;
    } finally {
        if (orig != null) {
            orig.reset();
        }
    }
}
Also used : Server(org.apache.cxf.endpoint.Server) ClassLoaderHolder(org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder)

Example 10 with ClassLoaderHolder

use of org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder in project cxf by apache.

the class WebServiceContextImpl method getEndpointReference.

public EndpointReference getEndpointReference(Element... referenceParameters) {
    WrappedMessageContext ctx = (WrappedMessageContext) getMessageContext();
    org.apache.cxf.message.Message msg = ctx.getWrappedMessage();
    Endpoint ep = msg.getExchange().getEndpoint();
    W3CEndpointReferenceBuilder builder = new W3CEndpointReferenceBuilder();
    builder.address(ep.getEndpointInfo().getAddress());
    builder.serviceName(ep.getService().getName());
    builder.endpointName(ep.getEndpointInfo().getName());
    URI wsdlDescription = ep.getEndpointInfo().getProperty("URI", URI.class);
    if (wsdlDescription == null) {
        String address = ep.getEndpointInfo().getAddress();
        try {
            wsdlDescription = new URI(address + "?wsdl");
        } catch (URISyntaxException e) {
        // do nothing
        }
        ep.getEndpointInfo().setProperty("URI", wsdlDescription);
    }
    if (wsdlDescription != null) {
        builder.wsdlDocumentLocation(wsdlDescription.toString());
    }
    /*
        if (ep.getEndpointInfo().getService().getDescription() != null) {
            builder.wsdlDocumentLocation(ep.getEndpointInfo().getService()
                                     .getDescription().getBaseURI());
        }
        */
    if (referenceParameters != null) {
        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();
        }
    }
}
Also used : W3CEndpointReferenceBuilder(javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder) Endpoint(org.apache.cxf.endpoint.Endpoint) Element(org.w3c.dom.Element) ClassLoaderHolder(org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Aggregations

ClassLoaderHolder (org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder)36 Bus (org.apache.cxf.Bus)24 Message (org.apache.cxf.message.Message)15 IOException (java.io.IOException)7 Exchange (org.apache.cxf.message.Exchange)6 PhaseInterceptorChain (org.apache.cxf.phase.PhaseInterceptorChain)6 ServerImpl (org.apache.cxf.endpoint.ServerImpl)5 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)5 Endpoint (org.apache.cxf.endpoint.Endpoint)4 URISyntaxException (java.net.URISyntaxException)3 List (java.util.List)3 Application (javax.ws.rs.core.Application)3 Fault (org.apache.cxf.interceptor.Fault)3 InterceptorChain (org.apache.cxf.interceptor.InterceptorChain)3 OperationResourceInfo (org.apache.cxf.jaxrs.model.OperationResourceInfo)3 Annotation (java.lang.annotation.Annotation)2 Method (java.lang.reflect.Method)2 URI (java.net.URI)2 URL (java.net.URL)2 HashMap (java.util.HashMap)2