use of org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder in project cxf by apache.
the class ColocMessageObserver method onMessage.
public void onMessage(Message m) {
Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus);
ClassLoaderHolder origLoader = null;
try {
if (loader != null) {
origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
}
if (LOG.isLoggable(Level.FINER)) {
LOG.finer("Processing Message at collocated endpoint. Request message: " + m);
}
Exchange ex = new ExchangeImpl();
setExchangeProperties(ex, m);
Message inMsg = endpoint.getBinding().createMessage();
MessageImpl.copyContent(m, inMsg);
// Copy Request Context to Server inBound Message
// TODO a Context Filter Strategy required.
inMsg.putAll(m);
inMsg.put(COLOCATED, Boolean.TRUE);
inMsg.put(Message.REQUESTOR_ROLE, Boolean.FALSE);
inMsg.put(Message.INBOUND_MESSAGE, Boolean.TRUE);
BindingOperationInfo boi = ex.getBindingOperationInfo();
OperationInfo oi = boi != null ? boi.getOperationInfo() : null;
if (oi != null) {
inMsg.put(MessageInfo.class, oi.getInput());
}
ex.setInMessage(inMsg);
inMsg.setExchange(ex);
if (LOG.isLoggable(Level.FINEST)) {
LOG.finest("Build inbound interceptor chain.");
}
// Add all interceptors between USER_LOGICAL and INVOKE.
SortedSet<Phase> phases = new TreeSet<Phase>(bus.getExtension(PhaseManager.class).getInPhases());
ColocUtil.setPhases(phases, Phase.USER_LOGICAL, Phase.INVOKE);
InterceptorChain chain = ColocUtil.getInInterceptorChain(ex, phases);
chain.add(addColocInterceptors());
inMsg.setInterceptorChain(chain);
// Convert the coloc object type if necessary
BindingOperationInfo bop = m.getExchange().getBindingOperationInfo();
OperationInfo soi = bop != null ? bop.getOperationInfo() : null;
if (soi != null && oi != null) {
if (ColocUtil.isAssignableOperationInfo(soi, Source.class) && !ColocUtil.isAssignableOperationInfo(oi, Source.class)) {
// converting source -> pojo
ColocUtil.convertSourceToObject(inMsg);
} else if (ColocUtil.isAssignableOperationInfo(oi, Source.class) && !ColocUtil.isAssignableOperationInfo(soi, Source.class)) {
// converting pojo -> source
ColocUtil.convertObjectToSource(inMsg);
}
}
chain.doIntercept(inMsg);
if (soi != null && oi != null) {
if (ColocUtil.isAssignableOperationInfo(soi, Source.class) && !ColocUtil.isAssignableOperationInfo(oi, Source.class) && ex.getOutMessage() != null) {
// converting pojo -> source
ColocUtil.convertObjectToSource(ex.getOutMessage());
} else if (ColocUtil.isAssignableOperationInfo(oi, Source.class) && !ColocUtil.isAssignableOperationInfo(soi, Source.class) && ex.getOutMessage() != null) {
// converting pojo -> source
ColocUtil.convertSourceToObject(ex.getOutMessage());
}
}
// Set Server OutBound Message onto InBound Exchange.
setOutBoundMessage(ex, m.getExchange());
} 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 doPublish.
/**
* Performs the publication action by setting up a {@link Server}
* instance based on this endpoint's configuration.
*
* @param addr the optional endpoint address.
*
* @throws IllegalStateException if the endpoint cannot be published/republished
* @throws SecurityException if permission checking is enabled and policy forbids publishing
* @throws WebServiceException if there is an error publishing the endpoint
*
* @see #checkPublishPermission()
* @see #checkPublishable()
* @see #getServer(String)
*/
protected void doPublish(String addr) {
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() == null || !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();
}
}
}
use of org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder in project cxf by apache.
the class JaxWsProxyFactoryBean method create.
/**
* Creates a JAX-WS proxy that can be used to make remote invocations.
*
* @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();
}
}
}
use of org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder in project cxf by apache.
the class CXFNonSpringServlet method invoke.
@Override
protected void invoke(HttpServletRequest request, HttpServletResponse response) throws ServletException {
ClassLoaderHolder origLoader = null;
Bus origBus = null;
try {
if (loader != null) {
origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
}
if (bus != null) {
origBus = BusFactory.getAndSetThreadDefaultBus(bus);
}
controller.invoke(request, response);
} 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 ServletController method invoke.
public boolean invoke(HttpServletRequest request, HttpServletResponse res, boolean returnErrors) throws ServletException {
try {
String pathInfo = request.getPathInfo() == null ? "" : request.getPathInfo();
AbstractHTTPDestination d = destinationRegistry.getDestinationForPath(pathInfo, true);
if (d == null) {
if (!isHideServiceList && (request.getRequestURI().endsWith(serviceListRelativePath) || request.getRequestURI().endsWith(serviceListRelativePath + "/") || StringUtils.isEmpty(pathInfo) || "/".equals(pathInfo))) {
if (isAuthServiceListPage) {
setAuthServiceListPageAttribute(request);
}
setBaseURLAttribute(request);
serviceListGenerator.service(request, res);
} else {
d = destinationRegistry.checkRestfulRequest(pathInfo);
if (d == null || d.getMessageObserver() == null) {
if (returnErrors) {
LOG.warning("Can't find the request for " + request.getRequestURL() + "'s Observer ");
generateNotFound(request, res);
}
return false;
}
}
}
if (d != null && d.getMessageObserver() != null) {
Bus bus = d.getBus();
ClassLoaderHolder orig = null;
try {
if (bus != null) {
ClassLoader loader = bus.getExtension(ClassLoader.class);
if (loader == null) {
ResourceManager manager = bus.getExtension(ResourceManager.class);
if (manager != null) {
loader = manager.resolveResource("", ClassLoader.class);
}
}
if (loader != null) {
// need to set the context classloader to the loader of the bundle
orig = ClassLoaderUtils.setThreadContextClassloader(loader);
}
}
updateDestination(request, d);
invokeDestination(request, res, d);
} finally {
if (orig != null) {
orig.reset();
}
}
}
} catch (IOException e) {
throw new ServletException(e);
}
return true;
}
Aggregations