use of org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder in project cxf by apache.
the class CXFNonSpringServlet method doFilter.
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
ClassLoaderHolder origLoader = null;
Bus origBus = null;
if (request instanceof HttpServletRequest && response instanceof HttpServletResponse) {
try {
if (loader != null) {
origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
}
if (bus != null) {
origBus = BusFactory.getAndSetThreadDefaultBus(bus);
}
HttpServletRequest httpRequest = (HttpServletRequest) request;
if (controller.filter(new HttpServletRequestFilter(httpRequest, super.getServletName()), (HttpServletResponse) response)) {
return;
}
} finally {
if (origBus != bus) {
BusFactory.setThreadDefaultBus(origBus);
}
if (origLoader != null) {
origLoader.reset();
}
}
}
chain.doFilter(request, response);
}
use of org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder in project cxf by apache.
the class ClientMessageObserver method onMessage.
public void onMessage(Message m) {
Message message = cfg.getConduitSelector().getEndpoint().getBinding().createMessage(m);
message.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
message.put(Message.INBOUND_MESSAGE, Boolean.TRUE);
PhaseInterceptorChain chain = AbstractClient.setupInInterceptorChain(cfg);
message.setInterceptorChain(chain);
message.getExchange().setInMessage(message);
Bus bus = cfg.getBus();
Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus);
ClassLoaderHolder origLoader = null;
try {
if (loader != null) {
origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
}
// execute chain
chain.doIntercept(message);
} finally {
if (origBus != bus) {
BusFactory.setThreadDefaultBus(origBus);
}
if (origLoader != null) {
origLoader.reset();
}
synchronized (message.getExchange()) {
message.getExchange().notifyAll();
}
}
}
use of org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder in project cxf by apache.
the class ClientProxyImpl method doChainedInvocation.
// CHECKSTYLE:OFF
private Object doChainedInvocation(URI uri, MultivaluedMap<String, String> headers, OperationResourceInfo ori, Object[] methodParams, Object body, int bodyIndex, Exchange exchange, Map<String, Object> invocationContext) throws Throwable {
// CHECKSTYLE:ON
Bus configuredBus = getConfiguration().getBus();
Bus origBus = BusFactory.getAndSetThreadDefaultBus(configuredBus);
ClassLoaderHolder origLoader = null;
try {
ClassLoader loader = configuredBus.getExtension(ClassLoader.class);
if (loader != null) {
origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
}
Message outMessage = createMessage(body, ori.getHttpMethod(), headers, uri, exchange, invocationContext, true);
if (bodyIndex != -1) {
outMessage.put(Type.class, ori.getMethodToInvoke().getGenericParameterTypes()[bodyIndex]);
}
outMessage.getExchange().setOneWay(ori.isOneway());
setSupportOnewayResponseProperty(outMessage);
outMessage.setContent(OperationResourceInfo.class, ori);
setPlainOperationNameProperty(outMessage, ori.getMethodToInvoke().getName());
outMessage.getExchange().put(Method.class, ori.getMethodToInvoke());
outMessage.put(Annotation.class.getName(), getMethodAnnotations(ori.getAnnotatedMethod(), bodyIndex));
outMessage.getExchange().put(Message.SERVICE_OBJECT, proxy);
if (methodParams != null) {
outMessage.put(List.class, Arrays.asList(methodParams));
}
if (body != null) {
outMessage.put(PROXY_METHOD_PARAM_BODY_INDEX, bodyIndex);
}
outMessage.getInterceptorChain().add(bodyWriter);
Map<String, Object> reqContext = getRequestContext(outMessage);
reqContext.put(OperationResourceInfo.class.getName(), ori);
reqContext.put(PROXY_METHOD_PARAM_BODY_INDEX, bodyIndex);
// execute chain
InvocationCallback<Object> asyncCallback = checkAsyncCallback(ori, reqContext);
if (asyncCallback != null) {
doInvokeAsync(ori, outMessage, asyncCallback);
return null;
}
doRunInterceptorChain(outMessage);
Object[] results = preProcessResult(outMessage);
if (results != null && results.length == 1) {
return results[0];
}
try {
return handleResponse(outMessage, ori.getClassResourceInfo().getServiceClass());
} finally {
completeExchange(outMessage.getExchange(), true);
}
} finally {
if (origLoader != null) {
origLoader.reset();
}
if (origBus != configuredBus) {
BusFactory.setThreadDefaultBus(origBus);
}
}
}
use of org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder in project cxf by apache.
the class WebClient method doChainedInvocation.
// CHECKSTYLE:OFF
protected Response doChainedInvocation(String httpMethod, MultivaluedMap<String, String> headers, Object body, Class<?> requestClass, Type inType, Annotation[] inAnns, Class<?> respClass, Type outType, Exchange exchange, Map<String, Object> invContext) {
// CHECKSTYLE:ON
Bus configuredBus = getConfiguration().getBus();
Bus origBus = BusFactory.getAndSetThreadDefaultBus(configuredBus);
ClassLoaderHolder origLoader = null;
try {
ClassLoader loader = configuredBus.getExtension(ClassLoader.class);
if (loader != null) {
origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
}
Message m = finalizeMessage(httpMethod, headers, body, requestClass, inType, inAnns, respClass, outType, exchange, invContext);
doRunInterceptorChain(m);
return doResponse(m, respClass, outType);
} finally {
if (origLoader != null) {
origLoader.reset();
}
if (origBus != configuredBus) {
BusFactory.setThreadDefaultBus(origBus);
}
}
}
use of org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder in project cxf by apache.
the class ClientProxyFactoryBean method create.
/**
* 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;
ClassLoader loader = null;
try {
if (getBus() != null) {
loader = getBus().getExtension(ClassLoader.class);
if (loader != null) {
orig = ClassLoaderUtils.setThreadContextClassloader(loader);
}
}
configureObject();
if (properties == null) {
properties = new HashMap<>();
}
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 = ProxyHelper.getProxy(getClassLoader(clientFactoryBean.getServiceClass()), classes, handler);
this.getServiceFactory().sendEvent(FactoryBeanListener.Event.PROXY_CREATED, classes, handler, obj);
return obj;
} finally {
if (orig != null) {
orig.reset();
}
}
}
Aggregations