use of javax.xml.ws.ProtocolException 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.ProtocolException in project cxf by apache.
the class TestSOAPHandler method getReturnValue.
private boolean getReturnValue(boolean outbound, SOAPMessageContext ctx) {
boolean ret = true;
try {
SOAPMessage msg = ctx.getMessage();
SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();
if (body.getFirstChild().getFirstChild() == null) {
return true;
}
Node commandNode = body.getFirstChild().getFirstChild().getFirstChild();
String arg = commandNode.getNodeValue();
String namespace = body.getFirstChild().getFirstChild().getNamespaceURI();
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)) {
// remove the incoming request body.
Document doc = body.getOwnerDocument();
// build the SOAP response for this message
//
Node wrapper = doc.createElementNS(namespace, "pingResponse");
wrapper.setPrefix("ns4");
body.removeChild(body.getFirstChild());
body.appendChild(wrapper);
for (String info : getHandlerInfoList(ctx)) {
//
if (!info.contains(getHandlerId())) {
Node newEl = doc.createElementNS(namespace, "HandlersInfo");
newEl.setPrefix("ns4");
newEl.appendChild(doc.createTextNode(info));
wrapper.appendChild(newEl);
}
}
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 ("SOAPFaultException".equals(exceptionType)) {
throw createSOAPFaultException(exceptionText);
} else if ("SOAPFaultExceptionWDetail".equals(exceptionType)) {
throw createSOAPFaultExceptionWithDetail(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);
} else if ("SOAPFaultException".equals(exceptionType)) {
throw createSOAPFaultException(exceptionText);
} else if ("SOAPFaultExceptionWDetail".equals(exceptionType)) {
throw createSOAPFaultExceptionWithDetail(exceptionText);
}
}
}
} catch (SOAPException e) {
e.printStackTrace();
}
return ret;
}
Aggregations