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;
}
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();
}
}
}
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;
}
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();
}
}
}
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();
}
}
}
Aggregations