use of javax.xml.ws.handler.MessageContext in project cxf by apache.
the class SOAPHandlerInterceptorTest method testGetUnderstoodHeadersReturnsNull.
@Test
public void testGetUnderstoodHeadersReturnsNull() {
@SuppressWarnings("rawtypes") List<Handler> list = new ArrayList<>();
list.add(new SOAPHandler<SOAPMessageContext>() {
public boolean handleMessage(SOAPMessageContext smc) {
return true;
}
public boolean handleFault(SOAPMessageContext smc) {
return true;
}
public Set<QName> getHeaders() {
return null;
}
public void close(MessageContext messageContext) {
}
});
HandlerChainInvoker invoker = new HandlerChainInvoker(list);
IMocksControl control = createNiceControl();
Binding binding = control.createMock(Binding.class);
expect(binding.getHandlerChain()).andReturn(list).anyTimes();
SoapMessage message = control.createMock(SoapMessage.class);
Exchange exchange = control.createMock(Exchange.class);
expect(message.getExchange()).andReturn(exchange).anyTimes();
expect(message.keySet()).andReturn(new HashSet<>());
expect(exchange.get(HandlerChainInvoker.class)).andReturn(invoker);
control.replay();
SOAPHandlerInterceptor li = new SOAPHandlerInterceptor(binding);
Set<QName> understood = li.getUnderstoodHeaders();
assertNotNull(understood);
assertTrue(understood.isEmpty());
}
use of javax.xml.ws.handler.MessageContext in project cxf by apache.
the class WebServiceContextImpl method setMessageContext.
/**
* Sets reference to the specified MessageContext and returns the previous reference, if any.
*
* @param ctx The MessageContext to set
* @return The former MessageContext reference, if any.
*/
public static MessageContext setMessageContext(MessageContext ctx) {
MessageContext oldCtx = context.get();
context.set(ctx);
return oldCtx;
}
use of javax.xml.ws.handler.MessageContext in project cxf by apache.
the class HandlerChainInvoker method invokeHandlerChain.
private boolean invokeHandlerChain(List<? extends Handler<?>> handlerChain, MessageContext ctx) {
if (handlerChain.isEmpty()) {
LOG.log(Level.FINEST, "no handlers registered");
return true;
}
if (isClosed()) {
return false;
}
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, "invoking handlers, direction: " + (outbound ? "outbound" : "inbound"));
}
if (!outbound) {
handlerChain = reverseHandlerChain(handlerChain);
}
boolean continueProcessing = true;
MessageContext oldCtx = null;
try {
oldCtx = WebServiceContextImpl.setMessageContext(ctx);
continueProcessing = invokeHandleMessage(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 SOAPHandlerFaultOutInterceptor method handleMessageInternal.
private void handleMessageInternal(SoapMessage message) {
MessageContext context = createProtocolMessageContext(message);
HandlerChainInvoker invoker = getInvoker(message);
invoker.setProtocolMessageContext(context);
try {
if (!invoker.invokeProtocolHandlersHandleFault(isRequestor(message), context)) {
// handleAbort(message, context);
}
} catch (RuntimeException exception) {
/*
* handleFault throws exception, in this case we need to replace
* SOAPFault with the exception thrown from HandleFault so that the
* exception can be dispatched.
*/
try {
SOAPMessage originalMsg = message.getContent(SOAPMessage.class);
SOAPBody body = originalMsg.getSOAPPart().getEnvelope().getBody();
body.removeContents();
SOAPFault soapFault = body.addFault();
if (exception instanceof SOAPFaultException) {
SOAPFaultException sf = (SOAPFaultException) exception;
soapFault.setFaultString(sf.getFault().getFaultString());
SAAJUtils.setFaultCode(soapFault, sf.getFault().getFaultCodeAsQName());
soapFault.setFaultActor(sf.getFault().getFaultActor());
if (sf.getFault().hasDetail()) {
Node nd = originalMsg.getSOAPPart().importNode(sf.getFault().getDetail().getFirstChild(), true);
soapFault.addDetail().appendChild(nd);
}
} else if (exception instanceof Fault) {
SoapFault sf = SoapFault.createFault((Fault) exception, message.getVersion());
soapFault.setFaultString(sf.getReason());
SAAJUtils.setFaultCode(soapFault, sf.getFaultCode());
if (sf.hasDetails()) {
soapFault.addDetail();
Node nd = originalMsg.getSOAPPart().importNode(sf.getDetail(), true);
nd = nd.getFirstChild();
while (nd != null) {
soapFault.getDetail().appendChild(nd);
nd = nd.getNextSibling();
}
}
} else {
soapFault.setFaultString(exception.getMessage());
SAAJUtils.setFaultCode(soapFault, new QName("http://cxf.apache.org/faultcode", "HandleFault"));
}
} catch (SOAPException e) {
// do nothing
e.printStackTrace();
}
}
onCompletion(message);
}
use of javax.xml.ws.handler.MessageContext in project cxf by apache.
the class SOAPHandlerInterceptor method handleMessageInternal.
private boolean handleMessageInternal(SoapMessage message) {
MessageContext context = createProtocolMessageContext(message);
if (context == null) {
return true;
}
HandlerChainInvoker invoker = getInvoker(message);
invoker.setProtocolMessageContext(context);
if (!invoker.invokeProtocolHandlers(isRequestor(message), context)) {
handleAbort(message, context);
}
// If this is the outbound and end of MEP, call MEP completion
if (isRequestor(message) && invoker.getLogicalHandlers().isEmpty() && !isOutbound(message) && isMEPComlete(message)) {
onCompletion(message);
} else if (isOutbound(message) && isMEPComlete(message)) {
onCompletion(message);
}
return false;
}
Aggregations