Package javax.jbi.messaging

Examples of javax.jbi.messaging.DeliveryChannel


        public void setContext(ComponentContext context) {
            this.context = context;
        }
       
        public void oneWay(Source src) throws Exception {
            DeliveryChannel channel = context.getDeliveryChannel();
            MessageExchangeFactory factory = channel.createExchangeFactory();
            InOnly inonly = factory.createInOnlyExchange();
            inonly.setService(ReceiverComponent.SERVICE);
            NormalizedMessage msg = inonly.createMessage();
            msg.setContent(src);
            inonly.setInMessage(msg);
            channel.send(inonly);
        }
View Full Code Here


            inonly.setInMessage(msg);
            channel.send(inonly);
        }
       
        public Source twoWay(Source src) throws Exception {
            DeliveryChannel channel = context.getDeliveryChannel();
            MessageExchangeFactory factory = channel.createExchangeFactory();
            InOut inout = factory.createInOutExchange();
            inout.setService(ReceiverComponent.SERVICE);
            NormalizedMessage msg = inout.createMessage();
            msg.setContent(src);
            inout.setInMessage(msg);
            channel.sendSync(inout);
            Source outSrc = inout.getOutMessage().getContent();
            inout.setStatus(ExchangeStatus.DONE);
            channel.send(inout);
            return outSrc;
        }
View Full Code Here

        return context;
    }

    protected MessageExchange createExchange(URI mep) throws MessagingException {
        ComponentContext context = endpoint.getServiceUnit().getComponent().getComponentContext();
        DeliveryChannel channel = context.getDeliveryChannel();
        MessageExchangeFactory factory = channel.createExchangeFactory();
        MessageExchange exchange = factory.createExchange(mep);
        return exchange;
    }
View Full Code Here

    public void testExchangeFactoryOnOpenChannel() throws Exception {
        // Retrieve a delivery channel
        TestComponent component = new TestComponent(null, null);
        container.activateComponent(new ActivationSpec("component", component));
        DeliveryChannel channel = component.getChannel();
        // test
        MessageExchangeFactory mef = channel.createExchangeFactory();
        assertNotNull(mef);
        assertNotNull(mef.createInOnlyExchange());
    }
View Full Code Here

    public void testExchangeFactoryOnClosedChannel() throws Exception {
        // Retrieve a delivery channel
        TestComponent component = new TestComponent(null, null);
        container.activateComponent(new ActivationSpec("component", component));
        DeliveryChannel channel = component.getChannel();
        // test
        channel.close();
        MessageExchangeFactory mef = channel.createExchangeFactory();
        assertNotNull(mef);
        try {
            mef.createInOnlyExchange();
            fail("Exchange creation should have failed (JBI: 5.5.2.1.4)");
        } catch (MessagingException e) {
View Full Code Here

    public void testSendSyncOnSameComponent() throws Exception {
        // Retrieve a delivery channel
        TestComponent component = new TestComponent(new QName("service"), "endpoint");
        container.activateComponent(new ActivationSpec("component", component));
        final DeliveryChannel channel = component.getChannel();
        final AtomicBoolean success = new AtomicBoolean(false);
        final AtomicBoolean done = new AtomicBoolean(false);

        // Create another thread
        Thread t = new Thread() {
            public void run() {
                try {
                    InOut me = (InOut) channel.accept(5000);
                    NormalizedMessage nm = me.createMessage();
                    nm.setContent(new StringSource("<response/>"));
                    me.setOutMessage(nm);
                    channel.sendSync(me);
                    success.set(true);
                    done.set(true);
                } catch (MessagingException e) {
                    LOG.error(e.getMessage(), e);
                    success.set(false);
                    done.set(true);
                }
            }
        };
        t.start();

        MessageExchangeFactory factory = channel.createExchangeFactoryForService(new QName("service"));
        InOut me = factory.createInOutExchange();
        NormalizedMessage nm = me.createMessage();
        nm.setContent(new StringSource("<request/>"));
        me.setInMessage(nm);
        channel.sendSync(me);
        assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
        me.setStatus(ExchangeStatus.DONE);
        channel.send(me);

        if (!done.get()) {
            synchronized (done) {
                done.wait(5000);
            }
View Full Code Here

    /**
     * Sends a number of messages
     */
    public void sendMessages(int count) throws MessagingException {
        DeliveryChannel deliveryChannel = context.getDeliveryChannel();
        MessageExchangeFactory factory = deliveryChannel.createExchangeFactory();

        for (int i = 0; i < count; i++) {
            InOnly exchange = factory.createInOnlyExchange();
            NormalizedMessage message = exchange.createMessage();
            exchange.setInMessage(message);

            message.setProperty("id", new Integer(i));
            message.setContent(new StringSource("<example id='" + i + "'/>"));

            deliveryChannel.send(exchange);
        }
    }
View Full Code Here

                exchange.setInMessage(message);
                // lets set the XML as a byte[], String or DOM etc
                String xml = "<s12:Envelope xmlns:s12='http://www.w3.org/2003/05/soap-envelope'><s12:Body> <foo>Hello!</foo> </s12:Body></s12:Envelope>";
                message.setContent(new StringSource(xml));
                System.out.println("sending message: " + i);
                DeliveryChannel deliveryChannel = context.getDeliveryChannel();
                System.out.println("sync send on deliverychannel: " + deliveryChannel);
                if (sync) {
                  deliveryChannel.sendSync(exchange);
                } else {
                  deliveryChannel.send(exchange);
                }
            }
        }
        else {
            log.warn("No endpoints available for interface: " + interfaceName);
View Full Code Here

    // Runnable interface
    //-------------------------------------------------------------------------
    public void run() {
        try {
            while (running) {
                DeliveryChannel deliveryChannel = context.getDeliveryChannel();
                System.out.println("about to do an accept on deliveryChannel: " + deliveryChannel);
                MessageExchange messageExchange = deliveryChannel.accept();
                System.out.println("received me: " + messageExchange);
                onMessageExchange(messageExchange);
            }
        }
        catch (MessagingException e) {
View Full Code Here

    /**
     * Creates a new InOnly exchange for the given service, interface and/or operation (any of which can be null).
     */
    public InOnly createInOnlyExchange(QName service, QName interfaceName, QName operation) throws MessagingException {
        DeliveryChannel channel = getDeliveryChannel();
        MessageExchangeFactory factory = null;
        if (service != null) {
            factory = channel.createExchangeFactoryForService(service);
        }
        else if (interfaceName != null) {
            factory = channel.createExchangeFactory(interfaceName);
        }
        else {
            factory = getExchangeFactory();
        }
        InOnly outExchange = factory.createInOnlyExchange();
View Full Code Here

TOP

Related Classes of javax.jbi.messaging.DeliveryChannel

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.