use of org.apache.cxf.message.MessageContentsList in project tomee by apache.
the class JAXRSInInterceptor method createOutMessage.
private Message createOutMessage(Message inMessage, Response r) {
Endpoint e = inMessage.getExchange().getEndpoint();
Message mout = e.getBinding().createMessage();
mout.setContent(List.class, new MessageContentsList(r));
mout.setExchange(inMessage.getExchange());
mout.setInterceptorChain(OutgoingChainInterceptor.getOutInterceptorChain(inMessage.getExchange()));
inMessage.getExchange().setOutMessage(mout);
if (r.getStatus() >= Response.Status.BAD_REQUEST.getStatusCode()) {
inMessage.getExchange().put("cxf.io.cacheinput", Boolean.FALSE);
}
return mout;
}
use of org.apache.cxf.message.MessageContentsList in project tomee by apache.
the class JAXRSInvoker method invoke.
public Object invoke(Exchange exchange, Object request) {
MessageContentsList responseList = checkExchangeForResponse(exchange);
if (responseList != null) {
return responseList;
}
AsyncResponse asyncResp = exchange.get(AsyncResponse.class);
if (asyncResp != null) {
AsyncResponseImpl asyncImpl = (AsyncResponseImpl) asyncResp;
asyncImpl.prepareContinuation();
try {
asyncImpl.handleTimeout();
return handleAsyncResponse(exchange, asyncImpl);
} catch (Throwable t) {
return handleAsyncFault(exchange, asyncImpl, t);
}
}
ResourceProvider provider = getResourceProvider(exchange);
Object rootInstance = null;
Message inMessage = exchange.getInMessage();
try {
rootInstance = getServiceObject(exchange);
Object serviceObject = getActualServiceObject(exchange, rootInstance);
return invoke(exchange, request, serviceObject);
} catch (WebApplicationException ex) {
responseList = checkExchangeForResponse(exchange);
if (responseList != null) {
return responseList;
}
return handleFault(ex, inMessage);
} finally {
boolean suspended = isSuspended(exchange);
if (suspended || exchange.isOneWay() || inMessage.get(Message.THREAD_CONTEXT_SWITCHED) != null) {
ServerProviderFactory.clearThreadLocalProxies(inMessage);
}
if (suspended || isServiceObjectRequestScope(inMessage)) {
persistRoots(exchange, rootInstance, provider);
} else {
provider.releaseInstance(inMessage, rootInstance);
}
}
}
use of org.apache.cxf.message.MessageContentsList in project tomee by apache.
the class ClientRequestContextImpl method doSetEntity.
private void doSetEntity(Object entity) {
Object actualEntity = InjectionUtils.getEntity(entity);
m.setContent(List.class, actualEntity == null ? new MessageContentsList() : new MessageContentsList(actualEntity));
if (entity != null) {
final Type type;
if (GenericEntity.class.isAssignableFrom(entity.getClass())) {
type = ((GenericEntity<?>) entity).getType();
} else {
type = entity.getClass();
}
m.put(Type.class, type);
m.remove("org.apache.cxf.empty.request");
}
}
use of org.apache.cxf.message.MessageContentsList 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) {
// perf: size 16 / factor 1 to avoid resize operation
outMessage = new MessageImpl(16, 1);
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());
}
}
}
use of org.apache.cxf.message.MessageContentsList in project cxf by apache.
the class AbstractJAXWSMethodInvoker method invoke.
@Override
protected Object invoke(Exchange exchange, final Object serviceObject, Method m, List<Object> params) {
JaxwsServerHandler h = exchange.get(JaxwsServerHandler.class);
if (h != null && h.isDone()) {
BindingOperationInfo bop = exchange.getBindingOperationInfo();
if (bop.isUnwrapped()) {
exchange.put(BindingOperationInfo.class, bop.getWrappedOperation());
}
try {
return new MessageContentsList(h.getObject());
} catch (ExecutionException ex) {
exchange.getInMessage().put(FaultMode.class, FaultMode.CHECKED_APPLICATION_FAULT);
throw createFault(ex.getCause(), m, params, true);
} catch (Exception ex) {
throw createFault(ex.getCause(), m, params, false);
}
}
Object o = super.invoke(exchange, serviceObject, m, params);
if (h != null && !h.hasContinuation()) {
h.waitForDone();
BindingOperationInfo bop = exchange.getBindingOperationInfo();
if (bop.isUnwrapped()) {
exchange.put(BindingOperationInfo.class, bop.getWrappedOperation());
}
try {
return new MessageContentsList(h.getObject());
} catch (ExecutionException ex) {
exchange.getInMessage().put(FaultMode.class, FaultMode.CHECKED_APPLICATION_FAULT);
throw createFault(ex.getCause(), m, params, true);
} catch (Exception ex) {
throw createFault(ex.getCause(), m, params, false);
}
}
return o;
}
Aggregations