Package org.apache.servicemix.soap.core

Examples of org.apache.servicemix.soap.core.MessageImpl


   
    public void testDeletePerson() throws Exception {
        PhaseInterceptorChain phaseIn = new PhaseInterceptorChain();
        phaseIn.add(binding.getInterceptors(Phase.ServerIn));
       
        Message message = new MessageImpl();
        message.put(Binding.class, binding);
        message.put(MessageExchangeFactory.class, new MockExchangeFactory());
        message.getTransportHeaders().put(HttpConstants.REQUEST_URI, "http://localhost:8192/person/312");
        message.getTransportHeaders().put(HttpConstants.REQUEST_METHOD, HttpConstants.METHOD_DELETE);
       
        phaseIn.doIntercept(message);

        MessageExchange me = message.getContent(MessageExchange.class);
        NormalizedMessage nm = message.getContent(NormalizedMessage.class);
        Document doc = DomUtil.parse(nm.getContent());

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DomUtil.getTransformerFactory().newTransformer().transform(nm.getContent(), new StreamResult(baos));
        log.info(baos.toString());
View Full Code Here


        Binding<?> binding = getBinding("HelloWorld-DOC.wsdl");
        PhaseInterceptorChain phaseIn = new PhaseInterceptorChain();
        phaseIn.add(binding.getInterceptors(Phase.ServerIn));
       
        Message msg = new MessageImpl();
        msg.put(Binding.class, binding);
        msg.setContent(InputStream.class, getClass().getResourceAsStream("HelloWorld-DOC-Input.xml"));
        msg.put(MessageExchangeFactory.class, new MockExchangeFactory());
        phaseIn.doIntercept(msg);

        NormalizedMessage nm = msg.getContent(NormalizedMessage.class);
        Document doc = DomUtil.parse(nm.getContent());
        baos = new ByteArrayOutputStream();
        DomUtil.getTransformerFactory().newTransformer().transform(nm.getContent(), new StreamResult(baos));
        log.info(baos.toString());
       
        // check jbi message element
        Element root = DomUtil.getFirstChildElement(doc);
        assertNotNull(root);
        assertEquals(JbiConstants.WSDL11_WRAPPER_NAMESPACE, root.getNamespaceURI());
        assertEquals("message", root.getLocalName());
        assertEquals("Hello", root.getAttribute("name"));

        // check body part
        Element part = DomUtil.getFirstChildElement(root);
        assertNotNull(part);
        assertEquals(JbiConstants.WSDL11_WRAPPER_NAMESPACE, part.getNamespaceURI());
        assertEquals("part", part.getLocalName());

        // check body element
        Element hello = DomUtil.getFirstChildElement(part);
        assertNotNull(hello);
        assertEquals("uri:HelloWorld", hello.getNamespaceURI());
        assertEquals("HelloRequest", hello.getLocalName());
       
        // check body content
        Element e = DomUtil.getFirstChildElement(hello);
        assertNotNull(e);
        assertEquals("uri:HelloWorld", e.getNamespaceURI());
        assertEquals("text", e.getLocalName());
        assertEquals("hello", e.getTextContent());

        // check header part
        Element part2 = DomUtil.getNextSiblingElement(part);
        assertNotNull(part2);
        assertEquals(JbiConstants.WSDL11_WRAPPER_NAMESPACE, part2.getNamespaceURI());
        assertEquals("part", part2.getLocalName());

        // check header element
        Element header = DomUtil.getFirstChildElement(part2);
        assertNotNull(header);
        assertEquals("uri:HelloWorld", header.getNamespaceURI());
        assertEquals("HelloHeader", header.getLocalName());
       
        // check header content
        e = DomUtil.getFirstChildElement(header);
        assertNotNull(e);
        assertEquals("uri:HelloWorld", e.getNamespaceURI());
        assertEquals("id", e.getLocalName());
        assertEquals("1234567890", e.getTextContent());
      
        PhaseInterceptorChain phaseOut = new PhaseInterceptorChain();
        phaseOut.add(binding.getInterceptors(Phase.ClientOut));
        baos = new ByteArrayOutputStream();

        Message msgOut = new MessageImpl();
        msgOut.put(Binding.class, binding);
        msgOut.setContent(OutputStream.class, baos);
        msgOut.setContent(MessageExchange.class, msg.getContent(MessageExchange.class));
        msgOut.setContent(NormalizedMessage.class, nm);
        msgOut.put(SoapVersion.class, msg.get(SoapVersion.class));
        phaseOut.doIntercept(msgOut);
        log.info(baos.toString());
       
        Document node = DomUtil.parse(new ByteArrayInputStream(baos.toByteArray()));
       
View Full Code Here

        Binding<?> binding = getBinding("HelloWorld-DOC.wsdl");
        PhaseInterceptorChain phaseIn = new PhaseInterceptorChain();
        phaseIn.add(binding.getInterceptors(Phase.ClientIn));
       
        Message msg = new MessageImpl();
        MessageExchange me = new MockMessageExchange();
        msg.put(Binding.class, binding);
        msg.put(Operation.class, binding.getOperations().iterator().next());
        msg.setContent(InputStream.class, getClass().getResourceAsStream("HelloWorld-DOC-Output.xml"));
        msg.setContent(MessageExchange.class, me);
        phaseIn.doIntercept(msg);

        NormalizedMessage nm = msg.getContent(NormalizedMessage.class);
        Document doc = DomUtil.parse(nm.getContent());
        baos = new ByteArrayOutputStream();
        DomUtil.getTransformerFactory().newTransformer().transform(nm.getContent(), new StreamResult(baos));
        log.info(baos.toString());
       
        // check jbi message element
        Element root = DomUtil.getFirstChildElement(doc);
        assertNotNull(msg);
        assertEquals(JbiConstants.WSDL11_WRAPPER_NAMESPACE, root.getNamespaceURI());
        assertEquals("message", root.getLocalName());
        assertEquals("HelloResponse", root.getAttribute("name"));

        // check body part
        Element part = DomUtil.getFirstChildElement(root);
        assertNotNull(part);
        assertEquals(JbiConstants.WSDL11_WRAPPER_NAMESPACE, part.getNamespaceURI());
        assertEquals("part", part.getLocalName());

        // check body element
        Element hello = DomUtil.getFirstChildElement(part);
        assertNotNull(hello);
        assertEquals("uri:HelloWorld", hello.getNamespaceURI());
        assertEquals("HelloResponse", hello.getLocalName());
       
        // check body content
        Element e = DomUtil.getFirstChildElement(hello);
        assertNotNull(e);
        assertEquals("uri:HelloWorld", e.getNamespaceURI());
        assertEquals("text", e.getLocalName());
        assertEquals("hello", e.getTextContent());

        PhaseInterceptorChain phaseOut = new PhaseInterceptorChain();
        phaseOut.add(binding.getInterceptors(Phase.ServerOut));

        baos = new ByteArrayOutputStream();
        Message msgOut = new MessageImpl();
        msgOut.put(Binding.class, binding);
        msgOut.put(Operation.class, binding.getOperations().iterator().next());
        msgOut.setContent(OutputStream.class, baos);
        msgOut.setContent(MessageExchange.class, msg.getContent(MessageExchange.class));
        msgOut.setContent(NormalizedMessage.class, nm);
        msgOut.put(SoapVersion.class, msg.get(SoapVersion.class));
        phaseOut.doIntercept(msgOut);
        log.info(baos.toString());
       
        Document node = DomUtil.parse(new ByteArrayInputStream(baos.toByteArray()));
        Element envelope = DomUtil.getFirstChildElement(node);
View Full Code Here

        Binding<?> binding = getBinding("HelloWorld-DOC.wsdl");
        PhaseInterceptorChain phaseIn = new PhaseInterceptorChain();
        phaseIn.add(binding.getInterceptors(Phase.ClientIn));
       
        Message msg = new MessageImpl();
        msg.put(Binding.class, binding);
        msg.put(Operation.class, binding.getOperations().iterator().next());
        msg.setContent(InputStream.class, getClass().getResourceAsStream("HelloWorld-DOC-Fault.xml"));
        msg.setContent(MessageExchange.class, new MockMessageExchange());
        phaseIn.doIntercept(msg);

        NormalizedMessage nm = msg.getContent(NormalizedMessage.class);
        Document doc = DomUtil.parse(nm.getContent());
        baos = new ByteArrayOutputStream();
        DomUtil.getTransformerFactory().newTransformer().transform(nm.getContent(), new StreamResult(baos));
        log.info(baos.toString());
       
        Element root = DomUtil.getFirstChildElement(doc);
        assertNotNull(root);
        assertEquals("uri:HelloWorld", root.getNamespaceURI());
        assertEquals("HelloFault", root.getLocalName());

        PhaseInterceptorChain phaseOut = new PhaseInterceptorChain();
        phaseOut.add(binding.getInterceptors(Phase.ServerOut));

        baos = new ByteArrayOutputStream();
        Message msgOut = new MessageImpl();
        msgOut.put(Binding.class, binding);
        msgOut.setContent(OutputStream.class, baos);
        msgOut.setContent(MessageExchange.class, msg.getContent(MessageExchange.class));
        msgOut.setContent(NormalizedMessage.class, nm);
        msgOut.put(SoapVersion.class, msg.get(SoapVersion.class));
       
        try {
            phaseOut.doIntercept(msgOut);
            fail("A soap fault should have been thrown");
        } catch (SoapFault fault) {
View Full Code Here

        Binding<?> binding = getBinding("HelloWorld-RPC.wsdl");
        PhaseInterceptorChain phaseIn = new PhaseInterceptorChain();
        phaseIn.add(binding.getInterceptors(Phase.ServerIn));
       
        Message msg = new MessageImpl();
        msg.put(Binding.class, binding);
        msg.setContent(InputStream.class, getClass().getResourceAsStream("HelloWorld-RPC-Input.xml"));
        msg.put(MessageExchangeFactory.class, new MockExchangeFactory());
        phaseIn.doIntercept(msg);
       
        NormalizedMessage nm = msg.getContent(NormalizedMessage.class);
        Document doc = DomUtil.parse(nm.getContent());

        baos = new ByteArrayOutputStream();
        DomUtil.getTransformerFactory().newTransformer().transform(nm.getContent(), new StreamResult(baos));
        log.info(baos.toString());

        Element root = DomUtil.getFirstChildElement(doc);
        assertNotNull(msg);
        assertEquals(JbiConstants.WSDL11_WRAPPER_NAMESPACE, root.getNamespaceURI());
        assertEquals("message", root.getLocalName());
        assertEquals("Hello", root.getAttribute("name"));

        // check part "header1"
        Element wrapper = DomUtil.getFirstChildElement(root);
        assertNotNull(wrapper);
        assertEquals(JbiConstants.WSDL11_WRAPPER_NAMESPACE, wrapper.getNamespaceURI());
        assertEquals("part", wrapper.getLocalName());

        Element header1 = DomUtil.getFirstChildElement(wrapper);
        assertNotNull(header1);
        assertEquals("uri:HelloWorld", header1.getNamespaceURI());
        assertEquals("HelloHeader1", header1.getLocalName());

        Element id1 = DomUtil.getFirstChildElement(header1);
        assertNotNull(id1);
        assertEquals("uri:HelloWorld", id1.getNamespaceURI());
        assertEquals("id1", id1.getLocalName());
        assertEquals("abcdefghij", id1.getTextContent());

        // check part "header2"
        wrapper = DomUtil.getNextSiblingElement(wrapper);
        assertNotNull(wrapper);
        assertEquals(JbiConstants.WSDL11_WRAPPER_NAMESPACE, wrapper.getNamespaceURI());
        assertEquals("part", wrapper.getLocalName());

        Element header2 = DomUtil.getFirstChildElement(wrapper);
        assertNotNull(header2);
        assertEquals("uri:HelloWorld", header2.getNamespaceURI());
        assertEquals("HelloHeader2", header2.getLocalName());

        Element id2 = DomUtil.getFirstChildElement(header2);
        assertNotNull(id2);
        assertEquals("uri:HelloWorld", id2.getNamespaceURI());
        assertEquals("id2", id2.getLocalName());
        assertEquals("1234567890", id2.getTextContent());

        // check part "param1"
        wrapper = DomUtil.getNextSiblingElement(wrapper);
        assertNotNull(wrapper);
        assertEquals(JbiConstants.WSDL11_WRAPPER_NAMESPACE, wrapper.getNamespaceURI());
        assertEquals("part", wrapper.getLocalName());

        assertNull(DomUtil.getFirstChildElement(wrapper));
        assertEquals("foo", wrapper.getTextContent());

        // check part "param2"
        wrapper = DomUtil.getNextSiblingElement(wrapper);
        assertNotNull(wrapper);
        assertEquals(JbiConstants.WSDL11_WRAPPER_NAMESPACE, wrapper.getNamespaceURI());
        assertEquals("part", wrapper.getLocalName());

        assertNull(DomUtil.getFirstChildElement(wrapper));
        assertEquals("bar", wrapper.getTextContent());

        PhaseInterceptorChain phaseOut = new PhaseInterceptorChain();
        phaseOut.add(binding.getInterceptors(Phase.ClientOut));

        baos = new ByteArrayOutputStream();
        Message msgOut = new MessageImpl();
        msgOut.put(Binding.class, binding);
        msgOut.setContent(OutputStream.class, baos);
        msgOut.setContent(MessageExchange.class, msg.getContent(MessageExchange.class));
        msgOut.setContent(NormalizedMessage.class, nm);
        msgOut.put(SoapVersion.class, msg.get(SoapVersion.class));
        phaseOut.doIntercept(msgOut);
        log.info(baos.toString());
       
        Document node = DomUtil.parse(new ByteArrayInputStream(baos.toByteArray()));
        Element envelope = DomUtil.getFirstChildElement(node);
View Full Code Here

        Binding<?> binding = getBinding("HelloWorld-RPC.wsdl");
        PhaseInterceptorChain phaseIn = new PhaseInterceptorChain();
        phaseIn.add(binding.getInterceptors(Phase.ClientIn));
       
        Message msg = new MessageImpl();
        MessageExchange me = new MockMessageExchange();
        msg.put(Binding.class, binding);
        msg.put(Operation.class, binding.getOperations().iterator().next());
        msg.setContent(InputStream.class, getClass().getResourceAsStream("HelloWorld-RPC-Output.xml"));
        msg.setContent(MessageExchange.class, me);
        phaseIn.doIntercept(msg);

        NormalizedMessage nm = msg.getContent(NormalizedMessage.class);
        Document doc = DomUtil.parse(nm.getContent());

        baos = new ByteArrayOutputStream();
        DomUtil.getTransformerFactory().newTransformer().transform(nm.getContent(), new StreamResult(baos));
        log.info(baos.toString());
       
        // check jbi message element
        Element root = DomUtil.getFirstChildElement(doc);
        assertNotNull(root);
        assertEquals(JbiConstants.WSDL11_WRAPPER_NAMESPACE, root.getNamespaceURI());
        assertEquals("message", root.getLocalName());
        assertEquals("HelloResponse", root.getAttribute("name"));

        // check part wrapper
        Element part = DomUtil.getFirstChildElement(root);
        assertNotNull(part);
        assertEquals(JbiConstants.WSDL11_WRAPPER_NAMESPACE, part.getNamespaceURI());
        assertEquals("part", part.getLocalName());

        // check part content
        assertTrue( "Unexpected part element", DomUtil.getFirstChildElement(part) == null);
        assertEquals("hello", part.getTextContent());

        PhaseInterceptorChain phaseOut = new PhaseInterceptorChain();
        phaseOut.add(binding.getInterceptors(Phase.ServerOut));

        baos = new ByteArrayOutputStream();
        Message msgOut = new MessageImpl();
        msgOut.put(Binding.class, binding);
        msgOut.put(Operation.class, binding.getOperations().iterator().next());
        msgOut.setContent(OutputStream.class, baos);
        msgOut.setContent(MessageExchange.class, msg.getContent(MessageExchange.class));
        msgOut.setContent(NormalizedMessage.class, nm);
        msgOut.put(SoapVersion.class, msg.get(SoapVersion.class));
        phaseOut.doIntercept(msgOut);
        log.info(baos.toString());
       
        Document node = DomUtil.parse(new ByteArrayInputStream(baos.toByteArray()));
        Element envelope = DomUtil.getFirstChildElement(node);
View Full Code Here

public class JbiInInterceptorTest extends TestCase {

    public void test() throws Exception {
        Interceptor interceptor = new JbiInInterceptor(true);
        Message message = new MessageImpl();
        message.put(JbiInInterceptor.OPERATION_MEP, JbiConstants.IN_ONLY);
        message.put(MessageExchangeFactory.class, new MockExchangeFactory());
        message.setContent(Source.class, new StreamSource(new StringReader("<hello/>")));
        message.getTransportHeaders().put("Content-Type", "text/xml");
       
        interceptor.handleMessage(message);
       
        MessageExchange me = message.getContent(MessageExchange.class);
        assertNotNull(me);
        assertTrue(me instanceof InOnly);
        NormalizedMessage nm = me.getMessage("in");
        assertNotNull(nm);
        assertNotNull(nm.getContent());
View Full Code Here

TOP

Related Classes of org.apache.servicemix.soap.core.MessageImpl

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.