Package org.switchyard

Examples of org.switchyard.Exchange


        try {
            JMSBindingData bindingData = new JMSBindingData(message);
            final String operation = _selector != null ? _selector.selectOperation(bindingData).getLocalPart() : null;
            SynchronousInOutHandler replyHandler = new SynchronousInOutHandler();
            Exchange exchange = createExchange(operation, replyHandler);
            exchange.send(_composer.compose(bindingData, exchange));

            if (_connectionFactory == null) {
                return;
            }
           
            // Process replyTo and faultTo if ConnectionFactory is available
            Context context = exchange.getContext();
            Connection connection = null;
           
            try {
                if (_userName != null) {
                    connection = _connectionFactory.createConnection(_userName, _password);
                } else {
                    connection = _connectionFactory.createConnection();
                }
                Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
               
                Destination faultTo = getFaultToDestinationFromContext(session, context);
                Destination replyTo = getReplyToDestinationFromContext(session, context);
                if (faultTo != null && ExchangeState.FAULT.equals(exchange.getState())) {
                    if (exchange.getMessage() != null) {
                        sendJMSMessage(session, faultTo, exchange, getOutputMessageTypeFromContext(context));
                    }
                } else if (replyTo != null && ExchangePattern.IN_OUT.equals(exchange.getPattern())) {
                        exchange = replyHandler.waitForOut();
                        if (exchange.getMessage() != null) {
                            sendJMSMessage(session, replyTo, exchange, getOutputMessageTypeFromContext(context));
                        }
                }
            } finally {
                if (connection != null) {
View Full Code Here


     * @throws WebApplicationException if any error
     */
    public RESTEasyBindingData invoke(final RESTEasyBindingData restMessageRequest, final boolean oneWay) throws WebApplicationException {
        RESTEasyBindingData output = new RESTEasyBindingData();
        SynchronousInOutHandler inOutHandler = new SynchronousInOutHandler();
        Exchange exchange = _service.createExchange(restMessageRequest.getOperationName(), inOutHandler);

        // identify ourselves
        exchange.getContext().setProperty(ExchangeCompletionEvent.GATEWAY_NAME, _gatewayName, Scope.EXCHANGE)
                .addLabels(BehaviorLabel.TRANSIENT.label());

        _securityContextManager.addCredentials(exchange, restMessageRequest.extractCredentials());

        Message message = null;
        try {
            message = _messageComposer.compose(restMessageRequest, exchange);
        } catch (WebApplicationException wae) {
            throw wae;
        } catch (Exception e) {
            RestEasyLogger.ROOT_LOGGER.unexpectedExceptionComposingInboundMessage(e);
            throw new WebApplicationException(e);
        }
        try {
            if (oneWay) {
                exchange.send(message);
                if (exchange.getState().equals(ExchangeState.FAULT)) {
                    output = _messageComposer.decompose(exchange, output);
                }
            } else {
                exchange.send(message);
                exchange = inOutHandler.waitForOut();
                output = _messageComposer.decompose(exchange, output);
            }
        } catch (WebApplicationException wae) {
            throw wae;
View Full Code Here

            }
        }
        );
        _service = _serviceDomain.registerServiceReference(
            _targetService.getServiceName(), new InOnlyService());
        Exchange exchange = _service.createExchange();

        MockEndpoint endpoint = getMockEndpoint("mock:result");
        endpoint.expectedBodiesReceived("foo");
        exchange.send(exchange.createMessage().setContent("foo"));
   
        assertThat(context.getRegistry().lookup(TransactionManagerFactory.TM), is(notNullValue()));
        _mixIn.uninitialize();
    }
View Full Code Here

    @Test
    public void verifyThatEsbPropetiesArePassedToCamel() throws Exception {
        final String propertyKey = "testProp";
        final String propertyValue = "dummyValue";
        final Exchange exchange = _service.createExchange();
        exchange.getContext().setProperty(propertyKey, propertyValue, Scope.EXCHANGE);

        Message message = exchange.createMessage();
        message.getContext().setProperty(propertyValue, propertyKey);
        exchange.send(message);

        assertThat(camelEndpoint.getReceivedCounter(), is(1));
        org.apache.camel.Exchange ex = camelEndpoint.getReceivedExchanges().get(0);
        final String actualPropertyValue = (String) ex.getProperty(propertyKey);
        final String actualPropertyKey = (String) ex.getIn().getHeader(propertyValue);
View Full Code Here

    }

    @Test
    public void routeInOutToCamel() throws Exception {
        final String body = "inOut test string";
        final Exchange exchange = _service.createExchange();
        final Message message = createMessageWithBody(exchange, body);

        exchange.send(message);

        final String payload = (String) exchange.getMessage().getContent();
        assertThat(payload, is(equalTo(body)));
    }
View Full Code Here

                setState(State.STARTED);
            }
        }
        );
        _service = _serviceDomain.registerServiceReference(serviceName, new InOutService());
        Exchange exchange = _service.createExchange();
        exchange.send(exchange.createMessage().setContent("foo"));
        assertThat((Boolean)exchange.getContext().getProperty("decomposeInvoked").getValue(), is(true));
        assertThat((Boolean)exchange.getContext().getProperty("composeInvoked").getValue(), is(true));
    }
View Full Code Here

        ex.consumer(reference, new InOnlyOperation("Test"));
        ex.provider(_domain.getServices().get(0), new InOnlyOperation("Test"));
        invoker.handleMessage(ex);
       
        Assert.assertTrue(_provider.getMessages().size() == 1);
        Exchange receivedEx = _provider.getMessages().poll();
        Assert.assertEquals("abc", receivedEx.getMessage().getContext().getPropertyValue("message-prop"));
    }
View Full Code Here

        SCAInvoker scaInvoker = new SCAInvoker(config);
        scaInvoker.setInvoker(clInovker);
        scaInvoker.start();
       
        // Verify that exchange is mapped to remote message correctly
        Exchange mockEx = Mockito.mock(Exchange.class, Mockito.RETURNS_DEEP_STUBS);
        Mockito.when(mockEx.getContract().getConsumerOperation().getName()).thenReturn("test-operation");
        Mockito.when(mockEx.getProvider().getDomain().getName()).thenReturn(new QName("test-domain"));
        Mockito.when(mockEx.getMessage().getContent()).thenReturn("test-content");
        scaInvoker.handleMessage(mockEx);
       
        RemoteMessage remoteMsg = msgs.pop();
        Assert.assertEquals(new QName("test-domain"), remoteMsg.getDomain());
        Assert.assertEquals("test-operation", remoteMsg.getOperation());
View Full Code Here

            .setService(TEST_SERVICE)
            .setOperation("bar");
        setRequestMessage(msg);
        servlet.doPost(request, response);
       
        Exchange ex = handler.getMessages().poll(300, TimeUnit.MILLISECONDS);
        Assert.assertNotNull(ex);
        Assert.assertEquals("bar", ex.getContract().getConsumerOperation().getName());
    }
View Full Code Here

                public void handleFault(Exchange exchange) {
                    responseQueue.offer(exchange);
                }
            });

            Exchange exchange = _serviceReference.createExchange(exchangeContract, responseExchangeHandler.get());
            Message message = exchange.createMessage().setContent(payload);

            exchange.send(message);
            Exchange exchangeOut = null;
            try {
                exchangeOut = responseQueue.take();
            } catch (InterruptedException e) {
                throw new SwitchYardException("Operation '" + operationName + "' on Service '" + _serviceReference.getName() + "' interrupted.", e);
            }

            if (exchangeOut.getState() == ExchangeState.OK) {
                return exchangeOut.getMessage().getContent();
            } else {
                Object failureObj = exchangeOut.getMessage().getContent();
                if (failureObj instanceof Throwable) {
                    if (failureObj instanceof InvocationTargetException) {
                        throw ((Throwable)failureObj).getCause();
                    } else {
                        throw (Throwable) failureObj;
                    }
                } else {
                    throw new SwitchYardException("Service invocation failure.  Service '" + _serviceReference.getName() + "', operation '" + operationName + "'.  Non Throwable failure message payload: " + failureObj);
                }
            }
        } else {
            Exchange exchange = _serviceReference.createExchange(exchangeContract);
            Message message = exchange.createMessage().setContent(payload);

            exchange.send(message);
        }

        return null;
    }
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.