Package org.apache.servicemix.nmr.api

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


                    Channel client = null;
                    try {
                        client = nmr1.createChannel();
                        lock.readLock().lock();
                        for (int i = 0; i < nbExchanges; i++) {
                            Exchange exchange = client.createExchange(Pattern.InOnly);
                            exchange.getIn().setBody(new StringSource("<hello id='" + id.getAndIncrement() + "'/>"));
                            exchange.setTarget(nmr1.getEndpointRegistry().lookup(ServiceHelper.createMap(Endpoint.NAME, PROXY_ENDPOINT_NAME)));
                            client.sendSync(exchange);
                            assertEquals(Status.Done, exchange.getStatus());
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    } finally {
                        lock.readLock().unlock();
View Full Code Here


                    Channel client = null;
                    try {
                        client = nmr1.createChannel();
                        lock.readLock().lock();
                        for (int i = 0; i < nbExchanges; i++) {
                            Exchange exchange = client.createExchange(Pattern.InOut);
                            exchange.getIn().setBody(new StringSource("<hello/>"));
                            exchange.setTarget(nmr1.getEndpointRegistry().lookup(ServiceHelper.createMap(Endpoint.NAME, PROXY_ENDPOINT_NAME)));
                            client.sendSync(exchange);
                            assertEquals(Status.Active, exchange.getStatus());
                            exchange.setStatus(Status.Done);
                            client.send(exchange);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    } finally {
View Full Code Here

        eip.setEndpoints(new EIPEndpoint[] { ep });
        eip.init(new ComponentContextImpl(reg, new SimpleComponentWrapper(eip), new HashMap()));
        eip.getLifeCycle().start();

        Channel channel = smx.createChannel();
        Exchange e = channel.createExchange(Pattern.InOnly);
        e.getIn().setBody("<hello/>");
        e.setTarget(smx.getEndpointRegistry().lookup(ServiceHelper.createMap(Endpoint.NAME, "{uri:foo}bar:ep")));
        channel.sendSync(e);
    }
View Full Code Here

        BindingMessageInfo bmi = control.createMock(BindingMessageInfo.class);
        EasyMock.expect(boi.getOutput()).andReturn(bmi);
        exchange.put(BindingOperationInfo.class, boi);
        Channel channel = control.createMock(Channel.class);
        EasyMock.expect(nmr.createChannel()).andReturn(channel);
        Exchange xchg = control.createMock(Exchange.class);
        EasyMock.expect(channel.createExchange(Pattern.InOut)).andReturn(xchg);
        org.apache.servicemix.nmr.api.Message inMsg = control.createMock(org.apache.servicemix.nmr.api.Message.class);
        EasyMock.expect(xchg.getIn()).andReturn(inMsg);
        // just need to make sure the customer header is set
        inMsg.setHeader("myHeader", "value");
        EasyMock.expectLastCall();
        EndpointRegistry endpoints = control.createMock(EndpointRegistry.class);
        EasyMock.expect(channel.getNMR()).andReturn(nmr);
        EasyMock.expect(nmr.getEndpointRegistry()).andReturn(endpoints);
        org.apache.servicemix.nmr.api.Message outMsg = control.createMock(org.apache.servicemix.nmr.api.Message.class);
        EasyMock.expect(xchg.getOut()).andReturn(outMsg);
       
        Source source = new StreamSource(new ByteArrayInputStream(
                            "<message>TestHelloWorld</message>".getBytes()));
        EasyMock.expect(outMsg.getBody(Source.class)).andReturn(source);
        EasyMock.expect(xchg.getOut()).andReturn(outMsg);
        EasyMock.expect(outMsg.getAttachments()).andReturn(new HashMap<String, Object>());
        EasyMock.expect(outMsg.getHeaders()).andReturn(new HashMap<String, Object>());
        control.replay();
        try {
            conduit.prepare(message);
View Full Code Here

    /*
     * Handle a successfully completed Camel Exchange
     */
    public void onComplete(org.apache.camel.Exchange exchange) {
        Exchange nmr = getEndpoint().getComponent().getBinding().extractNmrExchange(exchange);
        handleCamelResponse(nmr, exchange);
    }
View Full Code Here

    /*
     * Handle a Caml exchange failure
     */
    public void onFailure(org.apache.camel.Exchange exchange) {
        Exchange nmr = getEndpoint().getComponent().getBinding().extractNmrExchange(exchange);
        handleCamelResponse(nmr, exchange);
    }
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

                return;
            } else {
                InputStream bais = getInputStream();
                StreamSource ss = new StreamSource(bais);
                          
                Exchange xchng = inMessage.get(Exchange.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.hasDetails()) {
                        xchng.setError(f);
                    }
                    // As the fault is already marshalled by the fault handler
                    xchng.getFault().setBody(ss);
                } else {
                    //copy attachments
                    if (outMessage != null && outMessage.getAttachments() != null) {
                        for (Attachment att : outMessage.getAttachments()) {
                            xchng.getOut().addAttachment(att.getId(), att
                                    .getDataHandler());
                        }
                    }
                   
                    //copy properties
                    for (Map.Entry<String, Object> ent : outMessage.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)) {
                            xchng.getOut().setHeader(ent.getKey(), ent.getValue());
                        }
                    }

                    //copy securitySubject
                    xchng.getOut().setSecuritySubject((Subject) outMessage.get(NMRTransportFactory.NMR_SECURITY_SUBJECT));
                    xchng.getOut().setBody(ss);
                }
                LOG.fine(new org.apache.cxf.common.i18n.Message("POST.DISPATCH", LOG).toString());
                channel.send(xchng);
            }
        } catch (Exception ex) {
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.