use of org.apache.cxf.phase.PhaseInterceptorChain in project cxf by apache.
the class ColocUtil method getOutInterceptorChain.
public static InterceptorChain getOutInterceptorChain(Exchange ex, SortedSet<Phase> phases) {
Bus bus = ex.getBus();
PhaseInterceptorChain chain = new PhaseInterceptorChain(phases);
Endpoint ep = ex.getEndpoint();
List<Interceptor<? extends Message>> il = ep.getOutInterceptors();
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Interceptors contributed by endpoint: " + il);
}
chain.add(il);
il = ep.getService().getOutInterceptors();
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Interceptors contributed by service: " + il);
}
chain.add(il);
il = bus.getOutInterceptors();
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Interceptors contributed by bus: " + il);
}
chain.add(il);
if (ep.getService().getDataBinding() instanceof InterceptorProvider) {
il = ((InterceptorProvider) ep.getService().getDataBinding()).getOutInterceptors();
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Interceptors contributed by databinding: " + il);
}
chain.add(il);
}
modifyChain(chain, ex, false);
return chain;
}
use of org.apache.cxf.phase.PhaseInterceptorChain in project cxf by apache.
the class AbstractClient method setupOutInterceptorChain.
protected static PhaseInterceptorChain setupOutInterceptorChain(ClientConfiguration cfg) {
PhaseManager pm = cfg.getBus().getExtension(PhaseManager.class);
List<Interceptor<? extends Message>> i1 = cfg.getBus().getOutInterceptors();
List<Interceptor<? extends Message>> i2 = cfg.getOutInterceptors();
List<Interceptor<? extends Message>> i3 = cfg.getConduitSelector().getEndpoint().getOutInterceptors();
PhaseInterceptorChain chain = new PhaseChainCache().get(pm.getOutPhases(), i1, i2, i3);
chain.add(new ClientRequestFilterInterceptor());
return chain;
}
use of org.apache.cxf.phase.PhaseInterceptorChain in project cxf by apache.
the class OutgoingChainInterceptor method getOutInterceptorChain.
public static InterceptorChain getOutInterceptorChain(Exchange ex) {
Bus bus = ex.getBus();
Binding binding = ex.getBinding();
PhaseManager pm = bus.getExtension(PhaseManager.class);
PhaseInterceptorChain chain = new PhaseInterceptorChain(pm.getOutPhases());
Endpoint ep = ex.getEndpoint();
List<Interceptor<? extends Message>> il = ep.getOutInterceptors();
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Interceptors contributed by endpoint: " + il);
}
chain.add(il);
il = ep.getService().getOutInterceptors();
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Interceptors contributed by service: " + il);
}
chain.add(il);
il = bus.getOutInterceptors();
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Interceptors contributed by bus: " + il);
}
chain.add(il);
if (binding != null) {
il = binding.getOutInterceptors();
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Interceptors contributed by binding: " + il);
}
chain.add(il);
}
modifyChain(chain, ex);
chain.setFaultObserver(ep.getOutFaultObserver());
return chain;
}
use of org.apache.cxf.phase.PhaseInterceptorChain in project cxf by apache.
the class OutgoingChainInterceptor method getChain.
private static PhaseInterceptorChain getChain(Exchange ex, PhaseChainCache chainCache) {
Bus bus = ex.getBus();
Binding binding = ex.getBinding();
Endpoint ep = ex.getEndpoint();
List<Interceptor<? extends Message>> i1 = bus.getOutInterceptors();
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Interceptors contributed by bus: " + i1);
}
List<Interceptor<? extends Message>> i2 = ep.getService().getOutInterceptors();
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Interceptors contributed by service: " + i2);
}
List<Interceptor<? extends Message>> i3 = ep.getOutInterceptors();
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Interceptors contributed by endpoint: " + i3);
}
List<Interceptor<? extends Message>> i4 = null;
if (binding != null) {
i4 = binding.getOutInterceptors();
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Interceptors contributed by binding: " + i4);
}
}
List<Interceptor<? extends Message>> i5 = null;
if (ep.getService().getDataBinding() instanceof InterceptorProvider) {
i5 = ((InterceptorProvider) ep.getService().getDataBinding()).getOutInterceptors();
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Interceptors contributed by databinding: " + i5);
}
if (i4 == null) {
i4 = i5;
i5 = null;
}
}
PhaseInterceptorChain chain;
if (i5 != null) {
chain = chainCache.get(bus.getExtension(PhaseManager.class).getOutPhases(), i1, i2, i3, i4, i5);
} else if (i4 != null) {
chain = chainCache.get(bus.getExtension(PhaseManager.class).getOutPhases(), i1, i2, i3, i4);
} else {
chain = chainCache.get(bus.getExtension(PhaseManager.class).getOutPhases(), i1, i2, i3);
}
modifyChain(chain, ex);
chain.setFaultObserver(ep.getOutFaultObserver());
return chain;
}
use of org.apache.cxf.phase.PhaseInterceptorChain in project cxf by apache.
the class ServiceInvokerInterceptor method handleMessage.
public void handleMessage(final Message message) {
final Exchange exchange = message.getExchange();
final Endpoint endpoint = exchange.getEndpoint();
final Service service = endpoint.getService();
final Invoker invoker = service.getInvoker();
Runnable invocation = new Runnable() {
public void run() {
Exchange runableEx = message.getExchange();
Object result = invoker.invoke(runableEx, getInvokee(message));
if (!exchange.isOneWay()) {
Endpoint ep = exchange.getEndpoint();
Message outMessage = runableEx.getOutMessage();
if (outMessage == null) {
outMessage = new MessageImpl();
outMessage.setExchange(exchange);
outMessage = ep.getBinding().createMessage(outMessage);
exchange.setOutMessage(outMessage);
}
copyJaxwsProperties(message, outMessage);
if (result != null) {
MessageContentsList resList = null;
if (result instanceof MessageContentsList) {
resList = (MessageContentsList) result;
} else if (result instanceof List) {
resList = new MessageContentsList((List<?>) result);
} else if (result.getClass().isArray()) {
resList = new MessageContentsList((Object[]) result);
} else {
outMessage.setContent(Object.class, result);
}
if (resList != null) {
outMessage.setContent(List.class, resList);
}
}
}
}
};
Executor executor = getExecutor(endpoint);
Executor executor2 = exchange.get(Executor.class);
if (executor2 == executor || executor == null || !(message.getInterceptorChain() instanceof PhaseInterceptorChain)) {
// already executing on the appropriate executor
invocation.run();
} else {
exchange.put(Executor.class, executor);
// The current thread holds the lock on PhaseInterceptorChain.
// In order to avoid the executor threads deadlocking on any of
// synchronized PhaseInterceptorChain methods the current thread
// needs to release the chain lock and re-acquire it after the
// executor thread is done
final PhaseInterceptorChain chain = (PhaseInterceptorChain) message.getInterceptorChain();
final AtomicBoolean contextSwitched = new AtomicBoolean();
final FutureTask<Object> o = new FutureTask<Object>(invocation, null) {
@Override
protected void done() {
super.done();
if (contextSwitched.get()) {
PhaseInterceptorChain.setCurrentMessage(chain, null);
message.remove(Message.THREAD_CONTEXT_SWITCHED);
}
chain.releaseChain();
}
@Override
public void run() {
if (PhaseInterceptorChain.setCurrentMessage(chain, message)) {
contextSwitched.set(true);
message.put(Message.THREAD_CONTEXT_SWITCHED, true);
}
synchronized (chain) {
super.run();
}
}
};
synchronized (chain) {
executor.execute(o);
// the task will already be done if the executor uses the current thread
// but the chain lock status still needs to be re-set
chain.releaseAndAcquireChain();
}
try {
o.get();
} catch (InterruptedException e) {
throw new Fault(e);
} catch (ExecutionException e) {
if (e.getCause() instanceof RuntimeException) {
throw (RuntimeException) e.getCause();
}
throw new Fault(e.getCause());
}
}
}
Aggregations