Package org.apache.servicemix.nmr.core

Examples of org.apache.servicemix.nmr.core.ExchangeImpl


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());
View Full Code Here

        super(Phase.PRE_PROTOCOL);
        addBefore(NMROperationInInterceptor.class.getName());
    }

    public void handleMessage(NMRMessage message) throws Fault {
        ExchangeImpl exchange = new ExchangeImpl(Pattern.InOut);

        if (index == 1) {
            exchange.setOperation(new QName("http://apache.org/hello_world/nmr", "greetMe"));
            index++;
        } else if (index == 2) {
            exchange.setOperation(new QName("http://apache.org/hello_world/nmr", "sayHi"));
            index++;
        } else if (index == 3) {
            exchange.setOperation(new QName("http://apache.org/hello_world/nmr", "pingMe"));
            index++;
        }
        message.put(Exchange.class, exchange);
    }
View Full Code Here

        InternalEndpoint endpoint = new InternalEndpointWrapper(new EndpointImpl(ServiceHelper.createMap(Endpoint.ENDPOINT_NAME, "endpoint")),
                                                                ServiceHelper.createMap(Endpoint.ENDPOINT_NAME, "internal-endpoint"));
        listener.endpointRegistered(endpoint);
        listener.setAssembly(null);
       
        InternalExchange exchange = new ExchangeImpl(Pattern.InOnly);
        exchange.setSource(endpoint);
        exchange.setProperty(DeliveryChannelImpl.SEND_SYNC, Boolean.TRUE);
        listener.exchangeSent(exchange);
       
        assertEquals(1, listener.getPending(sa).size());
       
        exchange.setStatus(Status.Done);
        listener.exchangeDelivered(exchange);
       
        assertEquals(0, listener.getPending(sa).size());
    }
View Full Code Here

        InternalEndpoint endpoint = new InternalEndpointWrapper(new EndpointImpl(ServiceHelper.createMap(Endpoint.ENDPOINT_NAME, "endpoint")),
                                                                ServiceHelper.createMap(Endpoint.ENDPOINT_NAME, "internal-endpoint"));
        listener.endpointRegistered(endpoint);
        listener.setAssembly(null);
       
        InternalExchange exchange = new ExchangeImpl(Pattern.InOnly);
        exchange.setSource(endpoint);
        exchange.setProperty(DeliveryChannelImpl.SEND_SYNC, Boolean.TRUE);
        listener.exchangeSent(exchange);
       
        assertEquals(1, listener.getPending(sa).size());
       
        exchange.setStatus(Status.Error);
        listener.exchangeFailed(exchange);
       
        assertEquals(0, listener.getPending(sa).size());
    }
View Full Code Here

        InternalEndpoint endpoint = new InternalEndpointWrapper(new EndpointImpl(ServiceHelper.createMap(Endpoint.ENDPOINT_NAME, "endpoint")),
                                                                ServiceHelper.createMap(Endpoint.ENDPOINT_NAME, "internal-endpoint"));
        listener.endpointRegistered(endpoint);
        listener.setAssembly(null);
       
        InternalExchange exchange = new ExchangeImpl(Pattern.InOnly);
        exchange.setSource(endpoint);
        exchange.setProperty(DeliveryChannelImpl.SEND_SYNC, Boolean.TRUE);
        exchange.getConsumerLock(true);
        listener.exchangeSent(exchange);
       
        assertEquals(1, listener.getPending(sa).size());
       
        listener.cancelPendingSyncExchanges(sa);
        assertEquals(Status.Error, exchange.getStatus());
    }
View Full Code Here

public class ExchangeUtilsTest extends TestCase {

    private static final Log LOG = LogFactory.getLog(ExchangeUtilsTest.class);

    public void testReReadable() throws Exception {
        Exchange e = new ExchangeImpl(Pattern.InOnly);
        Message msg = e.getIn();
        msg.addAttachment("id", new BufferedInputStream(new ByteArrayInputStream(new byte[] { 1, 2, 3, 4 })));
        msg.setBody(new DOMSource(parse("<hello/>")));

        e.ensureReReadable();

        assertNotNull(msg.getBody());
        assertTrue(msg.getBody() instanceof StringSource);
        assertNotNull(msg.getAttachment("id"));
        assertTrue(msg.getAttachment("id") instanceof ByteArrayInputStream);
View Full Code Here

        assertNotNull(msg.getAttachment("id"));
        assertTrue(msg.getAttachment("id") instanceof ByteArrayInputStream);
    }

    public void testDisplay() throws Exception {
        Exchange e = new ExchangeImpl(Pattern.InOnly);
        e.setOperation(new QName("op"));
        e.setProperty("key", "value");
        e.setStatus(Status.Done);
        Message msg = e.getIn();
        msg.setHeader("header", "value");
        msg.addAttachment("id", new BufferedInputStream(new ByteArrayInputStream(new byte[] { 1, 2, 3, 4 })));
        msg.setBody(new StringSource("<hello/>"));

        String str = e.display(false);
        LOG.info(str);
        assertNotNull(msg.getBody());
        assertTrue(msg.getBody() instanceof StringSource);
        assertNotNull(msg.getAttachment("id"));
        assertTrue(msg.getAttachment("id") instanceof BufferedInputStream);

        str = e.display(true);
        LOG.info(str);
        assertNotNull(msg.getBody());
        assertTrue(msg.getBody() instanceof StringSource);
        assertNotNull(msg.getAttachment("id"));
        assertTrue(msg.getAttachment("id") instanceof ByteArrayInputStream);
View Full Code Here

     * @return InOnly exchange
     * @throws MessagingException
     */
    public InOnly createInOnlyExchange() throws MessagingException {
        checkNotClosed();
        InOnlyImpl result = new InOnlyImpl(new ExchangeImpl(Pattern.InOnly));
        setDefaults(result);
        return result;
    }
View Full Code Here

     * @return RobsutInOnly exchange
     * @throws MessagingException
     */
    public RobustInOnly createRobustInOnlyExchange() throws MessagingException {
        checkNotClosed();
        RobustInOnlyImpl result = new RobustInOnlyImpl(new ExchangeImpl(Pattern.RobustInOnly));
        setDefaults(result);
        return result;
    }
View Full Code Here

TOP

Related Classes of org.apache.servicemix.nmr.core.ExchangeImpl

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.