Examples of MessageExchange


Examples of javax.jbi.messaging.MessageExchange

     */
    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

Examples of javax.jbi.messaging.MessageExchange

        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

Examples of javax.jbi.messaging.MessageExchange

        } 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

Examples of javax.jbi.messaging.MessageExchange

    }

    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

Examples of javax.jbi.messaging.MessageExchange

            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

Examples of javax.jbi.messaging.MessageExchange

        // 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

Examples of javax.jbi.messaging.MessageExchange

        }
        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

Examples of javax.jbi.messaging.MessageExchange

            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

Examples of javax.jbi.messaging.MessageExchange

            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

Examples of javax.jbi.messaging.MessageExchange

            response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, request.getMethod() + " not supported");
            return;
        }
        // Not giving a specific mutex will synchronize on the contination itself
        Continuation cont = ContinuationSupport.getContinuation(request, null);
        MessageExchange exchange;
        // If the continuation is not a retry
        if (!cont.isPending()) {
            try {
                SoapMessage message = soapHelper.getSoapMarshaler().createReader().read(
                                            request.getInputStream(),
                                            request.getHeader(HEADER_CONTENT_TYPE));
                Context ctx = soapHelper.createContext(message);
                if (request.getUserPrincipal() != null) {
                    if (request.getUserPrincipal() instanceof JaasJettyPrincipal) {
                        Subject subject = ((JaasJettyPrincipal) request.getUserPrincipal()).getSubject();
                        ctx.getInMessage().setSubject(subject);
                    } else {
                        ctx.getInMessage().addPrincipal(request.getUserPrincipal());
                    }
                }
                request.setAttribute(Context.class.getName(), ctx);
                exchange = soapHelper.onReceive(ctx);
                NormalizedMessage inMessage = exchange.getMessage("in");
                if (getConfiguration().isWantHeadersFromHttpIntoExchange()) {
                    inMessage.setProperty(JbiConstants.PROTOCOL_HEADERS, getHeaders(request));
                }
                locks.put(exchange.getExchangeId(), cont);
                request.setAttribute(MessageExchange.class.getName(), exchange.getExchangeId());
                synchronized (cont) {
                    channel.send(exchange);
                    if (log.isDebugEnabled()) {
                        log.debug("Suspending continuation for exchange: " + exchange.getExchangeId());
                    }
                    boolean result = cont.suspend(suspentionTime);
                    exchanges.remove(exchange.getExchangeId());
                    if (!result) {
                        throw new Exception("Error sending exchange: aborted");
                    }
                    request.removeAttribute(MessageExchange.class.getName());
                }
            } catch (RetryRequest retry) {
                throw retry;
            } catch (SoapFault fault) {
                sendFault(fault, request, response);
                return;
            } catch (Exception e) {
                SoapFault fault = new SoapFault(e);
                sendFault(fault, request, response);
                return;
            }
        } else {
            String id = (String) request.getAttribute(MessageExchange.class.getName());
            exchange = exchanges.remove(id);
            request.removeAttribute(MessageExchange.class.getName());
            boolean result = cont.suspend(0);
            // Check if this is a timeout
            if (exchange == null) {
                throw new IllegalStateException("Exchange not found");
            }
            if (!result) {
                throw new Exception("Timeout");
            }
        }
        if (exchange.getStatus() == ExchangeStatus.ERROR) {
            if (exchange.getError() != null) {
                throw new Exception(exchange.getError());
            } else {
                throw new Exception("Unknown Error");
            }
        } else if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
            try {
                if (exchange.getFault() != null) {
                    processFault(exchange, request, response);
                } else {
                    processResponse(exchange, request, response);
                }
            } finally {
                exchange.setStatus(ExchangeStatus.DONE);
                channel.send(exchange);
            }
        } else if (exchange.getStatus() == ExchangeStatus.DONE) {
            // This happens when there is no response to send back
            response.setStatus(HttpServletResponse.SC_ACCEPTED);
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.