Package javax.jbi.messaging

Examples of javax.jbi.messaging.MessageExchange$Role


    public void run() {
        while (running) {
            try {
                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) {
                log.error("Failed to process inbound messages: " + e, e);
View Full Code Here


import junit.framework.TestCase;

public class MessageExchangeImplTest extends TestCase {
   
    protected void testSerializeDeserialize(Source src) throws Exception {
        MessageExchange me = new InOnlyImpl("exchangeId");
        me.setProperty("myProp", "myValue");
        NormalizedMessage msg = me.createMessage();
        msg.setProperty("myMsgProp", "myMsgValue");
        msg.setContent(src);
        //msg.addAttachment("myAttachment", null);
        me.setMessage(msg, "in");
       
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(baos);
        oos.writeObject(me);
        oos.close();
       
        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
        ObjectInputStream ois = new ObjectInputStream(bais);
        Object out = ois.readObject();
       
        assertNotNull(out);
        assertTrue(out instanceof MessageExchange);
        MessageExchange meOut = (MessageExchange) out;
        assertEquals("myValue", meOut.getProperty("myProp"));
        NormalizedMessage msgOut = meOut.getMessage("in");
        assertNotNull(msgOut);
        assertEquals("myMsgValue", msgOut.getProperty("myMsgProp"));
        Source outSrc = msgOut.getContent();
        assertNotNull(outSrc);
        String outStr = new SourceTransformer().toString(outSrc);
View Full Code Here

            __log.fatal("Error getting channel! ", ex);
            return;
        }

        while (_isRunning.get()) {
            final MessageExchange messageExchange;
            try {
                messageExchange = _channel.accept(TimeUnit.SECONDS.toMillis(ACCEPT_TIMEOUT));
                if (messageExchange != null) {
                    if (__log.isTraceEnabled()) {
                        __log.trace("Got JBI message for endpoint: " + messageExchange.getEndpoint().getEndpointName());
                    }

                    // Even if we got a message exchange, we only run it
                    // if we have not been told to cease.
                    if (_isRunning.get()) {
                        if (__log.isTraceEnabled()) {
                            __log.trace("Scheduling execution of " + messageExchange.getExchangeId());
                        }
                        _executorService.submit(new Runnable() {
                            public void run() {
                                try {
                                    _odeContext._jbiMessageExchangeProcessor.onJbiMessageExchange(messageExchange);
                                } catch (Throwable t) {
                                    __log.error("Error processing JBI message.", t);
                                }
                            }
                        });
                    } else {
                        __log.warn("Skipping processing of message exchange " + messageExchange.getExchangeId()
                                + "; component no longer active.");
                    }
                }
            } catch (MessagingException mex) {
                if (_isRunning.get())
View Full Code Here

        exchange.setOneWay(false);
        Message message = new MessageImpl();
        message.setExchange(exchange);
       
       
        MessageExchange messageExchange = control.createMock(MessageExchange.class);
        EasyMock.expect(messageExchange.createMessage()).andReturn(normalizedMessage);
        message.put(MessageExchange.class, messageExchange);
        channel.send(messageExchange);
        EasyMock.replay(channel);
       
        JBIDestinationOutputStream jbiOS = new JBIDestinationOutputStream(message, channel);
View Full Code Here

            }
         
            MessageExchangeFactory factory = channel.createExchangeFactoryForService(serviceName);
            LOG.info(new org.apache.cxf.common.i18n.Message("CREATE.MESSAGE.EXCHANGE", LOG).toString()
                     + serviceName);
            MessageExchange xchng = null;
            if (isOneWay) {
                xchng = factory.createInOnlyExchange();
            } else if (bop.getOutput() == null) {
                xchng = factory.createRobustInOnlyExchange();
            } else {
                xchng = factory.createInOutExchange();
            }

            NormalizedMessage inMsg = xchng.createMessage();
            LOG.info(new org.apache.cxf.common.i18n.Message("EXCHANGE.ENDPOINT", LOG).toString()
                     + xchng.getEndpoint());
            if (inMsg != null) {
                LOG.info("setup message contents on " + inMsg);
                inMsg.setContent(getMessageContent(message));
                xchng.setService(serviceName);
                LOG.info("service for exchange " + serviceName);

                xchng.setInterfaceName(interfaceName);

                xchng.setOperation(bop.getName());
                xchng.setMessage(inMsg, "in");
                LOG.info("sending message");
                if (!isOneWay) {
                    channel.sendSync(xchng);
                    NormalizedMessage outMsg = ((InOut)xchng).getOutMessage();
                    Source content = null;
View Full Code Here

            }
         
            MessageExchangeFactory factory = channel.createExchangeFactoryForService(serviceName);
            LOG.info(new org.apache.cxf.common.i18n.Message("CREATE.MESSAGE.EXCHANGE", LOG).toString()
                     + serviceName);
            MessageExchange xchng = null;
            if (isOneWay) {
                xchng = factory.createInOnlyExchange();
            } else if (bop.getOutput() == null) {
                xchng = factory.createRobustInOnlyExchange();
            } else {
                xchng = factory.createInOutExchange();
            }

            NormalizedMessage inMsg = xchng.createMessage();
            LOG.info(new org.apache.cxf.common.i18n.Message("EXCHANGE.ENDPOINT", LOG).toString()
                     + xchng.getEndpoint());
            if (inMsg != null) {
                LOG.info("setup message contents on " + inMsg);
                inMsg.setContent(getMessageContent(message));
                xchng.setService(serviceName);
                LOG.info("service for exchange " + serviceName);

                xchng.setInterfaceName(interfaceName);

                xchng.setOperation(bop.getName());
                //copy context
                Map<String, Object> invocationContext =
                    CastUtils.cast((Map)message.get(Message.INVOCATION_CONTEXT));
                if (invocationContext != null) {
                    for (Map.Entry<String, Object> ent
                        : CastUtils.cast((Map)invocationContext.get("RequestContext"),
                                             String.class, Object.class).entrySet()) {
                        // check if value is Serializable, and if value is Map
                        // or collection,
                        // just exclude it since the entry of it may not be
                        // Serializable as well
                        if (ent.getValue() instanceof Serializable
                                && !(ent.getValue() instanceof Map)
                                && !(ent.getValue() instanceof Collection)) {
                            inMsg.setProperty(ent.getKey(), ent.getValue());
                        }
                    }
                }
                xchng.setMessage(inMsg, "in");
                LOG.info("sending message");
                if (!isOneWay) {
                    channel.sendSync(xchng);
                    NormalizedMessage outMsg = ((InOut)xchng).getOutMessage();
                    Source content = null;
                    Set normalizedMessageProps = null;
                    if (outMsg != null) {
                        content = outMsg.getContent();
                        normalizedMessageProps = outMsg.getPropertyNames();
                    } else {
                        if (((InOut)xchng).getFault() == null) {
                            throw xchng.getError();
                        }
                        content = ((InOut)xchng).getFault().getContent();
                        normalizedMessageProps = ((InOut)xchng).getFault().getPropertyNames();
                    }
                    Message inMessage = new MessageImpl();
                    message.getExchange().setInMessage(inMessage);
                    InputStream ins = JBIMessageHelper.convertMessageToInputStream(content);
                    if (ins == null) {
                        throw new IOException(new org.apache.cxf.common.i18n.Message(
                            "UNABLE.RETRIEVE.MESSAGE", LOG).toString());
                    }
                    inMessage.setContent(InputStream.class, ins);
                    inMessage.put(MessageExchange.class, xchng);
                   
                   
                    if (normalizedMessageProps != null) {
                 
                        for (Object name : normalizedMessageProps) {
                            inMessage.put((String) name, outMsg
                                    .getProperty((String) name));

                        }
                    }
                    conduit.getMessageObserver().onMessage(inMessage);

                    xchng.setStatus(ExchangeStatus.DONE);
                    channel.send(xchng);                   
                } else {
                    channel.send(xchng);
                }
View Full Code Here

                    "BUILDING.DOCUMENT", LOG).toString());
                Document doc = StaxUtils.read(bais);
                bais.close();
               
               
                MessageExchange xchng = inMessage.get(MessageExchange.class);
                LOG.fine(new org.apache.cxf.common.i18n.Message(
                    "CREATE.NORMALIZED.MESSAGE", LOG).toString());
                if (inMessage.getExchange().getOutFaultMessage() != null) {
                    org.apache.cxf.interceptor.Fault f = (org.apache.cxf.interceptor.Fault)
                            inMessage.getContent(Exception.class);
                    if (!(f.getCause() instanceof Error)) {
                        Fault fault = xchng.createFault();
                        fault.setContent(new DOMSource(doc));
                        xchng.setFault(fault);
                        if (!f.hasDetails()) {
                            xchng.setProperty("faultstring", f.getMessage());
                        }
                    } else {
                        xchng.setError(f);
                    }
                } else {
                    NormalizedMessage msg = xchng.createMessage();
                    //copy attachments
                    if (outMessage != null && outMessage.getAttachments() != null) {
                        for (Attachment att : outMessage.getAttachments()) {
                            msg.addAttachment(att.getId(), att
                                    .getDataHandler());
                        }
                    }
                    //copy properties
                   
                    for (Map.Entry<String, Object> ent : inMessage.entrySet()) {
                        //check if value is Serializable, and if value is Map or collection,
                        //just exclude it since the entry of it may not be Serializable as well
                        if (ent.getValue() instanceof Serializable
                                && !(ent.getValue() instanceof Map)
                                && !(ent.getValue() instanceof Collection)) {
                            msg.setProperty(ent.getKey(), ent.getValue());
                        }
                    }


                    //copy contents
                    msg.setContent(new DOMSource(doc));
                    xchng.setMessage(msg, "out");
                   
                }
                LOG.fine(new org.apache.cxf.common.i18n.Message(
                    "POST.DISPATCH", LOG).toString());
                if (xchng.getStatus() == ExchangeStatus.ACTIVE
                        && Boolean.TRUE.equals(xchng.getProperty(SEND_SYNC))) {
                    channel.sendSync(xchng);
                } else {
                    channel.send(xchng);
                }
            }
View Full Code Here

import org.apache.servicemix.nmr.api.Pattern;

public class MessageExchangeImplTest extends TestCase {

    public void testMep() {
        MessageExchange me;

        me = new MessageExchangeImpl(new ExchangeImpl(Pattern.InOnly));
        assertEquals("http://www.w3.org/2004/08/wsdl/in-only", me.getPattern().toString());

        me = new MessageExchangeImpl(new ExchangeImpl(Pattern.InOut));
        assertEquals("http://www.w3.org/2004/08/wsdl/in-out", me.getPattern().toString());

        me = new MessageExchangeImpl(new ExchangeImpl(Pattern.InOptionalOut));
        assertEquals("http://www.w3.org/2004/08/wsdl/in-opt-out", me.getPattern().toString());

        me = new MessageExchangeImpl(new ExchangeImpl(Pattern.RobustInOnly));
        assertEquals("http://www.w3.org/2004/08/wsdl/robust-in-only", me.getPattern().toString());
    }
View Full Code Here

            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                throw new UnsupportedOperationException();
            }
        });

        MessageExchange me = new InOnlyImpl(new ExchangeImpl(Pattern.InOnly));
        URIResolver.configureExchange(me, ctx, "interface:urn:test");
        assertEquals(new QName("urn", "test"), me.getInterfaceName());
        assertNull(me.getOperation());
        assertNull(me.getService());
        assertNull(me.getEndpoint());

        me = new InOnlyImpl(new ExchangeImpl(Pattern.InOnly));
        URIResolver.configureExchange(me, ctx, "operation:urn:test:op");
        assertEquals(new QName("urn", "test"), me.getInterfaceName());
        assertEquals(new QName("urn", "op"), me.getOperation());
        assertNull(me.getService());
        assertNull(me.getEndpoint());

        me = new InOnlyImpl(new ExchangeImpl(Pattern.InOnly));
        URIResolver.configureExchange(me, ctx, "service:urn:test");
        assertNull(me.getInterfaceName());
        assertNull(me.getOperation());
        assertEquals(new QName("urn", "test"), me.getService());
        assertNull(me.getEndpoint());

        ctx = (ComponentContext) Proxy.newProxyInstance(ComponentContext.class.getClassLoader(),
                                                        new Class[] { ComponentContext.class },
                                                        new InvocationHandler() {
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                assertEquals("getEndpoint", method.getName());
                assertEquals(new QName("urn", "svc"), args[0]);
                assertEquals("ep", args[1]);
                return new ServiceEndpointImpl((QName) args[0], (String) args[1]);
            }
        });
        me = new InOnlyImpl(new ExchangeImpl(Pattern.InOnly));
        URIResolver.configureExchange(me, ctx, "endpoint:urn:svc:ep");
        assertNull(me.getInterfaceName());
        assertNull(me.getOperation());
        assertNull(me.getService());
        assertNotNull(me.getEndpoint());

        ctx = (ComponentContext) Proxy.newProxyInstance(ComponentContext.class.getClassLoader(),
                                                        new Class[] { ComponentContext.class },
                                                        new InvocationHandler() {
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                assertEquals("resolveEndpointReference", method.getName());
                assertTrue(args[0] instanceof DocumentFragment);
                return new ServiceEndpointImpl(new QName("svc"), "ep");
            }
        });
        me = new InOnlyImpl(new ExchangeImpl(Pattern.InOnly));
        URIResolver.configureExchange(me, ctx, "http://urn/");
        assertNull(me.getInterfaceName());
        assertNull(me.getOperation());
        assertNull(me.getService());
        assertNotNull(me.getEndpoint());

        try {
            URIResolver.configureExchange(null, ctx, "service:urn:test");
            fail("Should have thrown a NPE");
        } catch (NullPointerException e) {
View Full Code Here

        try {
            Exchange exchange = queue.take();
            if (exchange == null) {
                return null;
            }
            MessageExchange me = getMessageExchange(exchange);
            ((MessageExchangeImpl) me).beforeReceived();
            return me;
        } catch (InterruptedException e) {
            throw new MessagingException(e);
        }
View Full Code Here

TOP

Related Classes of javax.jbi.messaging.MessageExchange$Role

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.