Package org.apache.servicemix.client

Examples of org.apache.servicemix.client.ServiceMixClient


        http.setEndpoints(new HttpEndpointType[] {ep0, ep1 });
        container.activateComponent(http, "http");
       
        container.start();

        ServiceMixClient client = new DefaultServiceMixClient(container);
        InOut me = client.createInOutExchange();
        me.setService(new QName("http://servicemix.apache.org/samples/wsdl-first", "PersonService"));
        me.setOperation(new QName("http://servicemix.apache.org/samples/wsdl-first", "GetPerson"));
        me.getInMessage().setContent(new StringSource(
                                "<jbi:message xmlns:jbi=\"http://java.sun.com/xml/ns/jbi/wsdl-11-wrapper\""
                             "             xmlns:msg=\"http://servicemix.apache.org/samples/wsdl-first/types\" "
                             "             name=\"Hello\" "
                             "             type=\"msg:HelloRequest\" "
                             "             version=\"1.0\">"
                             "  <jbi:part>"
                             "    <msg:GetPerson><msg:personId>id</msg:personId></msg:GetPerson>"
                             "  </jbi:part>"
                             "</jbi:message>"));
        client.sendSync(me);
    }
View Full Code Here


        http.setEndpoints(new HttpEndpointType[] {ep0, ep1 });
        container.activateComponent(http, "http");
       
        container.start();

        ServiceMixClient client = new DefaultServiceMixClient(container);
        InOut me = client.createInOutExchange();
        me.setService(new QName("http://servicemix.apache.org/samples/wsdl-first", "PersonService"));
        me.setOperation(new QName("http://servicemix.apache.org/samples/wsdl-first", "GetPerson"));
        me.getInMessage().setContent(new StringSource(
                                "<jbi:message xmlns:jbi=\"http://java.sun.com/xml/ns/jbi/wsdl-11-wrapper\""
                             "             xmlns:msg=\"http://servicemix.apache.org/samples/wsdl-first/types\" "
                             "             name=\"Hello\" "
                             "             type=\"msg:HelloRequest\" "
                             "             version=\"1.0\">"
                             "  <jbi:part>"
                             "    <msg:GetPerson><msg:personId>id</msg:personId></msg:GetPerson>"
                             "  </jbi:part>"
                             "</jbi:message>"));
        client.sendSync(me);
    }
View Full Code Here

        http.addEndpoint(ep1);
        container.activateComponent(http, "http");

        container.start();

        ServiceMixClient client = new DefaultServiceMixClient(container);
        InOut me = client.createInOutExchange();
        me.setService(new QName("http://servicemix.apache.org/samples/wsdl-first", "PersonService"));
        me.setOperation(new QName("http://servicemix.apache.org/samples/wsdl-first", "GetPerson"));
        me.getInMessage().setContent(new StringSource(
                                "<jbi:message xmlns:jbi=\"http://java.sun.com/xml/ns/jbi/wsdl-11-wrapper\""
                             "             xmlns:msg=\"http://servicemix.apache.org/samples/wsdl-first/types\" "
                             "             name=\"Hello\" "
                             "             type=\"msg:HelloRequest\" "
                             "             version=\"1.0\">"
                             "  <jbi:part>"
                             "    <msg:GetPerson><msg:personId>id</msg:personId></msg:GetPerson>"
                             "  </jbi:part>"
                             "</jbi:message>"));
        client.sendSync(me);
        assertEquals(ExchangeStatus.ERROR, me.getStatus());
    }
View Full Code Here

    protected AbstractServiceEndpoint getEndpoint() {
        return endpoint;
    }

    public String send(String content, String operation, String mep) {
        ServiceMixClient client = null;
        try {
            client = registry.getContainer().getClientFactory().createClient();
            MessageExchange me = client.getExchangeFactory().createExchange(URI.create(mep));
            NormalizedMessage nm = me.createMessage();
            me.setMessage(nm, "in");
            nm.setContent(new StringSource(content));
            me.setEndpoint(endpoint);
            if (operation != null) {
                me.setOperation(QNameUtil.parse(operation));
            }
            client.sendSync(me);
            if (me.getError() != null) {
                throw me.getError();
            } else if (me.getFault() != null) {
                throw FaultException.newInstance(me);
            } else if (me.getMessage("out") != null) {
                return new SourceTransformer().contentToString(me.getMessage("out"));
            }
            return null;
        } catch (Exception e) {
            LOGGER.debug("Error proces test exchange", e);
            throw new RuntimeException(e);
        } finally {
            if (client != null) {
                try {
                    client.close();
                } catch (Exception e) {
                    // ignore
                }
            }
        }
View Full Code Here

    }

    public void testSendSync() throws Exception {
        AbstractXmlApplicationContext ctx = new ClassPathXmlApplicationContext("org/apache/servicemix/jbi/nmr/flow/jms/client.xml");
        try {
            ServiceMixClient client = (ServiceMixClient) ctx.getBean("client");
            Thread.sleep(2000);
            InOut exchange = client.createInOutExchange();
            exchange.setService(new QName("http://www.habuma.com/foo", "pingService"));
            NormalizedMessage in = exchange.getInMessage();
            in.setContent(new StringSource("<ping>Pinging you</ping>"));
            LOGGER.info("SENDING; exchange.status={}", exchange.getStatus());
            client.sendSync(exchange);
            assertNotNull(exchange.getOutMessage());
            LOGGER.info("GOT RESPONSE; exchange.out={}", new SourceTransformer().toString(exchange.getOutMessage().getContent()));
            client.done(exchange);
            // Wait for done to be delivered
            Thread.sleep(50);
        } finally {
            ctx.close();
        }
View Full Code Here

        return context.getSubject();
    }
   
    public void testOk() throws Exception {
        Subject subject = login("first", "secret");
        ServiceMixClient client = new DefaultServiceMixClient(jbi);
        InOnly me = client.createInOnlyExchange();
        me.setService(ReceiverComponent.SERVICE);
        me.getInMessage().setSecuritySubject(subject);
        me.getInMessage().setContent(new StringSource("<hello>world</hello>"));
        client.sendSync(me);
       
        receiver.getMessageList().assertMessagesReceived(1);
    }
View Full Code Here

        receiver.getMessageList().assertMessagesReceived(1);
    }
   
    public void testNOk() throws Exception {
        Subject subject = login("second", "password");
        ServiceMixClient client = new DefaultServiceMixClient(jbi);
        InOnly me = client.createInOnlyExchange();
        me.setService(ReceiverComponent.SERVICE);
        me.getInMessage().setSecuritySubject(subject);
        me.getInMessage().setContent(new StringSource("<hello>world</hello>"));
        try {
            client.sendSync(me);
            fail("Should have thrown a SecurityException");
        } catch (SecurityException e) {
            // ok
        }
    }
View Full Code Here

        receiver.getMessageList().assertMessagesReceived(1);
    }

    public void testSendUsingMapAndPOJOsUsingContainerRouting() throws Exception {

        ServiceMixClient clientNoRouting = (ServiceMixClient) context.getBean("clientWithRouting");

        Map properties = new HashMap();
        properties.put("name", "James");

        clientNoRouting.send(null, null, properties, "<hello>world</hello>");

        receiver.getMessageList().assertMessagesReceived(1);
    }
View Full Code Here

    }

    public void testRequestUsingPOJOWithXStreamMarshaling() throws Exception {
        QName service = new QName("http://servicemix.org/cheese/", "myService");

        ServiceMixClient client = (ServiceMixClient) context.getBean("clientWithXStream");

        Map properties = new HashMap();
        properties.put("name", "James");

        EndpointResolver resolver = client.createResolverForService(service);
        TestBean bean = new TestBean();
        bean.setName("James");
        bean.setLength(12);
        bean.getAddresses().addAll(Arrays.asList(new String[] {"London", "LA"}));

        Object response = client.request(resolver, null, properties, bean);

        assertNotNull("Should have returned a non-null response!", response);

        logger.info("Received result: {}", response);
    }
View Full Code Here

        LwContainerComponent component = new LwContainerComponent();
        container.activateComponent(component, "#ServiceMixComponent#");
        URL url = getClass().getResource("su1-src/servicemix.xml");
        File path = new File(new URI(url.toString()));
        path = path.getParentFile();
        ServiceMixClient client = new DefaultServiceMixClient(container);

        for (int i = 0; i < 2; i++) {
            // Deploy and start su
            component.getServiceUnitManager().deploy("su1", path.getAbsolutePath());
            component.getServiceUnitManager().init("su1", path.getAbsolutePath());
            component.getServiceUnitManager().start("su1");

            // Send message
            InOut inout = client.createInOutExchange();
            inout.setService(new QName("http://servicemix.apache.org/demo/", "chained"));
            client.send(inout);

            // Stop and undeploy
            component.getServiceUnitManager().stop("su1");
            component.getServiceUnitManager().shutDown("su1");
            component.getServiceUnitManager().undeploy("su1", path.getAbsolutePath());

            // Send message
            inout = client.createInOutExchange();
            inout.setService(new QName("http://servicemix.apache.org/demo/", "chained"));
            try {
                client.send(inout);
            } catch (MessagingException e) {
                // Ok, the lw component is undeployed
            }

        }
View Full Code Here

TOP

Related Classes of org.apache.servicemix.client.ServiceMixClient

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.