Package org.codehaus.xfire

Examples of org.codehaus.xfire.MessageContext


     */
    protected Document invokeService(String service, String document)
            throws Exception
    {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        MessageContext context = new MessageContext();
        context.setXFire(getXFire());
        context.setProperty(Channel.BACKCHANNEL_URI, out);

        if (service != null)
            context.setService(getServiceRegistry().getService(service));
       
        InputStream stream = getResourceAsStream(document);
        InMessage msg = new InMessage(STAXUtils.createXMLStreamReader(stream, "UTF-8",null));

        Transport t = getXFire().getTransportManager().getTransport(LocalTransport.BINDING_ID);
View Full Code Here


                }
            }
            else
            {
                // Send a response from the Channel to the client
                MessageContext oldContext = (MessageContext)context.getProperty( OLD_CONTEXT );

                Channel channel = oldContext.getOutMessage().getChannel();
                sendViaNewChannel( context, oldContext, message, channel, (String)context.getProperty( SENDER_URI ) );
            }
        }
        else
        {
            // Send a request from the channel to the service
            MessageContext receivingContext = new MessageContext();
            receivingContext.setXFire( context.getXFire() );
            receivingContext.setService( getService( context.getXFire(), message.getUri() ) );
            receivingContext.setProperty( OLD_CONTEXT, context );
            receivingContext.setProperty( SENDER_URI, getUri() );
            receivingContext.setSession( session );

            final Channel channel;
            final String uri = message.getUri();
            try
            {
View Full Code Here

        System.out.println("Received message");
        JMSTransport transport = (JMSTransport) getTransport();
        try
        {
            String text = ((TextMessage) message).getText();
            MessageContext context = new MessageContext();
            context.setId(message.getJMSCorrelationID());
           
            String destName = getDestinationName(getUri());
            if (selector.equals(""))
            {
                context.setService(((JMSTransport) getTransport()).getXFire().getServiceRegistry()
                                .getService(destName));
            }
            else
            {
                context.setService(((JMSTransport) getTransport()).getXFire().getServiceRegistry()
                                .getService(selector));
            }
           
            context.setProperty(REPLY_TO, message.getJMSReplyTo());
            String srcID = message.getStringProperty("Source");
            System.out.println("onMessage -> Source ID: " + srcID + ", Message ID: " + message.getJMSMessageID());

            context.setProperty("Destination", srcID);

            context.setXFire(((JMSTransport) getTransport()).getXFire());

            XMLStreamReader reader = STAXUtils.createXMLStreamReader(new StringReader(text), context);
            InMessage in = new InMessage(reader, getUri());

            receive(context, in);
View Full Code Here

    }
   
    public void open()
        throws IOException, XFireException
    {
        MessageContext context = getMessageContext();

        createClient();
       
        // Pull the HttpState from the context if possible. Otherwise create
        // one in the ThreadLocal
        state = getHttpState();
       
        postMethod = new PostMethod(getUri());
       
        if (Boolean.valueOf((String) context.getContextualProperty(DISABLE_KEEP_ALIVE)).booleanValue()) {
            postMethod.setRequestHeader("Connection", "Close");
        }

        // set the username and password if present
        String username = (String) context.getContextualProperty(Channel.USERNAME);
        if (username != null)
        {
           
            client.getParams().setAuthenticationPreemptive(true);
           
            String password = (String) context.getContextualProperty(Channel.PASSWORD);
           
            state.setCredentials(AuthScope.ANY,  getCredentials(username, password));
                       
        }
       
        if (getSoapAction() != null)
        {
            postMethod.setRequestHeader("SOAPAction", getQuotedSoapAction());
        }
       
        OutMessage message = getMessage();
        boolean mtomEnabled = Boolean.valueOf((String) context.getContextualProperty(SoapConstants.MTOM_ENABLED)).booleanValue();
        Attachments atts = message.getAttachments();
       
        if (mtomEnabled || atts != null)
        {
            if (atts == null)
            {
                atts = new JavaMailAttachments();
                message.setAttachments(atts);
            }
           
            source = new OutMessageDataSource(context, message);
            DataHandler soapHandler = new DataHandler(source);
            atts.setSoapContentType(HttpChannel.getSoapMimeType(message, false));
            atts.setSoapMessage(new SimpleAttachment(source.getName(), soapHandler));
           
            postMethod.setRequestHeader("Content-Type", atts.getContentType());
        }
        else
        {
            postMethod.setRequestHeader("Content-Type", HttpChannel.getSoapMimeType(getMessage(), true));
        }
       
        if (isGzipResponseEnabled(context))
        {
            postMethod.setRequestHeader("Accept-Encoding", GZIP_CONTENT_ENCODING);
        }
       
        if (isGzipRequestEnabled(context))
        {
            postMethod.setRequestHeader("Content-Encoding", GZIP_CONTENT_ENCODING);
        }
       
        Map headersMap = (Map) context.getContextualProperty(HTTP_HEADERS);
        if (headersMap != null) {
      for (Iterator iter = headersMap.entrySet().iterator(); iter.hasNext();) {
        Map.Entry entry = (Entry) iter.next();
        postMethod.addRequestHeader(entry.getKey().toString(), entry.getValue().toString());
      }
View Full Code Here

       
    }
   
    private int getIntValue(String key, int defaultValue ){
        int result = defaultValue;
        MessageContext context = getMessageContext();
        String str = (String)context.getContextualProperty(key);
        if( str != null )
        {
            result = Integer.parseInt(str);
        }
        return result;
View Full Code Here

      return client;
    }
   
    protected synchronized void createClient()
    {
        MessageContext context = getMessageContext();
        client = (HttpClient) ((HttpChannel) getMessage().getChannel()).getProperty(HTTP_CLIENT);
        if (client == null)
        {
            client = new HttpClient();
            MultiThreadedHttpConnectionManager manager = new MultiThreadedHttpConnectionManager();
            HttpConnectionManagerParams conParams = new HttpConnectionManagerParams ();
            manager.setParams(conParams);
            int maxConnPerHost = getIntValue(MAX_CONN_PER_HOST, DEFAULT_MAX_CONN_PER_HOST);
            conParams.setDefaultMaxConnectionsPerHost(maxConnPerHost );
            int maxTotalConn  = getIntValue(MAX_TOTAL_CONNECTIONS, DEFAULT_MAX_TOTAL_CONNECTIONS);
            conParams.setMaxTotalConnections(maxTotalConn);
            client.setHttpConnectionManager(manager);
            ((HttpChannel) getMessage().getChannel()).setProperty(HTTP_CLIENT, client);

            HttpClientParams params = (HttpClientParams) context.getContextualProperty(HTTP_CLIENT_PARAMS);
            if (params == null)
            {
                params = client.getParams();
                client.getParams().setParameter("http.useragent", USER_AGENT);
                boolean disableEC = Boolean.valueOf((String)context.getContextualProperty(DISABLE_EXPECT_CONTINUE)).booleanValue();
                client.getParams().setBooleanParameter("http.protocol.expect-continue", !disableEC);
                client.getParams().setVersion(HttpVersion.HTTP_1_1);
                String timeoutStr = (String) context.getContextualProperty(HTTP_TIMEOUT);
                if (timeoutStr != null)
                {
                    client.getParams().setSoTimeout(Integer.parseInt(timeoutStr));
                }
            }
            else
            {
                client.setParams(params);
            }

            if (isNonProxyHost(getMessage().getUri(), context))
            {
                return;
            }
           
            // Setup the proxy settings
            String proxyHost = (String) context.getContextualProperty(HTTP_PROXY_HOST);
            if (proxyHost == null)
            {
                proxyHost = System.getProperty(HTTP_PROXY_HOST);
            }
           
            if (proxyHost != null)
            {
                String portS = (String) context.getContextualProperty(HTTP_PROXY_PORT);
                if (portS == null)
                {
                    portS = System.getProperty(HTTP_PROXY_PORT);
                }
                int port = 80;
                if (portS != null)
                    port = Integer.parseInt(portS);

                client.getHostConfiguration().setProxy(proxyHost, port);
               
                String proxyUser = (String) context.getContextualProperty(HTTP_PROXY_USER);
                String proxyPass = (String) context.getContextualProperty(HTTP_PROXY_PASS);
                if( proxyUser != null && proxyPass != null )
                  getHttpState().setProxyCredentials(AuthScope.ANY,getCredentials(proxyUser, proxyPass));
            }
        }
    }
View Full Code Here

    private RequestEntity getByteArrayRequestEntity()
        throws IOException, XFireException
    {
        OutMessage message = getMessage();
        MessageContext context = getMessageContext();
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        OutputStream os = bos;

        if (isGzipRequestEnabled(context))
        {
View Full Code Here

                          HttpServletRequest request,
                          HttpServletResponse response,
                          String service)
    {
        XFireHttpSession session = new XFireHttpSession(request);
        MessageContext context = new MessageContext();
        context.setXFire(getXFire());
        context.setSession(session);
        context.setService(getService(service));
        context.setProperty(HTTP_SERVLET_REQUEST, request);
        context.setProperty(HTTP_SERVLET_RESPONSE, response);
       
        if (servletContext != null)
            context.setProperty(HTTP_SERVLET_CONTEXT, servletContext);

        return context;
    }
View Full Code Here

            throws ServletException, IOException, UnsupportedEncodingException
    {
        response.setStatus(200);
        response.setBufferSize(1024 * 8);

        MessageContext context = createMessageContext(request, response, service);
        Channel channel = createChannel(context);
       
        String soapAction = getSoapAction(request);
        String contentType = request.getContentType();
        if (null == contentType)
View Full Code Here

TOP

Related Classes of org.codehaus.xfire.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.