use of org.apache.handler_test.types.PingWithArgs 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.PingWithArgs 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.PingWithArgs 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;
}
Aggregations