Package javax.jbi.messaging

Examples of javax.jbi.messaging.DeliveryChannel


                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));
                LOGGER.info("sending message: {}", i);
                DeliveryChannel deliveryChannel = context.getDeliveryChannel();
                LOGGER.info("sync send on deliverychannel: {}", deliveryChannel);
                if (sync) {
                    deliveryChannel.sendSync(exchange);
                } else {
                    deliveryChannel.send(exchange);
                }
            }
        } else {
            LOGGER.warn("No endpoints available for interface: {}", interfaceName);
        }
View Full Code Here


            LOGGER.debug("Subscription Endpoint: {}", endpoint.getEndpointName());
        }
        // SM-229: Avoid StackOverflowException
        Boolean source = (Boolean) exchange.getProperty(FROM_SUBSCRIPTION_MANAGER);
        if (source == null || !source.booleanValue()) {
            DeliveryChannel channel = getDeliveryChannel();
            InOnly me = channel.createExchangeFactory().createInOnlyExchange();
            // SM-229: Avoid StackOverflowException
            me.setProperty(FROM_SUBSCRIPTION_MANAGER, Boolean.TRUE);
            NormalizedMessage in = me.createMessage();
            getMessageTransformer().transform(me, exchange.getInMessage(), in);
            me.setInMessage(in);
            me.setEndpoint(endpoint);
            Set names = exchange.getPropertyNames();
            for (Iterator iter = names.iterator(); iter.hasNext();) {
                String name = (String) iter.next();
                me.setProperty(name, exchange.getProperty(name));
            }
            if (Boolean.TRUE.equals(exchange.getProperty(JbiConstants.SEND_SYNC))) {
                channel.sendSync(me);
            } else {
                channel.send(me);
            }
        }
    }
View Full Code Here

    // Runnable interface
    //-------------------------------------------------------------------------
    public void run() {
        while (running) {
            try {
                DeliveryChannel deliveryChannel = context.getDeliveryChannel();
                LOGGER.info("about to do an accept on deliveryChannel: {}", deliveryChannel);
                MessageExchange messageExchange = deliveryChannel.accept();
                LOGGER.info("received me: {}", messageExchange);
                onMessageExchange(messageExchange);
            } catch (MessagingException e) {
                LOGGER.error("Failed to process inbound messages: {}", e.getMessage(), e);
            }
View Full Code Here

            }
        }
        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

    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) {
                    LOGGER.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) {
                    LOGGER.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

        this.oneWay = oneWay;
    }
   
    public void initialize() {
        try {
            DeliveryChannel channel =
                    JavaEEServiceEngineContext.getInstance(). getDeliveryChannel();
            String key = DescriptorEndpointInfo.getDEIKey(service, endpointName);
            DescriptorEndpointInfo dei = EndpointRegistry.getInstance().getJBIEndpts().get(key);
            QName service = (dei == null)? this.service:dei.getServiceName();
            String endpointName = (dei == null)? this.endpointName:dei.getEndpointName();

            // Create MessageExchange
            MessageExchangeFactory factory =
                    channel.createExchangeFactoryForService(service);
            me =  oneWay ? factory.createInOnlyExchange() : factory.createInOutExchange();
            me.setService(service);
            ComponentContext context = JavaEEServiceEngineContext.getInstance().getJBIContext();
            me.setEndpoint(context.getEndpoint(service, endpointName));
            me.setOperation(operation);
View Full Code Here

    try {
      AgilaComponent component = AgilaComponent.getInstance();
      if (component == null) {
        throw new IllegalStateException("AgilaComponent is not initialized");
      }
      DeliveryChannel channel = component.getContext().getDeliveryChannel();
      MessageExchangeFactory mef = channel.createExchangeFactory();
      MessageExchange me = mef.createInOnlyExchange();
      me.setInterfaceName(new QName(namespace, portType));
      me.setOperation(new QName(namespace, operation));
      NormalizedMessage in = me.createMessage();
      in.setContent(new DocumentSource(message));
      me.setMessage(in, "in");
      channel.send(me);
    } catch (Exception e) {
      throw new EngineRuntimeException(e);
    }
  }
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.