Methods Summary |
---|
public void | destroy()
if (debug) {
System.out.println("Server-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("handleRequest called");
}
String userName = null;
String password = null;
SOAPMessage message = ((SOAPMessageContext)ctx).getMessage();
SOAPHeader header = message.getSOAPPart().getEnvelope().getHeader();
if (header != null) {
// Locate the "auth" header
Iterator iter = header.getChildElements(authHeaderName);
if (iter.hasNext()) {
SOAPElement element = (SOAPElement)iter.next();
Iterator children = element.getChildElements();
while (children.hasNext()) {
SOAPElement childElement = (SOAPElement)children.next();
String localPart = childElement.getElementName().getLocalName();
if (localPart.equals("UserName") && userName == null) {
userName = childElement.getValue();
} else if (localPart.equals("Password") && password == null) {
password = childElement.getValue();
}
}
// Remove this header
element.detachNode();
}
// Remove any other "auth" headers.
while (iter.hasNext()) {
((SOAPElement)iter.next()).detachNode();
}
// Install the user name and password in the MessageContext.
// This installs null if either attribute was missing.
ctx.setProperty(HandlerBookServiceConstants.USERNAME_PROPERTY, userName);
ctx.setProperty(HandlerBookServiceConstants.PASSWORD_PROPERTY, password);
if (debug) {
System.out.println("Got auth: user: [" + userName + "], password: [" + password + "]");
}
}
} 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) {
header = message.getSOAPPart().getEnvelope().addHeader();
}
SOAPElement element = header.addChildElement(timeHeaderName);
String text = format.format(new Date());
element.addTextNode(text);
if (debug) {
System.out.println("Added time header, value " + text);
}
} catch (SOAPException ex) {
throw new JAXRPCException("Error in handleRequest", ex);
}
return true;
|
public void | init(javax.xml.rpc.handler.HandlerInfo info)
// Performs initialization
// 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();
// 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);
}
if (debug) {
System.out.println("Server-side handler initialized");
}
|