public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
long t0=0, t1=0, t2=0, t3=0, t4=0;
String soapAction=null;
MessageContext msgContext=null;
if (isDebug)
log.debug("Enter: doPost()");
if( tlog.isDebugEnabled() ) {
t0=System.currentTimeMillis();
}
Message responseMsg = null;
String contentType = null;
try {
AxisEngine engine = getEngine();
if (engine == null) {
// !!! should return a SOAP fault...
ServletException se =
new ServletException(Messages.getMessage("noEngine00"));
log.debug("No Engine!", se);
throw se;
}
res.setBufferSize(1024 * 8); // provide performance boost.
/** get message context w/ various properties set
*/
msgContext = createMessageContext(engine, req, res);
// ? OK to move this to 'getMessageContext',
// ? where it would also be picked up for 'doGet()' ?
if (securityProvider != null) {
if (isDebug) log.debug("securityProvider:" + securityProvider);
msgContext.setProperty("securityProvider", securityProvider);
}
/* Get request message
*/
Message requestMsg =
new Message(req.getInputStream(),
false,
req.getHeader(HTTPConstants.HEADER_CONTENT_TYPE),
req.getHeader(HTTPConstants.HEADER_CONTENT_LOCATION));
if(isDebug) log.debug("Request Message:" + requestMsg);
/* Set the request(incoming) message field in the context */
/**********************************************************/
msgContext.setRequestMessage(requestMsg);
try {
/**
* Save the SOAPAction header in the MessageContext bag.
* This will be used to tell the Axis Engine which service
* is being invoked. This will save us the trouble of
* having to parse the Request message - although we will
* need to double-check later on that the SOAPAction header
* does in fact match the URI in the body.
*/
// (is this last stmt true??? (I don't think so - Glen))
/********************************************************/
soapAction = getSoapAction(req);
if (soapAction != null) {
msgContext.setUseSOAPAction(true);
msgContext.setSOAPActionURI(soapAction);
}
// Create a Session wrapper for the HTTP session.
// These can/should be pooled at some point.
// (Sam is Watching! :-)
msgContext.setSession(new AxisHttpSession(req));
if( tlog.isDebugEnabled() ) {
t1=System.currentTimeMillis();
}
/* Invoke the Axis engine... */
/*****************************/
if(isDebug) log.debug("Invoking Axis Engine.");
engine.invoke(msgContext);
if(isDebug) log.debug("Return from Axis Engine.");
if( tlog.isDebugEnabled() ) {
t2=System.currentTimeMillis();
}
responseMsg = msgContext.getResponseMessage();
contentType = responseMsg.getContentType(msgContext.getSOAPConstants());
} catch (AxisFault e) {
log.error(Messages.getMessage("exception00"), e);
// It's been suggested that a lack of SOAPAction
// should produce some other error code (in the 400s)...
int status = getHttpServletResponseStatus(e);
if (status == HttpServletResponse.SC_UNAUTHORIZED)
res.setHeader("WWW-Authenticate","Basic realm=\"AXIS\"");
// TODO: less generic realm choice?
res.setStatus(status);
responseMsg = msgContext.getResponseMessage();
if (responseMsg == null)
responseMsg = new Message(e);
contentType = responseMsg.getContentType(msgContext.getSOAPConstants());
} catch (Exception e) {
log.error(Messages.getMessage("exception00"), e);
res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
responseMsg = msgContext.getResponseMessage();
if (responseMsg == null)
responseMsg = new Message(AxisFault.makeFault(e));
contentType = responseMsg.getContentType(msgContext.getSOAPConstants());
}
} catch (AxisFault fault) {
log.error(Messages.getMessage("axisFault00"), fault);
responseMsg = msgContext.getResponseMessage();
if (responseMsg == null)
responseMsg = new Message(fault);
contentType = responseMsg.getContentType(msgContext.getSOAPConstants());
}
if( tlog.isDebugEnabled() ) {
t3=System.currentTimeMillis();
}
/* Send response back along the wire... */
/***********************************/
if (responseMsg != null)
sendResponse(getProtocolVersion(req), contentType,
res, responseMsg);
if (isDebug) {
log.debug("Response sent.");
log.debug("Exit: doPost()");
}
if( tlog.isDebugEnabled() ) {
t4=System.currentTimeMillis();
tlog.debug("axisServlet.doPost: " + soapAction +
" pre=" + (t1-t0) +
" invoke=" + (t2-t1) +
" post=" + (t3-t2) +
" send=" + (t4-t3) +
" " + msgContext.getTargetService() + "." +
((msgContext.getOperation( ) == null) ?
"" : msgContext.getOperation().getName()) );
}
}