use of org.apache.cxf.jaxws.handler.HandlerChainInvoker 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 org.apache.cxf.jaxws.handler.HandlerChainInvoker in project cxf by apache.
the class LogicalHandlerOutInterceptor method handleMessage.
public void handleMessage(Message message) throws Fault {
if (binding.getHandlerChain().isEmpty()) {
return;
}
HandlerChainInvoker invoker = getInvoker(message);
if (invoker.getLogicalHandlers().isEmpty()) {
return;
}
XMLStreamWriter origWriter = message.getContent(XMLStreamWriter.class);
Node nd = message.getContent(Node.class);
SOAPMessage m = message.getContent(SOAPMessage.class);
Document document = null;
if (m != null) {
document = m.getSOAPPart();
} else if (nd != null) {
document = nd.getOwnerDocument();
} else {
document = DOMUtils.newDocument();
message.setContent(Node.class, document);
}
W3CDOMStreamWriter writer = new W3CDOMStreamWriter(document.createDocumentFragment());
// Replace stax writer with DomStreamWriter
message.setContent(XMLStreamWriter.class, writer);
message.put(ORIGINAL_WRITER, origWriter);
message.getInterceptorChain().add(ending);
}
use of org.apache.cxf.jaxws.handler.HandlerChainInvoker 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 org.apache.cxf.jaxws.handler.HandlerChainInvoker 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;
}
use of org.apache.cxf.jaxws.handler.HandlerChainInvoker in project cxf by apache.
the class LogicalHandlerFaultInInterceptor method handleMessage.
@Override
public void handleMessage(Message message) {
if (binding.getHandlerChain().isEmpty()) {
return;
}
HandlerChainInvoker invoker = getInvoker(message);
if (invoker.getLogicalHandlers().isEmpty()) {
return;
}
LogicalMessageContextImpl lctx = new LogicalMessageContextImpl(message);
invoker.setLogicalMessageContext(lctx);
boolean requestor = isRequestor(message);
if (!invoker.invokeLogicalHandlersHandleFault(requestor, lctx)) {
if (!requestor) {
// server side, wont get here
} else {
// Client side inbound, thus no response expected, do nothing, the close will
// be handled by MEPComplete later
}
}
// If this is the inbound and end of MEP, call MEP completion
if (!isOutbound(message) && isMEPComlete(message)) {
onCompletion(message);
}
}
Aggregations