Package org.apache.axis

Examples of org.apache.axis.MessageContext


   this method save path to the config files in session
   */
  private void getPATH()
  {
    String PATH;
    MessageContext mc = MessageContext.getCurrentContext();
    PATH = (String)((HttpServlet)mc.getProperty(HTTPConstants.MC_HTTP_SERVLET)).getServletContext().getRealPath("/") + "WEB-INF/";
    session.set("PATH", PATH);
  }
View Full Code Here


      AxisService service = ( AxisService ) lookup( AxisService.ROLE );
      AxisServer server = service.getAxisServer();
   
      LocalTransport transport = new LocalTransport(server);
   
      MessageContext msgContext = new MessageContext(server);
      msgContext.setSOAPConstants(SOAPConstants.SOAP12_CONSTANTS);
      msgContext.setEncodingStyle(SOAPConstants.SOAP12_CONSTANTS.getEncodingURI());
   
      msgContext.setTargetService( serviceName );
       
      // During a real invocation this is set by the handler, however we
      // need to set it hear to get the wsdl generation working.
      msgContext.setProperty( MessageContext.TRANS_URL,
                  services + serviceName );
      server.generateWSDL( msgContext );       
       
      // another one of those undocumented "features"
      Document doc = (Document) msgContext.getProperty( "WSDL" );
       
        DOMReader xmlReader = new DOMReader();
        return xmlReader.read(doc);
    }
View Full Code Here

            (HttpServletResponse) objectModel.get(HttpEnvironment.HTTP_RESPONSE_OBJECT);
        ServletContext con =
            (ServletContext) objectModel.get(HttpEnvironment.HTTP_SERVLET_CONTEXT);

        String soapAction = null;
        MessageContext msgContext = null;
        Message responseMsg = null;

        try
        {
            res.setBufferSize(1024 * 8); // provide performance boost.

            // Get message context w/ various properties set
            msgContext = m_server.createMessageContext(req, res, con);

            // Get request message
            Message requestMsg =
                new Message(
                    req.getInputStream(), false,
                    req.getHeader(HTTPConstants.HEADER_CONTENT_TYPE),
                    req.getHeader(HTTPConstants.HEADER_CONTENT_LOCATION)
                );

            if (getLogger().isDebugEnabled())
            {
                getLogger().debug("Request message:\n" + messageToString(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.
                msgContext.setSession(new AxisHttpSession(req));

                // Invoke the Axis engine...
                if(getLogger().isDebugEnabled())
                {
                    getLogger().debug("Invoking Axis Engine");
                }

                m_server.invoke(msgContext);

                if(getLogger().isDebugEnabled())
                {
                    getLogger().debug("Return from Axis Engine");
                }

                responseMsg = msgContext.getResponseMessage();
            }
            catch (AxisFault e)
            {
                if (getLogger().isErrorEnabled())
                {
                    getLogger().error("Axis Fault", 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\"");
                }

                res.setStatus(status);
                responseMsg = new Message(e);
            }
            catch (Exception e)
            {
                if (getLogger().isErrorEnabled())
                {
                    getLogger().error("Error during SOAP call", e);
                }

                res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                responseMsg = new Message(AxisFault.makeFault(e));
            }
        }
        catch (AxisFault fault)
        {
            if (getLogger().isErrorEnabled())
            {
                getLogger().error("Axis fault occured while perforing request", fault);
            }

            responseMsg = new Message(fault);
        }
        catch (Exception e)
        {
            throw new ProcessingException("Exception thrown while performing request", e);
        }

        // Send response back
        if (responseMsg != null)
        {
            if (getLogger().isDebugEnabled())
            {
                getLogger().debug("Sending response:\n" + messageToString(responseMsg));
            }

            sendResponse(getProtocolVersion(req), msgContext.getSOAPConstants(), res, responseMsg);
        }

        if (getLogger().isDebugEnabled())
        {
            getLogger().debug("AxisRPCReader.generate() complete");
View Full Code Here

    private final Object rpc(String method, Object[] parms)
        throws AxisFault, SAXException
    {

        // Create the message context
        MessageContext msgContext = new MessageContext(engine);

        // Set the dispatch either by SOAPAction or methodNS
        String methodNS = null;
        msgContext.setTargetService(SOAPAction);

        // Construct the soap request
        SOAPEnvelope envelope = new SOAPEnvelope();
        msgContext.setRequestMessage(new Message(envelope));
        RPCElement body = new RPCElement(methodNS, method, parms);
        envelope.addBodyElement(body);

        // Invoke the Axis engine
        engine.invoke(msgContext);

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

        // Extract the body from the envelope
        body = (RPCElement)envelope.getFirstBody();
View Full Code Here

            for (int i = 0; i < reps; i++) {
                try {
                    String ret = (String)call.invoke("hello", null);
                    if (ret == null) {
                        MessageContext msgContext = call.getMessageContext();
                        String respStr = msgContext.getResponseMessage().getSOAPPartAsString();

                        String reqStr = msgContext.getRequestMessage().getSOAPPartAsString();
                        String nullStr = "Got null response! Request message:\r\n" + reqStr + "\r\n\r\n" +
                                  "Response message:\r\n" + respStr;
                        log.fatal(nullStr);
                        setError(new Exception(nullStr));
                    } else if (!ret.equals(TestService.MESSAGE)) {
View Full Code Here

            if (server == null) init();
            targetServer = server;
        }

        // Define a new messageContext per request
        MessageContext serverContext = new MessageContext(targetServer);

        // copy the request, and force its format to String in order to
        // exercise the serializers.
        String msgStr = clientContext.getRequestMessage().getSOAPPartAsString();

        if (log.isDebugEnabled()) {
            log.debug(Messages.getMessage("sendingXML00", "LocalSender"));
            log.debug(msgStr);
        }

        serverContext.setRequestMessage(new Message(msgStr));
        serverContext.setTransportName("local");

        // Also copy authentication info if present
        String user = clientContext.getUsername();
        if (user != null) {
            serverContext.setUsername(user);
            String pass = clientContext.getPassword();
            if (pass != null)
                serverContext.setPassword(pass);
        }

        // set the realpath if possible
        String transURL = clientContext.getStrProp(MessageContext.TRANS_URL);
        if (transURL != null) {
            try {
                URL url = new URL(transURL);
                String file = url.getFile();
                if (file.length()>0 && file.charAt(0)=='/') file = file.substring(1);
                serverContext.setProperty(Constants.MC_REALPATH, file);
               
                // This enables "local:///AdminService" and the like to work.
                serverContext.setTargetService(file);
            } catch (Exception e) {
                throw AxisFault.makeFault(e);
            }
        }

        // If we've been given an explicit "remote" service to invoke,
        // use it. (Note that right now this overrides the setting above;
        // is this the correct precedence?)
        String remoteService = clientContext.getStrProp(LocalTransport.REMOTE_SERVICE);
        if (remoteService != null)
            serverContext.setTargetService(remoteService);

        // invoke the request
        try {
            targetServer.invoke(serverContext);
        } catch (AxisFault fault) {
            Message respMsg = serverContext.getResponseMessage();
            if (respMsg == null) {
                respMsg = new Message(fault);
                serverContext.setResponseMessage(respMsg);
            } else {
                SOAPFault faultEl = new SOAPFault(fault);
                SOAPEnvelope env = respMsg.getSOAPEnvelope();
                env.clearBody();
                env.addBodyElement(faultEl);
            }
        }

        // copy back the response, and force its format to String in order to
        // exercise the deserializers.
        clientContext.setResponseMessage(serverContext.getResponseMessage());
        //clientContext.getResponseMessage().getAsString();

        if (log.isDebugEnabled()) {
            log.debug("Exit: LocalSender::invoke");
        }
View Full Code Here

    public TestAttributes(String name) {
        super(name);
    }

    public void testBean () throws Exception {
        MessageContext msgContext = new MessageContext(new AxisServer(new BasicServerConfig()));
        SOAPEnvelope msg = new SOAPEnvelope();

        // Create bean with data
        AttributeBean bean = new AttributeBean();
        bean.setAge(35);
View Full Code Here

   
    private void checkSimpleBeanRoundTrip(String text, float temp) throws Exception {
        SimpleBean bean = new SimpleBean(text);
        bean.temp = temp;

        MessageContext msgContext = new MessageContext(new AxisServer(new BasicServerConfig()));
        SOAPEnvelope msg = new SOAPEnvelope();

        RPCParam arg = new RPCParam("", "simple", bean);
        RPCElement body = new RPCElement("urn:myNamespace", "method1", new Object[]{ arg });
        msg.addBodyElement(body);
View Full Code Here

        // setup
        AxisEngine engine = new AxisServer(provider);
        engine.init();

        // create a message in context
        MessageContext msgContext = new MessageContext(engine);
        Message message = new Message(request);
        message.setMessageContext(msgContext);

        // ensure that the message is parsed
        SOAPEnvelope envelope = message.getSOAPEnvelope();
        RPCElement body = (RPCElement) envelope.getFirstBody();

        // This is not necessarily true anymore...
        //assertEquals("Namespace does not equal the message context target service.", namespace, msgContext.getTargetService());

        // verify the service is set
        assertEquals("The target is not the same as the message context service handler", target, msgContext.getService());
    }
View Full Code Here

     */
    public Element[] AdminService(Element [] xml)
        throws Exception
    {
        log.debug("Enter: Admin::AdminService");
        MessageContext msgContext = MessageContext.getCurrentContext();
        Document doc = process( msgContext, xml[0] );
        Element[] result = new Element[1];
        result[0] = doc.getDocumentElement();
        log.debug("Exit: Admin::AdminService");
        return result;
View Full Code Here

TOP

Related Classes of org.apache.axis.MessageContext

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.