Package org.apache.servicemix.client

Examples of org.apache.servicemix.client.ServiceMixClient


    }

    public void testConfigAsync() throws Exception {
        ActivationSpec as = new ActivationSpec();
        as.setComponentName("client");
        ServiceMixClient client = new DefaultServiceMixClient(jbi, as);
       
        int nbMsgs = 100;
        for (int i = 0; i < nbMsgs; i++) {
            InOnly me = client.createInOnlyExchange();
            me.setService(new QName("http://test", "entryPoint"));
            me.getInMessage().setContent(new StringSource("<test xmlns=\"http://test\"><echo/><world/><earth/></test>"));
            client.send(me);
        }
        for (int i = 0; i < nbMsgs; i++) {
            client.receive();
        }
        ((Receiver) getBean("trace1")).getMessageList().assertMessagesReceived(1 * nbMsgs);
        ((Receiver) getBean("trace2")).getMessageList().assertMessagesReceived(1 * nbMsgs);
        ((Receiver) getBean("trace3")).getMessageList().assertMessagesReceived(1 * nbMsgs);
        ((Receiver) getBean("trace4")).getMessageList().assertMessagesReceived(2 * nbMsgs);
 
View Full Code Here


       
        container.activateComponent(http, "http");
       
        container.start();
       
        ServiceMixClient client = new DefaultServiceMixClient(container);
        client.request(new ServiceNameEndpointResolver(new QName("urn:test", "s2")), null, null,
                       new StreamSource(getClass().getResourceAsStream("soap-request.xml")));
       
    }
View Full Code Here

       
        container.activateComponent(http, "http");
       
        container.start();
       
        ServiceMixClient client = new DefaultServiceMixClient(container);
        Destination dest = client.createDestination("service:urn:test:s2");
        InOut me = dest.createInOutExchange();
        me.getInMessage().setContent(new StringSource("<hello>world</hello>"));
        client.sendSync(me);
        assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
        String str = new SourceTransformer().contentToString(me.getOutMessage());
        client.done(me);
        logger.info(str);
    }
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) {
            log.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

        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

import org.springframework.context.support.AbstractXmlApplicationContext;

public class BPESpringComponentTest extends SpringTestSupport {

    public void test() throws Exception {
        ServiceMixClient client = new DefaultServiceMixClient(jbi);
        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"));
        System.err.println(out);
        System.err.println("Time: " + (t1 - t0));
        client.done(me);
    }
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

    }

    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>"));
            System.out.println("SENDING; exchange.status=" + exchange.getStatus());
            client.sendSync(exchange);
            assertNotNull(exchange.getOutMessage());
            System.out.println("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

        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);

        System.err.println(new SourceTransformer().contentToString(me.getOutMessage()));
    }
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.