Package org.switchyard

Examples of org.switchyard.Exchange


        boolean isGatewayRoute = camelExchange.getProperty(SwitchYardConsumer.IMPLEMENTATION_ROUTE) == null;
       
        // the composer is not used for switchyard:// endpoints invoked from service routes
        MessageComposer<CamelBindingData> composer =
                isGatewayRoute ? getMessageComposer(camelExchange) : null;
        final Exchange switchyardExchange = createSwitchyardExchange(camelExchange, serviceRef, composer);

        // Set appropriate policy based on Camel exchange properties
        if (camelExchange.isTransacted()) {
            PolicyUtil.provide(switchyardExchange, TransactionPolicy.PROPAGATES_TRANSACTION);
            PolicyUtil.provide(switchyardExchange, TransactionPolicy.MANAGED_TRANSACTION_GLOBAL);
        }
       
        // Message composition depends on whether this switchyard:// endpoint is called from
        // a Camel service implementation or a Camel gateway
        Message switchyardMessage;
        if (isGatewayRoute) {
            switchyardMessage = composeForGateway(composer, camelExchange, switchyardExchange);
        } else {
            switchyardMessage = ExchangeMapper.mapCamelToSwitchYard(
                    camelExchange, switchyardExchange, ExchangePhase.IN);
        }
       
        switchyardExchange.send(switchyardMessage);
    }
View Full Code Here


            }

            if (method.getReturnType() != null && !Void.TYPE.isAssignableFrom(method.getReturnType())) {
                SynchronousInOutHandler inOutHandler = new SynchronousInOutHandler();

                Exchange exchangeIn = createExchange(_service, method, inOutHandler);
                // Don't set the message content as an array unless there are multiple arguments
                if (args != null && args.length == 1) {
                    exchangeIn.send(exchangeIn.createMessage().setContent(args[0]));
                } else {
                    exchangeIn.send(exchangeIn.createMessage().setContent(args));
                }

                Exchange exchangeOut = inOutHandler.waitForOut();
                if (exchangeOut.getState() == ExchangeState.OK) {
                    return exchangeOut.getMessage().getContent(method.getReturnType());
                } else {
                    return handleException(exchangeOut, method);
                }
            } else {
                Exchange exchange = createExchange(_service, method, null);
                // Don't set the message content as an array unless there are multiple arguments
                if (args == null) {
                    exchange.send(exchange.createMessage());
                } else if (args.length == 1) {
                    exchange.send(exchange.createMessage().setContent(args[0]));
                } else {
                    exchange.send(exchange.createMessage().setContent(args));
                }

                Object propagateException = _service.getDomain().getProperty(Exchange.PROPAGATE_EXCEPTION_ON_IN_ONLY);
                if (propagateException != null && Boolean.parseBoolean(propagateException.toString())
                        && exchange.getState().equals(ExchangeState.FAULT)) {
                    handleException(exchange, method);
                }
                return null;
            }
        }
View Full Code Here

    /**
     * Gets the {@link Exchange} for the current thread.
     * @return the message
     */
    private static Exchange getExchange() {
        Exchange exchange = EXCHANGE.get();
        if (exchange == null) {
            throw BeanMessages.MESSAGES.illegalExchangeAccessOutsideHandlerChain();
        }
        return exchange;
    }
View Full Code Here

    @Override
    public ReferenceInvocation newInvocation(String operation) {
        assertReference();
        InvocationResponseHandler handler = new InvocationResponseHandler();
        Exchange exchange = _reference.createExchange(operation, handler);
        return new ExchangeInvocation(exchange, handler);
    }
View Full Code Here

            // Unwrap the first two levels, to remove the part wrapper
            Node node=WSDLHelper.unwrapMessagePart(mesg);
           
            // Need to create an exchange
            SynchronousInOutHandler rh = new SynchronousInOutHandler();
            Exchange exchange=_serviceReference.createExchange(operationName, rh);

            Message req = exchange.createMessage();
            req.setContent(node);
            if (headers != null) {
               
                for (Map.Entry<String, Object> e : headers.entrySet()) {
                    exchange.getContext(req).setProperty(e.getKey(), headers.get(e.getKey())).addLabels(EndpointLabel.SOAP.label());
                   
                }
               
                // Clear the headers in preparation for response headers
                headers.clear();
            }
           
            exchange.send(req);

            try {
                exchange = rh.waitForOut(_waitTimeout);
            } catch (DeliveryException e) {
                throw BPELMessages.MESSAGES.timedOutAfterMsWaitingOnSynchronousResponseFromTargetService(_waitTimeout, _serviceReference.getName().toString());
            }
           
            Message resp=exchange.getMessage();
           
            if (resp == null) {
                throw BPELMessages.MESSAGES.responseNotReturnedFromOperationOnService(operationName, _serviceReference.getName().toString());
            }
           
            // Process header values associated with the response
            for (org.switchyard.Property p : exchange.getContext().getProperties(Scope.MESSAGE)) {
                if (p.hasLabel(EndpointLabel.SOAP.label())) {
                    headers.put(p.getName(), p.getValue());
                }
            }
           
            // Check for exception - but don't rethrow a BPEL
            // fault as it will be converted to a message
            // response
            if (resp.getContent() instanceof Exception
                    && !(resp.getContent() instanceof BPELFault)) {
                throw (Exception)resp.getContent();
            }
           
            Element respelem=(Element)resp.getContent(Node.class);
           
            javax.wsdl.Operation operation=_portType.getOperation(operationName, null, null);
           
            if (exchange.getState() == ExchangeState.FAULT) {
                QName faultCode=null;
               
                if (respelem instanceof SOAPFault) {
                    SOAPFault fault=(SOAPFault)respelem;
                   
View Full Code Here

    }
   
    void exchangeCompleted(ExchangeCompletionEvent event) {
        // Recording metrics at multiple levels at this point instead of
        // aggregating them.
        Exchange exchange = event.getExchange();
        QName serviceName = exchange.getProvider().getName();
        QName referenceName = ComponentNames.unqualify(exchange.getConsumer().getName());
        for (Service service : _switchYard.getServices()) {
            if (service.getName().equals(serviceName)) {
                // 1 - the aggregate switchyard stats
                _switchYard.recordMetrics(exchange);
               
View Full Code Here

        MockHandler provider = new MockHandler().forwardInToOut();
        ServiceReference service = _domain.createInOutService(serviceName, provider);
       
        // Consume the service
        MockHandler consumer = new MockHandler();
        Exchange exchange = service.createExchange(consumer);
        exchange.send(exchange.createMessage());
       
        // wait, since this is async
        provider.waitForOKMessage();
        consumer.waitForOKMessage();
    }
View Full Code Here

        MockHandler provider = new MockHandler().forwardInToFault();
        ServiceReference service = _domain.createInOutService(serviceName, provider);
       
        // Consume the service
        MockHandler consumer = new MockHandler();
        Exchange exchange = service.createExchange(consumer);
        exchange.send(exchange.createMessage());
       
        // wait, since this is async
        provider.waitForOKMessage();
        consumer.waitForFaultMessage();
       
View Full Code Here

        };

        ServiceReference service = _domain.createInOnlyService(serviceName, provider);
       
        // Consume the service
        Exchange exchange = service.createExchange();
        exchange.send(exchange.createMessage());
       
        // wait a sec, since this is async
        Thread.sleep(200);
        Assert.assertTrue(inEvents.size() == 1);
    }
View Full Code Here

    public void testCopyFromExchange() throws Exception {
        ServiceReference inOnly = new ServiceReferenceImpl(
            new QName("exchange-copy"), new InOnlyService(), _domain, null);
        ExchangeDispatcher dispatch = _provider.createDispatcher(inOnly);
       
        Exchange ex = dispatch.createExchange(null, ExchangePattern.IN_ONLY);
        Context ctx = ex.getContext();
        ctx.setProperty("message-prop", "message-val", Scope.MESSAGE);
        ctx.setProperty("exchange-prop", "exchange-val", Scope.EXCHANGE).addLabels(BehaviorLabel.TRANSIENT.label());
        Assert.assertEquals(ctx.getProperty("message-prop", Scope.MESSAGE).getValue(), "message-val");
        Assert.assertEquals(ctx.getProperty("exchange-prop", Scope.EXCHANGE).getValue(), "exchange-val");
        Assert.assertTrue(ctx.getProperty("exchange-prop", Scope.EXCHANGE).getLabels().contains(BehaviorLabel.TRANSIENT.label()));
       
        // Merge the context from ex into the context for ex2
        Exchange ex2 = dispatch.createExchange(null, ExchangePattern.IN_ONLY);
        Context ctx2 = ex2.getContext();
        ctx.mergeInto(ctx2);
        Assert.assertNotNull(ctx2.getProperty("message-prop", Scope.MESSAGE));
        Assert.assertNull(ctx2.getProperty("exchange-prop", Scope.EXCHANGE));
    }
View Full Code Here

TOP

Related Classes of org.switchyard.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.