Java Reference
In-Depth Information
System.out.println("\nSending Response:\n");
reply.writeTo(System.out);
//Return response
OutputStream os = response.getOutputStream();
reply.writeTo(os);
os.flush();
os.close();
} else {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
}
} catch (Exception ex){
throw new ServletException("SAAJ could not " +
"understand request. " + ex.getMessage());
}
}
private SOAPMessage createReply(HttpServletRequest request)
throws SOAPException, IOException {
String ns = "urn:soacookbook:saaj";
//Get all HTTP Headers
MimeHeaders headers = getHeaders(request);
//Get incoming request as stream
InputStream is = request.getInputStream();
//use headers and request stream to create SOAP Msg
SOAPMessage reqMsg = mf.createMessage(headers, is);
//Create new message for response
SOAPMessage msg = mf.createMessage();
SOAPPart part = msg.getSOAPPart();
SOAPEnvelope env = part.getEnvelope();
SOAPBody body = env.getBody();
//Add Namespace
env.createName("message", "soa", ns);
//Put data in response
Name bn = env.createName("message", "soa", ns);
SOAPBodyElement be = body.addBodyElement(bn);
//Inspect request and get data from it as necessary...
String name = request.getParameter("name");
Search WWH ::




Custom Search