Search in sources :

Example 1 with IMSMQClient

use of org.apache.axis2.transport.msmq.util.IMSMQClient in project wso2-axis2-transports by wso2.

the class MSMQSender method sendOverMSMQ.

private void sendOverMSMQ(MessageContext msgCtx, String queuName, String contentType) throws AxisFault {
    IMSMQClient mqClient = new MSMQCamelClient();
    Message message = null;
    try {
        message = createMSMQMessage(msgCtx, contentType, queuName);
        message.setLabel(contentType);
    } catch (AxisFault axisFault) {
        handleException("Error creaging the MSMQ message from the message context", axisFault);
    }
    // TODO: should we wait for a response, ok we need to support MSMQ
    // request/response scenario
    // get the reply queue name and start to receive from here. See
    // JMSSender.java:166 for more
    // information
    boolean waitForResponse = waitForSynchronousResponse(msgCtx);
    if (waitForResponse) {
        try {
            String correlationId = "";
            if (msgCtx.getRelatesTo() != null) {
                correlationId = msgCtx.getRelatesTo().getValue();
            } else {
                // TODO: if we are having a one way message we don't have this
                correlationId = MSMQConstants.DEFAULT_MSG_CORRELATION_ID;
            }
            message.setCorrelationIdAsString(correlationId);
        } catch (UnsupportedEncodingException e) {
            handleException("Error while setting up message Correlation", e);
        }
    } else {
        message.setCorrelationId(MSMQConstants.DEFAULT_MSG_CORRELATION_ID.getBytes());
    }
    try {
        try {
            // By default we are handling queues without transactional
            mqClient.create(queuName, "MSMQ-WSO2", false);
        } catch (MessageQueueException e) {
            log.warn("Queue " + queuName + "  already there.");
        }
        // TODO: how to handle transactional messages
        mqClient.open(queuName, org.apache.axis2.transport.msmq.util.IMSMQClient.Access.SEND);
    } catch (AxisFault axisFault) {
        log.error("Queue " + queuName + "  already there.");
        handleException("Could not open the queu: " + queuName + " for lisinting", axisFault);
    }
    try {
        if (message != null) {
            mqClient.send(message);
        }
    } catch (AxisFault axisFault) {
        handleException("Cloud not send the message: " + axisFault);
    } finally {
        try {
            mqClient.close();
        } catch (AxisFault axisFault) {
            handleException("Cloud not close the queue: ", axisFault);
        }
    }
    if (waitForResponse) {
    // TODO: logic to be finalized on handling synchronous request/reply
    // for the given MSMQ message
    // MSMQClient replyClient = new MSMQClient();
    }
}
Also used : MSMQCamelClient(org.apache.axis2.transport.msmq.util.MSMQCamelClient) AxisFault(org.apache.axis2.AxisFault) Message(org.apache.axis2.transport.msmq.util.Message) IMSMQClient(org.apache.axis2.transport.msmq.util.IMSMQClient) MessageQueueException(org.apache.axis2.transport.msmq.util.MessageQueueException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 AxisFault (org.apache.axis2.AxisFault)1 IMSMQClient (org.apache.axis2.transport.msmq.util.IMSMQClient)1 MSMQCamelClient (org.apache.axis2.transport.msmq.util.MSMQCamelClient)1 Message (org.apache.axis2.transport.msmq.util.Message)1 MessageQueueException (org.apache.axis2.transport.msmq.util.MessageQueueException)1