Package org.apache.servicemix.nmr.api

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


        smx.init();
        nmr = smx;
    }

    protected void sendExchange(Object content) {
        Channel client = nmr.createChannel();
        Exchange exchange = client.createExchange(Pattern.InOnly);
        exchange.setTarget(client.getNMR().getEndpointRegistry().lookup(
                ServiceHelper.createMap(Endpoint.NAME, RECEIVER_ENDPOINT_NAME)));
        exchange.setProperty("prop1", "value1");
        exchange.getIn().setBody(content);
        exchange.getIn().setHeader("prop1", "value2");
        exchange.getIn().setHeader("prop2", "value3");
        client.sendSync(exchange);

    }
View Full Code Here


        final AtomicInteger id = new AtomicInteger();
        lock.writeLock().lock();
        for (int i = 0; i < nbThreads; i++) {
            new Thread() {
                public void run() {
                    Channel client = null;
                    try {
                        client = nmr1.createChannel();
                        lock.readLock().lock();
                        for (int i = 0; i < nbExchanges; i++) {
                            Exchange exchange = client.createExchange(Pattern.InOnly);
                            exchange.getIn().setBody(new StringSource("<hello id='" + id.getAndIncrement() + "'/>"));
                            exchange.setTarget(nmr1.getEndpointRegistry().lookup(ServiceHelper.createMap(Endpoint.NAME, PROXY_ENDPOINT_NAME)));
                            client.sendSync(exchange);
                            assertEquals(Status.Done, exchange.getStatus());
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    } finally {
                        lock.readLock().unlock();
                        latch.countDown();
                        if (client != null) {
                            client.close();
                        }
                    }
                }
            }.start();
        }
View Full Code Here

        final CountDownLatch latch = new CountDownLatch(nbThreads);
        lock.writeLock().lock();
        for (int i = 0; i < nbThreads; i++) {
            new Thread() {
                public void run() {
                    Channel client = null;
                    try {
                        client = nmr1.createChannel();
                        lock.readLock().lock();
                        for (int i = 0; i < nbExchanges; i++) {
                            Exchange exchange = client.createExchange(Pattern.InOut);
                            exchange.getIn().setBody(new StringSource("<hello/>"));
                            exchange.setTarget(nmr1.getEndpointRegistry().lookup(ServiceHelper.createMap(Endpoint.NAME, PROXY_ENDPOINT_NAME)));
                            client.sendSync(exchange);
                            assertEquals(Status.Active, exchange.getStatus());
                            exchange.setStatus(Status.Done);
                            client.send(exchange);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    } finally {
                        lock.readLock().unlock();
                        latch.countDown();
                        if (client != null) {
                            client.close();
                        }
                    }
                }
            }.start();
        }
View Full Code Here

        ep.getTarget().setService(new QName("target"));
        eip.setEndpoints(new EIPEndpoint[] { ep });
        eip.init(new ComponentContextImpl(reg, new SimpleComponentWrapper(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

        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);
        // just need to make sure the customer header is set
        inMsg.setHeader("myHeader", "value");
        EasyMock.expectLastCall();
        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

        assertNotNull(destination);
       
        Subject subject = new Subject();
        subject.getPrincipals().add(new UserPrincipal("ffang"));

        Channel channel = nmr.createChannel();
        org.apache.servicemix.nmr.api.Exchange exchange = channel.createExchange(Pattern.InOut);
        exchange.setTarget(
                nmr.getEndpointRegistry().lookup(ServiceHelper.createMap(Endpoint.NAME, "dumy")));
        exchange.getIn().setSecuritySubject(subject);
        Source source = new StreamSource(new ByteArrayInputStream(
                "<message>TestHelloWorld</message>".getBytes()));
        exchange.getIn().setBody(source);
        observer = new MessageObserver() {
            public void onMessage(Message m) {                   
                inMessage = m;
                Subject receivedSubject =
                  (Subject)inMessage.get(NMRTransportFactory.NMR_SECURITY_SUBJECT);
                assertNotNull(receivedSubject);
                assertEquals(receivedSubject.getPrincipals().size(), 1);
                assertEquals(receivedSubject.getPrincipals().iterator().next().getName(), "ffang");
                Subject onBefalfsubject = Subject.getSubject(AccessController.getContext());
                assertNotNull(onBefalfsubject);
                assertEquals(onBefalfsubject, receivedSubject);
            }
        };
        destination.setMessageObserver(observer);
        channel.send(exchange);      
        Thread.sleep(2000);
        assertNotNull(inMessage);
    }
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

        ep.getTarget().setService(new QName("target"));
        eip.setEndpoints(new EIPEndpoint[] { ep });
        eip.init(new ComponentContextImpl(reg, new SimpleComponentWrapper(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);
        if (e.getError() != null) {
            throw e.getError();
        }
        assertEquals(Status.Done, e.getStatus());
    }
View Full Code Here

        IMocksControl control = EasyMock.createControl();
        ExchangeListener listener = control.createMock(ExchangeListener.class);
        control.makeThreadSafe(true);
        nmr.getListenerRegistry().register(listener, null);

        Channel channel = nmr.createChannel();
        Exchange e = channel.createExchange(Pattern.InOnly);
        e.setTarget(nmr.getEndpointRegistry().lookup(ServiceHelper.createMap(Endpoint.NAME, "zz")));

        listener.exchangeSent(same(e));
        listener.exchangeFailed(same(e));

        replay(listener);

        try {
            channel.send(e);
            fail("Exepected an exception to be thrown");
        } catch (ServiceMixException t) {
            // ok
        }
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.