Package javax.jbi.messaging

Examples of javax.jbi.messaging.DeliveryChannel


    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

        this.serviceUnit = ScaServiceUnit.getCurrentScaServiceUnit();
    }

    public Object invokeTarget(Object payload) throws InvocationTargetException {
        try {
            DeliveryChannel channel = serviceUnit.getComponent().getComponentContext().getDeliveryChannel();

            // TODO: in-only case ?
            // TODO: interface based routing ?
            // TODO: explicit endpoint selection ?

            InOut inout = channel.createExchangeFactory().createInOutExchange();
            inout.setService(serviceName);
            NormalizedMessage in = inout.createMessage();
            inout.setInMessage(in);
            in.setContent(new StringSource(payload.toString()));

            boolean sent = channel.sendSync(inout);
            // TODO: check for error ?

            NormalizedMessage out = inout.getOutMessage();
            Object response = out.getContent();
            inout.setStatus(ExchangeStatus.DONE);
            channel.send(inout);

            return response;

        } catch (MessagingException e) {
            throw new InvocationTargetException(e);
View Full Code Here

            Class outputClass = method.getReturnType();
            JAXBContext context = JAXBContext.newInstance(inputClass, outputClass);
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            context.createMarshaller().marshal(payload, baos);
           
            DeliveryChannel channel = serviceUnit.getComponent().getComponentContext().getDeliveryChannel();
            // TODO: in-only case ?
            // TODO: interface based routing ?
            // TODO: explicit endpoint selection ?
            InOut inout = channel.createExchangeFactory().createInOutExchange();
            inout.setService(jbiBinding.getServiceName());
            NormalizedMessage in = inout.createMessage();
            inout.setInMessage(in);
            in.setContent(new StringSource(baos.toString()));
            boolean sent = channel.sendSync(inout);
            // TODO: check for error ?
            NormalizedMessage out = inout.getOutMessage();
            Object response = context.createUnmarshaller().unmarshal(out.getContent());
            inout.setStatus(ExchangeStatus.DONE);
            channel.send(inout);
            return response;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here

     * Gets the delivery channel.
     *
     * @return delivery channel
     */
    public DeliveryChannel getChannel() {
        DeliveryChannel chnl = null;

        if (_context != null) {
            try {
                chnl = _context.getDeliveryChannel();
            } catch (Exception e) {
View Full Code Here

     * Gets the delivery channel.
     *
     * @return delivery channel
     */
    public DeliveryChannel getChannel() {
        DeliveryChannel chnl = null;

        if (_context != null) {
            try {
                chnl = _context.getDeliveryChannel();
            } catch (Exception e) {
View Full Code Here

     * Gets the delivery channel.
     *
     * @return delivery channel
     */
    public DeliveryChannel getChannel() {
        DeliveryChannel chnl = null;

        if (_context != null) {
            try {
                chnl = _context.getDeliveryChannel();
            } catch (Exception 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
            DeliveryChannel dc = channel;
            message.put(MessageExchange.class, inMessage.get(MessageExchange.class));
            message.setContent(OutputStream.class,
                               new JBIDestinationOutputStream(inMessage, message, dc));
        }       
View Full Code Here

            LOG.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

    /**
     * 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

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.