use of org.apache.handler_test.types.PingResponse in project cxf by apache.
the class TestHandler method addHandlerId.
private void addHandlerId(LogicalMessage msg, T ctx, boolean outbound) {
Object obj = msg.getPayload(jaxbCtx);
if (obj instanceof PingResponse) {
PingResponse origResp = (PingResponse) obj;
PingResponse newResp = new PingResponse();
newResp.getHandlersInfo().addAll(origResp.getHandlersInfo());
newResp.getHandlersInfo().add(getHandlerId());
msg.setPayload(newResp, jaxbCtx);
} else if (obj instanceof Ping || obj instanceof PingWithArgs) {
getHandlerInfoList(ctx).add(getHandlerId());
}
}
use of org.apache.handler_test.types.PingResponse in project cxf by apache.
the class TestHandler method handleMessage.
public boolean handleMessage(T ctx) {
methodCalled("handleMessage");
printHandlerInfo("handleMessage", isOutbound(ctx));
boolean outbound = (Boolean) ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
boolean ret = getHandleMessageRet();
if (!isServerSideHandler()) {
return true;
}
try {
verifyJAXWSProperties(ctx);
} catch (PingException e) {
e.printStackTrace();
throw new ProtocolException(e);
}
Object obj = ctx.getMessage().getPayload(jaxbCtx);
if (obj instanceof Ping || obj instanceof PingResponse) {
ret = handlePingMessage(outbound, ctx);
} else if (obj instanceof PingWithArgs) {
ret = handlePingWithArgsMessage(outbound, ctx);
}
return ret;
}
use of org.apache.handler_test.types.PingResponse in project cxf by apache.
the class TestHandler method checkServerOutBindStopHandler.
private boolean checkServerOutBindStopHandler(boolean outbound, T ctx) {
if (outbound) {
LogicalMessage msg = ctx.getMessage();
Object obj = msg.getPayload(jaxbCtx);
if (obj instanceof PingResponse) {
// only check if we need call for the server response handler false
PingResponse origResp = (PingResponse) obj;
for (String handler : origResp.getHandlersInfo()) {
if (handler.indexOf("server") == 0 && handler.indexOf(getHandlerId()) > 0 && handler.indexOf("stop") > 0) {
return true;
}
}
}
}
return false;
}
use of org.apache.handler_test.types.PingResponse 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 org.apache.handler_test.types.PingResponse in project cxf by apache.
the class HandlerInvocationTest method getHandlerNames.
List<String> getHandlerNames(SOAPBody soapBody) throws Exception {
Element elNode = DOMUtils.getFirstElement(soapBody);
List<String> stringList = null;
JAXBContext jaxbCtx = JAXBContext.newInstance(PingResponse.class);
Unmarshaller um = jaxbCtx.createUnmarshaller();
Object obj = um.unmarshal(elNode);
if (obj instanceof PingResponse) {
PingResponse pr = PingResponse.class.cast(obj);
stringList = pr.getHandlersInfo();
}
return stringList;
}
Aggregations