use of javax.xml.ws.handler.MessageContext in project cxf by apache.
the class HandlerChainInvoker method invokeHandlerChainHandleFault.
/*
* REVISIT: the logic of current implemetation is if the exception is thrown
* from previous handlers, we only invoke handleFault if it is
* ProtocolException (per spec), if the exception is thrown from other
* places other than handlers, we always invoke handleFault.
*/
private boolean invokeHandlerChainHandleFault(List<? extends Handler<?>> handlerChain, MessageContext ctx) {
if (handlerChain.isEmpty()) {
LOG.log(Level.FINEST, "no handlers registered");
return true;
}
if (isClosed()) {
return false;
}
// if the fault is a ProtocolException
if (fault != null) {
if (!(fault instanceof ProtocolException)) {
return true;
} else if (!responseExpected && !messageDirectionReversed) {
// in the chain, the exception is dispatched (see section 9.1.2.3).
return true;
}
}
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, "invoking handlers, direction: " + (outbound ? "outbound" : "inbound"));
}
setMessageOutboundProperty(ctx);
if (!outbound) {
handlerChain = reverseHandlerChain(handlerChain);
}
boolean continueProcessing = true;
MessageContext oldCtx = null;
try {
oldCtx = WebServiceContextImpl.setMessageContext(ctx);
continueProcessing = invokeHandleFault(handlerChain, ctx);
} finally {
// restore the WebServiceContextImpl's ThreadLocal variable to the previous value
if (oldCtx == null) {
WebServiceContextImpl.clear();
} else {
WebServiceContextImpl.setMessageContext(oldCtx);
}
}
return continueProcessing;
}
use of javax.xml.ws.handler.MessageContext in project cxf by apache.
the class SOAPHandlerFaultInInterceptor method handleMessage.
public void handleMessage(SoapMessage message) {
if (binding.getHandlerChain().isEmpty()) {
return;
}
if (getInvoker(message).getProtocolHandlers().isEmpty()) {
return;
}
checkUnderstoodHeaders(message);
MessageContext context = createProtocolMessageContext(message);
HandlerChainInvoker invoker = getInvoker(message);
invoker.setProtocolMessageContext(context);
if (!invoker.invokeProtocolHandlersHandleFault(isRequestor(message), context)) {
handleAbort(message, context);
}
SOAPMessage msg = message.getContent(SOAPMessage.class);
if (msg != null) {
XMLStreamReader xmlReader = createXMLStreamReaderFromSOAPMessage(msg);
message.setContent(XMLStreamReader.class, xmlReader);
}
}
use of javax.xml.ws.handler.MessageContext in project cxf by apache.
the class WebServiceContextImplTest method testGetSetMessageContext.
@Test
public void testGetSetMessageContext() {
WebServiceContextImpl wsci = new WebServiceContextImpl();
assertNull(wsci.getMessageContext());
MessageImpl msg = new MessageImpl();
final MessageContext ctx = new WrappedMessageContext(msg);
WebServiceContextImpl.setMessageContext(ctx);
assertSame(ctx, wsci.getMessageContext());
Thread t = new Thread() {
public void run() {
WebServiceContextImpl threadLocalWSCI = new WebServiceContextImpl();
assertNull(threadLocalWSCI.getMessageContext());
MessageImpl msg1 = new MessageImpl();
MessageContext threadLocalCtx = new WrappedMessageContext(msg1);
WebServiceContextImpl.setMessageContext(threadLocalCtx);
assertSame(threadLocalCtx, threadLocalWSCI.getMessageContext());
assertTrue(ctx != threadLocalWSCI.getMessageContext());
}
};
t.start();
try {
t.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
use of javax.xml.ws.handler.MessageContext in project cxf by apache.
the class LogicalHandlerInterceptorTest method xtestReturnFalseClientSide.
// JAX-WS spec: If handler returns false, for a request-response MEP, if the message
// direction is reversed during processing of a request message then the message
// becomes a response message.
// NOTE: commented out as this has been covered by other tests.
@Test
@org.junit.Ignore
public void xtestReturnFalseClientSide() throws Exception {
@SuppressWarnings("rawtypes") List<Handler> list = new ArrayList<>();
list.add(new LogicalHandler<LogicalMessageContext>() {
public void close(MessageContext arg0) {
}
public boolean handleFault(LogicalMessageContext messageContext) {
return true;
}
public boolean handleMessage(LogicalMessageContext messageContext) {
LogicalMessage msg = messageContext.getMessage();
AddNumbersResponse resp = new AddNumbersResponse();
resp.setReturn(11);
msg.setPayload(resp, null);
return false;
}
});
HandlerChainInvoker invoker1 = new HandlerChainInvoker(list);
IMocksControl control1 = createNiceControl();
Binding binding1 = control1.createMock(Binding.class);
@SuppressWarnings("rawtypes") List<Handler> hList = CastUtils.cast(list);
expect(binding1.getHandlerChain()).andReturn(hList).anyTimes();
Exchange exchange1 = control1.createMock(Exchange.class);
expect(exchange1.get(HandlerChainInvoker.class)).andReturn(invoker1).anyTimes();
Message outMessage = new MessageImpl();
outMessage.setExchange(exchange1);
InterceptorChain chain = control1.createMock(InterceptorChain.class);
outMessage.setInterceptorChain(chain);
chain.abort();
EasyMock.expectLastCall();
MessageObserver observer = control1.createMock(MessageObserver.class);
expect(exchange1.get(MessageObserver.class)).andReturn(observer).anyTimes();
observer.onMessage(isA(Message.class));
EasyMock.expectLastCall();
control1.replay();
LogicalHandlerInInterceptor li = new LogicalHandlerInInterceptor(binding1);
li.handleMessage(outMessage);
control1.verify();
}
use of javax.xml.ws.handler.MessageContext in project cxf by apache.
the class LogicalHandlerInterceptorTest method testInterceptSuccess.
@Test
public void testInterceptSuccess() {
List<LogicalHandler<?>> list = new ArrayList<LogicalHandler<?>>();
list.add(new LogicalHandler<LogicalMessageContext>() {
public void close(MessageContext arg0) {
}
public boolean handleFault(LogicalMessageContext arg0) {
return true;
}
public boolean handleMessage(LogicalMessageContext arg0) {
return true;
}
});
@SuppressWarnings("rawtypes") List<Handler> hList = CastUtils.cast(list);
expect(binding.getHandlerChain()).andReturn(hList).anyTimes();
expect(invoker.getLogicalHandlers()).andReturn(list);
expect(message.getExchange()).andReturn(exchange).anyTimes();
expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.TRUE).anyTimes();
expect(message.keySet()).andReturn(new TreeSet<String>()).anyTimes();
expect(exchange.get(HandlerChainInvoker.class)).andReturn(invoker);
expect(exchange.getOutMessage()).andReturn(message);
expect(invoker.invokeLogicalHandlers(eq(true), isA(LogicalMessageContext.class))).andReturn(true);
control.replay();
LogicalHandlerInInterceptor li = new LogicalHandlerInInterceptor(binding);
assertEquals("unexpected phase", "pre-protocol-frontend", li.getPhase());
li.handleMessage(message);
control.verify();
}
Aggregations