}
public Object invokeTarget(org.apache.tuscany.spi.model.Operation<?> op, Object[] args)
throws InvocationTargetException {
InvocationChain chain = inboundWire.getInvocationChains().get(op);
Interceptor headInterceptor = chain.getHeadInterceptor();
if (headInterceptor == null) {
try {
// short-circuit the dispatch and invoke the target directly
if (chain.getTargetInvoker() == null) {
throw new AssertionError("No target invoker [" + chain.getOperation().getName() + "]");
}
return chain.getTargetInvoker().invokeTarget(args);
} catch (InvocationTargetException e) {
// the cause was thrown by the target so throw it
throw e;
}
} else {
Object messageId = workContext.getCurrentMessageId();
workContext.setCurrentMessageId(null);
Object correlationId = workContext.getCurrentCorrelationId();
workContext.setCurrentCorrelationId(null);
Message msg = new MessageImpl();
msg.setTargetInvoker(chain.getTargetInvoker());
msg.setFromAddress(getFromAddress());
if (messageId == null) {
messageId = new MessageId();
}
msg.setMessageId(messageId);
msg.setCorrelationId(correlationId);
msg.setBody(args);
Message resp;
// dispatch the wire down the chain and get the response
// TODO http://issues.apache.org/jira/browse/TUSCANY-777
ClassLoader oldtccl = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
resp = headInterceptor.invoke(msg);
} finally {
Thread.currentThread().setContextClassLoader(oldtccl);
}
Object body = resp.getBody();
if (resp.isFault()) {