Search in sources :

Example 1 with AxisHttpSession

use of org.apache.axis.transport.http.AxisHttpSession in project Lucee by lucee.

the class RPCServer method doPost.

/**
 * Process a POST to the servlet by handing it off to the Axis Engine.
 * Here is where SOAP messages are received
 * @param req posted request
 * @param res respose
 * @throws ServletException trouble
 * @throws IOException different trouble
 */
public void doPost(HttpServletRequest req, HttpServletResponse res, Component component) throws ServletException, IOException {
    long t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0;
    String soapAction = null;
    MessageContext msgContext = null;
    Message responseMsg = null;
    String contentType = null;
    InputStream is = 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;
        }
        // provide performance boost.
        res.setBufferSize(1024 * 8);
        /**
         * get message context w/ various properties set
         */
        msgContext = createMessageContext(engine, req, res, component);
        ComponentController.set(msgContext);
        // ? where it would also be picked up for 'doGet()' ?
        if (securityProvider != null) {
            if (isDebug) {
                log.debug("securityProvider:" + securityProvider);
            }
            msgContext.setProperty(MessageContext.SECURITY_PROVIDER, securityProvider);
        }
        is = req.getInputStream();
        Message requestMsg = new Message(is, false, req.getHeader(HTTPConstants.HEADER_CONTENT_TYPE), req.getHeader(HTTPConstants.HEADER_CONTENT_LOCATION));
        // Transfer HTTP headers to MIME headers for request message.
        MimeHeaders requestMimeHeaders = requestMsg.getMimeHeaders();
        for (Enumeration e = req.getHeaderNames(); e.hasMoreElements(); ) {
            String headerName = (String) e.nextElement();
            for (Enumeration f = req.getHeaders(headerName); f.hasMoreElements(); ) {
                String headerValue = (String) f.nextElement();
                requestMimeHeaders.addHeader(headerName, headerValue);
            }
        }
        if (isDebug) {
            log.debug("Request Message:" + requestMsg);
        /* Set the request(incoming) message field in the context */
        /**
         *******************************************************
         */
        }
        msgContext.setRequestMessage(requestMsg);
        String url = HttpUtils.getRequestURL(req).toString().toLowerCase();
        msgContext.setProperty(MessageContext.TRANS_URL, url);
        // put character encoding of request to message context
        // in order to reuse it during the whole process.
        String requestEncoding;
        try {
            requestEncoding = (String) requestMsg.getProperty(SOAPMessage.CHARACTER_SET_ENCODING);
            if (requestEncoding != null) {
                msgContext.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, requestEncoding);
            }
        } catch (SOAPException e1) {
        }
        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 (log.isDebugEnabled()) {
                t1 = System.currentTimeMillis();
            }
            /**
             **************************
             */
            if (isDebug) {
                log.debug("Invoking Axis Engine.");
            // here we run the message by the engine
            }
            engine.invoke(msgContext);
            if (isDebug) {
                log.debug("Return from Axis Engine.");
            }
            if (log.isDebugEnabled())
                t2 = System.currentTimeMillis();
            responseMsg = msgContext.getResponseMessage();
        // We used to throw exceptions on null response messages.
        // They are actually OK in certain situations (asynchronous
        // services), so fall through here and return an ACCEPTED
        // status code below.  Might want to install a configurable
        // error check for this later.
        } catch (AxisFault fault) {
            // log and sanitize
            processAxisFault(fault);
            configureResponseFromAxisFault(res, fault);
            responseMsg = msgContext.getResponseMessage();
            if (responseMsg == null) {
                responseMsg = new Message(fault);
                ((org.apache.axis.SOAPPart) responseMsg.getSOAPPart()).getMessage().setMessageContext(msgContext);
            }
        } catch (Throwable t) {
            ExceptionUtil.rethrowIfNecessary(t);
            if (t instanceof InvocationTargetException)
                t = ((InvocationTargetException) t).getTargetException();
            // Exception
            if (t instanceof Exception) {
                Exception e = (Exception) t;
                // other exceptions are internal trouble
                responseMsg = msgContext.getResponseMessage();
                res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                responseMsg = convertExceptionToAxisFault(e, responseMsg);
                ((org.apache.axis.SOAPPart) responseMsg.getSOAPPart()).getMessage().setMessageContext(msgContext);
            } else // throwable
            {
                logException(t);
                // other exceptions are internal trouble
                responseMsg = msgContext.getResponseMessage();
                res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                responseMsg = new Message(new AxisFault(t.toString(), t));
                ((org.apache.axis.SOAPPart) responseMsg.getSOAPPart()).getMessage().setMessageContext(msgContext);
            }
        }
    } catch (AxisFault fault) {
        processAxisFault(fault);
        configureResponseFromAxisFault(res, fault);
        responseMsg = msgContext.getResponseMessage();
        if (responseMsg == null) {
            responseMsg = new Message(fault);
            ((org.apache.axis.SOAPPart) responseMsg.getSOAPPart()).getMessage().setMessageContext(msgContext);
        }
    } finally {
        IOUtil.closeEL(is);
    }
    if (log.isDebugEnabled()) {
        t3 = System.currentTimeMillis();
    }
    /**
     ********************************
     */
    if (responseMsg != null) {
        // Transfer MIME headers to HTTP headers for response message.
        MimeHeaders responseMimeHeaders = responseMsg.getMimeHeaders();
        for (Iterator i = responseMimeHeaders.getAllHeaders(); i.hasNext(); ) {
            MimeHeader responseMimeHeader = (MimeHeader) i.next();
            res.addHeader(responseMimeHeader.getName(), responseMimeHeader.getValue());
        }
        // synchronize the character encoding of request and response
        String responseEncoding = (String) msgContext.getProperty(SOAPMessage.CHARACTER_SET_ENCODING);
        if (responseEncoding != null) {
            try {
                responseMsg.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, responseEncoding);
            } catch (SOAPException e) {
            }
        }
        // determine content type from message response
        contentType = responseMsg.getContentType(msgContext.getSOAPConstants());
        sendResponse(contentType, res, responseMsg);
    } else {
        // No content, so just indicate accepted
        res.setStatus(202);
    }
    if (isDebug) {
        log.debug("Response sent.");
        log.debug("Exit: doPost()");
    }
    if (log.isDebugEnabled()) {
        t4 = System.currentTimeMillis();
        log.debug("axisServlet.doPost: " + soapAction + " pre=" + (t1 - t0) + " invoke=" + (t2 - t1) + " post=" + (t3 - t2) + " send=" + (t4 - t3) + " " + msgContext.getTargetService() + "." + ((msgContext.getOperation() == null) ? "" : msgContext.getOperation().getName()));
    }
}
Also used : AxisFault(org.apache.axis.AxisFault) Enumeration(java.util.Enumeration) Message(org.apache.axis.Message) SOAPMessage(javax.xml.soap.SOAPMessage) InputStream(java.io.InputStream) AxisHttpSession(org.apache.axis.transport.http.AxisHttpSession) InvocationTargetException(java.lang.reflect.InvocationTargetException) ServletException(javax.servlet.ServletException) SOAPException(javax.xml.soap.SOAPException) PageServletException(lucee.runtime.exp.PageServletException) PageException(lucee.runtime.exp.PageException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ClassException(lucee.commons.lang.ClassException) ConfigurationException(org.apache.axis.ConfigurationException) IOException(java.io.IOException) ServletException(javax.servlet.ServletException) PageServletException(lucee.runtime.exp.PageServletException) MimeHeaders(javax.xml.soap.MimeHeaders) MimeHeader(javax.xml.soap.MimeHeader) SOAPException(javax.xml.soap.SOAPException) Iterator(java.util.Iterator) MessageContext(org.apache.axis.MessageContext) AxisEngine(org.apache.axis.AxisEngine)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Enumeration (java.util.Enumeration)1 Iterator (java.util.Iterator)1 ServletException (javax.servlet.ServletException)1 MimeHeader (javax.xml.soap.MimeHeader)1 MimeHeaders (javax.xml.soap.MimeHeaders)1 SOAPException (javax.xml.soap.SOAPException)1 SOAPMessage (javax.xml.soap.SOAPMessage)1 ClassException (lucee.commons.lang.ClassException)1 PageException (lucee.runtime.exp.PageException)1 PageServletException (lucee.runtime.exp.PageServletException)1 AxisEngine (org.apache.axis.AxisEngine)1 AxisFault (org.apache.axis.AxisFault)1 ConfigurationException (org.apache.axis.ConfigurationException)1 Message (org.apache.axis.Message)1 MessageContext (org.apache.axis.MessageContext)1 AxisHttpSession (org.apache.axis.transport.http.AxisHttpSession)1