Package org.apache.servicemix.soap.api

Examples of org.apache.servicemix.soap.api.Message


    private StaxOutInterceptor interceptor = new StaxOutInterceptor();
   
    public void testNullInput() {
        try {
            Message msg = new MessageImpl();
            interceptor.handleMessage(msg);
            fail("Interceptor should have thrown an NPE");
        } catch (NullPointerException e) {
        }
    }
View Full Code Here


    public void testValidInputWithEmptyBody() throws Exception {
        String str = "<s:Envelope xmlns:s='http://www.w3.org/2003/05/soap-envelope'>" +
                     "  <s:Body>" +
                     "  </s:Body>" +
                     "</s:Envelope>";
        Message msg = new MessageImpl();
        InputStream is = new ByteArrayInputStream(str.getBytes());
        msg.setContent(InputStream.class, is);
        new StaxInInterceptor().handleMessage(msg);
        interceptor.handleMessage(msg);
       
        assertNotNull(msg.get(SoapVersion.class));
        assertEquals("s", msg.get(SoapVersion.class).getPrefix());
        assertEquals(0, msg.getSoapHeaders().size());
        assertNull(msg.getContent(XMLStreamReader.class));
        //assertNotNull(msg.getContent(XMLStreamReader.class));
        //assertEquals(XMLStreamConstants.END_ELEMENT, msg.getContent(XMLStreamReader.class).getEventType());
        //assertEquals(msg.get(SoapVersion.class).getBody(), msg.getContent(XMLStreamReader.class).getName());
    }
View Full Code Here

        } catch (NullPointerException e) {
        }
    }
   
    public void testValidInput() throws Exception {
        Message msg = new MessageImpl();
        msg.setContent(OutputStream.class, new ByteArrayOutputStream());
        PhaseInterceptorChain chain = new PhaseInterceptorChain();
        chain.add(interceptor);
        chain.doIntercept(msg);
        XMLStreamWriter writer = msg.getContent(XMLStreamWriter.class);
        assertNotNull(writer);
    }
View Full Code Here

        response.setStatus(HttpServletResponse.SC_ACCEPTED);
    }

    public void sendOut(MessageExchange exchange, NormalizedMessage outMsg, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
        Message in = (Message) request.getAttribute(Message.class.getName());
        Message msg = binding.createMessage(in);
        msg.setContent(OutputStream.class, response.getOutputStream());
        msg.setContent(MessageExchange.class, exchange);
        msg.setContent(NormalizedMessage.class, outMsg);
        msg.put(SoapVersion.class, in.get(SoapVersion.class));
        msg.put(JbiConstants.USE_JBI_WRAPPER, useJbiWrapper);
        InterceptorChain phase = getChain(Phase.ServerOut);
        phase.doIntercept(msg);
        // TODO: handle http headers: Content-Type, ...
    }
View Full Code Here

    }

    public void sendError(MessageExchange exchange, Exception error, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        Message in = (Message) request.getAttribute(Message.class.getName());
        Message msg = binding.createMessage(in);
        msg.setContent(OutputStream.class, response.getOutputStream());
        msg.setContent(MessageExchange.class, exchange);
        msg.put(SoapVersion.class, in.get(SoapVersion.class));
        msg.put(JbiConstants.USE_JBI_WRAPPER, useJbiWrapper);
        InterceptorChain phase = getChain(Phase.ServerOutFault);
        SoapFault soapFault;
        if (error instanceof SoapFault) {
            soapFault = (SoapFault) error;
        } else {
            soapFault = new SoapFault(error);
        }
        msg.setContent(Exception.class, soapFault);
        phase.doIntercept(msg);
    }
View Full Code Here

    }

    public void sendFault(MessageExchange exchange, Fault fault, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        Message in = (Message) request.getAttribute(Message.class.getName());
        Message msg = binding.createMessage(in);
        msg.setContent(OutputStream.class, response.getOutputStream());
        msg.setContent(MessageExchange.class, exchange);
        msg.setContent(NormalizedMessage.class, fault);
        msg.put(SoapVersion.class, in.get(SoapVersion.class));
        msg.put(JbiConstants.USE_JBI_WRAPPER, useJbiWrapper);
        InterceptorChain phase = getChain(Phase.ServerOutFault);
        QName code = (QName) fault.getProperty("org.apache.servicemix.soap.fault.code");
        String reason = (String) fault.getProperty("org.apache.servicemix.soap.fault.reason");
        SoapFault soapFault = new SoapFault(code, reason, null, null, fault.getContent());
        msg.setContent(Exception.class, soapFault);
        phase.doIntercept(msg);
        // TODO: handle http headers: Content-Type, ...
    }
View Full Code Here

    public void setStyle(Style style) {
        this.style = style;
    }

    public Message createMessage() {
        Message msg = super.createMessage();
        if (msg.get(SoapVersion.class) == null && soapVersion != null) {
            msg.put(SoapVersion.class, soapVersion);
        }
        return msg;
    }
View Full Code Here

        }
        return msg;
    }
   
    public Message createMessage(Message request) {
        Message msg = super.createMessage(request);
        if (msg.get(SoapVersion.class) == null && request.get(SoapVersion.class) != null) {
            msg.put(SoapVersion.class, request.get(SoapVersion.class));
        }
        if (msg.get(SoapVersion.class) == null && soapVersion != null) {
            msg.put(SoapVersion.class, soapVersion);
        }
        return msg;
    }
View Full Code Here

   
    public void createRequest(final MessageExchange exchange,
                              final NormalizedMessage inMsg,
                              final SmxHttpExchange httpExchange) throws Exception {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        Message msg = binding.createMessage();
        msg.put(JbiConstants.USE_JBI_WRAPPER, useJbiWrapper);
        msg.setContent(MessageExchange.class, exchange);
        msg.setContent(NormalizedMessage.class, inMsg);
        msg.setContent(OutputStream.class, baos);
        exchange.setProperty(Message.class.getName(), msg);

        InterceptorChain phaseOut = getChain(Phase.ClientOut);
        phaseOut.doIntercept(msg);
        httpExchange.setMethod(HttpMethods.POST);
        httpExchange.setURL(baseUrl);
        httpExchange.setRequestContent(new ByteArrayBuffer(baos.toByteArray()));
       
        for (String header : msg.getTransportHeaders().keySet()) {
            httpExchange.setRequestHeader(header, msg.getTransportHeaders().get(header));
        }
        if (soapAction != null) {
            httpExchange.setRequestHeader(SoapConstants.SOAP_ACTION_HEADER, soapAction);
        }
        /*
 
View Full Code Here

        */       
        // TODO: use streaming when appropriate (?)
    }

    public void handleResponse(MessageExchange exchange, SmxHttpExchange httpExchange) throws Exception {
        Message req = (Message) exchange.getProperty(Message.class.getName());
        exchange.setProperty(Message.class.getName(), null);
        Message msg = binding.createMessage(req);
        msg.put(JbiConstants.USE_JBI_WRAPPER, useJbiWrapper);
        msg.setContent(MessageExchange.class, exchange);
        msg.setContent(InputStream.class, new ByteArrayInputStream(httpExchange.getResponseData()));
        msg.put(StaxInInterceptor.ENCODING, httpExchange.getResponseEncoding());
        InterceptorChain phaseOut = getChain(Phase.ClientIn);
        phaseOut.doIntercept(msg);
        // TODO: Retrieve headers ?
    }
View Full Code Here

TOP

Related Classes of org.apache.servicemix.soap.api.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.