Package org.apache.servicemix.nmr.api

Examples of org.apache.servicemix.nmr.api.Exchange


    assertNull(e.getFault());
  }

  @Test
  public void testRobustInOnly() {
    Exchange e = new ExchangeImpl(Pattern.RobustInOnly);
    assertNotNull(e.getIn());
    assertNull(e.getOut());
    assertNotNull(e.getFault());
  }
View Full Code Here


    assertNotNull(e.getFault());
  }

  @Test
  public void testInOut() {
    Exchange e = new ExchangeImpl(Pattern.InOut);
    assertNotNull(e.getIn());
    assertNotNull(e.getOut());
    assertNotNull(e.getFault());
  }
View Full Code Here

    assertNotNull(e.getFault());
  }

  @Test
  public void testInOptionalOut() {
    Exchange e = new ExchangeImpl(Pattern.InOptionalOut);
    assertNotNull(e.getIn());
    assertNotNull(e.getOut());
    assertNotNull(e.getFault());
  }
View Full Code Here

        return factory;
    }

    public MessageExchange accept() throws MessagingException {
        try {
            Exchange exchange = queue.take();
            if (exchange == null) {
                return null;
            }
            MessageExchange me = getMessageExchange(exchange);
            ((MessageExchangeImpl) me).beforeReceived();
View Full Code Here

    public MessageExchange accept(long timeout) throws MessagingException {
        try {
            long t0  = System.currentTimeMillis();
            long cur = t0;
            while (cur - t0 < timeout) {
                Exchange exchange = queue.poll(t0 + timeout - cur, TimeUnit.MILLISECONDS);
                if (exchange == null || exchange.getError() instanceof AbortedException) {
                    cur = System.currentTimeMillis();
                    continue;
                }
                MessageExchange me = getMessageExchange(exchange);
                ((MessageExchangeImpl) me).beforeReceived();
View Full Code Here

        ((MessageExchangeImpl) exchange).afterSend();
        return channel.sendSync(((MessageExchangeImpl) exchange).getInternalExchange(), timeout);
    }

    protected void createTarget(MessageExchange messageExchange) throws MessagingException {
        Exchange exchange = ((MessageExchangeImpl) messageExchange).getInternalExchange();
        if (exchange.getTarget() == null) {
            Map<String, Object> props = new HashMap<String, Object>();
            if (messageExchange.getEndpoint() != null) {
                props.put(Endpoint.SERVICE_NAME, messageExchange.getEndpoint().getServiceName());
                props.put(Endpoint.ENDPOINT_NAME, messageExchange.getEndpoint().getEndpointName());
            } else {
                QName serviceName = messageExchange.getService();
                if (serviceName != null) {
                    props.put(Endpoint.SERVICE_NAME, serviceName);
                } else {
                    QName interfaceName = messageExchange.getInterfaceName();
                    if (interfaceName != null) {
                        props.put(Endpoint.INTERFACE_NAME, interfaceName);
                    }
                }
            }
            if (props.isEmpty()) {
                throw new MessagingException("No endpoint, service or interface name specified for routing");
            }
            Reference target = context.getNmr().getEndpointRegistry().lookup(props);
            exchange.setTarget(target);
        }
    }
View Full Code Here

public class ExchangeImplTest {

    @Test
    public void testWrite() 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", "att");
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream os = new ObjectOutputStream(baos);
        os.writeObject(e);
        os.close();
        ObjectInputStream is = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
        Exchange cpy = (Exchange) is.readObject();
        assertNotNull(cpy);
        assertEquals(e.getId(), cpy.getId());
        assertEquals(e.getStatus(), cpy.getStatus());
        assertEquals(e.getRole(), cpy.getRole());
        assertEquals(e.getPattern(), cpy.getPattern());
        assertEquals(e.getOperation(), cpy.getOperation());
        assertEquals(e.getProperty("key"), cpy.getProperty("key"));
        assertNotNull(cpy.getIn());
        assertNotNull(cpy.getIn().getHeader("header"));
        assertNotNull(cpy.getIn().getAttachment("id"));
    }
View Full Code Here

                }
                return super.loadClass(name, resolve);
            }
        };
        Class cls = cl.loadClass(ExchangeImpl.class.getName());
        Exchange e = (Exchange) cls.getConstructor(Pattern.class).newInstance(Pattern.InOut);
        e.setProperty("key", "<hello>world</hello>");
        assertNull(e.getProperty("key", byte[].class));
    }
View Full Code Here

        assertNull(e.getProperty("key", byte[].class));
    }

    @Test
    public void testCopy() {
        Exchange e = new ExchangeImpl(Pattern.InOut);
        Exchange cpy = e.copy();
        assertNotNull(cpy);
        assertNull(cpy.getIn(false));
        assertNull(cpy.getOut(false));
        assertNull(cpy.getFault(false));

        e = new ExchangeImpl(Pattern.InOut);
        e.setProperty("header", "value");
        e.getIn();
        cpy = e.copy();
        assertNotNull(cpy);
        assertNotNull(cpy.getProperty("header"));
        assertNotNull(cpy.getIn(false));
    }
View Full Code Here

        assertNotNull(cpy.getIn(false));
    }

    @Test
    public void testMessages() {
        Exchange e = new ExchangeImpl(Pattern.InOut);
        assertNull(e.getMessage(Type.In, false));
        assertNull(e.getMessage(Type.Out, false));
        assertNull(e.getMessage(Type.Fault, false));
        assertNotNull(e.getMessage(Type.In));
        assertNotNull(e.getMessage(Type.Out));
        assertNotNull(e.getMessage(Type.Fault));
        assertNotNull(e.getMessage(Type.In));
        assertNotNull(e.getMessage(Type.Out));
        assertNotNull(e.getMessage(Type.Fault));
        assertNotNull(e.getMessage(Type.In, false));
        assertNotNull(e.getMessage(Type.Out, false));
        assertNotNull(e.getMessage(Type.Fault, false));
        e.setMessage(Type.In, null);
        e.setMessage(Type.Out, null);
        e.setMessage(Type.Fault, null);
    }
View Full Code Here

TOP

Related Classes of org.apache.servicemix.nmr.api.Exchange

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.