Methods Summary |
---|
public void | destroy()
if (debug) {
System.out.println("Client-side handler destroyed");
}
|
public javax.xml.namespace.QName[] | getHeaders()
return headers;
|
public boolean | handleRequest(javax.xml.rpc.handler.MessageContext ctx)
try {
if (debug) {
System.out.println("----------------------\nhandleRequest called");
}
// Add authentication info to the outgoing message,
// adding a SOAPHeader part if it is not already there
if (userName != null && password != null) {
SOAPMessage message = ((SOAPMessageContext)ctx).getMessage();
SOAPHeader header = message.getSOAPPart().getEnvelope().getHeader();
if (header == null) {
header = message.getSOAPPart().getEnvelope().addHeader();
}
SOAPElement element = header.addChildElement(authHeaderName);
element.addChildElement("UserName").addTextNode(userName);
element.addChildElement("Password").addTextNode(password);
if (debug) {
System.out.println("OUTGOING MESSAGE: ");
try {
message.writeTo(System.out);
} catch (IOException ex) {
}
System.out.println();
}
}
} catch (SOAPException ex) {
throw new JAXRPCException("Error in handleRequest", ex);
}
return true;
|
public boolean | handleResponse(javax.xml.rpc.handler.MessageContext ctx)
try {
if (debug) {
System.out.println("handleResponse called");
}
SOAPMessage message = ((SOAPMessageContext)ctx).getMessage();
SOAPHeader header = message.getSOAPPart().getEnvelope().getHeader();
if (header != null) {
// Locate the "time" header
Iterator iter = header.getChildElements(timeHeaderName);
if (iter.hasNext()) {
SOAPElement element = (SOAPElement)iter.next();
String value = element.getValue();
// Just print the timer
System.out.println("Request processed at: " + value);
// Remove this header
element.detachNode();
}
// Remove any other "time" headers.
while (iter.hasNext()) {
((SOAPElement)iter.next()).detachNode();
}
}
} catch (SOAPException ex) {
throw new JAXRPCException("Error in handleRequest", ex);
}
return true;
|
public void | init(javax.xml.rpc.handler.HandlerInfo info)
// Performs initialization
// Create Names
try {
factory = SOAPFactory.newInstance();
authHeaderName = factory.createName("auth", NS_PREFIX, NS_URI);
timeHeaderName = factory.createName("time", NS_PREFIX, NS_URI);
headers = new QName[] { authHeader, timeHeader };
} catch (SOAPException ex) {
throw new JAXRPCException("Init failure", ex);
}
// Get the user name and password to use
userName = System.getProperty("HandlerBooks.user");
password = System.getProperty("HandlerBooks.password");
// Extract the debug setting from the configuration
Map config = info.getHandlerConfig();
String value = (String)config.get("debug");
debug = value == null ? false : Boolean.valueOf(value).booleanValue();
if (debug) {
System.out.println("Client-side handler initialized");
System.out.println("User: [" + userName + "], password: [" + password + "]");
}
|