Search in sources :

Example 1 with ContentTypeInfo

use of org.apache.axis2.transport.jms.ctype.ContentTypeInfo in project wso2-axis2-transports by wso2.

the class JMSMessageReceiver method processThoughEngine.

/**
 * Process the new message through Axis2
 *
 * @param message the JMS message
 * @param ut      the UserTransaction used for receipt
 * @return true if the caller should commit
 * @throws JMSException, on JMS exceptions
 * @throws AxisFault     on Axis2 errors
 */
private boolean processThoughEngine(Message message, UserTransaction ut) throws JMSException, AxisFault {
    MessageContext msgContext = endpoint.createMessageContext();
    // set the JMS Message ID as the Message ID of the MessageContext
    try {
        msgContext.setMessageID(message.getJMSMessageID());
        String jmsCorrelationID = message.getJMSCorrelationID();
        if (jmsCorrelationID != null && jmsCorrelationID.length() > 0) {
            msgContext.setProperty(JMSConstants.JMS_COORELATION_ID, jmsCorrelationID);
        } else {
            msgContext.setProperty(JMSConstants.JMS_COORELATION_ID, message.getJMSMessageID());
        }
    } catch (JMSException ignore) {
    }
    String soapAction = JMSUtils.getProperty(message, BaseConstants.SOAPACTION);
    ContentTypeInfo contentTypeInfo = endpoint.getContentTypeRuleSet().getContentTypeInfo(message);
    if (contentTypeInfo == null) {
        throw new AxisFault("Unable to determine content type for message " + msgContext.getMessageID());
    }
    // set the message property OUT_TRANSPORT_INFO
    // the reply is assumed to be over the JMSReplyTo destination, using
    // the same incoming connection factory, if a JMSReplyTo is available
    Destination replyTo = message.getJMSReplyTo();
    if (replyTo == null) {
        // does the service specify a default reply destination ?
        String jndiReplyDestinationName = endpoint.getJndiReplyDestinationName();
        if (jndiReplyDestinationName != null) {
            replyTo = jmsConnectionFactory.getDestination(jndiReplyDestinationName, endpoint.getReplyDestinationType());
        }
    }
    if (replyTo != null) {
        msgContext.setProperty(Constants.OUT_TRANSPORT_INFO, new JMSOutTransportInfo(jmsConnectionFactory, replyTo, contentTypeInfo.getPropertyName()));
    }
    // Setting JMSXDeliveryCount header on the message context
    try {
        int deliveryCount = message.getIntProperty(JMS_MESSAGE_DELIVERY_COUNT_HEADER);
        msgContext.setProperty(JMSConstants.DELIVERY_COUNT, deliveryCount);
    } catch (NumberFormatException nfe) {
        if (log.isDebugEnabled()) {
            log.debug("JMSXDeliveryCount is not set in the received message");
        }
    }
    JMSUtils.setSOAPEnvelope(message, msgContext, contentTypeInfo.getContentType());
    if (ut != null) {
        msgContext.setProperty(BaseConstants.USER_TRANSACTION, ut);
    }
    msgContext.setProperty(JMSConstants.PARAM_JMS_HYPHEN_MODE, endpoint.getHyphenSupport());
    jmsListener.handleIncomingMessage(msgContext, JMSUtils.getTransportHeaders(message, msgContext), soapAction, contentTypeInfo.getContentType());
    Object o = msgContext.getProperty(BaseConstants.SET_ROLLBACK_ONLY);
    if (o != null) {
        if ((o instanceof Boolean && ((Boolean) o)) || (o instanceof String && Boolean.valueOf((String) o))) {
            return false;
        }
    }
    return true;
}
Also used : AxisFault(org.apache.axis2.AxisFault) ContentTypeInfo(org.apache.axis2.transport.jms.ctype.ContentTypeInfo) MessageContext(org.apache.axis2.context.MessageContext)

Example 2 with ContentTypeInfo

use of org.apache.axis2.transport.jms.ctype.ContentTypeInfo in project wso2-axis2-transports by wso2.

the class MSMQMessageReceiver method processThroughEngine.

/**
 * Set up message properties to header as it received as MSMQ message properties
 *
 * @param message
 * @return
 * @throws AxisFault
 */
private boolean processThroughEngine(Message message) throws AxisFault {
    // TODO: this only support text messages, need to improve it for binay
    // messages
    // Get the contentType from the MSMQ message
    String contentType = message.getLabel();
    if (log.isDebugEnabled()) {
        log.info("Content Type of the message is : " + contentType);
    }
    MessageContext msgContext = endpoint.createMessageContext();
    SOAPEnvelope soapEnvelope;
    if (message.getCorrelationId() != null) {
        msgContext.setProperty(MSMQConstants.MSMQ_CORRELATION_ID, message.getCorrelationId());
    }
    if (msgContext.getParameter(MSMQConstants.PARAM_CONTENT_TYPE).getValue() != null) {
        // Overwrite the message's content type with the defined content type in the proxy
        contentType = String.valueOf(msgContext.getParameter(MSMQConstants.PARAM_CONTENT_TYPE).getValue());
    }
    /*
		 * ContentTypeInfo contentTypeInfo =
		 * endpoint.getContentTypeRuleSet().getContentTypeInfo(message);
		 */
    MSMQUtil.setSOAPEnvelope(message, msgContext, contentType);
    soapEnvelope = msgContext.getEnvelope();
    msmqListener.handleIncomingMessage(msgContext, MSMQUtil.getTransportHeaders(message), null, contentType);
    return true;
}
Also used : MessageContext(org.apache.axis2.context.MessageContext) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope)

Aggregations

MessageContext (org.apache.axis2.context.MessageContext)2 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)1 AxisFault (org.apache.axis2.AxisFault)1 ContentTypeInfo (org.apache.axis2.transport.jms.ctype.ContentTypeInfo)1