Example usage for javax.jms Message getJMSType

List of usage examples for javax.jms Message getJMSType

Introduction

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

Prototype


String getJMSType() throws JMSException;

Source Link

Document

Gets the message type identifier supplied by the client when the message was sent.

Usage

From source file:org.exist.messaging.JmsMessageSender.java

/**
 * Create messaging results report//from   w  w  w  .j  av a  2s . com
 * 
 * TODO shared code
 */
private NodeImpl createReport(Message message, XQueryContext xqcontext) {

    MemTreeBuilder builder = xqcontext.getDocumentBuilder();

    // start root element
    int nodeNr = builder.startElement("", "JMS", "JMS", null);

    try {
        String txt = message.getJMSMessageID();
        if (txt != null) {
            builder.startElement("", "MessageID", "MessageID", null);
            builder.characters(message.getJMSMessageID());
            builder.endElement();
        }
    } catch (JMSException ex) {
        LOG.error(ex);
    }

    try {
        String txt = message.getJMSCorrelationID();
        if (txt != null) {
            builder.startElement("", "CorrelationID", "CorrelationID", null);
            builder.characters(message.getJMSCorrelationID());
            builder.endElement();
        }
    } catch (JMSException ex) {
        LOG.error(ex);
    }

    try {
        String txt = message.getJMSType();
        if (txt != null) {
            builder.startElement("", "Type", "Type", null);
            builder.characters(message.getJMSType());
            builder.endElement();
        }
    } catch (JMSException ex) {
        LOG.error(ex);
    }

    // finish root element
    builder.endElement();

    // return result
    return ((DocumentImpl) builder.getDocument()).getNode(nodeNr);

}

From source file:org.genemania.broker.Worker.java

public synchronized void onMessage(Message msg) {
    if (msg instanceof TextMessage) {
        String responseBody = "";
        try {/*from   w ww .  ja v  a2  s.c o m*/
            // extract message data
            Queue queue = (Queue) msg.getJMSDestination();
            requestMessage = (TextMessage) msg;
            LOG.debug("new " + msg.getJMSType() + " message received on queue " + queue.getQueueName()
                    + "[correlation id: " + msg.getJMSCorrelationID() + "]");
            responseMessage = session.createTextMessage();
            responseMessage.setJMSDestination(requestMessage.getJMSReplyTo());
            responseMessage.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
            responseMessage.setJMSCorrelationID(msg.getJMSCorrelationID());
            // invoke engine
            if (queue.getQueueName().equalsIgnoreCase(mqRequestsQueueName)) {
                if (MessageType.RELATED_GENES.equals(MessageType.fromCode(msg.getJMSType()))) {
                    RelatedGenesRequestMessage data = RelatedGenesRequestMessage
                            .fromXml(requestMessage.getText());
                    RelatedGenesResponseMessage response = getRelatedGenes(data);
                    responseBody = response.toXml();
                } else if (MessageType.TEXT2NETWORK.equals(MessageType.fromCode(msg.getJMSType()))) {
                    UploadNetworkRequestMessage data = UploadNetworkRequestMessage
                            .fromXml(requestMessage.getText());
                    UploadNetworkResponseMessage response = uploadNetwork(data);
                    responseBody = response.toXml();
                } else if (MessageType.PROFILE2NETWORK.equals(MessageType.fromCode(msg.getJMSType()))) {
                    LOG.warn("invoking engine.profile2network: not implemented");
                } else {
                    LOG.warn("Unknown jms type: " + msg.getJMSType());
                }
            }
            processedMessages++;
        } catch (JMSException e) {
            LOG.error(e);
            try {
                responseBody = buildErrorMessage(e.getMessage(), MessageType.fromCode(msg.getJMSType()));
            } catch (JMSException x) {
                LOG.error(x);
            }
        } finally {
            if ((requestMessage != null) && (responseMessage != null)) {
                try {
                    if (StringUtils.isNotEmpty(responseBody)) {
                        responseMessage.setText(responseBody);
                        LOG.debug("Responding to " + responseMessage.getJMSDestination() + ", msg id "
                                + responseMessage.getJMSCorrelationID() + ", response body size "
                                + (int) responseBody.length());
                        responseHandler.send(responseMessage.getJMSDestination(), responseMessage);
                    } else {
                        responseBody = buildErrorMessage("Empty response body detected",
                                MessageType.fromCode(msg.getJMSType()));
                    }
                } catch (JMSException e) {
                    LOG.error("JMS Exception: " + e.getMessage());
                    try {
                        responseBody = buildErrorMessage(e.getMessage(),
                                MessageType.fromCode(msg.getJMSType()));
                        responseHandler.send(responseMessage);
                    } catch (JMSException e1) {
                        LOG.error("JMS Exception", e1);
                    }
                }
            } else {
                if (requestMessage == null) {
                    LOG.error("request message is null");
                }
                if (responseMessage == null) {
                    LOG.error("response message is null");
                }
            }
        }
    } else {
        LOG.warn("Unknown message type: " + msg);
    }
    LOG.info("successfully processed messages: " + processedMessages);
}

From source file:org.mule.transport.jms.JmsMessageUtils.java

public static Message copyJMSProperties(Message from, Message to, JmsConnector connector) throws JMSException {
    if (connector.supportsProperty(JmsConstants.JMS_CORRELATION_ID)) {
        to.setJMSCorrelationID(from.getJMSCorrelationID());
    }/*  w  ww . j  a  va2  s. com*/
    if (connector.supportsProperty(JmsConstants.JMS_DELIVERY_MODE)) {
        to.setJMSDeliveryMode(from.getJMSDeliveryMode());
    }
    if (connector.supportsProperty(JmsConstants.JMS_DESTINATION)) {
        to.setJMSDestination(from.getJMSDestination());
    }
    if (connector.supportsProperty(JmsConstants.JMS_EXPIRATION)) {
        to.setJMSExpiration(from.getJMSExpiration());
    }
    if (connector.supportsProperty(JmsConstants.JMS_MESSAGE_ID)) {
        to.setJMSMessageID(from.getJMSMessageID());
    }
    if (connector.supportsProperty(JmsConstants.JMS_PRIORITY)) {
        to.setJMSPriority(from.getJMSPriority());
    }
    if (connector.supportsProperty(JmsConstants.JMS_REDELIVERED)) {
        to.setJMSRedelivered(from.getJMSRedelivered());
    }
    if (connector.supportsProperty(JmsConstants.JMS_REPLY_TO)) {
        to.setJMSReplyTo(from.getJMSReplyTo());
    }
    if (connector.supportsProperty(JmsConstants.JMS_TIMESTAMP)) {
        to.setJMSTimestamp(from.getJMSTimestamp());
    }
    if (connector.supportsProperty(JmsConstants.JMS_TYPE)) {
        to.setJMSType(from.getJMSType());
    }
    return to;
}

From source file:org.sakaiproject.nakamura.grouper.event.SyncJMSMessageConsumer.java

@SuppressWarnings("unchecked")
public void onMessage(Message message) {
    log.debug("Receiving a message on {} : {}", SyncJMSMessageProducer.QUEUE_NAME, message);
    try {//from  w w  w  .jav  a 2s .com

        String topic = message.getJMSType();
        String groupId = (String) message.getStringProperty("path");

        String operation = "UNKNOWN";

        // A group was DELETED
        if ("org/sakaiproject/nakamura/lite/authorizables/DELETE".equals(topic) && config.getDeletesEnabled()) {
            Map<String, Object> attributes = (Map<String, Object>) message
                    .getObjectProperty(StoreListener.BEFORE_EVENT_PROPERTY);
            grouperManager.deleteGroup(groupId, attributes);
            operation = "DELETED";
        }

        // A new group was ADDED or an existing group was UPDATED
        if ("org/sakaiproject/nakamura/lite/authorizables/ADDED".equals(topic)
                || "org/sakaiproject/nakamura/lite/authorizables/UPDATED".equals(topic)) {
            // These events should be under org/sakaiproject/nakamura/lite/authorizables/UPDATED
            // http://jira.sakaiproject.org/browse/KERN-1795
            String membersAdded = (String) message.getStringProperty(GrouperEventUtils.MEMBERS_ADDED_PROP);
            if (membersAdded != null) {
                // membership adds can be attached to the same event for the group add.
                grouperManager.createGroup(groupId, config.getGroupTypes());
                grouperManager.addMemberships(groupId, Arrays.asList(StringUtils.split(membersAdded, ",")));
                operation = "ADD_MEMBERS";
            }

            String membersRemoved = (String) message.getStringProperty(GrouperEventUtils.MEMBERS_REMOVED_PROP);
            if (membersRemoved != null) {
                grouperManager.removeMemberships(groupId,
                        Arrays.asList(StringUtils.split(membersRemoved, ",")));
                operation = "REMOVE_MEMBERS";
            }

            if (membersAdded == null && membersRemoved == null) {
                org.sakaiproject.nakamura.api.lite.Session repositorySession = repository.loginAdministrative();
                AuthorizableManager am = repositorySession.getAuthorizableManager();
                Group group = (Group) am.findAuthorizable(groupId);
                repositorySession.logout();

                if (groupId.startsWith(ContactsGrouperNameProviderImpl.CONTACTS_GROUPID_PREFIX)) {
                    // TODO Why are we not getting added and removed properties on the Message
                    grouperManager.createGroup(groupId, null);
                    grouperManager.addMemberships(groupId, Arrays.asList(group.getMembers()));
                    operation = "UPDATE CONTACTS";
                } else {
                    grouperManager.createGroup(groupId, config.getGroupTypes());
                    grouperManager.addMemberships(groupId, Arrays.asList(group.getMembers()));
                    operation = "CREATE";
                }
            }
        }

        // The message was processed successfully. No exceptions were thrown.
        // We acknowledge the message and its removed from the queue
        message.acknowledge();

        // We got a message that we didn't know what to do with.
        if (operation.equals("UNKNOWN")) {
            log.error("I don't know what to do with this topic: {}. Turn on debug logs to see the message.",
                    topic);
            log.debug(message.toString());
        } else {
            log.info("Successfully processed and acknowledged. {}, {}", operation, groupId);
            log.debug(message.toString());
        }

    } catch (JMSException jmse) {
        log.error("JMSException while processing message.", jmse);
    } catch (Exception e) {
        log.error("Exception while processing message.", e);
    }
}

From source file:org.springframework.integration.jms.DefaultJmsHeaderMapper.java

public Map<String, Object> toHeaders(javax.jms.Message jmsMessage) {
    Map<String, Object> headers = new HashMap<String, Object>();
    try {//from www. j  ava2s .  c o  m
        try {
            String messageId = jmsMessage.getJMSMessageID();
            if (messageId != null) {
                headers.put(JmsHeaders.MESSAGE_ID, messageId);
            }
        } catch (Exception e) {
            logger.info("failed to read JMSMessageID property, skipping", e);
        }
        try {
            String correlationId = jmsMessage.getJMSCorrelationID();
            if (correlationId != null) {
                headers.put(JmsHeaders.CORRELATION_ID, correlationId);
            }
        } catch (Exception e) {
            logger.info("failed to read JMSCorrelationID property, skipping", e);
        }
        try {
            Destination replyTo = jmsMessage.getJMSReplyTo();
            if (replyTo != null) {
                headers.put(JmsHeaders.REPLY_TO, replyTo);
            }
        } catch (Exception e) {
            logger.info("failed to read JMSReplyTo property, skipping", e);
        }
        try {
            headers.put(JmsHeaders.REDELIVERED, jmsMessage.getJMSRedelivered());
        } catch (Exception e) {
            logger.info("failed to read JMSRedelivered property, skipping", e);
        }
        try {
            String type = jmsMessage.getJMSType();
            if (type != null) {
                headers.put(JmsHeaders.TYPE, type);
            }
        } catch (Exception e) {
            logger.info("failed to read JMSType property, skipping", e);
        }
        try {
            headers.put(JmsHeaders.TIMESTAMP, jmsMessage.getJMSTimestamp());
        } catch (Exception e) {
            logger.info("failed to read JMSTimestamp property, skipping", e);
        }
        Enumeration<?> jmsPropertyNames = jmsMessage.getPropertyNames();
        if (jmsPropertyNames != null) {
            while (jmsPropertyNames.hasMoreElements()) {
                String propertyName = jmsPropertyNames.nextElement().toString();
                try {
                    String headerName = this.toHeaderName(propertyName);
                    headers.put(headerName, jmsMessage.getObjectProperty(propertyName));
                } catch (Exception e) {
                    if (logger.isWarnEnabled()) {
                        logger.warn("error occurred while mapping JMS property '" + propertyName
                                + "' to Message header", e);
                    }
                }
            }
        }
    } catch (JMSException e) {
        if (logger.isWarnEnabled()) {
            logger.warn("error occurred while mapping from JMS properties to MessageHeaders", e);
        }
    }
    return headers;
}

From source file:org.springframework.jms.support.converter.SimpleJmsHeaderMapper.java

@Override
public Map<String, Object> toHeaders(javax.jms.Message jmsMessage) {
    Map<String, Object> headers = new HashMap<String, Object>();
    try {//  w  ww.ja v  a 2 s. co m
        try {
            String correlationId = jmsMessage.getJMSCorrelationID();
            if (correlationId != null) {
                headers.put(JmsHeaders.CORRELATION_ID, correlationId);
            }
        } catch (Exception e) {
            logger.info("failed to read JMSCorrelationID property, skipping", e);
        }
        try {
            Destination destination = jmsMessage.getJMSDestination();
            if (destination != null) {
                headers.put(JmsHeaders.DESTINATION, destination);
            }
        } catch (Exception e) {
            logger.info("failed to read JMSDestination property, skipping", e);
        }
        try {
            int deliveryMode = jmsMessage.getJMSDeliveryMode();
            headers.put(JmsHeaders.DELIVERY_MODE, deliveryMode);
        } catch (Exception e) {
            logger.info("failed to read JMSDeliveryMode property, skipping", e);
        }
        try {
            long expiration = jmsMessage.getJMSExpiration();
            headers.put(JmsHeaders.EXPIRATION, expiration);
        } catch (Exception e) {
            logger.info("failed to read JMSExpiration property, skipping", e);
        }
        try {
            String messageId = jmsMessage.getJMSMessageID();
            if (messageId != null) {
                headers.put(JmsHeaders.MESSAGE_ID, messageId);
            }
        } catch (Exception e) {
            logger.info("failed to read JMSMessageID property, skipping", e);
        }
        try {
            headers.put(JmsHeaders.PRIORITY, jmsMessage.getJMSPriority());
        } catch (Exception e) {
            logger.info("failed to read JMSPriority property, skipping", e);
        }
        try {
            Destination replyTo = jmsMessage.getJMSReplyTo();
            if (replyTo != null) {
                headers.put(JmsHeaders.REPLY_TO, replyTo);
            }
        } catch (Exception e) {
            logger.info("failed to read JMSReplyTo property, skipping", e);
        }
        try {
            headers.put(JmsHeaders.REDELIVERED, jmsMessage.getJMSRedelivered());
        } catch (Exception e) {
            logger.info("failed to read JMSRedelivered property, skipping", e);
        }
        try {
            String type = jmsMessage.getJMSType();
            if (type != null) {
                headers.put(JmsHeaders.TYPE, type);
            }
        } catch (Exception e) {
            logger.info("failed to read JMSType property, skipping", e);
        }
        try {
            headers.put(JmsHeaders.TIMESTAMP, jmsMessage.getJMSTimestamp());
        } catch (Exception e) {
            logger.info("failed to read JMSTimestamp property, skipping", e);
        }

        Enumeration<?> jmsPropertyNames = jmsMessage.getPropertyNames();
        if (jmsPropertyNames != null) {
            while (jmsPropertyNames.hasMoreElements()) {
                String propertyName = jmsPropertyNames.nextElement().toString();
                try {
                    String headerName = this.toHeaderName(propertyName);
                    headers.put(headerName, jmsMessage.getObjectProperty(propertyName));
                } catch (Exception e) {
                    if (logger.isWarnEnabled()) {
                        logger.warn("error occurred while mapping JMS property '" + propertyName
                                + "' to Message header", e);
                    }
                }
            }
        }
    } catch (JMSException e) {
        if (logger.isWarnEnabled()) {
            logger.warn("error occurred while mapping from JMS properties to MessageHeaders", e);
        }
    }
    return headers;
}

From source file:org.springframework.jms.support.SimpleJmsHeaderMapper.java

@Override
public MessageHeaders toHeaders(javax.jms.Message jmsMessage) {
    Map<String, Object> headers = new HashMap<String, Object>();
    try {//ww  w . j a  v a2 s  .c  om
        try {
            String correlationId = jmsMessage.getJMSCorrelationID();
            if (correlationId != null) {
                headers.put(JmsHeaders.CORRELATION_ID, correlationId);
            }
        } catch (Exception ex) {
            logger.info("failed to read JMSCorrelationID property, skipping", ex);
        }
        try {
            Destination destination = jmsMessage.getJMSDestination();
            if (destination != null) {
                headers.put(JmsHeaders.DESTINATION, destination);
            }
        } catch (Exception ex) {
            logger.info("failed to read JMSDestination property, skipping", ex);
        }
        try {
            int deliveryMode = jmsMessage.getJMSDeliveryMode();
            headers.put(JmsHeaders.DELIVERY_MODE, deliveryMode);
        } catch (Exception ex) {
            logger.info("failed to read JMSDeliveryMode property, skipping", ex);
        }
        try {
            long expiration = jmsMessage.getJMSExpiration();
            headers.put(JmsHeaders.EXPIRATION, expiration);
        } catch (Exception ex) {
            logger.info("failed to read JMSExpiration property, skipping", ex);
        }
        try {
            String messageId = jmsMessage.getJMSMessageID();
            if (messageId != null) {
                headers.put(JmsHeaders.MESSAGE_ID, messageId);
            }
        } catch (Exception ex) {
            logger.info("failed to read JMSMessageID property, skipping", ex);
        }
        try {
            headers.put(JmsHeaders.PRIORITY, jmsMessage.getJMSPriority());
        } catch (Exception ex) {
            logger.info("failed to read JMSPriority property, skipping", ex);
        }
        try {
            Destination replyTo = jmsMessage.getJMSReplyTo();
            if (replyTo != null) {
                headers.put(JmsHeaders.REPLY_TO, replyTo);
            }
        } catch (Exception ex) {
            logger.info("failed to read JMSReplyTo property, skipping", ex);
        }
        try {
            headers.put(JmsHeaders.REDELIVERED, jmsMessage.getJMSRedelivered());
        } catch (Exception ex) {
            logger.info("failed to read JMSRedelivered property, skipping", ex);
        }
        try {
            String type = jmsMessage.getJMSType();
            if (type != null) {
                headers.put(JmsHeaders.TYPE, type);
            }
        } catch (Exception ex) {
            logger.info("failed to read JMSType property, skipping", ex);
        }
        try {
            headers.put(JmsHeaders.TIMESTAMP, jmsMessage.getJMSTimestamp());
        } catch (Exception ex) {
            logger.info("failed to read JMSTimestamp property, skipping", ex);
        }

        Enumeration<?> jmsPropertyNames = jmsMessage.getPropertyNames();
        if (jmsPropertyNames != null) {
            while (jmsPropertyNames.hasMoreElements()) {
                String propertyName = jmsPropertyNames.nextElement().toString();
                try {
                    String headerName = this.toHeaderName(propertyName);
                    headers.put(headerName, jmsMessage.getObjectProperty(propertyName));
                } catch (Exception ex) {
                    if (logger.isWarnEnabled()) {
                        logger.warn("Error occurred while mapping JMS property '" + propertyName
                                + "' to Message header", ex);
                    }
                }
            }
        }
    } catch (JMSException ex) {
        if (logger.isWarnEnabled()) {
            logger.warn("Error occurred while mapping from JMS properties to MessageHeaders", ex);
        }
    }
    return new MessageHeaders(headers);
}

From source file:org.wso2.carbon.inbound.endpoint.protocol.jms.JMSInjectHandler.java

/**
 * Invoke the mediation logic for the passed message
 * *//*from   w w w .j a  v  a  2s  .  c o m*/
public boolean invoke(Object object, String name) throws SynapseException {

    Message msg = (Message) object;
    try {
        org.apache.synapse.MessageContext msgCtx = createMessageContext();
        msgCtx.setProperty("inbound.endpoint.name", name);
        InboundEndpoint inboundEndpoint = msgCtx.getConfiguration().getInboundEndpoint(name);
        CustomLogSetter.getInstance().setLogAppender(inboundEndpoint.getArtifactContainerName());
        String contentType = msg.getJMSType();

        if (contentType == null || contentType.trim().equals("")) {
            String contentTypeProperty = jmsProperties.getProperty(JMSConstants.CONTENT_TYPE_PROPERTY);
            if (contentTypeProperty != null) {
                contentType = msg.getStringProperty(contentTypeProperty);
            }
        } else {
            msgCtx.setProperty(JMSConstants.JMS_MESSAGE_TYPE, contentType);
        }

        if (contentType == null || contentType.trim().equals("")) {
            contentType = jmsProperties.getProperty(JMSConstants.CONTENT_TYPE);
        }
        if (log.isDebugEnabled()) {
            log.debug("Processed JMS Message of Content-type : " + contentType);
        }
        MessageContext axis2MsgCtx = ((org.apache.synapse.core.axis2.Axis2MessageContext) msgCtx)
                .getAxis2MessageContext();
        //setting transport headers
        axis2MsgCtx.setProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS,
                JMSUtils.getTransportHeaders(msg, axis2MsgCtx));
        // set the JMS Message ID as the Message ID of the MessageContext
        try {
            msgCtx.setMessageID(msg.getJMSMessageID());
            String jmsCorrelationID = msg.getJMSCorrelationID();
            if (jmsCorrelationID != null && !jmsCorrelationID.isEmpty()) {
                msgCtx.setProperty(JMSConstants.JMS_COORELATION_ID, jmsCorrelationID);
            } else {
                msgCtx.setProperty(JMSConstants.JMS_COORELATION_ID, msg.getJMSMessageID());
            }
        } catch (JMSException ignore) {
            log.warn("Error getting the COORELATION ID from the message.");
        }

        // Handle dual channel
        Destination replyTo = msg.getJMSReplyTo();
        if (replyTo != null) {
            msgCtx.setProperty(SynapseConstants.IS_INBOUND, true);
            // Create the cachedJMSConnectionFactory with the existing
            // connection
            CachedJMSConnectionFactory cachedJMSConnectionFactory = new CachedJMSConnectionFactory(
                    jmsProperties, connection);
            String strUserName = jmsProperties.getProperty(JMSConstants.PARAM_JMS_USERNAME);
            String strPassword = jmsProperties.getProperty(JMSConstants.PARAM_JMS_PASSWORD);
            JMSReplySender jmsReplySender = new JMSReplySender(replyTo, cachedJMSConnectionFactory, strUserName,
                    strPassword);
            msgCtx.setProperty(InboundEndpointConstants.INBOUND_ENDPOINT_RESPONSE_WORKER, jmsReplySender);
        } else if (replyDestination != null) {
            msgCtx.setProperty(SynapseConstants.IS_INBOUND, true);
            // Create the cachedJMSConnectionFactory with the existing
            // connection
            CachedJMSConnectionFactory cachedJMSConnectionFactory = new CachedJMSConnectionFactory(
                    jmsProperties, connection);
            String strUserName = jmsProperties.getProperty(JMSConstants.PARAM_JMS_USERNAME);
            String strPassword = jmsProperties.getProperty(JMSConstants.PARAM_JMS_PASSWORD);
            JMSReplySender jmsReplySender = new JMSReplySender(replyDestination, cachedJMSConnectionFactory,
                    strUserName, strPassword);
            msgCtx.setProperty(InboundEndpointConstants.INBOUND_ENDPOINT_RESPONSE_WORKER, jmsReplySender);
        }

        // Determine the message builder to use
        Builder builder;
        if (contentType == null) {
            log.debug("No content type specified. Using SOAP builder.");
            builder = new SOAPBuilder();
        } else {
            int index = contentType.indexOf(';');
            String type = index > 0 ? contentType.substring(0, index) : contentType;
            builder = BuilderUtil.getBuilderFromSelector(type, axis2MsgCtx);
            if (builder == null) {
                if (log.isDebugEnabled()) {
                    log.debug("No message builder found for type '" + type + "'. Falling back to SOAP.");
                }
                builder = new SOAPBuilder();
            }
        }
        OMElement documentElement = null;
        // set the message payload to the message context
        try {
            if (msg instanceof TextMessage) {
                String message = ((TextMessage) msg).getText();
                InputStream in = new AutoCloseInputStream(new ByteArrayInputStream(message.getBytes()));
                documentElement = builder.processDocument(in, contentType, axis2MsgCtx);
            } else if (msg instanceof BytesMessage) {
                if (builder instanceof DataSourceMessageBuilder) {
                    documentElement = ((DataSourceMessageBuilder) builder).processDocument(
                            new BytesMessageDataSource((BytesMessage) msg), contentType, axis2MsgCtx);
                } else {
                    documentElement = builder.processDocument(new BytesMessageInputStream((BytesMessage) msg),
                            contentType, axis2MsgCtx);
                }
            } else if (msg instanceof MapMessage) {
                documentElement = convertJMSMapToXML((MapMessage) msg);
            }
        } catch (Exception ex) {
            // Handle message building error
            log.error("Error while building the message", ex);
            msgCtx.setProperty(SynapseConstants.ERROR_CODE, GenericConstants.INBOUND_BUILD_ERROR);
            msgCtx.setProperty(SynapseConstants.ERROR_MESSAGE, ex.getMessage());
            SequenceMediator faultSequence = getFaultSequence(msgCtx, inboundEndpoint);
            faultSequence.mediate(msgCtx);

            if (isRollback(msgCtx)) {
                return false;
            }
            return true;
        }

        // Setting JMSXDeliveryCount header on the message context
        try {
            int deliveryCount = msg.getIntProperty("JMSXDeliveryCount");
            msgCtx.setProperty(JMSConstants.DELIVERY_COUNT, deliveryCount);
        } catch (NumberFormatException nfe) {
            if (log.isDebugEnabled()) {
                log.debug("JMSXDeliveryCount is not set in the received message");
            }
        }

        // Inject the message to the sequence.
        msgCtx.setEnvelope(TransportUtils.createSOAPEnvelope(documentElement));
        if (injectingSeq == null || injectingSeq.equals("")) {
            log.error("Sequence name not specified. Sequence : " + injectingSeq);
            return false;
        }
        SequenceMediator seq = (SequenceMediator) synapseEnvironment.getSynapseConfiguration()
                .getSequence(injectingSeq);
        if (seq != null) {
            if (log.isDebugEnabled()) {
                log.debug("injecting message to sequence : " + injectingSeq);
            }
            if (!seq.isInitialized()) {
                seq.init(synapseEnvironment);
            }
            SequenceMediator faultSequence = getFaultSequence(msgCtx, inboundEndpoint);
            MediatorFaultHandler mediatorFaultHandler = new MediatorFaultHandler(faultSequence);
            msgCtx.pushFaultHandler(mediatorFaultHandler);

            if (!synapseEnvironment.injectInbound(msgCtx, seq, sequential)) {
                return false;
            }
        } else {
            log.error("Sequence: " + injectingSeq + " not found");
        }

        if (isRollback(msgCtx)) {
            return false;
        }
    } catch (SynapseException se) {
        throw se;
    } catch (Exception e) {
        log.error("Error while processing the JMS Message", e);
        throw new SynapseException("Error while processing the JMS Message", e);
    }
    return true;
}