use of javax.xml.ws.handler.soap.SOAPMessageContext in project cxf by apache.
the class HandlerInvocationUsingAddNumbersTest method testInvokeFromDispatchWithJAXBPayload.
@Test
public void testInvokeFromDispatchWithJAXBPayload() throws Exception {
URL wsdl = getClass().getResource("/wsdl/addNumbers.wsdl");
assertNotNull(wsdl);
AddNumbersService service = new AddNumbersService(wsdl, serviceName);
assertNotNull(service);
JAXBContext jc = JAXBContext.newInstance("org.apache.handlers.types");
Dispatch<Object> disp = service.createDispatch(portName, jc, Service.Mode.PAYLOAD);
setAddress(disp, addNumbersAddress);
SmallNumberHandler sh = new SmallNumberHandler();
TestSOAPHandler soapHandler = new TestSOAPHandler(false) {
public boolean handleMessage(SOAPMessageContext ctx) {
super.handleMessage(ctx);
Boolean outbound = (Boolean) ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (outbound) {
try {
SOAPMessage msg = ctx.getMessage();
// System.out.println("aaaaaaaaaaaa");
// msg.writeTo(System.out);
assertNotNull(msg);
} catch (Exception e) {
e.printStackTrace();
fail(e.toString());
}
}
return true;
}
};
addHandlersProgrammatically(disp, sh, soapHandler);
org.apache.handlers.types.AddNumbers req = new org.apache.handlers.types.AddNumbers();
req.setArg0(10);
req.setArg1(20);
ObjectFactory factory = new ObjectFactory();
JAXBElement<org.apache.handlers.types.AddNumbers> e = factory.createAddNumbers(req);
JAXBElement<?> response = (JAXBElement<?>) disp.invoke(e);
assertNotNull(response);
AddNumbersResponse value = (AddNumbersResponse) response.getValue();
assertEquals(200, value.getReturn());
}
use of javax.xml.ws.handler.soap.SOAPMessageContext in project cxf by apache.
the class HandlerInvocationTest method testSOAPHandlerHandleMessageReturnFalseClientOutbound.
@Test
public void testSOAPHandlerHandleMessageReturnFalseClientOutbound() throws Exception {
final String clientHandlerMessage = "client side";
TestHandler<LogicalMessageContext> handler1 = new TestHandler<>(false);
TestHandler<LogicalMessageContext> handler2 = new TestHandler<LogicalMessageContext>(false) {
public boolean handleMessage(LogicalMessageContext ctx) {
super.handleMessage(ctx);
try {
Boolean outbound = (Boolean) ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (outbound) {
LogicalMessage msg = ctx.getMessage();
assertNotNull("logical message is null", msg);
JAXBContext jaxbCtx = JAXBContext.newInstance(PackageUtils.getPackageName(PingOneWay.class));
PingResponse resp = new PingResponse();
resp.getHandlersInfo().add(clientHandlerMessage);
msg.setPayload(resp, jaxbCtx);
}
} catch (Exception e) {
e.printStackTrace();
fail(e.toString());
}
return true;
}
};
TestSOAPHandler soapHandler1 = new TestSOAPHandler(false);
TestSOAPHandler soapHandler2 = new TestSOAPHandler(false) {
public boolean handleMessage(SOAPMessageContext ctx) {
super.handleMessage(ctx);
Boolean outbound = (Boolean) ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (outbound) {
return false;
}
return true;
}
};
addHandlersToChain((BindingProvider) handlerTest, handler1, handler2, soapHandler1, soapHandler2);
List<String> resp = handlerTest.ping();
assertEquals(clientHandlerMessage, resp.get(0));
assertEquals(2, handler1.getHandleMessageInvoked());
assertEquals(2, handler2.getHandleMessageInvoked());
assertEquals(2, soapHandler1.getHandleMessageInvoked());
assertEquals(1, soapHandler2.getHandleMessageInvoked());
assertEquals("close must be called", 1, handler1.getCloseInvoked());
assertEquals("close must be called", 1, handler2.getCloseInvoked());
assertEquals("close must be called", 1, soapHandler1.getCloseInvoked());
assertEquals("close must be called", 1, soapHandler2.getCloseInvoked());
assertTrue(soapHandler2.getInvokeOrderOfClose() < soapHandler1.getInvokeOrderOfClose());
assertTrue(soapHandler1.getInvokeOrderOfClose() < handler2.getInvokeOrderOfClose());
assertTrue(handler2.getInvokeOrderOfClose() < handler1.getInvokeOrderOfClose());
}
use of javax.xml.ws.handler.soap.SOAPMessageContext in project cxf by apache.
the class HandlerInvocationTest method testServerSOAPInboundHandlerThrowsSOAPFaultToClientHandlers.
@Test
public void testServerSOAPInboundHandlerThrowsSOAPFaultToClientHandlers() throws Exception {
TestHandler<LogicalMessageContext> handler1 = new TestHandler<>(false);
TestHandler<LogicalMessageContext> handler2 = new TestHandler<LogicalMessageContext>(false) {
public boolean handleFault(LogicalMessageContext ctx) {
super.handleFault(ctx);
try {
Boolean outbound = (Boolean) ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (!outbound) {
LogicalMessage msg = ctx.getMessage();
Source source = msg.getPayload();
assertNotNull(source);
}
} catch (Exception e) {
e.printStackTrace();
fail(e.toString());
}
return true;
}
};
TestSOAPHandler soapHandler1 = new TestSOAPHandler(false);
TestSOAPHandler soapHandler2 = new TestSOAPHandler(false) {
public boolean handleFault(SOAPMessageContext ctx) {
super.handleFault(ctx);
Boolean outbound = (Boolean) ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (!outbound) {
try {
SOAPMessage msg = ctx.getMessage();
assertNotNull(msg);
} catch (Exception e) {
e.printStackTrace();
fail(e.toString());
}
}
return true;
}
};
addHandlersToChain((BindingProvider) handlerTest, handler1, handler2, soapHandler1, soapHandler2);
try {
handlerTest.pingWithArgs("soapHandler3 inbound throw SOAPFaultException");
fail("did not get expected SOAPFaultException");
} catch (SOAPFaultException e) {
// e.printStackTrace();
/* ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos, true);
e.printStackTrace(ps);
assertTrue("Did not get expected exception message", baos.toString()
.indexOf("HandleMessage throws exception") > -1);
assertTrue("Did not get expected javax.xml.ws.soap.SOAPFaultException", baos.toString()
.indexOf("javax.xml.ws.soap.SOAPFaultException") > -1);*/
}
/* assertEquals("handle message was not invoked", 1, handler1.getHandleMessageInvoked());
assertEquals("handle message was not invoked", 1, handler2.getHandleMessageInvoked());
assertEquals("handle message was not invoked", 1, soapHandler1.getHandleMessageInvoked());
assertEquals("handle message was not invoked", 1, soapHandler2.getHandleMessageInvoked());
assertEquals("handle message was not invoked", 1, handler1.getHandleFaultInvoked());
assertEquals("handle message was not invoked", 1, handler2.getHandleFaultInvoked());
assertEquals("handle message was not invoked", 1, soapHandler1.getHandleFaultInvoked());
assertEquals("handle message was not invoked", 1, soapHandler2.getHandleFaultInvoked());
assertEquals("close must be called", 1, handler1.getCloseInvoked());
assertEquals("close must be called", 1, handler2.getCloseInvoked());
assertEquals("close must be called", 1, soapHandler1.getCloseInvoked());
assertEquals("close must be called", 1, soapHandler2.getCloseInvoked());
assertTrue(soapHandler2.getInvokeOrderOfClose()
< soapHandler1.getInvokeOrderOfClose());
assertTrue(soapHandler1.getInvokeOrderOfClose()
< handler2.getInvokeOrderOfClose());
assertTrue(handler2.getInvokeOrderOfClose()
< handler1.getInvokeOrderOfClose()); */
}
use of javax.xml.ws.handler.soap.SOAPMessageContext in project nhin-d by DirectProject.
the class RepositorySOAPHandler method handleFault.
/**
* Handles SOAP-Errors.
*
* @param context
* the SOAPMessageContext object.
* @return true for successful fault handling.
*/
@Override
public boolean handleFault(SOAPMessageContext context) {
LOGGER.info("ServerSOAPHandler.handleFault");
boolean outbound = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (outbound) {
LOGGER.info("Direction=outbound (handleFault)");
} else {
LOGGER.info("Direction=inbound (handleFault)");
}
try {
@SuppressWarnings("unused") SOAPMessage msg = ((SOAPMessageContext) context).getMessage();
if (context.getMessage().getSOAPBody().getFault() != null) {
String detailName = null;
try {
detailName = context.getMessage().getSOAPBody().getFault().getDetail().getFirstChild().getLocalName();
LOGGER.info("detailName=" + detailName);
} catch (Exception e) {
LOGGER.warn("Error extracting detailName", e);
}
}
} catch (SOAPException e) {
LOGGER.warn("Error handling fault", e);
}
return true;
}
use of javax.xml.ws.handler.soap.SOAPMessageContext in project nhin-d by DirectProject.
the class DirectSOAPHandler method handleFault.
/*
* (non-Javadoc)
*
* @see javax.xml.ws.handler.Handler#handleFault(javax.xml.ws.handler.MessageContext)
*/
@Override
public boolean handleFault(SOAPMessageContext context) {
LOGGER.info("ServerSOAPHandler.handleFault");
boolean outbound = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (outbound) {
LOGGER.info("Direction=outbound (handleFault)");
} else {
LOGGER.info("Direction=inbound (handleFault)");
}
try {
@SuppressWarnings("unused") SOAPMessage msg = ((SOAPMessageContext) context).getMessage();
if (context.getMessage().getSOAPBody().getFault() != null) {
String detailName = null;
try {
detailName = context.getMessage().getSOAPBody().getFault().getDetail().getFirstChild().getLocalName();
LOGGER.info("detailName=" + detailName);
} catch (Exception e) {
LOGGER.warn("Unable to extract detailName", e);
}
}
} catch (SOAPException e) {
LOGGER.warn("Error handling fault", e);
}
return true;
}
Aggregations