Package javax.jbi.messaging

Examples of javax.jbi.messaging.MessageExchange$Role


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

            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

    public void process(HttpServletRequest request, HttpServletResponse response) throws Exception {
        if (logger.isDebugEnabled()) {
            logger.debug("Receiving HTTP request: " + request);
        }
        MessageExchange exchange = null;
        try {
            // Handle WSDLs, XSDs
            if (handleStaticResource(request, response)) {
                return;
            }
            // Not giving a specific mutex will synchronize on the continuation itself
            Continuation cont = ContinuationSupport.getContinuation(request, null);
            // If the continuation is not a retry
            if (!cont.isPending()) {
                exchange = createExchange(request);
                locks.put(exchange.getExchangeId(), cont);
                request.setAttribute(MessageExchange.class.getName(), exchange.getExchangeId());
                synchronized (cont) {
                    send(exchange);
                    if (logger.isDebugEnabled()) {
                        logger.debug("Suspending continuation for exchange: " + exchange.getExchangeId());
                    }
                    long to = this.timeout;
                    if (to == 0) {
                        to = ((HttpComponent) getServiceUnit().getComponent()).getConfiguration()
                                            .getConsumerProcessorSuspendTime();
                    }
                    boolean result = cont.suspend(to);
                    exchanges.remove(exchange.getExchangeId());
                    if (!result) {
                        locks.remove(exchange.getExchangeId());
                        throw new Exception("Exchange timed out");
                    }
                    request.removeAttribute(MessageExchange.class.getName());
                }
                return;
            } else {
                String id = (String) request.getAttribute(MessageExchange.class.getName());
                locks.remove(id);
                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) {
                Exception e = exchange.getError();
                if (e == null) {
                    e = new Exception("Unkown error (exchange aborted ?)");
                }
                throw e;
            } else if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
                try {
                    Fault fault = exchange.getFault();
                    if (fault != null) {
                        sendFault(exchange, fault, request, response);
                    } else {
                        NormalizedMessage outMsg = exchange.getMessage("out");
                        if (outMsg != null) {
                            sendOut(exchange, outMsg, request, response);
                        }
                    }
                    exchange.setStatus(ExchangeStatus.DONE);
                    send(exchange);
                } catch (Exception e) {
                    exchange.setError(e);
                    send(exchange);
                    throw e;
                }
            } else if (exchange.getStatus() == ExchangeStatus.DONE) {
                // This happens when there is no response to send back
                sendAccepted(exchange, request, response);
            }
        } catch (RetryRequest e) {
            throw e;
View Full Code Here

        Document document = combineToDOMDocument(exchange.getMessage("in"), enricherTargetME.getMessage("out"));

        done(enricherTargetME);

        MessageExchange outExchange = getExchangeFactory().createInOnlyExchange();
        NormalizedMessage out = outExchange.createMessage();
        target.configureTarget(outExchange, getContext());
        out.setContent(new DOMSource(document));

        outExchange.setMessage(out, "in");

        sendSync(outExchange);
        done(exchange);

    }
View Full Code Here

        HttpComponent comp = (HttpComponent) getServiceUnit().getComponent();
        return comp.getServer();
    }

    public MessageExchange createExchange(HttpServletRequest request) throws Exception {
        MessageExchange me = marshaler.createExchange(request, getContext());
        configureExchangeTarget(me);
        // If the user has been authenticated, put these informations on
        // the in NormalizedMessage.
        if (request.getUserPrincipal() instanceof JaasJettyPrincipal) {
            Subject subject = ((JaasJettyPrincipal) request.getUserPrincipal()).getSubject();
            me.getMessage("in").setSecuritySubject(subject);
        }
        return me;
    }
View Full Code Here

    }

    private void processMessage(MessageExchange sourceExchange) throws MessagingException, InterruptedException {
        NormalizedMessage source = sourceExchange.getMessage("in");
        NormalizedMessage copy = getMessageCopier().copy(source);
        MessageExchange targetExchange = createTargetExchange(copy, sourceExchange.getPattern());
        // add target exchange to resequencer (blocking if capacity is reached)
        reseq.put(targetExchange);
    }
View Full Code Here

    public void setDefaultMep(URI defaultMep) {
        this.defaultMep = defaultMep;
    }

    public MessageExchange createExchange(HttpServletRequest request, ComponentContext context) throws Exception {
        MessageExchange me = context.getDeliveryChannel().createExchangeFactory().createExchange(getDefaultMep());
        NormalizedMessage in = me.createMessage();
        InputStream is = request.getInputStream();
        is = new BufferedInputStream(is);
        in.setContent(new StreamSource(is));
        me.setMessage(in, "in");
        return me;
    }
View Full Code Here

TOP

Related Classes of javax.jbi.messaging.MessageExchange$Role

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.