Java Reference
In-Depth Information
SOAPFactory sf = SOAPFactory.newInstance();
SOAPMessage response = mf.createMessage();
//Could go to database here to check creds
if ("jgosling".equals(user)) {
//Create Header
QName q = new QName("urn:myNS", "sso");
SOAPHeader h = response.getSOAPHeader();
SOAPHeaderElement headerEl = h.addHeaderElement(q);
headerEl.addAttribute(new QName("gateway"),
"192.168.1.102");
headerEl.addAttribute(new QName("authToken"),
UUID.randomUUID().toString());
//Create Body
SOAPBody body = response.getSOAPBody();
SOAPElement respContent =
body.addChildElement("gatewayResponse");
respContent.setValue("ADMIN");
} else {
//Create body for unauthorized user, and no header
SOAPBody body = response.getSOAPBody();
SOAPElement respContent =
body.addChildElement("gatewayResponse");
respContent.setValue("N/A");
}
response.saveChanges();
LOGGER.debug("Returning response.");
response.writeTo(System.out);
return response;
}
}
The provider implements the required invoke method; it reads the request and returns a re-
sponse, delegating the work of sending authentication tokens to valid users, and denying in-
valid users. The example demonstrates a few things:
▪ How to implement a Provider
▪ How the Provider relates to the given WSDL
Search WWH ::




Custom Search