Example usage for javax.jms Message getJMSMessageID

List of usage examples for javax.jms Message getJMSMessageID

Introduction

In this page you can find the example usage for javax.jms Message getJMSMessageID.

Prototype


String getJMSMessageID() throws JMSException;

Source Link

Document

Gets the message ID.

Usage

From source file:ConsumerTool.java

public void onMessage(Message message) {

    messagesReceived++;/* w  w  w.  j a  va 2 s.  co m*/

    try {

        if (message instanceof TextMessage) {
            TextMessage txtMsg = (TextMessage) message;
            if (verbose) {

                String msg = txtMsg.getText();
                int length = msg.length();
                if (length > 50) {
                    msg = msg.substring(0, 50) + "...";
                }
                System.out.println("[" + this.getName() + "] Received: '" + msg + "' (length " + length + ")");
            }
        } else {
            if (verbose) {
                System.out.println("[" + this.getName() + "] Received: '" + message + "'");
            }
        }

        if (message.getJMSReplyTo() != null) {
            replyProducer.send(message.getJMSReplyTo(),
                    session.createTextMessage("Reply: " + message.getJMSMessageID()));
        }

        if (transacted) {
            if ((messagesReceived % batch) == 0) {
                System.out.println("Commiting transaction for last " + batch + " messages; messages so far = "
                        + messagesReceived);
                session.commit();
            }
        } else if (ackMode == Session.CLIENT_ACKNOWLEDGE) {
            if ((messagesReceived % batch) == 0) {
                System.out.println(
                        "Acknowledging last " + batch + " messages; messages so far = " + messagesReceived);
                message.acknowledge();
            }
        }

    } catch (JMSException e) {
        System.out.println("[" + this.getName() + "] Caught: " + e);
        e.printStackTrace();
    } finally {
        if (sleepTime > 0) {
            try {
                Thread.sleep(sleepTime);
            } catch (InterruptedException e) {
            }
        }
    }
}

From source file:com.espertech.esperio.jms.SpringJMSTemplateInputAdapter.java

public void onMessage(Message message) {
    try {//  ww  w .  j a  v a  2  s.  c o m
        if (stateManager.getState() == AdapterState.DESTROYED) {
            log.warn(
                    ".onMessage Event message not sent to engine, state of adapter is destroyed, message ack'd");
            message.acknowledge();
            return;
        }

        if (epServiceProviderSPI == null) {
            log.warn(
                    ".onMessage Event message not sent to engine, service provider not set yet, message ack'd");
            message.acknowledge();
            return;
        }

        synchronized (message) {
            Object theEvent = jmsMessageUnmarshaller.unmarshal(epServiceProviderSPI.getEventAdapterService(),
                    message);

            if (theEvent != null) {
                if (theEvent instanceof Node) {
                    epServiceProviderSPI.getEPRuntime().sendEvent((Node) theEvent);
                } else {
                    epServiceProviderSPI.getEPRuntime().sendEvent(theEvent);
                }
            } else {
                if (log.isWarnEnabled()) {
                    log.warn(".onMessage Event object not sent to engine: " + message.getJMSMessageID());
                }
            }

            message.acknowledge();
        }
    } catch (JMSException ex) {
        throw new EPException(ex);
    } catch (EPException ex) {
        log.error(".onMessage exception", ex);
        if (stateManager.getState() == AdapterState.STARTED) {
            stop();
        } else {
            destroy();
        }
    }
}

From source file:com.chinamobile.bcbsp.comm.ConsumerTool.java

/**
 * Put message into messageQueue and update information.
 *///from   w w w .  ja  v  a  2s .c om
public void onMessage(Message message) {
    messagesReceived++;
    try {
        if (message instanceof ObjectMessage) {
            ObjectMessage objMsg = (ObjectMessage) message;
            BSPMessagesPack msgPack = (BSPMessagesPack) objMsg.getObject();
            IMessage bspMsg;
            Iterator<IMessage> iter = msgPack.getPack().iterator();
            while (iter.hasNext()) {
                bspMsg = iter.next();
                String vertexID = bspMsg.getDstVertexID();
                this.messageQueues.incomeAMessage(vertexID, bspMsg);
                this.messageCount++;
                this.messageBytesCount += bspMsg.size();
            }
        } else {
            // Message received is not ObjectMessage.
            LOG.error("[ConsumerTool] Message received is not ObjectMessage!");
        }
        if (message.getJMSReplyTo() != null) {
            replyProducer.send(message.getJMSReplyTo(),
                    session.createTextMessage("Reply: " + message.getJMSMessageID()));
        }
        if (transacted) {
            if ((messagesReceived % batch) == 0) {
                LOG.info("Commiting transaction for last " + batch + " messages; messages so far = "
                        + messagesReceived);
                session.commit();
            }
        } else if (ackMode == Session.CLIENT_ACKNOWLEDGE) {
            if ((messagesReceived % batch) == 0) {
                LOG.info("Acknowledging last " + batch + " messages; messages so far = " + messagesReceived);
                message.acknowledge();
            }
        }
    } catch (JMSException e) {
        throw new RuntimeException("[ConsumerTool] caught: ", e);
    } finally {
        if (sleepTime > 0) {
            try {
                Thread.sleep(sleepTime);
            } catch (InterruptedException e) {
                LOG.error("[ConsumerTool] Message received not ObjectMessage!", e);
                throw new RuntimeException("[ConsumerTool] Message received not ObjectMessage! s", e);
            }
        }
    }
}

From source file:edu.harvard.i2b2.crc.ejb.QueryExecutorMDB.java

/**
 * Take the XML based message and delegate to the system coordinator to
 * handle the actual processing//  ww w .jav a  2s . c  o  m
 * 
 * @param msg
 *            th JMS TextMessage object containing XML data
 */
public void onMessage(Message msg) {
    MapMessage message = null;
    QueueConnection conn = null;
    QueueSession session = null;
    QueueSender sender = null;
    QueryProcessorUtil qpUtil = QueryProcessorUtil.getInstance();
    Queue replyToQueue = null;
    UserTransaction transaction = sessionContext.getUserTransaction();
    // default timeout three minutes
    int transactionTimeout = 0;

    try {

        transactionTimeout = this.readTimeoutPropertyValue(SMALL_QUEUE);
        if (callingMDBName.equalsIgnoreCase(QueryExecutorMDB.MEDIUM_QUEUE)) {
            // four hours
            // transactionTimeout = 14400;
            transactionTimeout = this.readTimeoutPropertyValue(MEDIUM_QUEUE);
        } else if (callingMDBName.equalsIgnoreCase(QueryExecutorMDB.LARGE_QUEUE)) {
            // twelve hours
            // transactionTimeout = 43200;
            transactionTimeout = this.readTimeoutPropertyValue(LARGE_QUEUE);
        }

        transaction.setTransactionTimeout(transactionTimeout);

        transaction.begin();
        message = (MapMessage) msg;
        String sessionId = msg.getJMSCorrelationID();
        replyToQueue = (Queue) msg.getJMSReplyTo();
        log.debug("Extracting the message [" + msg.getJMSMessageID() + " ] on " + callingMDBName);
        transaction.commit();
        ExecRunnable er = new ExecRunnable(transaction, transactionTimeout, callingMDBName, message, sessionId);
        er.execute();

    } catch (Exception ex) {
        ex.printStackTrace();
        try {
            if (transaction.getStatus() != 4) {

                transaction.rollback();

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        log.error("Error extracting message", ex);
    } finally {

        QueryManagerBeanUtil qmBeanUtil = new QueryManagerBeanUtil();
        qmBeanUtil.closeAll(sender, null, conn, session);
    }
}

From source file:com.redhat.jenkins.plugins.ci.messaging.ActiveMqMessagingWorker.java

private static String formatHeaders(Message message) {
    Destination dest = null;// w  ww.ja  v  a2s.c  o  m
    int delMode = 0;
    long expiration = 0;
    Time expTime = null;
    int priority = 0;
    String msgID = null;
    long timestamp = 0;
    Time timestampTime = null;
    String correlID = null;
    Destination replyTo = null;
    boolean redelivered = false;
    String type = null;

    StringBuilder sb = new StringBuilder();
    try {

        try {
            dest = message.getJMSDestination();
            sb.append("  JMSDestination: ");
            sb.append(dest);
            sb.append("\n");
        } catch (Exception e) {
            log.log(Level.WARNING, "Unable to generate JMSDestination header\n", e);
        }

        try {
            delMode = message.getJMSDeliveryMode();
            if (delMode == DeliveryMode.NON_PERSISTENT) {
                sb.append("  JMSDeliveryMode: non-persistent\n");
            } else if (delMode == DeliveryMode.PERSISTENT) {
                sb.append("  JMSDeliveryMode: persistent\n");
            } else {
                sb.append("  JMSDeliveryMode: neither persistent nor non-persistent; error\n");
            }
        } catch (Exception e) {
            log.log(Level.WARNING, "Unable to generate JMSDeliveryMode header\n", e);
        }

        try {
            expiration = message.getJMSExpiration();
            if (expiration != 0) {
                expTime = new Time(expiration);
                sb.append("  JMSExpiration: ");
                sb.append(expTime);
                sb.append("\n");
            } else {
                sb.append("  JMSExpiration: 0\n");
            }
        } catch (Exception e) {
            log.log(Level.WARNING, "Unable to generate JMSExpiration header\n", e);
        }

        try {
            priority = message.getJMSPriority();
            sb.append("  JMSPriority: ");
            sb.append(priority);
            sb.append("\n");
        } catch (Exception e) {
            log.log(Level.WARNING, "Unable to generate JMSPriority header\n", e);
        }

        try {
            msgID = message.getJMSMessageID();
            sb.append("  JMSMessageID: ");
            sb.append(msgID);
            sb.append("\n");
        } catch (Exception e) {
            log.log(Level.WARNING, "Unable to generate JMSMessageID header\n", e);
        }

        try {
            timestamp = message.getJMSTimestamp();
            if (timestamp != 0) {
                timestampTime = new Time(timestamp);
                sb.append("  JMSTimestamp: ");
                sb.append(timestampTime);
                sb.append("\n");
            } else {
                sb.append("  JMSTimestamp: 0\n");
            }
        } catch (Exception e) {
            log.log(Level.WARNING, "Unable to generate JMSTimestamp header\n", e);
        }

        try {
            correlID = message.getJMSCorrelationID();
            sb.append("  JMSCorrelationID: ");
            sb.append(correlID);
            sb.append("\n");
        } catch (Exception e) {
            log.log(Level.WARNING, "Unable to generate JMSCorrelationID header\n", e);
        }

        try {
            replyTo = message.getJMSReplyTo();
            sb.append("  JMSReplyTo: ");
            sb.append(replyTo);
            sb.append("\n");
        } catch (Exception e) {
            log.log(Level.WARNING, "Unable to generate JMSReplyTo header\n", e);
        }

        try {
            redelivered = message.getJMSRedelivered();
            sb.append("  JMSRedelivered: ");
            sb.append(redelivered);
            sb.append("\n");
        } catch (Exception e) {
            log.log(Level.WARNING, "Unable to generate JMSRedelivered header\n", e);
        }

        try {
            type = message.getJMSType();
            sb.append("  JMSType: ");
            sb.append(type);
            sb.append("\n");
        } catch (Exception e) {
            log.log(Level.WARNING, "Unable to generate JMSType header\n", e);
        }

    } catch (Exception e) {
        log.log(Level.WARNING, "Unable to generate JMS headers\n", e);
    }
    return sb.toString();
}

From source file:com.chinamobile.bcbsp.comm.ConsumerTool.java

/**
 * Put message into messageQueue with serialize method.
 *///from w ww .j  a va  2 s. c o  m
public void onMessageOptimistic(Message message) throws IOException {
    messagesReceived++;
    try {
        if (message instanceof BytesMessage) {
            BytesMessage mapMsg = (BytesMessage) message;
            BSPMessage bspMsg;
            int packSize = mapMsg.readInt();
            int count = 0;
            int partitionID;
            String srcVertexID;
            String dstVertexID;
            byte[] tag;
            byte[] data;
            int tagLen;
            int dataLen;
            while (count < packSize) {
                partitionID = mapMsg.readInt();
                dstVertexID = mapMsg.readUTF();
                tagLen = mapMsg.readInt();
                tag = new byte[tagLen];
                mapMsg.readBytes(tag);
                dataLen = mapMsg.readInt();
                data = new byte[dataLen];
                mapMsg.readBytes(data);
                // bspMsg = new BSPMessage(partitionID, dstVertexID, tag, data);
                // dst is message if it is not null.
                bspMsg = new BSPMessage(partitionID, dstVertexID, tag, data);
                this.messageQueues.incomeAMessage(dstVertexID, bspMsg);
                this.messageCount++;
                this.messageBytesCount += bspMsg.size();
                count++;
            }
        } else {
            // Message received is not ObjectMessage.
            LOG.error("[ConsumerTool] Message received is not BytesMessage!");
        }
        if (message.getJMSReplyTo() != null) {
            replyProducer.send(message.getJMSReplyTo(),
                    session.createTextMessage("Reply: " + message.getJMSMessageID()));
        }
        if (transacted) {
            if ((messagesReceived % batch) == 0) {
                LOG.info("Commiting transaction for last " + batch + " messages; messages so far = "
                        + messagesReceived);
                session.commit();
            }
        } else if (ackMode == Session.CLIENT_ACKNOWLEDGE) {
            if ((messagesReceived % batch) == 0) {
                LOG.info("Acknowledging last " + batch + " messages; messages so far = " + messagesReceived);
                message.acknowledge();
            }
        }
    } catch (JMSException e) {
        LOG.error("[ConsumerTool] caught: ", e);
    } finally {
        if (sleepTime > 0) {
            try {
                Thread.sleep(sleepTime);
            } catch (InterruptedException e) {
                LOG.error("[ConsumerTool] caught: ", e);
            }
        }
    }
}

From source file:hermes.impl.DefaultXMLHelper.java

public XMLMessage createXMLMessage(ObjectFactory factory, Message message)
        throws JMSException, IOException, EncoderException {
    try {/*from   w  w  w  .ja  v a 2 s  . c om*/
        XMLMessage rval = factory.createXMLMessage();

        if (message instanceof TextMessage) {
            rval = factory.createXMLTextMessage();

            XMLTextMessage textRval = (XMLTextMessage) rval;
            TextMessage textMessage = (TextMessage) message;

            if (isBase64EncodeTextMessages()) {
                byte[] bytes = base64EncoderTL.get().encode(textMessage.getText().getBytes());
                textRval.setText(new String(bytes, "ASCII"));
                textRval.setCodec(BASE64_CODEC);
            } else {
                textRval.setText(textMessage.getText());
            }
        } else if (message instanceof MapMessage) {
            rval = factory.createXMLMapMessage();

            XMLMapMessage mapRval = (XMLMapMessage) rval;
            MapMessage mapMessage = (MapMessage) message;

            for (Enumeration iter = mapMessage.getMapNames(); iter.hasMoreElements();) {
                String propertyName = (String) iter.nextElement();
                Object propertyValue = mapMessage.getObject(propertyName);
                Property xmlProperty = factory.createProperty();

                if (propertyValue != null) {
                    xmlProperty.setValue(propertyValue.toString());
                    xmlProperty.setType(propertyValue.getClass().getName());
                }
                xmlProperty.setName(propertyName);

                mapRval.getBodyProperty().add(xmlProperty);
            }
        } else if (message instanceof BytesMessage) {
            rval = factory.createXMLBytesMessage();

            XMLBytesMessage bytesRval = (XMLBytesMessage) rval;
            BytesMessage bytesMessage = (BytesMessage) message;
            ByteArrayOutputStream bosream = new ByteArrayOutputStream();

            bytesMessage.reset();

            try {
                for (;;) {
                    bosream.write(bytesMessage.readByte());
                }
            } catch (MessageEOFException ex) {
                // NOP
            }

            bytesRval.setBytes(new String(base64EncoderTL.get().encode(bosream.toByteArray())));
        } else if (message instanceof ObjectMessage) {
            rval = factory.createXMLObjectMessage();

            XMLObjectMessage objectRval = (XMLObjectMessage) rval;
            ObjectMessage objectMessage = (ObjectMessage) message;

            ByteArrayOutputStream bostream = new ByteArrayOutputStream();
            ObjectOutputStream oostream = new ObjectOutputStream(bostream);

            oostream.writeObject(objectMessage.getObject());
            oostream.flush();
            byte b[] = base64EncoderTL.get().encode(bostream.toByteArray());
            String s = new String(b, "ASCII");
            objectRval.setObject(s);
        }

        if (message.getJMSReplyTo() != null) {
            rval.setJMSReplyTo(JMSUtils.getDestinationName(message.getJMSReplyTo()));
            rval.setJMSReplyToDomain(Domain.getDomain(message.getJMSReplyTo()).getId());
        }

        // try/catch each individually as we sometime find some JMS
        // providers
        // can barf
        try {
            rval.setJMSDeliveryMode(message.getJMSDeliveryMode());
        } catch (JMSException ex) {
            log.error(ex.getMessage(), ex);
        }

        try {
            rval.setJMSExpiration(message.getJMSExpiration());
        } catch (JMSException ex) {
            log.error(ex.getMessage(), ex);
        }

        try {
            rval.setJMSMessageID(message.getJMSMessageID());
        } catch (JMSException ex) {
            log.error(ex.getMessage(), ex);
        }

        try {
            rval.setJMSPriority(message.getJMSPriority());
        } catch (JMSException ex) {
            log.error(ex.getMessage(), ex);
        }

        try {
            rval.setJMSRedelivered(message.getJMSRedelivered());
        } catch (JMSException ex) {
            log.error(ex.getMessage(), ex);
        } catch (IllegalStateException ex) {
            // http://hermesjms.com/forum/viewtopic.php?f=4&t=346

            log.error(ex.getMessage(), ex);
        }

        try {
            rval.setJMSTimestamp(message.getJMSTimestamp());
        } catch (JMSException ex) {
            log.error(ex.getMessage(), ex);
        }

        try {
            rval.setJMSType(message.getJMSType());
        } catch (JMSException ex) {
            log.error(ex.getMessage(), ex);
        }

        try {
            rval.setJMSCorrelationID(message.getJMSCorrelationID());
        } catch (JMSException ex) {
            log.error(ex.getMessage(), ex);
        }

        try {
            if (message.getJMSDestination() != null) {
                rval.setJMSDestination(JMSUtils.getDestinationName(message.getJMSDestination()));
                rval.setFromQueue(JMSUtils.isQueue(message.getJMSDestination()));
            }
        } catch (JMSException ex) {
            log.error(ex.getMessage(), ex);
        }

        for (final Enumeration iter = message.getPropertyNames(); iter.hasMoreElements();) {
            String propertyName = (String) iter.nextElement();

            if (!propertyName.startsWith("JMS")) {
                Object propertyValue = message.getObjectProperty(propertyName);
                Property property = factory.createProperty();

                property.setName(propertyName);

                if (propertyValue != null) {
                    property.setValue(StringEscapeUtils.escapeXml(propertyValue.toString()));
                    property.setType(propertyValue.getClass().getName());
                }

                rval.getHeaderProperty().add(property);
            }
        }

        return rval;
    } catch (Exception ex) {
        throw new HermesException(ex);
    }
}

From source file:net.timewalker.ffmq4.admin.RemoteAdministrationThread.java

@Override
public void run() {
    log.info("Starting remote administration thread ...");

    try {//w  w w.j a  v  a2  s  .c o  m
        LocalQueue inputQueue = engine.getLocalQueue(FFMQConstants.ADM_REQUEST_QUEUE);
        LocalQueue outputQueue = engine.getLocalQueue(FFMQConstants.ADM_REPLY_QUEUE);

        conn = new LocalQueueConnection(engine, null, null);
        session = conn.createQueueSession(true, Session.SESSION_TRANSACTED);
        receiver = session.createReceiver(inputQueue);
        sender = session.createSender(outputQueue);

        conn.start();

        // Flush input queue on startup
        inputQueue.purge(null);
        outputQueue.purge(null);

        // Enter listening loop
        notifyStartup();
        while (!stopRequired) {
            Message message = receiver.receive();
            if (message == null)
                break; // Interrupted
            log.debug("Received message " + message);

            try {
                // Process the command
                String errorMsg = process(message);

                // Build response message
                Message response = session.createMessage();
                response.setJMSCorrelationID(message.getJMSMessageID());
                if (errorMsg != null)
                    response.setStringProperty(FFMQAdminConstants.ADM_HEADER_ERRMSG, errorMsg);

                sender.send(response, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY,
                        Message.DEFAULT_TIME_TO_LIVE);
            } catch (JMSException e) {
                log.error("Cannot process admin command", e);
            } finally {
                session.commit();
            }
        }

        log.debug("Remote administration thread has stopped");
    } catch (Throwable e) {
        log.fatal("Administration thread failed", e);
        notifyStartup();
    } finally {
        try {
            if (sender != null)
                sender.close();
        } catch (JMSException e) {
            ErrorTools.log(e, log);
        }

        try {
            if (receiver != null)
                receiver.close();
        } catch (JMSException e) {
            ErrorTools.log(e, log);
        }

        try {
            if (session != null)
                session.close();
        } catch (JMSException e) {
            ErrorTools.log(e, log);
        }

        try {
            if (conn != null)
                conn.close();
        } catch (JMSException e) {
            ErrorTools.log(e, log);
        }
    }
}

From source file:net.timewalker.ffmq4.remote.session.RemoteSession.java

protected final void dispatch(Message message) throws JMSException {
    if (debugEnabled)
        log.debug("#" + id + " Sending message " + message.getJMSMessageID());

    boolean asyncDispatch = transacted || message.getJMSDeliveryMode() == DeliveryMode.NON_PERSISTENT;

    PutQuery query = new PutQuery();
    query.setSessionId(id);/* w ww.  j av  a  2 s .  co m*/

    if (asyncDispatch) {
        // Create a message copy to make sure the message is not modified concurrently
        Message msgCopy = MessageTools.makeInternalCopy(message);
        query.setMessage((AbstractMessage) msgCopy);
    } else
        query.setMessage((AbstractMessage) message);

    if (asyncDispatch)
        transportEndpoint.nonBlockingRequest(query);
    else {
        if (retryOnQueueFull)
            retriableBlockingQuery(query, retryTimeout);
        else
            transportEndpoint.blockingRequest(query);
    }
}

From source file:nl.nn.adapterframework.extensions.esb.EsbUtils.java

public static String receiveMessageAndMoveToErrorStorage(EsbJmsListener esbJmsListener,
        JdbcTransactionalStorage errorStorage) {
    String result = null;/*from w  w w. j a v a2  s  .  c  o  m*/

    PoolingConnectionFactory jmsConnectionFactory = null;
    PoolingDataSource jdbcDataSource = null;
    BitronixTransactionManager btm = null;
    javax.jms.Connection jmsConnection = null;

    try {
        jmsConnectionFactory = getPoolingConnectionFactory(esbJmsListener);
        if (jmsConnectionFactory != null) {
            jdbcDataSource = getPoolingDataSource(errorStorage);
            if (jdbcDataSource != null) {
                String instanceNameLc = AppConstants.getInstance().getString("instance.name.lc", null);
                String logDir = AppConstants.getInstance().getString("log.dir", null);
                TransactionManagerServices.getConfiguration().setServerId(instanceNameLc + ".tm");
                TransactionManagerServices.getConfiguration()
                        .setLogPart1Filename(logDir + File.separator + instanceNameLc + "-btm1.tlog");
                TransactionManagerServices.getConfiguration()
                        .setLogPart2Filename(logDir + File.separator + instanceNameLc + "-btm2.tlog");
                btm = TransactionManagerServices.getTransactionManager();

                jmsConnection = jmsConnectionFactory.createConnection();

                Session jmsSession = null;
                MessageConsumer jmsConsumer = null;

                java.sql.Connection jdbcConnection = null;

                btm.begin();
                log.debug("started transaction [" + btm.getCurrentTransaction().getGtrid() + "]");

                try {
                    jmsSession = jmsConnection.createSession(true, Session.AUTO_ACKNOWLEDGE);
                    String queueName = esbJmsListener.getPhysicalDestinationShortName();
                    Queue queue = jmsSession.createQueue(queueName);
                    jmsConsumer = jmsSession.createConsumer(queue);

                    jmsConnection.start();

                    long timeout = 30000;
                    log.debug("looking for message on queue [" + queueName + "] with timeout of [" + timeout
                            + "] msec");
                    Message rawMessage = jmsConsumer.receive(timeout);

                    if (rawMessage == null) {
                        log.debug("no message found on queue [" + queueName + "]");
                    } else {
                        String id = rawMessage.getJMSMessageID();
                        log.debug("found message on queue [" + queueName + "] with messageID [" + id + "]");
                        Serializable sobj = null;
                        if (rawMessage != null) {
                            if (rawMessage instanceof Serializable) {
                                sobj = (Serializable) rawMessage;
                            } else {
                                try {
                                    sobj = new MessageWrapper(rawMessage, esbJmsListener);
                                } catch (ListenerException e) {
                                    log.error("could not wrap non serializable message for messageId [" + id
                                            + "]", e);
                                    if (rawMessage instanceof TextMessage) {
                                        TextMessage textMessage = (TextMessage) rawMessage;
                                        sobj = textMessage.getText();
                                    } else {
                                        sobj = rawMessage.toString();
                                    }
                                }
                            }
                        }

                        jdbcConnection = jdbcDataSource.getConnection();

                        result = errorStorage.storeMessage(jdbcConnection, id, id,
                                new Date(System.currentTimeMillis()), "moved message", null, sobj);
                    }

                    log.debug("committing transaction [" + btm.getCurrentTransaction().getGtrid() + "]");
                    btm.commit();
                } catch (Exception e) {
                    if (btm.getCurrentTransaction() != null) {
                        log.debug("rolling back transaction [" + btm.getCurrentTransaction().getGtrid() + "]");
                        btm.rollback();
                    }
                    log.error("exception on receiving message and moving to errorStorage", e);
                } finally {
                    if (jdbcConnection != null) {
                        jdbcConnection.close();
                    }
                    if (jmsConnection != null) {
                        jmsConnection.stop();
                    }
                    if (jmsConsumer != null) {
                        jmsConsumer.close();
                    }
                    if (jmsSession != null) {
                        jmsSession.close();
                    }
                }
            }
        }
    } catch (Exception e) {
        log.error("exception on receiving message and moving to errorStorage", e);
    } finally {
        if (jmsConnection != null) {
            try {
                jmsConnection.close();
            } catch (JMSException e) {
                log.warn("exception on closing connection", e);
            }
        }
        if (jmsConnectionFactory != null) {
            jmsConnectionFactory.close();
        }
        if (jdbcDataSource != null) {
            jdbcDataSource.close();
        }
        if (btm != null) {
            btm.shutdown();
        }
    }
    return result;
}