1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
package test.jaxrpc;
import javax.xml.namespace.QName;
import javax.xml.rpc.handler.Handler;
import javax.xml.rpc.handler.HandlerInfo;
import javax.xml.rpc.handler.MessageContext;
import java.util.Map;
public class AAAHandler implements Handler {
private int handleRequestInvocations = 0;
private int handleResponseInvocations = 0;
private int handleFaultInvocations = 0;
public Object handleRequestReturnValue = null;
public Object handleResponseReturnValue = null;
public Object handleFaultReturnValue = null;
public boolean handleRequest(MessageContext context) {
handleRequestInvocations++;
return returnAppropriateValue(handleRequestReturnValue);
}
public boolean handleResponse(MessageContext context) {
handleResponseInvocations++;
return returnAppropriateValue(handleResponseReturnValue);
}
public boolean handleFault(MessageContext context) {
handleFaultInvocations++;
return returnAppropriateValue(handleFaultReturnValue);
}
private boolean returnAppropriateValue(Object returnValue) {
if (returnValue == null)
return true;
else if (returnValue instanceof Boolean)
return ((Boolean) returnValue).booleanValue();
else if (returnValue instanceof RuntimeException)
throw (RuntimeException) returnValue;
else {
throw new RuntimeException();
}
}
public void init(HandlerInfo config) {
Map map = config.getHandlerConfig();
handleRequestReturnValue = map.get("HANDLE_REQUEST_RETURN_VALUE");
handleResponseReturnValue = map.get("HANDLE_RESPONSE_RETURN_VALUE");
handleFaultReturnValue = map.get("HANDLE_FAULT_RETURN_VALUE");
}
public void destroy() {
}
public QName[] getHeaders() {
return new QName[0];
}
public int getHandleRequestInvocations() {
return handleRequestInvocations;
}
public int getHandleResponseInvocations() {
return handleResponseInvocations;
}
public int getHandleFaultInvocations() {
return handleFaultInvocations;
}
public Object getHandleRequestReturnValue() {
return handleRequestReturnValue;
}
public void setHandleRequestReturnValue(Object handleRequestReturnValue) {
this.handleRequestReturnValue = handleRequestReturnValue;
}
public Object getHandleResponseReturnValue() {
return handleResponseReturnValue;
}
public void setHandleResponseReturnValue(Object handleResponseReturnValue) {
this.handleResponseReturnValue = handleResponseReturnValue;
}
public Object getHandleFaultReturnValue() {
return handleFaultReturnValue;
}
public void setHandleFaultReturnValue(Object handleFaultReturnValue) {
this.handleFaultReturnValue = handleFaultReturnValue;
}
}
|