Package org.apache.servicemix.nmr.api

Examples of org.apache.servicemix.nmr.api.Channel


           
        }, null);
       
       
        final CountDownLatch done = new CountDownLatch(1);
        final Channel channel = nmr.createChannel();
        final Exchange exchange = channel.createExchange(Pattern.InOnly);
        exchange.setTarget(nmr.getEndpointRegistry().lookup(props));
       
        Thread thread = new Thread(new Runnable() {
            public void run() {
                channel.sendSync(exchange);
                done.countDown();
            }
        });
        thread.start();
       
View Full Code Here


    public NMR getNmr() {
        return nmr;
    }

    public void run() {
        Channel client = null;
        try {
            // Create the client channel
            client = nmr.createChannel();
            // Create a reference that will be used as the target for our exchanges
            Reference ref = nmr.getEndpointRegistry().lookup(ServiceHelper.createMap(Endpoint.NAME, "EchoEndpoint"));
            while (run) {
                try {
                    // Create an exchange and send it
                    Exchange e = client.createExchange(Pattern.InOut);
                    e.setTarget(ref);
                    e.getIn().setBody("Hello");
                    client.sendSync(e);
                    logger.info("Response from Endpoint {}", e.getOut().getBody());
                    // Send back the Done status
                    e.setStatus(Status.Done);
                    client.send(e);
                } catch (Exception e) {
                    e.printStackTrace();
                    logger.error(e.getMessage());
                }
                // Sleep a bit
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                }
            }
        } finally {
            if (client != null) {
                client.close();
            }
        }
    }
View Full Code Here

    public NMR getNmr() {
        return nmr;
    }

    public void run() {
        Channel client = null;
        try {
            // Create the client channel
            client = nmr.createChannel();
            // Create a reference that will be used as the target for our exchanges
            Reference ref = nmr.getEndpointRegistry().lookup(ServiceHelper.createMap(Endpoint.NAME, "EchoEndpoint"));
            while (run) {
                try {
                    // Create an exchange and send it
                    Exchange e = client.createExchange(Pattern.InOut);
                    e.setTarget(ref);
                    e.getIn().setBody("Hello");
                    client.sendSync(e);
                    LOG.info("Response from Endpoint " + e.getOut().getBody());
                    // Send back the Done status
                    e.setStatus(Status.Done);
                    client.send(e);
                } catch (Exception e) {
                    e.printStackTrace();
                    LOG.error(e.getMessage());
                }
                // Sleep a bit
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                }
            }
        } finally {
            if (client != null) {
                client.close();
            }
        }
    }
View Full Code Here

    }

    public void process(Exchange exchange) throws Exception {
     
      NMR nmr = getEndpoint().getComponent().getNmr();
      Channel client = nmr.createChannel();
     
        org.apache.servicemix.nmr.api.Exchange e = client.createExchange(
            Pattern.fromWsdlUri(exchange.getPattern().getWsdlUri()));
       
        try {
          e.setTarget(nmr.getEndpointRegistry().lookup(
            ServiceHelper.createMap(org.apache.servicemix.nmr.api.Endpoint.NAME,
                getEndpoint().getEndpointName())));
        } catch (Exception ex) {
          ex.printStackTrace();
        }
        e.getIn().setBody(exchange.getIn().getBody());
        e.getIn().setHeader(OPERATION_NAME,
            exchange.getIn().getHeader(OPERATION_NAME));
               
        client.sendSync(e);
        if (e.getPattern() != Pattern.InOnly) {
          if (e.getError() != null) {
            exchange.setException(e.getError());
          } else if (e.getFault().getBody() != null) {
            exchange.getFault().setBody(e.getFault().getBody());
View Full Code Here

        waitOnContextCreation("cxf-nmr-osgi");
        Thread.sleep(5000);
        NMR nmr = getOsgiService(NMR.class);
        assertNotNull(nmr);
       
        Channel client = nmr.createChannel();
        Exchange e = client.createExchange(Pattern.InOut);
        for (Endpoint ep : nmr.getEndpointRegistry().getServices()) {
          e.setTarget(nmr.getEndpointRegistry().lookup(nmr.getEndpointRegistry().getProperties(ep)));
          e.getIn().setBody(new StringSource("<?xml version=\"1.0\" encoding=\"UTF-8\"?><soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><ns2:sayHi xmlns:ns2=\"http://cxf.examples.servicemix.apache.org/\"><arg0>Bonjour</arg0></ns2:sayHi></soap:Body></soap:Envelope>"));
          boolean res = client.sendSync(e);
          assertTrue(res);
        }
   
    }
View Full Code Here

        ep.getTarget().setService(new QName("target"));
        eip.setEndpoints(new EIPEndpoint[] { ep });
        eip.init(new ComponentContextImpl(reg, null, null, eip, new HashMap()));
        eip.getLifeCycle().start();

        Channel channel = smx.createChannel();
        Exchange e = channel.createExchange(Pattern.InOnly);
        e.getIn().setBody("<hello/>");
        e.setTarget(smx.getEndpointRegistry().lookup(ServiceHelper.createMap(Endpoint.NAME, "{uri:foo}bar:ep")));
        channel.sendSync(e);
    }
View Full Code Here

         *
         * @param message the message to be sent.
         */
        public void prepare(Message message) throws IOException {
            // setup the message to be send back
            Channel dc = channel;
            message.put(Exchange.class, inMessage.get(Exchange.class));
            message.setContent(OutputStream.class, new NMRDestinationOutputStream(inMessage, dc));
        }       
View Full Code Here

        exchange.setInMessage(message);
        BindingOperationInfo boi = control.createMock(BindingOperationInfo.class);
        BindingMessageInfo bmi = control.createMock(BindingMessageInfo.class);
        EasyMock.expect(boi.getOutput()).andReturn(bmi);
        exchange.put(BindingOperationInfo.class, boi);
        Channel channel = control.createMock(Channel.class);
        EasyMock.expect(nmr.createChannel()).andReturn(channel);
        Exchange xchg = control.createMock(Exchange.class);
        EasyMock.expect(channel.createExchange(Pattern.InOut)).andReturn(xchg);
        org.apache.servicemix.nmr.api.Message inMsg = control.createMock(org.apache.servicemix.nmr.api.Message.class);
        EasyMock.expect(xchg.getIn()).andReturn(inMsg);
        EndpointRegistry endpoints = control.createMock(EndpointRegistry.class);
        EasyMock.expect(channel.getNMR()).andReturn(nmr);
        EasyMock.expect(nmr.getEndpointRegistry()).andReturn(endpoints);
        org.apache.servicemix.nmr.api.Message outMsg = control.createMock(org.apache.servicemix.nmr.api.Message.class);
        EasyMock.expect(xchg.getOut()).andReturn(outMsg);
       
        Source source = new StreamSource(new ByteArrayInputStream(
View Full Code Here

   
    @Test
    public void testOutputStreamSubstitutionDoesntCauseExceptionInDoClose() throws Exception {
        //Create enough of the object structure to get through the code.
        org.apache.servicemix.nmr.api.Message normalizedMessage = control.createMock(org.apache.servicemix.nmr.api.Message.class);
        Channel channel = control.createMock(Channel.class);
        Exchange exchange = new ExchangeImpl();
        exchange.setOneWay(false);
        Message message = new MessageImpl();
        message.setExchange(exchange);
       
       
        org.apache.servicemix.nmr.api.Exchange messageExchange = control.createMock(org.apache.servicemix.nmr.api.Exchange.class);
        EasyMock.expect(messageExchange.getOut()).andReturn(normalizedMessage).times(2);
        message.put(org.apache.servicemix.nmr.api.Exchange.class, messageExchange);
        channel.send(messageExchange);
        EasyMock.replay(channel);
       
        NMRDestinationOutputStream jbiOS = new NMRDestinationOutputStream(message, new MessageImpl(), channel);
       
        //Create array of more than what is in threshold in CachedOutputStream,
View Full Code Here

         *
         * @param message the message to be sent.
         */
        public void prepare(Message message) throws IOException {
            // setup the message to be send back
            Channel dc = channel;
            message.put(Exchange.class, inMessage.get(Exchange.class));
            NMRTransportFactory.removeUnusedInterceptprs(message);   
            message.setContent(OutputStream.class, new NMRDestinationOutputStream(inMessage, message, dc));
           
        }       
View Full Code Here

TOP

Related Classes of org.apache.servicemix.nmr.api.Channel

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.