Package javax.jbi.messaging

Examples of javax.jbi.messaging.MessageExchange


    /* (non-Javadoc)
     * @see org.apache.servicemix.eip.EIPEndpoint#processSync(javax.jbi.messaging.MessageExchange)
     */
    protected void processSync(MessageExchange exchange) throws Exception {
        // Create exchange for target
        MessageExchange tme = getExchangeFactory().createExchange(exchange.getPattern());
        // Now copy input to new exchange
        // We need to read the message once for finding routing target
        // so ensure we have a re-readable source
        NormalizedMessage in = MessageUtil.copyIn(exchange);
        MessageUtil.transferToIn(in, tme);
        // Retrieve target
        ExchangeTarget target = getDestination(tme);
        target.configureTarget(tme, getContext());
        // Send in to target
        sendSync(tme);
        // Send back the result
        if (tme.getStatus() == ExchangeStatus.DONE) {
            done(exchange);
        } else if (tme.getStatus() == ExchangeStatus.ERROR) {
            fail(exchange, tme.getError());
        } else if (tme.getFault() != null) {
            Fault fault = MessageUtil.copyFault(tme);
            done(tme);
            MessageUtil.transferToFault(fault, exchange);
            sendSync(exchange);
        } else if (tme.getMessage("out") != null) {
            NormalizedMessage out = MessageUtil.copyOut(tme);
            done(tme);
            MessageUtil.transferToOut(out, exchange);
            sendSync(exchange);
        } else {
View Full Code Here


     */
    protected void processAsync(MessageExchange exchange) throws Exception {
        if (exchange.getRole() == MessageExchange.Role.PROVIDER
            && exchange.getProperty(correlation) == null) {
            // Create exchange for target
            MessageExchange tme = getExchangeFactory().createExchange(exchange.getPattern());
            if (store.hasFeature(Store.CLUSTERED)) {
                exchange.setProperty(JbiConstants.STATELESS_PROVIDER, Boolean.TRUE);
                tme.setProperty(JbiConstants.STATELESS_CONSUMER, Boolean.TRUE);
            }
            // Set correlations
            tme.setProperty(correlation, exchange.getExchangeId());
            exchange.setProperty(correlation, tme.getExchangeId());
            // Put exchange to store
            store.store(exchange.getExchangeId(), exchange);
            // Now copy input to new exchange
            // We need to read the message once for finding routing target
            // so ensure we have a re-readable source
            NormalizedMessage in = MessageUtil.copyIn(exchange);
            MessageUtil.transferToIn(in, tme);
            // Retrieve target
            ExchangeTarget target = getDestination(tme);
            target.configureTarget(tme, getContext());
            // Send in to target
            send(tme);
        // Mimic the exchange on the other side and send to needed listener
        } else {
            String id = (String) exchange.getProperty(correlation);
            if (id == null) {
                throw new IllegalStateException(correlation + " property not found");
            }
            MessageExchange org = (MessageExchange) store.load(id);
            if (org == null) {
                throw new IllegalStateException("Could not load original exchange with id " + id);
            }
            // Reproduce DONE status to the other side
            if (exchange.getStatus() == ExchangeStatus.DONE) {
View Full Code Here

        assertEquals("wrong number of messages", numMessages, ml.getMessageCount());
        for (int i = 0; i < numMessages; i++) {
            assertSequenceProperties((NormalizedMessage)ml.getMessages().get(i), i + 1);
        }
        for (int i = 0; i < numMessages; i++) {
            MessageExchange me = (InOnly)client.receive();
            assertEquals(ExchangeStatus.DONE, me.getStatus());
        }
    }
View Full Code Here

        } else if (tme.getOutMessage() == null) {
            throw new IllegalStateException("Exchange status is " + ExchangeStatus.ACTIVE
                    + " but has no correlation set");
        // This is the answer from the transformer
        } else {
            MessageExchange me = getExchangeFactory().createExchange(exchange.getPattern());
            target.configureTarget(me, getContext());
            MessageUtil.transferOutToIn(tme, me);
            sendSync(me);
            done(tme);
            if (me.getStatus() == ExchangeStatus.DONE) {
                done(exchange);
            } else if (me.getStatus() == ExchangeStatus.ERROR) {
                fail(exchange, me.getError());
            } else if (me.getFault() != null) {
                if (exchange instanceof InOnly) {
                    // Do not use the fault has it may contain streams
                    // So just transform it to a string and send an error
                    String fault = new SourceTransformer().contentToString(me.getFault());
                    done(me);
                    fail(exchange, new FaultException(fault, null, null));
                } else {
                    Fault fault = MessageUtil.copyFault(me);
                    MessageUtil.transferToFault(fault, exchange);
View Full Code Here

    }

    private void processFault(MessageExchange exchange, InOut tme) throws Exception {
        // Faults must be sent to the target / faultsTarget
        if (faultsTarget != null || sendFaultsToTarget) {
            MessageExchange me = getExchangeFactory().createExchange(exchange.getPattern());
            (faultsTarget != null ? faultsTarget : target).configureTarget(me, getContext());
            MessageUtil.transferToIn(tme.getFault(), me);
            sendSync(me);
            done(tme);
            if (me.getStatus() == ExchangeStatus.DONE) {
                done(exchange);
            } else if (me.getStatus() == ExchangeStatus.ERROR) {
                fail(exchange, me.getError());
            } else if (me.getFault() != null) {
                if (exchange instanceof InOnly) {
                    // Do not use the fault has it may contain streams
                    // So just transform it to a string and send an error
                    String fault = new SourceTransformer().contentToString(me.getFault());
                    done(me);
                    fail(exchange, new FaultException(fault, null, null));
                } else {
                    Fault fault = MessageUtil.copyFault(me);
                    MessageUtil.transferToFault(fault, exchange);
View Full Code Here

            if (transformerId == null && targetId == null) {
                throw new IllegalStateException("Exchange status is " + ExchangeStatus.DONE
                        + " but has no correlation set");
            }
            // Load the exchange
            MessageExchange me = (MessageExchange) store.load(targetId != null ? targetId : transformerId);
            done(me);
        // Errors must be sent back to the target or transformer
        } else if (exchange.getStatus() == ExchangeStatus.ERROR) {
            String transformerId = (String) exchange.getProperty(correlationTransformer);
            String targetId = (String) exchange.getProperty(correlationTarget);
            if (transformerId == null && targetId == null) {
                throw new IllegalStateException("Exchange status is " + ExchangeStatus.DONE
                        + " but has no correlation set");
            }
            // Load the exchange
            MessageExchange me = (MessageExchange) store.load(targetId != null ? targetId : transformerId);
            fail(me, exchange.getError());
        // This is a new exchange
        } else if (exchange.getProperty(correlationTransformer) == null) {
            if (!(exchange instanceof InOnly) && !(exchange instanceof RobustInOnly)) {
                fail(exchange, new UnsupportedOperationException("Use an InOnly or RobustInOnly MEP"));
                return;
            }
            // Create exchange for target
            MessageExchange tme = getExchangeFactory().createInOutExchange();
            transformer.configureTarget(tme, getContext());
            // Set correlations
            exchange.setProperty(correlationTransformer, tme.getExchangeId());
            tme.setProperty(correlationConsumer, exchange.getExchangeId());
            tme.setProperty(TRANSFORMER, Boolean.TRUE);
            tme.setProperty(CONSUMER_MEP, exchange.getPattern());
            // Put exchange to store
            store.store(exchange.getExchangeId(), exchange);
            // Send in to listener and target
            MessageUtil.transferInToIn(exchange, tme);
            send(tme);
View Full Code Here

        // and the DONE status is always sent by the consumer (us)
        if (exchange.getStatus() == ExchangeStatus.DONE) {
            throw new IllegalStateException("Received a DONE status from the transformer");
        // Errors must be sent back to the consumer
        } else if (exchange.getStatus() == ExchangeStatus.ERROR) {
            MessageExchange me = (MessageExchange) store.load(consumerId);
            fail(me, exchange.getError());
        } else if (exchange.getFault() != null) {
            // Faults must be sent to faultsTarget / target
            if (faultsTarget != null || sendFaultsToTarget) {
                // Retrieve the consumer MEP
                URI mep = (URI) exchange.getProperty(CONSUMER_MEP);
                if (mep == null) {
                    throw new IllegalStateException("Exchange does not carry the consumer MEP");
                }
                MessageExchange me = getExchangeFactory().createExchange(mep);
                (faultsTarget != null ? faultsTarget : target).configureTarget(me, getContext());
                me.setProperty(correlationConsumer, consumerId);
                me.setProperty(correlationTransformer, exchange.getExchangeId());
                store.store(exchange.getExchangeId(), exchange);
                MessageUtil.transferToIn(exchange.getFault(), me);
                send(me);
            // Faults must be sent back to the consumer
            } else {
                MessageExchange me = (MessageExchange) store.load(consumerId);
                if (me instanceof InOnly) {
                    // Do not use the fault has it may contain streams
                    // So just transform it to a string and send an error
                    String fault = new SourceTransformer().contentToString(exchange.getFault());
                    fail(me, new FaultException(fault, null, null));
                    done(exchange);
                } else {
                    store.store(exchange.getExchangeId(), exchange);
                    MessageUtil.transferFaultToFault(exchange, me);
                    send(me);
                }
            }
        // This is the answer from the transformer
        } else if (exchange.getMessage("out") != null) {
            // Retrieve the consumer MEP
            URI mep = (URI) exchange.getProperty(CONSUMER_MEP);
            if (mep == null) {
                throw new IllegalStateException("Exchange does not carry the consumer MEP");
            }
            MessageExchange me = getExchangeFactory().createExchange(mep);
            target.configureTarget(me, getContext());
            me.setProperty(correlationConsumer, consumerId);
            me.setProperty(correlationTransformer, exchange.getExchangeId());
            store.store(exchange.getExchangeId(), exchange);
            MessageUtil.transferOutToIn(exchange, me);
            send(me);
        // This should not happen
        } else {
View Full Code Here

        }
        fail(exchange, new UnsupportedOperationException("Use an InOnly or RobustInOnly MEP"));
    }

    protected MessageExchange createTargetExchange(NormalizedMessage message, URI exchangePattern) throws MessagingException {
        MessageExchange targetExchange = getExchangeFactory().createExchange(exchangePattern);
        target.configureTarget(targetExchange, getContext());
        MessageUtil.transferToIn(message, targetExchange);
        return targetExchange;
    }
View Full Code Here

            throw new IllegalStateException(correlationTransformer + " property not found");
        }
        // This should be the last message received
        if (exchange.getStatus() == ExchangeStatus.DONE) {
            // Need to ack the transformer
            MessageExchange tme = (MessageExchange) store.load(transformerId);
            done(tme);
            // Need to ack the consumer
            MessageExchange cme = (MessageExchange) store.load(consumerId);
            done(cme);
        // Errors should be sent back to the consumer
        } else if (exchange.getStatus() == ExchangeStatus.ERROR) {
            // Need to ack the transformer
            MessageExchange tme = (MessageExchange) store.load(transformerId);
            done(tme);
            // Send error to consumer
            MessageExchange cme = (MessageExchange) store.load(consumerId);
            fail(cme, exchange.getError());
        // If we have a robust-in-only MEP, we can receive a fault
        } else if (exchange.getFault() != null) {
            // Need to ack the transformer
            MessageExchange tme = (MessageExchange) store.load(transformerId);
            done(tme);
            // Send fault back to consumer
            store.store(exchange.getExchangeId(), exchange);
            MessageExchange cme = (MessageExchange) store.load(consumerId);
            cme.setProperty(correlationTarget, exchange.getExchangeId());
            MessageUtil.transferFaultToFault(exchange, cme);
            send(cme);
        // This should not happen
        } else {
            throw new IllegalStateException("Exchange from target has a " + ExchangeStatus.ACTIVE
View Full Code Here

            String value = action.getValue();
           
            if (value != null && value.endsWith(JbiConstants.JBI_SUFFIX)) {
                value = value.substring(0, value.indexOf(JbiConstants.JBI_SUFFIX) - 1);
                String[] parts = URIResolver.split3(value);
                MessageExchange exchange = message.getContent(MessageExchange.class);
                exchange.setOperation(new QName(parts[0], parts[2]));
                exchange.setInterfaceName(new QName(parts[0], parts[1]));
            }
        }
       
        AttributedURIType to = maps.getTo();
        if (to != null) {
            String toAddress = to.getValue();
            if (toAddress != null && toAddress.endsWith(JbiConstants.JBI_SUFFIX)) {
                toAddress = toAddress.substring(0, toAddress.indexOf(JbiConstants.JBI_SUFFIX) - 1);
                String[] parts = URIResolver.split3(toAddress);
                MessageExchange exchange = message.getContent(MessageExchange.class);
                exchange.setService(new QName(parts[0], parts[1]));
            }
        }
       
    }
View Full Code Here

TOP

Related Classes of javax.jbi.messaging.MessageExchange

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.