Package org.apache.servicemix.jbi.jaxp

Examples of org.apache.servicemix.jbi.jaxp.StringSource


    public void testSoapFault11() throws Exception {
        TransformComponentSupport echo = new TransformComponentSupport() {
            protected boolean transform(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out)
                throws MessagingException {
                Fault f = exchange.createFault();
                f.setContent(new StringSource("<hello xmlns='myuri'>this is a fault</hello>"));
                f.setProperty(JBIMarshaler.SOAP_FAULT_REASON, "My reason");
                throw new FaultException(null, exchange, f);
            }
        };
        echo.setService(new QName("urn:test", "echo"));
        echo.setEndpoint("echo");
        container.activateComponent(echo, "echo");

        HttpEndpoint ep1 = createInOutEndpoint("ep1");
        ep1.setTargetService(new QName("urn:test", "echo"));
        ep1.setTargetEndpoint("echo");
        ep1.setLocationURI("http://localhost:8194/ep1/");
        ep1.setRoleAsString("consumer");
        ep1.setSoap(true);
        ep1.setSoapVersion("1.1");

        HttpEndpoint ep2 = createInOutEndpoint("ep2");
        ep2.setTargetService(new QName("urn:test", "http"));
        ep2.setTargetEndpoint("ep3");
        ep2.setLocationURI("http://localhost:8194/ep2/");
        ep2.setRoleAsString("consumer");
        ep2.setSoap(true);
        ep2.setSoapVersion("1.1");

        HttpEndpoint ep3 = createInOutEndpoint("ep3");
        ep3.setLocationURI("http://localhost:8194/ep1/");
        ep3.setRoleAsString("provider");
        ep3.setSoap(true);
        ep3.setSoapVersion("1.1");

        HttpComponent http = new HttpComponent();
        http.setEndpoints(new HttpEndpoint[] {ep1, ep2, ep3});
        container.activateComponent(http, "http1");

        container.start();

        PostMethod method = new PostMethod("http://localhost:8194/ep2/");
        method.setRequestEntity(new InputStreamRequestEntity(getClass().getResourceAsStream("soap-request.xml")));
        int state = new HttpClient().executeMethod(method);
        String str = method.getResponseBodyAsString();
        logger.info(str);
        assertEquals(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, state);
        SourceTransformer st = new SourceTransformer();
        Node node = st.toDOMNode(new StringSource(str));

        Element e = ((Document) node).getDocumentElement();
        assertEquals(new QName(SoapMarshaler.SOAP_11_URI, SoapMarshaler.ENVELOPE), DOMUtil.getQName(e));
        e = DOMUtils.getFirstChildElement(e);
        assertEquals(new QName(SoapMarshaler.SOAP_11_URI, SoapMarshaler.BODY), DOMUtil.getQName(e));
        e = DOMUtils.getFirstChildElement(e);
        assertEquals(new QName(SoapMarshaler.SOAP_11_URI, SoapMarshaler.FAULT), DOMUtil.getQName(e));

        method = new PostMethod("http://localhost:8194/ep2/");
        method.setRequestBody("hello");
        state = new HttpClient().executeMethod(method);
        str = method.getResponseBodyAsString();
        logger.info(str);
        assertEquals(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, state);
        node = st.toDOMNode(new StringSource(str));
        e = ((Document) node).getDocumentElement();
        assertEquals(new QName(SoapMarshaler.SOAP_11_URI, SoapMarshaler.ENVELOPE), DOMUtil.getQName(e));
        e = DOMUtils.getFirstChildElement(e);
        assertEquals(new QName(SoapMarshaler.SOAP_11_URI, SoapMarshaler.BODY), DOMUtil.getQName(e));
        e = DOMUtils.getFirstChildElement(e);
        assertEquals(new QName(SoapMarshaler.SOAP_11_URI, SoapMarshaler.FAULT), DOMUtil.getQName(e));

        method = new PostMethod("http://localhost:8194/ep2/");
        method.setRequestBody("<hello/>");
        state = new HttpClient().executeMethod(method);
        str = method.getResponseBodyAsString();
        logger.info(str);
        assertEquals(HttpServletResponse.SC_BAD_REQUEST, state);
        node = st.toDOMNode(new StringSource(str));
        e = ((Document) node).getDocumentElement();
        assertEquals(new QName(SoapMarshaler.SOAP_11_URI, SoapMarshaler.ENVELOPE), DOMUtil.getQName(e));
        e = DOMUtils.getFirstChildElement(e);
        assertEquals(new QName(SoapMarshaler.SOAP_11_URI, SoapMarshaler.BODY), DOMUtil.getQName(e));
        e = DOMUtils.getFirstChildElement(e);
View Full Code Here


        container.start();

        DefaultServiceMixClient client = new DefaultServiceMixClient(container);
        Destination d = client.createDestination("service:urn:test:s0");
        InOut me = d.createInOutExchange();
        me.getInMessage().setContent(new StringSource("<hello>world</hello>"));
        File f = new File(getClass().getResource("servicemix.jpg").getFile());
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        FileUtil.copyInputStream(new FileInputStream(f), baos);
        DataSource ds = new ByteArrayDataSource(baos.toByteArray(), "image/jpeg");
        DataHandler dh = new DataHandler(ds);
View Full Code Here

        ServiceEndpoint se = client.getContext().resolveEndpointReference(epr);
        assertNotNull("We should find a service endpoint!", se);

        InOnly exchange = client.createInOnlyExchange();
        exchange.setEndpoint(se);
        exchange.getInMessage().setContent(new StringSource("<hello>world</hello>"));
        client.sendSync(exchange);

        assertExchangeWorked(exchange);

        ListenerBean bean = (ListenerBean) getBean("listenerBean");
View Full Code Here

        ServiceEndpoint se = client.getContext().resolveEndpointReference(epr);
        assertNotNull("We should find a service endpoint!", se);

        InOut exchange = client.createInOutExchange();
        exchange.setEndpoint(se);
        exchange.getInMessage().setContent(new StringSource("<hello>world</hello>"));
        client.sendSync(exchange);
        client.done(exchange);

        assertExchangeWorked(exchange);
View Full Code Here

        component.getServiceUnitManager().start("proxy");
       
        DefaultServiceMixClient client = new DefaultServiceMixClient(container);
        InOut me = client.createInOutExchange(new QName("http://test", "Echo"), null, null);
        me.setInMessage(me.createMessage());
        me.getInMessage().setContent(new StringSource("<echo xmlns='http://test'><msg>world</msg></echo>"));
        client.sendSync(me);
        assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
        assertNotNull(me.getOutMessage());
        client.done(me);
    }
View Full Code Here

        // Message for bank1 and bank2
        //
        MessageExchange me = client.createInOutExchange();
        me.setService(new QName("urn:logicblaze:soa:loanbroker", "LoanBrokerService"));
        me.setOperation(new QName("getLoanQuote"));
        me.getMessage("in").setContent(new StringSource(
                                "<getLoanQuoteRequest xmlns=\"urn:logicblaze:soa:loanbroker\">"
                                + "<ssn>1234341</ssn><amount>100000.0</amount><duration>12</duration>"
                                + "</getLoanQuoteRequest>"));
        long t0 = System.currentTimeMillis();
        client.sendSync(me);
        long t1 = System.currentTimeMillis();
        if (me.getError() != null) {
            throw me.getError();
        }
        assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
        String out = new SourceTransformer().contentToString(me.getMessage("out"));
        log.info(out);
        log.info("Time: " + (t1 - t0));
        client.done(me);

        //
        // Message for bank3 and bank4
        //
        me = client.createInOutExchange();
        me.setService(new QName("urn:logicblaze:soa:loanbroker", "LoanBrokerService"));
        me.setOperation(new QName("getLoanQuote"));
        me.getMessage("in").setContent(new StringSource(
                                "<getLoanQuoteRequest xmlns=\"urn:logicblaze:soa:loanbroker\">"
                                + "<ssn>1234341</ssn><amount>50000.0</amount><duration>12</duration>"
                                + "</getLoanQuoteRequest>"));
        t0 = System.currentTimeMillis();
        client.sendSync(me);
        t1 = System.currentTimeMillis();
        if (me.getError() != null) {
            throw me.getError();
        }
        assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
        out = new SourceTransformer().contentToString(me.getMessage("out"));
        log.info(out);
        log.info("Time: " + (t1 - t0));
        client.done(me);

        //
        // Message for bank5
        //
        me = client.createInOutExchange();
        me.setService(new QName("urn:logicblaze:soa:loanbroker", "LoanBrokerService"));
        me.setOperation(new QName("getLoanQuote"));
        me.getMessage("in").setContent(new StringSource(
                                "<getLoanQuoteRequest xmlns=\"urn:logicblaze:soa:loanbroker\">"
                                + "<ssn>1234341</ssn><amount>1200.0</amount><duration>12</duration>"
                                + "</getLoanQuoteRequest>"));
        t0 = System.currentTimeMillis();
        client.sendSync(me);
View Full Code Here

        bpe.getServiceUnitManager().start("loanbroker");

        MessageExchange me = client.createInOutExchange();
        me.setService(new QName("urn:logicblaze:soa:loanbroker", "LoanBrokerService"));
        me.setOperation(new QName("getLoanQuote"));
        me.getMessage("in").setContent(new StringSource(
                                "<getLoanQuoteRequest xmlns=\"urn:logicblaze:soa:loanbroker\">"
                                + "<ssn>234341</ssn></getLoanQuoteRequest>"));
        client.sendSync(me);
        if (me.getError() != null) {
            throw me.getError();
View Full Code Here

        bpe.getServiceUnitManager().start("loanbroker");

        MessageExchange me = client.createInOutExchange();
        me.setService(new QName("urn:logicblaze:soa:loanbroker", "LoanBrokerService"));
        me.setOperation(new QName("getLoanQuote"));
        me.getMessage("in").setContent(new StringSource(
                                "<getLoanQuoteRequest xmlns=\"urn:logicblaze:soa:loanbroker\">"
                                + "<ssn></ssn></getLoanQuoteRequest>"));
        client.sendSync(me);
        assertEquals(ExchangeStatus.ERROR, me.getStatus());
        assertNotNull(me.getError());
View Full Code Here

        jbi.activateComponent(http, "http");

        DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
        Destination d = client.createDestination("service:urn:test:s0");
        InOut me = d.createInOutExchange();
        me.getInMessage().setContent(new StringSource("<hello>world</hello>"));
       
        tm.begin();
        boolean ok = client.sendSync(me);
        assertTrue(ok);
        client.done(me);
View Full Code Here

        jbi.activateComponent(http, "http");

        DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
        Destination d = client.createDestination("service:urn:test:s0");
        InOut me = d.createInOutExchange();
        me.getInMessage().setContent(new StringSource("<hello>world</hello>"));
       
        tm.begin();
        client.send(me);
        tm.commit();
        me = (InOut) client.receive();
View Full Code Here

TOP

Related Classes of org.apache.servicemix.jbi.jaxp.StringSource

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.