use of org.apache.cxf.message.Message 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.message.Message in project tomee by apache.
the class OneWayProcessorInterceptor method createMessage.
private static Message createMessage(Exchange exchange) {
Endpoint ep = exchange.getEndpoint();
Message msg = null;
if (ep != null) {
msg = new MessageImpl();
msg.setExchange(exchange);
msg = ep.getBinding().createMessage(msg);
}
return msg;
}
use of org.apache.cxf.message.Message in project tomee by apache.
the class OneWayProcessorInterceptor method handleMessage.
public void handleMessage(Message message) {
if (message.getExchange().isOneWay() && !isRequestor(message) && message.get(OneWayProcessorInterceptor.class) == null && message.getExchange().get(Executor.class) == null) {
// one way on server side, fork the rest of this chain onto the
// workqueue, call the Outgoing chain directly.
message.put(OneWayProcessorInterceptor.class, this);
final InterceptorChain chain = message.getInterceptorChain();
boolean robust = MessageUtils.getContextualBoolean(message, Message.ROBUST_ONEWAY, false);
boolean useOriginalThread = MessageUtils.getContextualBoolean(message, USE_ORIGINAL_THREAD, false);
if (!useOriginalThread && !robust) {
// need to suck in all the data from the input stream as
// the transport might discard any data on the stream when this
// thread unwinds or when the empty response is sent back
DelegatingInputStream in = message.getContent(DelegatingInputStream.class);
if (in != null) {
in.cacheInput();
}
}
if (robust) {
// continue to invoke the chain
chain.pause();
chain.resume();
if (message.getContent(Exception.class) != null) {
// CXF-5629 fault has been delivered alread in resume()
return;
}
}
try {
Message partial = createMessage(message.getExchange());
partial.remove(Message.CONTENT_TYPE);
partial.setExchange(message.getExchange());
Conduit conduit = message.getExchange().getDestination().getBackChannel(message);
if (conduit != null) {
message.getExchange().setInMessage(null);
// for a one-way, the back channel could be
// null if it knows it cannot send anything.
conduit.prepare(partial);
conduit.close(partial);
message.getExchange().setInMessage(message);
}
} catch (IOException e) {
// IGNORE
}
if (!useOriginalThread && !robust) {
chain.pause();
try {
final Object lock = new Object();
synchronized (lock) {
message.getExchange().getBus().getExtension(WorkQueueManager.class).getAutomaticWorkQueue().execute(new Runnable() {
public void run() {
synchronized (lock) {
lock.notifyAll();
}
chain.resume();
}
});
// wait a few milliseconds for the background thread to start processing
// Mostly just to make an attempt at keeping the ordering of the
// messages coming in from a client. Not guaranteed though.
lock.wait(20L);
}
} catch (RejectedExecutionException e) {
LOG.warning("Executor queue is full, run the oneway invocation task in caller thread." + " Users can specify a larger executor queue to avoid this.");
// only block the thread if the prop is unset or set to false, otherwise let it go
if (!MessageUtils.getContextualBoolean(message, "org.apache.cxf.oneway.rejected_execution_exception", false)) {
// the executor queue is full, so run the task in the caller thread
chain.unpause();
}
} catch (InterruptedException e) {
// ignore - likely a busy work queue so we'll just let the one-way go
}
}
}
}
use of org.apache.cxf.message.Message in project ddf by codice.
the class PepInterceptorActionsTest method testMessageWithDefaultUriAction.
@Test
public void testMessageWithDefaultUriAction() throws SecurityServiceException {
SecurityManager mockSecurityManager = mock(SecurityManager.class);
interceptor.setSecurityManager(mockSecurityManager);
Message messageWithAction = mock(Message.class);
SecurityToken mockSecurityToken = mock(SecurityToken.class);
Subject mockSubject = mock(Subject.class);
assertNotNull(mockSecurityAssertion);
// SecurityLogger is already stubbed out
when(mockSecurityAssertion.getToken()).thenReturn(mockSecurityToken);
when(mockSecurityToken.getToken()).thenReturn(null);
when(mockSecurityManager.getSubject(mockSecurityToken)).thenReturn(mockSubject);
QName op = new QName("urn:catalog:query", "search", "ns1");
QName port = new QName("urn:catalog:query", "query-port", "ns1");
when(messageWithAction.get(MessageContext.WSDL_OPERATION)).thenReturn(op);
when(messageWithAction.get(MessageContext.WSDL_PORT)).thenReturn(port);
Exchange mockExchange = mock(Exchange.class);
BindingOperationInfo mockBOI = mock(BindingOperationInfo.class);
when(messageWithAction.getExchange()).thenReturn(mockExchange);
when(mockExchange.get(BindingOperationInfo.class)).thenReturn(mockBOI);
when(mockBOI.getExtensor(SoapOperationInfo.class)).thenReturn(null);
doAnswer(new Answer<Boolean>() {
@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
CollectionPermission perm = (CollectionPermission) invocation.getArguments()[0];
assertEquals("urn:catalog:query:query-port:searchRequest", perm.getAction());
return true;
}
}).when(mockSubject).isPermitted(isA(CollectionPermission.class));
// This should work.
interceptor.handleMessage(messageWithAction);
}
use of org.apache.cxf.message.Message in project ddf by codice.
the class PepInterceptorActionsTest method testMessageWithMessageAction.
@Test
public void testMessageWithMessageAction() throws SecurityServiceException {
SecurityManager mockSecurityManager = mock(SecurityManager.class);
interceptor.setSecurityManager(mockSecurityManager);
Message messageWithAction = mock(Message.class);
SecurityToken mockSecurityToken = mock(SecurityToken.class);
Subject mockSubject = mock(Subject.class);
assertNotNull(mockSecurityAssertion);
// SecurityLogger is already stubbed out
when(mockSecurityAssertion.getToken()).thenReturn(mockSecurityToken);
when(mockSecurityToken.getToken()).thenReturn(null);
when(mockSecurityManager.getSubject(mockSecurityToken)).thenReturn(mockSubject);
MessageInfo mockMessageInfo = mock(MessageInfo.class);
when(messageWithAction.get(MessageInfo.class.getName())).thenReturn(mockMessageInfo);
when(mockMessageInfo.getExtensionAttribute(new QName(Names.WSA_NAMESPACE_WSDL_METADATA, Names.WSAW_ACTION_NAME))).thenReturn("urn:catalog:query:query-port:search");
doAnswer(new Answer<Boolean>() {
@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
CollectionPermission perm = (CollectionPermission) invocation.getArguments()[0];
assertEquals("urn:catalog:query:query-port:search", perm.getAction());
return true;
}
}).when(mockSubject).isPermitted(isA(CollectionPermission.class));
// This should work.
interceptor.handleMessage(messageWithAction);
}
Aggregations