Package org.apache.axis

Examples of org.apache.axis.Message


     *
     * @throws IOException
     */
    private InputStream readFromSocket(Socket sock, MessageContext msgContext,InputStream  inp, Hashtable headers )
            throws IOException {
        Message outMsg = null;
        byte b;
        int len = 0;
        int colonIndex = -1;
        boolean headersOnly= false;
        if(null != headers){
            headersOnly= true;
        }else{
            headers=  new Hashtable();
        }
        String name, value;
        String statusMessage = "";
        int returnCode = 0;
        if(null == inp) inp = new BufferedInputStream(sock.getInputStream());

        // Should help performance. Temporary fix only till its all stream oriented.
        // Need to add logic for getting the version # and the return code
        // but that's for tomorrow!

        /* Logic to read HTTP response headers */
        boolean readTooMuch = false;

        b = 0;
        for (ByteArrayOutputStream buf = new ByteArrayOutputStream(4097); ;) {
            if (!readTooMuch) {
                b = (byte) inp.read();
            }
            if (b == -1) {
                break;
            }
            readTooMuch = false;
            if ((b != '\r') && (b != '\n')) {
                if ((b == ':') && (colonIndex == -1)) {
                    colonIndex = len;
                }
                len++;
                buf.write(b);
            } else if (b == '\r') {
                continue;
            } else {    // b== '\n'
                if (len == 0) {
                    break;
                }
                b = (byte) inp.read();
                readTooMuch = true;

                // A space or tab at the begining of a line means the header continues.
                if ((b == ' ') || (b == '\t')) {
                    continue;
                }
                buf.close();
                byte[] hdata = buf.toByteArray();
                buf.reset();
                if (colonIndex != -1) {
                    name =
                            new String(hdata, 0, colonIndex,
                                    HTTPConstants.HEADER_DEFAULT_CHAR_ENCODING);
                    value =
                            new String(hdata, colonIndex + 1, len - 1 - colonIndex,
                                    HTTPConstants.HEADER_DEFAULT_CHAR_ENCODING);
                    colonIndex = -1;
                } else {

                    name =
                            new String(hdata, 0, len,
                                    HTTPConstants.HEADER_DEFAULT_CHAR_ENCODING);
                    value = "";
                }
                if (log.isDebugEnabled()) {
                    log.debug(name + value);
                }
                if (msgContext.getProperty(HTTPConstants.MC_HTTP_STATUS_CODE)
                        == null) {

                    // Reader status code
                    int start = name.indexOf(' ') + 1;
                    String tmp = name.substring(start).trim();
                    int end = tmp.indexOf(' ');

                    if (end != -1) {
                        tmp = tmp.substring(0, end);
                    }
                    returnCode = Integer.parseInt(tmp);
                    msgContext.setProperty(HTTPConstants.MC_HTTP_STATUS_CODE,
                            new Integer(returnCode));
                    statusMessage = name.substring(start + end + 1);
                    msgContext.setProperty(HTTPConstants.MC_HTTP_STATUS_MESSAGE,
                            statusMessage);
                } else {
                    headers.put(name.toLowerCase(), value);
                }
                len = 0;
            }
        }

        if(headersOnly){
           return inp;
        }

        /* All HTTP headers have been read. */
        String contentType =
                (String) headers
                .get(HTTPConstants.HEADER_CONTENT_TYPE.toLowerCase());

        contentType = (null == contentType)
                ? null
                : contentType.trim();
        if ((returnCode > 199) && (returnCode < 300)) {
            // SOAP return is OK - so fall through
        } else if ((contentType != null) && !contentType.startsWith("text/html")
                && ((returnCode > 499) && (returnCode < 600))) {
            // SOAP Fault should be in here - so fall through
        } else {
            // Unknown return code - so wrap up the content into a
            // SOAP Fault.
            ByteArrayOutputStream buf = new ByteArrayOutputStream(4097);

            while (-1 != (b = (byte) inp.read())) {
                buf.write(b);
            }
            AxisFault fault = new AxisFault("HTTP", "(" + returnCode + ")" + statusMessage, null, null);

            fault.setFaultDetailString(Messages.getMessage("return01",
                    "" + returnCode, buf.toString()));
            throw fault;
        }
        if (b != -1) {    // more data than just headers.
            String contentLocation =
                    (String) headers
                    .get(HTTPConstants.HEADER_CONTENT_LOCATION.toLowerCase());

            contentLocation = (null == contentLocation)
                    ? null
                    : contentLocation.trim();

            String contentLength =
                    (String) headers
                    .get(HTTPConstants.HEADER_CONTENT_LENGTH.toLowerCase());

            contentLength = (null == contentLength)
                    ? null
                    : contentLength.trim();

            String transferEncoding =
                    (String) headers
                    .get(HTTPConstants.HEADER_TRANSFER_ENCODING.toLowerCase());
            if (null != transferEncoding
                    && transferEncoding.trim()
                    .equals(HTTPConstants.HEADER_TRANSFER_ENCODING_CHUNKED)) {
                inp = new ChunkedInputStream(inp);
            }


            outMsg = new Message( new SocketInputStream(inp, sock), false, contentType,
                    contentLocation);
            outMsg.setMessageType(Message.RESPONSE);
            msgContext.setResponseMessage(outMsg);
            if (log.isDebugEnabled()) {
                if (null == contentLength) {
                    log.debug("\n"
                            + Messages.getMessage("no00", "Content-Length"));
                }
                log.debug("\n" + Messages.getMessage("xmlRecd00"));
                log.debug("-----------------------------------------------");
                log.debug((String) outMsg.getSOAPPartAsString());
            }
        }

        // if we are maintaining session state,
        // handle cookies (if any)
View Full Code Here


        MessageContext msgContext = context.getMessageContext();

        // Figure out if we should be looking for out params or in params
        // (i.e. is this message a response?)
        Message msg = msgContext.getCurrentMessage();
        boolean isResponse = ((msg != null) &&
                              Message.RESPONSE.equals(msg.getMessageType()));

        // We're going to need this below, so create one.
        RPCHandler rpcHandler = new RPCHandler(this, isResponse);

        if (operations != null && !msgContext.isClient()) {
View Full Code Here

                endElement();
            }
            return;
        }

        Message msg= getCurrentMessage();
        if(null != msg){
            //Get attachments. returns null if no attachment support.
            Attachments attachments= getCurrentMessage().getAttachmentsImpl();

            if( null != attachments && attachments.isAttachment(value)){
View Full Code Here

            "</SOAP-ENV:Envelope>";

        ByteArrayInputStream istream =
            new ByteArrayInputStream(msgtxt.getBytes());

        Message msg = new Message(istream, false);
        msgContext.setRequestMessage(msg);
        engine.invoke(msgContext);
        Message respMsg = msgContext.getResponseMessage();
        if (respMsg != null) {
            response.setContentType("text/xml");
            writer.println(respMsg.getSOAPPartAsString());
        } else {
            //TODO: error code
            writer.println("<p>" +
                   Messages.getMessage("noResponse01") +
                           "</p>");
View Full Code Here

            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();
        }
View Full Code Here

                          methodNS + "\">";
        String bodyElemFoot = "</m:" + method + ">";
        // Construct the soap request
        String msgStr = header + bodyElemHead + bodyStr +
                        bodyElemFoot + footer;
        msgContext.setRequestMessage(new Message(msgStr));
        msgContext.setTypeMappingRegistry(engine.getTypeMappingRegistry());

        // Invoke the Axis engine
        try {
            engine.invoke(msgContext);
        } catch (AxisFault af) {
            return af;
        }

        // Extract the response Envelope
        Message message = msgContext.getResponseMessage();
        assertNotNull("Response message was null!", message);
        SOAPEnvelope envelope = (SOAPEnvelope)message.getSOAPEnvelope();
        assertNotNull("SOAP envelope was null", envelope);

        // Extract the body from the envelope
        RPCElement body = (RPCElement)envelope.getFirstBody();
        assertNotNull("SOAP body was null", body);
View Full Code Here

    * Extract the fault string from the Soap Response
    *
    **/
    String getFaultString(MessageContext msgContext) {
      String stRetval = null;
      Message message = msgContext.getResponseMessage();
      try {
          if (message != null) {
            SOAPBody oBody  = message.getSOAPEnvelope().getBody();
            stRetval = oBody.getFault().getFaultString();
          }
      }
      catch (javax.xml.soap.SOAPException e) {
          assertTrue("Unforseen soap exception", false);
View Full Code Here

            if ( !(params[0] instanceof SOAPEnvelope) )
                for ( i = 0 ; i < params.length ; i++ )
                    env.addBodyElement( (SOAPBodyElement) params[i] );

            Message msg = new Message( env );
            setRequestMessage(msg);

            invoke();
            if (getAsyncStatus() != ASYNC_READY) return null;
            msg = msgContext.getResponseMessage();
            if (msg == null) {
              if (FAULT_ON_NO_RESPONSE) {
                throw new AxisFault(Messages.getMessage("nullResponse00"));
              } else {
                return null;
              }
            }
            env = msg.getSOAPEnvelope();
            return( env.getBodyElements() );
        }


        if ( operationName == null )
View Full Code Here

     * @exception AxisFault
     */
    public SOAPEnvelope invoke(SOAPEnvelope env)
                                  throws java.rmi.RemoteException {
        try {
            Message msg = null ;

            msg = new Message( env );
            setRequestMessage( msg );
            invoke();
            if (getAsyncStatus() != ASYNC_READY) return null;
            msg = msgContext.getResponseMessage();
            if (msg == null) {
              if (this.FAULT_ON_NO_RESPONSE) {
                throw new AxisFault(Messages.getMessage("nullResponse00"));
              } else {
                return null;
              }
            }
            return( msg.getSOAPEnvelope() );
        }
        catch( Exception exp ) {
            if ( exp instanceof AxisFault ) throw (AxisFault) exp ;

            entLog.info(Messages.getMessage("toAxisFault00"), exp);
View Full Code Here

            log.error(Messages.getMessage("mustSpecifyReturnType"));
        }

        SOAPEnvelope         reqEnv = new SOAPEnvelope(msgContext.getSOAPConstants());
        SOAPEnvelope         resEnv = null ;
        Message              reqMsg = new Message( reqEnv );
        Message              resMsg = null ;
        Vector               resArgs = null ;
        Object               result = null ;

        // Clear the output params
        outParams = new HashMap();
        outParamsList = new ArrayList();

        // Set both the envelope and the RPCElement encoding styles
        try {
            body.setEncodingStyle(getEncodingStyle());

            setRequestMessage(reqMsg);

            reqEnv.addBodyElement(body);
            reqEnv.setMessageType(Message.REQUEST);

            invoke();
        } catch (Exception e) {
            entLog.info(Messages.getMessage("toAxisFault00"), e);
            throw AxisFault.makeFault(e);
        }

        if (getAsyncStatus() != ASYNC_READY) return null;
       
        resMsg = msgContext.getResponseMessage();

        if (resMsg == null) {
          if (FAULT_ON_NO_RESPONSE) {
            throw new AxisFault(Messages.getMessage("nullResponse00"));
          } else {
            return null;
          }
        }

        resEnv = (SOAPEnvelope)resMsg.getSOAPEnvelope();
        SOAPBodyElement bodyEl = resEnv.getFirstBody();
        if (bodyEl instanceof RPCElement) {
            try {
                resArgs = ((RPCElement) bodyEl).getParams();
            } catch (Exception e) {
View Full Code Here

TOP

Related Classes of org.apache.axis.Message

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.