Package org.switchyard

Examples of org.switchyard.Exchange


            }
            final ServiceOperation serviceOperation = operations.iterator().next();
            operation = serviceOperation.getName();
        }
       
        Exchange exchange = _serviceRef.createExchange(operation, handler);
        if (_transacted) {
            PolicyUtil.provide(exchange, TransactionPolicy.PROPAGATES_TRANSACTION);
            PolicyUtil.provide(exchange, TransactionPolicy.MANAGED_TRANSACTION_GLOBAL);
        }

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

        return exchange;
       
View Full Code Here


     * @return The OUT Exchange instance.
     * @throws DeliveryException Timeout or interrupt while waiting on OUT message.
     */
    public Exchange waitForOut(long timeout) throws DeliveryException {
        try {
            Exchange outExchange;

            try {
                outExchange = _responseQueue.poll(timeout, TimeUnit.MILLISECONDS);
            } catch (InterruptedException e) {
                synchronized (this) {
View Full Code Here

            }
            ServiceReference serviceReference = serviceDomain.getServiceReference(serviceName);
            if (serviceReference == null) {
                throw CommonKnowledgeMessages.MESSAGES.serviceReferenceNull(serviceName.toString());
            }
            final Exchange exchangeIn;
            FaultHandler handler = new FaultHandler();
            String operationName = request.getOperationName();
            if (operationName != null) {
                exchangeIn = serviceReference.createExchange(operationName, handler);
            } else {
                exchangeIn = serviceReference.createExchange(handler);
            }
            Message messageIn = exchangeIn.createMessage();
            Context contextIn = exchangeIn.getContext(messageIn);
            for (Map.Entry<String,Object> entry : request.getContext().entrySet()) {
                contextIn.setProperty(entry.getKey(), entry.getValue());
            }
            Object contentIn = request.getContent();
            if (contentIn != null) {
                messageIn.setContent(contentIn);
            }
            exchangeIn.send(messageIn);
            if (ExchangePattern.IN_OUT.equals(exchangeIn.getContract().getConsumerOperation().getExchangePattern())) {
                Exchange exchangeOut = handler.waitForOut();
                Message messageOut = exchangeOut.getMessage();
                contentOut = messageOut.getContent();
                for (Property property : exchangeOut.getContext(messageOut).getProperties()) {
                    contextOut.put(property.getName(), property.getValue());
                }
            }
            fault = handler.getFault();
        } catch (Throwable t) {
View Full Code Here

    }

    @Test
    public void authenticationMissing() throws Exception {
        MockHandler handler = new MockHandler();
        Exchange ex = _proxyConsumerService2.operation(METHOD_NAME).createExchange(handler);
        Message requestMsg = ex.createMessage().setContent(INPUT);
        ex.send(requestMsg);
        handler.waitForFaultMessage();
        String response = ex.getMessage().getContent(String.class);
        Assert.assertTrue(response.contains("407 Proxy Authentication Required"));
    }
View Full Code Here

    }

    @Test
    public void httpStatus() throws Exception {
        MockHandler handler = new MockHandler();
        Exchange ex = _consumerService.operation(METHOD_NAME).createExchange(handler);
        Message requestMsg = ex.createMessage().setContent(INPUT);
        requestMsg.getContext().setProperty("SomeRequestHeader", "BAR");
        ex.send(requestMsg);
        handler.waitForOKMessage();
        Assert.assertEquals(200, ex.getContext().getProperty(HttpContextMapper.HTTP_RESPONSE_STATUS).getValue());
    }
View Full Code Here

    }

    @Test
    public void httpFault() throws Exception {
        MockHandler handler = new MockHandler();
        Exchange ex = _consumerService2.operation(METHOD_NAME).createExchange(handler);
        Message requestMsg = ex.createMessage().setContent(INPUT);
        ex.send(requestMsg);
        handler.waitForFaultMessage();
        Assert.assertEquals(404, ex.getContext().getProperty(HttpContextMapper.HTTP_RESPONSE_STATUS).getValue());
    }
View Full Code Here

                _log.debug("Remote servlet received request for service " + msg.getService());
            }
           
            ServiceReference service = domain.getServiceReference(msg.getService());
            SynchronousInOutHandler replyHandler = new SynchronousInOutHandler();
            Exchange ex = msg.getOperation() == null
                    ? service.createExchange(replyHandler)
                    : service.createExchange(msg.getOperation(), replyHandler);
            Message m = ex.createMessage();
            if (msg.getContext() != null) {
                m.getContext().setProperties(msg.getContext().getProperties());
            }
            m.setContent(msg.getContent());
           
            if (_log.isDebugEnabled()) {
                _log.debug("Invoking service " + msg.getService());
            }
            ex.send(m);
           
            // handle reply or fault
            RemoteMessage reply = null;
            if (ExchangePattern.IN_OUT.equals(ex.getPattern())) {
                replyHandler.waitForOut();
                reply = createReplyMessage(ex);
            } else if (ExchangeState.FAULT.equals(ex.getState())) {
                // Even though this is in-only, we need to report a runtime fault on send
                reply = createReplyMessage(ex);
            }
            if (transactionPropagated) {
                bridgeOutgoingTransaction();
View Full Code Here

        // Allow for the JMS Message to be processed.
        Thread.sleep(3000);

        final LinkedBlockingQueue<Exchange> recievedMessages = simpleCamelService.getMessages();
        assertThat(recievedMessages, is(notNullValue()));
        final Exchange recievedExchange = recievedMessages.iterator().next();
        assertThat(recievedExchange.getMessage().getContent(String.class), is(equalTo(payload)));
    }
View Full Code Here

        ServiceReference ref = exchange.getProvider().getDomain().getServiceReference(serviceName);
        if (ref == null) {
            throw SCAMessages.MESSAGES.serviceReferenceNotFoundInDomain(serviceName.toString(), exchange.getProvider().getDomain().getName().toString());
        }
        SynchronousInOutHandler replyHandler = new SynchronousInOutHandler();
        Exchange ex = ref.createExchange(exchange.getContract().getProviderOperation().getName(), replyHandler);
       
        // Can't send same message twice, so make a copy
        Message invokeMsg = exchange.getMessage().copy();
        exchange.getContext().mergeInto(invokeMsg.getContext());
       
        // Since this invocation may cross application boundaries, we need to set the TCCL
        // based on the target service's application class loader
        ClassLoader origCL = null;
        try {
            ClassLoader targetCL = (ClassLoader)
                    ref.getDomain().getProperty(Deployment.CLASSLOADER_PROPERTY);
            origCL = Classes.setTCCL(targetCL);
            ex.send(invokeMsg);
        } finally {
            if (origCL != null) {
                Classes.setTCCL(origCL);
            }
        }
       
        if (ExchangePattern.IN_OUT.equals(ex.getPattern())) {
            replyHandler.waitForOut();
            if (ex.getMessage() != null) {
                Message replyMsg = ex.getMessage().copy();
                ex.getContext().mergeInto(replyMsg.getContext());
                if (ExchangeState.FAULT.equals(ex.getState())) {
                    exchange.sendFault(replyMsg);
                } else {
                    exchange.send(replyMsg);
                }
            }
        } else if (ExchangeState.FAULT.equals(ex.getState())) {
            // Even though this is in-only, we need to report a runtime fault on send
            throw createHandlerException(ex.getMessage());
        }
    }
View Full Code Here

        SynchronousInOutHandler inOutHandler = new SynchronousInOutHandler();
        MappedRecord sourceRecord = MappedRecord.class.cast(record);
        try {
            MappedRecordBindingData bindingData = new MappedRecordBindingData(sourceRecord);
            String operation = _selector != null ? _selector.selectOperation(bindingData).getLocalPart() : null;
            Exchange exchange = createExchange(operation, inOutHandler);
            exchange.send(_composer.compose(bindingData, exchange));

            exchange = inOutHandler.waitForOut(_waitTimeout);
            MappedRecord returnRecord = _recordFactory.createMappedRecord(_recordName);
            returnRecord.setRecordShortDescription(_description);
            return _composer.decompose(exchange, new MappedRecordBindingData(returnRecord)).getRecord();
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.