use of org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder in project wildfly-camel by wildfly-extras.
the class UndertowHTTPDestination method doService.
public void doService(ServletContext context, HttpServletRequest req, HttpServletResponse resp) throws IOException {
if (context == null) {
context = servletContext;
}
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 tomee by apache.
the class AutomaticWorkQueueImpl method execute.
public void execute(final Runnable command) {
// Grab the context classloader of this thread. We'll make sure we use that
// on the thread the runnable actually runs on.
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
Runnable r = new Runnable() {
public void run() {
ClassLoaderHolder orig = ClassLoaderUtils.setThreadContextClassloader(loader);
try {
command.run();
} finally {
if (orig != null) {
orig.reset();
}
}
}
};
// The ThreadPoolExecutor in the JDK doesn't expand the number
// of threads until the queue is full. However, we would
// prefer the number of threads to expand immediately and
// only uses the queue if we've reached the maximum number
// of threads.
ThreadPoolExecutor ex = getExecutor();
ex.execute(r);
if (addWorkerMethod != null && !ex.getQueue().isEmpty() && this.approxThreadCount.get() < highWaterMark && addThreadLock.tryLock()) {
try {
mainLock.lock();
try {
int ps = this.getPoolSize();
int sz = executor.getQueue().size();
int sz2 = this.getActiveCount();
if ((sz + sz2) > ps) {
// Needs --add-opens java.base/java.util.concurrent=ALL-UNNAMED for JDK16+
ReflectionUtil.setAccessible(addWorkerMethod).invoke(executor, addWorkerArgs);
}
} catch (Exception exc) {
// ignore
} finally {
mainLock.unlock();
}
} finally {
addThreadLock.unlock();
}
}
}
use of org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder in project tomee by apache.
the class WebClient method doChainedInvocation.
// CHECKSTYLE:OFF
protected // NOPMD
Response doChainedInvocation(// NOPMD
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 tomee by apache.
the class AbstractFaultChainInitiatorObserver method onMessage.
public void onMessage(Message message) {
assert null != message;
Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus);
ClassLoaderHolder origLoader = null;
try {
if (loader != null) {
origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
}
Exchange exchange = message.getExchange();
Message faultMessage;
if (isOutboundObserver()) {
Exception ex = message.getContent(Exception.class);
if (!(ex instanceof Fault)) {
ex = new Fault(ex);
}
FaultMode mode = message.get(FaultMode.class);
faultMessage = exchange.getOutMessage();
if (null == faultMessage) {
faultMessage = new MessageImpl();
faultMessage.setExchange(exchange);
faultMessage = exchange.getEndpoint().getBinding().createMessage(faultMessage);
}
faultMessage.setContent(Exception.class, ex);
if (null != mode) {
faultMessage.put(FaultMode.class, mode);
}
// CXF-3981
if (message.get("javax.xml.ws.addressing.context.inbound") != null) {
faultMessage.put("javax.xml.ws.addressing.context.inbound", message.get("javax.xml.ws.addressing.context.inbound"));
}
exchange.setOutMessage(null);
exchange.setOutFaultMessage(faultMessage);
if (message.get(BindingFaultInfo.class) != null) {
faultMessage.put(BindingFaultInfo.class, message.get(BindingFaultInfo.class));
}
} else {
faultMessage = message;
exchange.setInMessage(null);
exchange.setInFaultMessage(faultMessage);
}
// setup chain
PhaseInterceptorChain chain = new PhaseInterceptorChain(getPhases());
initializeInterceptors(faultMessage.getExchange(), chain);
faultMessage.setInterceptorChain(chain);
try {
chain.doIntercept(faultMessage);
} catch (RuntimeException exc) {
LOG.log(Level.SEVERE, "ERROR_DURING_ERROR_PROCESSING", exc);
throw exc;
} catch (Exception exc) {
LOG.log(Level.SEVERE, "ERROR_DURING_ERROR_PROCESSING", exc);
throw new RuntimeException(exc);
}
} 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 AutomaticWorkQueueImpl method execute.
public void execute(final Runnable command) {
// Grab the context classloader of this thread. We'll make sure we use that
// on the thread the runnable actually runs on.
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
Runnable r = new Runnable() {
public void run() {
ClassLoaderHolder orig = ClassLoaderUtils.setThreadContextClassloader(loader);
try {
command.run();
} finally {
if (orig != null) {
orig.reset();
}
}
}
};
// The ThreadPoolExecutor in the JDK doesn't expand the number
// of threads until the queue is full. However, we would
// prefer the number of threads to expand immediately and
// only uses the queue if we've reached the maximum number
// of threads.
ThreadPoolExecutor ex = getExecutor();
ex.execute(r);
if (addWorkerMethod != null && !ex.getQueue().isEmpty() && this.approxThreadCount.get() < highWaterMark && addThreadLock.tryLock()) {
try {
mainLock.lock();
try {
int ps = this.getPoolSize();
int sz = executor.getQueue().size();
int sz2 = this.getActiveCount();
if ((sz + sz2) > ps) {
// Needs --add-opens java.base/java.util.concurrent=ALL-UNNAMED for JDK16+
ReflectionUtil.setAccessible(addWorkerMethod).invoke(executor, addWorkerArgs);
}
} catch (Exception exc) {
// ignore
} finally {
mainLock.unlock();
}
} finally {
addThreadLock.unlock();
}
}
}
Aggregations