Package org.switchyard

Examples of org.switchyard.Exchange


     */
    public HttpResponseBindingData invoke(final HttpRequestBindingData input) {
        HttpResponseBindingData response = null;
        try {
            SynchronousInOutHandler inOutHandler = new SynchronousInOutHandler();
            Exchange exchange = _serviceRef.createExchange(getOperationName(input), inOutHandler);

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

            Message message = _messageComposer.compose(input, exchange);
            _securityContextManager.addCredentials(exchange, input.extractCredentials());
            if (exchange.getContract().getConsumerOperation().getExchangePattern() == ExchangePattern.IN_ONLY) {
                exchange.send(message);
                if (exchange.getState().equals(ExchangeState.FAULT)) {
                    response = (HttpResponseBindingData) _messageComposer.decompose(exchange, new HttpResponseBindingData());
                } else {
                    response = new HttpResponseBindingData();
                }
            } else {
                exchange.send(message);
                exchange = inOutHandler.waitForOut();
                response = (HttpResponseBindingData) _messageComposer.decompose(exchange, new HttpResponseBindingData());
            }
        } catch (Exception e) {
            HttpLogger.ROOT_LOGGER.unexpectedExceptionInvokingSwitchyardServcie(e);
View Full Code Here


            }
        });
        _camelContext.createProducerTemplate().sendBody("netty://foo", "baja");

        LinkedBlockingQueue<Exchange> msgs = mockService.getMessages();
        Exchange exchange = msgs.iterator().next();
        assertTrue(PolicyUtil.isProvided(exchange, SecurityPolicy.CONFIDENTIALITY));
    }
View Full Code Here

        sendBody("direct:input", PAYLOAD);
        mock.waitForOKMessage();
        List<Exchange> exchanges = new ArrayList<Exchange>();
        mock.getMessages().drainTo(exchanges);
        assertEquals(1, exchanges.size());
        Exchange exchange = exchanges.get(0);
        Property property = exchange.getContext().getProperty(Mapper.PROPERTY);
        assertNotNull(property);
        assertEquals(Mapper.VALUE, property.getValue());

        handler.stop();
    }
View Full Code Here

        String faultStr = "SOAPFaultInfo [_actor=null, _codeAsQName={http://schemas.xmlsoap.org/soap/envelope/}Server.AppError, "
                            + "_reasonTexts={}, _role=null, _string=Invalid name, _stringLocale=null, _subcodes=[], _detail=[detail: null]]";

        MockHandler handler = new MockHandler();
        Exchange ex = _consumerService11.operation("sayHello").createExchange(handler);

        Message requestMsg = ex.createMessage().setContent(input);
        ex.send(requestMsg);
        handler.waitForFaultMessage();
        Exchange exchange = handler.getFaults().iterator().next();
        Property faultInfoProperty = exchange.getContext().getProperty(SOAPComposition.SOAP_FAULT_INFO);
        Assert.assertNotNull(faultInfoProperty);
        Assert.assertEquals(faultStr, faultInfoProperty.getValue().toString());
    }
View Full Code Here

                    SOAPMessages.MESSAGES.operationNotAvailableTarget(firstBodyElement.toString(), _service.getName() + "'."));
        }

        try {
            SynchronousInOutHandler inOutHandler = new SynchronousInOutHandler();
            Exchange exchange = _service.createExchange(operationName, inOutHandler);

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

            SOAPBindingData soapBindingData = new SOAPBindingData(soapMessage, wsContext);

            // add any thread-local and/or binding-extracted credentials
            SecurityContext securityContext = _securityContextManager.getContext(exchange);
            securityContext.getCredentials().addAll(credentials);
            securityContext.getCredentials().addAll(soapBindingData.extractCredentials());
            _securityContextManager.setContext(exchange, securityContext);

            Message message;
            try {
                message = _messageComposer.compose(soapBindingData, exchange);
            } catch (Exception e) {
                throw e instanceof SOAPException ? (SOAPException)e : new SOAPException(e);
            }

            // Do not perfom this check if the message has been unwrapped
            if (!_unwrapped) {
                assertComposedMessageOK(message, operation);
            }

            exchange.getContext(message).setProperty(MESSAGE_NAME, operation.getInput().getMessage().getQName().getLocalPart());

            if (oneWay) {
                exchange.send(message);
                if (exchange.getState().equals(ExchangeState.FAULT)) {
                    return composeResponse(exchange, msgContext, operation, true);
                } else {
                    return null;
                }
            } else {
                exchange.send(message);
                try {
                    exchange = inOutHandler.waitForOut(_waitTimeout);
                } catch (DeliveryException e) {
                    return handleException(oneWay,
                            SOAPMessages.MESSAGES.timedOut(String.valueOf(_waitTimeout),
                                    _service.getName().toString()));
                }
               
                if (SOAPUtil.getFactory(_bindingId) == null) {
                    throw SOAPMessages.MESSAGES.failedToInstantiateSOAPMessageFactory();
                }
                if (msgContext != null) {
                    msgContext.put(SOAPUtil.SWITCHYARD_CONTEXT, exchange.getContext());
                }
                return composeResponse(exchange, msgContext, operation, false);
            }
        } catch (SOAPException se) {
            if (msgContext != null) {
View Full Code Here

    }

    @Test
    public void messageComposerComposeTest() throws InterruptedException {
        _mock.expectedBodiesReceived(Composer.DECOMPOSE_PREFIX + PAYLOAD);
        Exchange exchange = createExchange(new Composer().setContextMapper(new CamelContextMapper()));
        exchange.send(exchange.createMessage().setContent(PAYLOAD));
        _mock.assertIsSatisfied();
    }
View Full Code Here

    @Test
    public void contextMapperMapToTest() throws InterruptedException {
        _mock.expectedBodiesReceived(PAYLOAD);
        _mock.expectedHeaderReceived(Mapper.PROPERTY, Mapper.VALUE);

        Exchange exchange = createExchange(new CamelMessageComposer().setContextMapper(new Mapper()));
        exchange.send(exchange.createMessage().setContent(PAYLOAD));
        _mock.assertIsSatisfied();
    }
View Full Code Here

    @Test
    public void testInject() {
        Invoker invoker = _testKit.newInvoker("InjectService.doSomething");
        SynchronousInOutHandler handler = new SynchronousInOutHandler();
        Exchange exchange = invoker.createExchange(handler);
        Message message = exchange.createMessage();
        Context context = exchange.getContext(message);
        context.setProperty("someProp", "somePropVal");
        message.setContent("blah");
        DataSource attach = new TestDataSource("someAttach", "text/plain", "someAttachData");
        message.addAttachment(attach.getName(), attach);
        exchange.send(message);
        Exchange outExchange = handler.waitForOut();
        Assert.assertEquals("true, true, true", outExchange.getMessage().getContent());
    }
View Full Code Here

   
    @Test
    public void sendReply() throws Exception {
        MockHandler handler = new MockHandler();
        handler.setWaitTimeout(3000);
        Exchange ex = sendReply.createExchange(handler);
        ex.send(ex.createMessage().setContent(TEST_IN_CONTENT));
        Assert.assertEquals(1, handler.waitForOKMessage().getMessages().size());
        Assert.assertEquals(TEST_OUT_CONTENT,
                handler.getMessages().poll().getMessage().getContent());
    }
View Full Code Here

   
    @Test
    public void attachments() throws Exception {
        MockHandler handler = new MockHandler();
        handler.setWaitTimeout(3000);
        Exchange ex = attachments.createExchange(handler);
        ex.send(ex.createMessage()
                .setContent(TEST_IN_CONTENT)
                .addAttachment(TEST_IN_ATTACHMENT, new DummyDataSource(TEST_IN_ATTACHMENT)));
        Assert.assertEquals(1, handler.waitForOKMessage().getMessages().size());
        Message reply = handler.getMessages().poll().getMessage();
        DataSource attachOut = reply.getAttachment(TEST_OUT_ATTACHMENT);
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.