Package javax.jbi.messaging

Examples of javax.jbi.messaging.DeliveryChannel


            }
        }
        public void run() {
            while (running) {
                try {
                    DeliveryChannel deliveryChannel = getContext().getDeliveryChannel();
                    MessageExchange messageExchange = deliveryChannel.accept();
                    process(messageExchange);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
View Full Code Here


        }
        try {
          if (soapAction != null) {
            XFireServletController.getResponse().setHeader("SOAPAction", soapAction);
          }
            DeliveryChannel channel = getDeliveryChannel();
            MessageExchangeFactory factory = channel.createExchangeFactory();
            InOnly exchange = factory.createInOnlyExchange();
            populateExchange(exchange, source, context);
            boolean result = channel.sendSync(exchange);
            if (!result) {
                throw new XFireFault("Error sending exchange", XFireFault.SENDER);
            }
        } catch (XFireFault e) {
            throw e;
View Full Code Here

        }
        try {
          if (soapAction != null) {
            XFireServletController.getResponse().setHeader("SOAPAction", soapAction);
          }
            DeliveryChannel channel = getDeliveryChannel();
            MessageExchangeFactory factory = channel.createExchangeFactory();
            InOut exchange = factory.createInOutExchange();
            populateExchange(exchange, source, context);
            boolean result = channel.sendSync(exchange);
            if (!result) {
                throw new XFireFault("Error sending exchange", XFireFault.SENDER);
            }
            if (exchange.getStatus() == ExchangeStatus.ERROR) {
                Exception e = exchange.getError();
                if (e == null) {
                    throw new XFireFault("Received error", XFireFault.SENDER);
                } else {
                    throw new XFireFault(e, XFireFault.SENDER);
                }
            }
            NormalizedMessage outMessage = exchange.getOutMessage();
            if (outMessage == null) {
                exchange.setError(new Exception("Expected an out message"));
                channel.sendSync(exchange);
                throw new XFireFault("No response", XFireFault.SENDER);
            }                   
            Source src = exchange.getOutMessage().getContent();
            exchange.setStatus(ExchangeStatus.DONE);
            channel.send(exchange);
            src = transformer.toDOMSource(src);
            return src;
        } catch (XFireFault e) {
            throw e;
        } catch (Exception e) {
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

    public void testThrottle() 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();
        // test
        ComponentMBeanImpl componentMbeanImpl = container.getRegistry().getComponent("component");
        assertNotNull(componentMbeanImpl);
        componentMbeanImpl.setExchangeThrottling(true);
        componentMbeanImpl.setThrottlingTimeout(4000);
       

        class ProviderThread extends Thread {
            private int counter;
            private DeliveryChannel channel;
            public ProviderThread(int counter, DeliveryChannel channel) {
                this.counter = counter;
                this.channel = channel;
            }

            public void run() {

                try {
                    InOut me = (InOut) channel.accept(10000);
                    NormalizedMessage nm = me.createMessage();
                    nm.setContent(new StringSource("<response>" + counter
                            + "</response>"));
                    me.setOutMessage(nm);
                    channel.sendSync(me);

                } catch (MessagingException e) {
                    LOG.error(e.getMessage(), e);

                }
            }
           
        }
       
       
        for (int i = 0; i < 6; i++) {
          
            MessageExchangeFactory factory = channel.createExchangeFactoryForService(new QName("service"));
            InOut me = factory.createInOutExchange();
            NormalizedMessage nm = me.createMessage();
            nm.setContent(new StringSource("<request>" + i + "</request>"));
            me.setInMessage(nm);
            Thread t = new ProviderThread(i, channel);
            t.start();
            long before = System.currentTimeMillis();
            channel.sendSync(me, 5000);
            long after = System.currentTimeMillis();
            if (i % 2 == 1) {
                // throttle sleep 4000ms for every 2 message, so
                // the duration should > 4000ms
                assertTrue(after - before > 4000);
            } else {
                assertTrue(after - before < 4000);
            }
            assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
            me.setStatus(ExchangeStatus.DONE);
            channel.send(me);
            t.join();
        }
    }
View Full Code Here

      if (folder == null || !folder.exists()) {
        throw new Exception("Folder not found or invalid: " + mailBox);
      }
      folder.open(Folder.READ_WRITE);
      int msgCount = Math.min(folder.getMessageCount(),maxFetchSize);
      DeliveryChannel channel = getDeliveryChannel();
      MessageExchangeFactory mef = getExchangeFactory();
        for(int i=1; i <= msgCount;i++) {
          MimeMessage mailMsg = (MimeMessage) folder.getMessage(i);
          InOnly io = mef.createInOnlyExchange();
          NormalizedMessage normalizedMessage = io.createMessage();
          this.marshaler.prepareExchange(io,normalizedMessage,mailMsg);
          io.setInMessage(normalizedMessage);
          channel.send(io);
            mailMsg.setFlag(Flags.Flag.DELETED,true);
        }
    } finally {
      try {
        if (folder != null) {
View Full Code Here

    }

    // Helper methods for the rule base
    //-------------------------------------------------------------------------
    public void forwardToService(MessageExchange exchange, NormalizedMessage in, QName name) throws MessagingException {
        DeliveryChannel channel = getDeliveryChannel();
        MessageExchangeFactory factory = channel.createExchangeFactoryForService(name);
        InOnly outExchange = factory.createInOnlyExchange();
        String processCorrelationId = (String)exchange.getProperty(JbiConstants.CORRELATION_ID);
        if (processCorrelationId != null) {
            outExchange.setProperty(JbiConstants.CORRELATION_ID, processCorrelationId);
        }
View Full Code Here

        forwardToExchange(exchange, outExchange, in);
    }


    public void forwardToInterface(QName name, MessageExchange exchange, NormalizedMessage in) throws MessagingException {
        DeliveryChannel channel = getDeliveryChannel();
        MessageExchangeFactory factory = channel.createExchangeFactory(name);
        InOnly outExchange = factory.createInOnlyExchange();
        String processCorrelationId = (String)exchange.getProperty(JbiConstants.CORRELATION_ID);
        if (processCorrelationId != null) {
            outExchange.setProperty(JbiConstants.CORRELATION_ID, processCorrelationId);
        }
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.