use of javax.xml.ws.LogicalMessage 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<LogicalMessageContext>(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.LogicalMessage in project scout.rt by eclipse.
the class AbstractValidationHandler method handleMessage.
@Override
public boolean handleMessage(LogicalMessageContext context) {
if (MessageContexts.isOutboundMessage(context)) {
return true;
}
LogicalMessage message = context.getMessage();
Source payload = message.getPayload();
Schema xsd = getXsd();
try {
xsd.newValidator().validate(payload);
} catch (SAXException e) {
throw new WebServiceException("Soap request message is not valid.", e);
} catch (IOException e) {
throw new WebServiceException(e);
}
return true;
}
use of javax.xml.ws.LogicalMessage in project cxf by apache.
the class TestHandler method handlePingMessage.
private boolean handlePingMessage(boolean outbound, T ctx) {
LogicalMessage msg = ctx.getMessage();
addHandlerId(msg, ctx, outbound);
if (checkServerOutBindStopHandler(outbound, ctx)) {
return false;
}
return getHandleMessageRet();
}
use of javax.xml.ws.LogicalMessage in project cxf by apache.
the class TestHandler method handlePingWithArgsMessage.
private boolean handlePingWithArgsMessage(boolean outbound, T ctx) {
LogicalMessage msg = ctx.getMessage();
Object payload = msg.getPayload(jaxbCtx);
addHandlerId(ctx.getMessage(), ctx, outbound);
boolean ret = true;
if (payload instanceof PingWithArgs) {
String arg = ((PingWithArgs) payload).getHandlersCommand();
StringTokenizer strtok = new StringTokenizer(arg, " ");
String hid = "";
String direction = "";
String command = "";
if (strtok.countTokens() >= 3) {
hid = strtok.nextToken();
direction = strtok.nextToken();
command = strtok.nextToken();
}
if (!getHandlerId().equals(hid)) {
return true;
}
if ("stop".equals(command)) {
if (!outbound && "inbound".equals(direction)) {
PingResponse resp = new PingResponse();
resp.getHandlersInfo().addAll(getHandlerInfoList(ctx));
msg.setPayload(resp, jaxbCtx);
ret = false;
} else if (outbound && "outbound".equals(direction)) {
ret = false;
}
} else if ("throw".equals(command)) {
String exceptionType = null;
String exceptionText = "HandleMessage throws exception";
if (strtok.hasMoreTokens()) {
exceptionType = strtok.nextToken();
}
if (strtok.hasMoreTokens()) {
exceptionText = strtok.nextToken();
}
if (exceptionType != null && !outbound && "inbound".equals(direction)) {
if ("RuntimeException".equals(exceptionType)) {
throw new RuntimeException(exceptionText);
} else if ("ProtocolException".equals(exceptionType)) {
throw new ProtocolException(exceptionText);
}
} else if (exceptionType != null && outbound && "outbound".equals(direction)) {
if ("RuntimeException".equals(exceptionType)) {
throw new RuntimeException(exceptionText);
} else if ("ProtocolException".equals(exceptionType)) {
throw new ProtocolException(exceptionText);
}
}
}
}
return ret;
}
use of javax.xml.ws.LogicalMessage in project cxf by apache.
the class HandlerInvocationTest method testServerEndpointRemoteFault.
@Test
public void testServerEndpointRemoteFault() throws PingException {
TestHandler<LogicalMessageContext> handler1 = new TestHandler<LogicalMessageContext>(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();
String payload = convertDOMToString(msg.getPayload());
assertTrue(payload.indexOf("<faultstring>" + "servant throws SOAPFaultException" + "</faultstring>") > -1);
}
} catch (Exception e) {
e.printStackTrace();
fail(e.toString());
}
return true;
}
private String convertDOMToString(Source s) throws TransformerException {
StringWriter stringWriter = new StringWriter();
StreamResult streamResult = new StreamResult(stringWriter);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
transformerFactory.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true);
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "no");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.transform(s, streamResult);
return stringWriter.toString();
}
};
TestSOAPHandler soapHandler1 = new TestSOAPHandler(false);
TestSOAPHandler soapHandler2 = new TestSOAPHandler(false) {
public boolean handleFault(SOAPMessageContext ctx) {
super.handleFault(ctx);
try {
Boolean outbound = (Boolean) ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (!outbound) {
SOAPEnvelope env = ctx.getMessage().getSOAPPart().getEnvelope();
assertTrue("expected SOAPFault in SAAJ model", env.getBody().hasFault());
}
} catch (Exception e) {
e.printStackTrace();
fail(e.toString());
}
return true;
}
};
addHandlersToChain((BindingProvider) handlerTest, handler1, handler2, soapHandler1, soapHandler2);
try {
handlerTest.pingWithArgs("servant throw SOAPFaultException");
fail("did not get expected Exception");
} catch (SOAPFaultException sfe) {
// expected
}
assertEquals(1, handler1.getHandleMessageInvoked());
assertEquals(1, handler2.getHandleMessageInvoked());
assertEquals(1, soapHandler1.getHandleMessageInvoked());
assertEquals(1, soapHandler2.getHandleMessageInvoked());
assertEquals(1, handler2.getHandleFaultInvoked());
assertEquals(1, handler1.getHandleFaultInvoked());
assertEquals(1, soapHandler1.getHandleFaultInvoked());
assertEquals(1, soapHandler2.getHandleFaultInvoked());
assertEquals(1, handler1.getCloseInvoked());
assertEquals(1, handler2.getCloseInvoked());
assertEquals(1, soapHandler1.getCloseInvoked());
assertEquals(1, soapHandler2.getCloseInvoked());
assertTrue(handler2.getInvokeOrderOfClose() < handler1.getInvokeOrderOfClose());
}
Aggregations