Methods Summary |
---|
public void | doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)Handles a POST request from a client. The request is assumed
to contain a SOAP message with the HTTP binding.
try {
// Get all the HTTP headers and convert them to a MimeHeaders object
MimeHeaders mimeHeaders = getMIMEHeaders(request);
// Create a SOAPMessage from the content of the HTTP request
SOAPMessage message = messageFactory.createMessage(mimeHeaders,
request.getInputStream());
// Let the subclass handle the message
SOAPMessage reply = onMessage(message);
// If there is a reply, return it to the sender.
if (reply != null) {
// Set OK HTTP status, unless there is a fault.
boolean hasFault = reply.getSOAPPart().getEnvelope().getBody().hasFault();
response.setStatus(hasFault ?
HttpServletResponse.SC_INTERNAL_SERVER_ERROR :
HttpServletResponse.SC_OK);
// Force generation of the MIME headers
if (reply.saveRequired()) {
reply.saveChanges();
}
// Copy the MIME headers to the HTTP response
setHttpHeaders(reply.getMimeHeaders(), response);
// Send the completed message
OutputStream os = response.getOutputStream();
reply.writeTo(os);
os.flush();
} else {
// No reply - set the HTTP status to indicate this
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
}
} catch (SOAPException ex) {
throw new ServletException("SOAPException: " + ex);
}
|
private javax.xml.soap.MimeHeaders | getMIMEHeaders(javax.servlet.http.HttpServletRequest request)Creates a MIMEHeaders object from the HTTP headers
received with a SOAP message.
MimeHeaders mimeHeaders = new MimeHeaders();
Enumeration enum = request.getHeaderNames();
while (enum.hasMoreElements()) {
String headerName = (String)enum.nextElement();
String headerValue = request.getHeader(headerName);
StringTokenizer st = new StringTokenizer(headerValue, ",");
while (st.hasMoreTokens()) {
mimeHeaders.addHeader(headerName, st.nextToken().trim());
}
}
return mimeHeaders;
|
public void | init(javax.servlet.ServletConfig config)Initialisation - create the MessageFactory
super.init(config);
try {
messageFactory = MessageFactory.newInstance();
} catch (SOAPException ex) {
throw new ServletException("Failed to create MessageFactory", ex);
}
|
protected abstract javax.xml.soap.SOAPMessage | onMessage(javax.xml.soap.SOAPMessage message)Method implemented by subclasses to handle a received SOAP message.
|
private void | setHttpHeaders(javax.xml.soap.MimeHeaders mimeHeaders, javax.servlet.http.HttpServletResponse response)Converts the MIMEHeaders for a SOAP message to
HTTP headers in the response.
Iterator iter = mimeHeaders.getAllHeaders();
while (iter.hasNext()) {
MimeHeader mimeHeader = (MimeHeader)iter.next();
String headerName = mimeHeader.getName();
String[] headerValues = mimeHeaders.getHeader(headerName);
int count = headerValues.length;
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < count; i++) {
if (i != 0) {
buffer.append(',");
}
buffer.append(headerValues[i]);
}
response.setHeader(headerName, buffer.toString());
}
|