Examples of MessageExchange


Examples of javax.jbi.messaging.MessageExchange

    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

Examples of javax.jbi.messaging.MessageExchange

        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

Examples of javax.jbi.messaging.MessageExchange

        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

Examples of javax.jbi.messaging.MessageExchange

    }

    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

Examples of javax.jbi.messaging.MessageExchange

    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

Examples of javax.jbi.messaging.MessageExchange

        if (!(exchange instanceof InOnly)
            && !(exchange instanceof RobustInOnly)) {
            fail(exchange, new UnsupportedOperationException("Use an InOnly or RobustInOnly MEP"));
        } else {
            NormalizedMessage in = MessageUtil.copyIn(exchange);
            MessageExchange me = getExchangeFactory().createExchange(exchange.getPattern());
            target.configureTarget(me, getContext());
            MessageUtil.transferToIn(in, me);
            if (filter.matches(me)) {
                sendSync(me);
                if (me.getStatus() == ExchangeStatus.ERROR && reportErrors) {
                    fail(exchange, me.getError());
                } else if (me.getStatus() == ExchangeStatus.DONE) {
                    done(exchange);
                } else if (me.getFault() != null && reportErrors) {
                    Fault fault = MessageUtil.copyFault(me);
                    done(me);
                    MessageUtil.transferToFault(fault, exchange);
                    sendSync(exchange);
                }
View Full Code Here

Examples of javax.jbi.messaging.MessageExchange

                fail(exchange, new UnsupportedOperationException("Use an InOnly or RobustInOnly MEP"));
            } else if (exchange.getFault() != null) {
                done(exchange);
            } else {
                NormalizedMessage in = MessageUtil.copyIn(exchange);
                MessageExchange me = getExchangeFactory().createExchange(exchange.getPattern());
                target.configureTarget(me, getContext());
                MessageUtil.transferToIn(in, me);
                if (filter.matches(me)) {
                    send(me);
                }
View Full Code Here

Examples of javax.jbi.messaging.MessageExchange

   
    protected MessageExchange toNMS(Message message, Context ctx) throws Exception {
        SoapMessage soap = endpoint.getMarshaler().toSOAP(message);
        ctx.setInMessage(soap);
        ctx.setProperty(Message.class.getName(), message);
        MessageExchange exchange = soapHelper.onReceive(ctx);
        // TODO: copy protocol messages
        //inMessage.setProperty(JbiConstants.PROTOCOL_HEADERS, getHeaders(message));
        return exchange;
    }
View Full Code Here

Examples of javax.jbi.messaging.MessageExchange

        try {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Received jms message " + message);
            }
            Context context = createContext();
            MessageExchange exchange = toNMS(message, context);
            if (!(exchange instanceof InOnly)) {
                throw new UnsupportedOperationException("JCA consumer endpoints can only use InOnly MEP");
            }
            exchange.setProperty(MessageExchange.JTA_TRANSACTION_PROPERTY_NAME, transactionManager.getTransaction());
            pendingMessages.put(exchange.getExchangeId(), context);
            if (endpoint.isSynchronous()) {
                channel.sendSync(exchange);
                process(exchange);
            } else {
                BaseLifeCycle lf = (BaseLifeCycle) endpoint.getServiceUnit().getComponent().getLifeCycle();
View Full Code Here

Examples of javax.jbi.messaging.MessageExchange

        client.sendSync(exchange);

        assertExchangeWorked(exchange);

        ListenerBean bean = (ListenerBean) getBean("listenerBean");
        MessageExchange answer = bean.getLastExchange();

        log.info("Bean's process() method has been invoked: " + answer);

        assertNotNull("Bean's process() method should bave been invoked", answer);
    }
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.