use of org.apache.axis2.transport.msmq.util.Message in project wso2-axis2-transports by wso2.
the class SynchronousCallback method setInMessageContext.
public synchronized void setInMessageContext(MessageContext inMessageContext) throws AxisFault {
// thread should have activate by the first message.
if (!isComplete) {
// this code is invoked only if the code use with axis2 at the client side
// when axis2 client receive messages it waits in the sending thread until the response comes.
// so this thread only notify the waiting thread and hence we need to build the message here.
inMessageContext.getEnvelope().build();
OperationContext operationContext = outMessageContext.getOperationContext();
MessageContext msgCtx = operationContext.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
if (msgCtx == null) {
// try to see whether there is a piggy back message context
if (outMessageContext.getProperty(org.apache.axis2.Constants.PIGGYBACK_MESSAGE) != null) {
msgCtx = (MessageContext) outMessageContext.getProperty(org.apache.axis2.Constants.PIGGYBACK_MESSAGE);
msgCtx.setTransportIn(inMessageContext.getTransportIn());
msgCtx.setTransportOut(inMessageContext.getTransportOut());
msgCtx.setServerSide(false);
msgCtx.setProperty(BaseConstants.MAIL_CONTENT_TYPE, inMessageContext.getProperty(BaseConstants.MAIL_CONTENT_TYPE));
// FIXME: this class must not be transport dependent since it is used by AbstractTransportListener
msgCtx.setIncomingTransportName(org.apache.axis2.Constants.TRANSPORT_MAIL);
msgCtx.setEnvelope(inMessageContext.getEnvelope());
} else {
inMessageContext.setOperationContext(operationContext);
inMessageContext.setServiceContext(outMessageContext.getServiceContext());
if (!operationContext.isComplete()) {
operationContext.addMessageContext(inMessageContext);
}
AxisOperation axisOp = operationContext.getAxisOperation();
AxisMessage inMessage = axisOp.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
inMessageContext.setAxisMessage(inMessage);
inMessageContext.setServerSide(false);
}
} else {
msgCtx.setOperationContext(operationContext);
msgCtx.setServiceContext(outMessageContext.getServiceContext());
AxisOperation axisOp = operationContext.getAxisOperation();
AxisMessage inMessage = axisOp.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
msgCtx.setAxisMessage(inMessage);
msgCtx.setTransportIn(inMessageContext.getTransportIn());
msgCtx.setTransportOut(inMessageContext.getTransportOut());
msgCtx.setServerSide(false);
msgCtx.setProperty(BaseConstants.MAIL_CONTENT_TYPE, inMessageContext.getProperty(BaseConstants.MAIL_CONTENT_TYPE));
// FIXME: this class must not be transport dependent since it is used by AbstractTransportListener
msgCtx.setIncomingTransportName(org.apache.axis2.Constants.TRANSPORT_MAIL);
msgCtx.setEnvelope(inMessageContext.getEnvelope());
}
this.inMessageContext = inMessageContext;
isComplete = true;
this.notifyAll();
}
}
use of org.apache.axis2.transport.msmq.util.Message 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();
}
}
use of org.apache.axis2.transport.msmq.util.Message in project wso2-axis2-transports by wso2.
the class MSMQSender method createMSMQMessage.
/**
* Generating MSMQ message wrapper in order to communicate with JNI
* @param msgCtx
* @param contentTypeProperty
* @param queuName
* @return
* @throws AxisFault
*/
private Message createMSMQMessage(MessageContext msgCtx, String messageContentType, String queuName) throws AxisFault {
String msgBody = null;
byte[] msgByteBody = null;
String msgType = getProperty(msgCtx, MSMQConstants.MSMQ_MESSAGE_TYPE);
// String msgLable = "L:" + queuName+"["+contentType+"]"; // TODO
// check the first element of the SOAP body, do we have content wrapped
// using the
// default wrapper elements for binary
// (BaseConstants.DEFAULT_BINARY_WRAPPER) or
// text (BaseConstants.DEFAULT_TEXT_WRAPPER) ? If so, do not create SOAP
// messages
// for MSMQ but just get the payload in its native format
String msmqMessageType = guessMessageType(msgCtx);
if (msmqMessageType == null) {
OMOutputFormat format = BaseUtils.getOMOutputFormat(msgCtx);
MessageFormatter messageFormatter = null;
try {
messageFormatter = MessageProcessorSelector.getMessageFormatter(msgCtx);
} catch (AxisFault axisFault) {
handleException("Unable to get the message formatter to use", axisFault);
}
String contentType = messageFormatter != null ? messageFormatter.getContentType(msgCtx, format, msgCtx.getSoapAction()) : "";
boolean useBytesMessage = msgType != null && MSMQConstants.MSMQ_BYTE_MESSAGE.equals(msgType) || contentType.indexOf(HTTPConstants.HEADER_ACCEPT_MULTIPART_RELATED) > -1;
OutputStream out = null;
StringWriter sw = null;
if (useBytesMessage) {
// TODO: handle MSMQ byte message here
} else {
sw = new StringWriter();
try {
out = new WriterOutputStream(sw, format.getCharSetEncoding());
} catch (UnsupportedCharsetException ex) {
handleException("Unsupported encoding " + format.getCharSetEncoding(), ex);
}
}
try {
if (out != null) {
messageFormatter.writeTo(msgCtx, format, out, true);
out.close();
}
} catch (IOException e) {
handleException("IO Error while creating BytesMessage", e);
}
if (!useBytesMessage) {
msgBody = sw.toString();
}
} else if (MSMQConstants.MSMQ_BYTE_MESSAGE.equals(msmqMessageType)) {
// TODO. handle .net byte messages here.
} else if (MSMQConstants.MSMQ_TEXT_MESSAGE.equals(msmqMessageType)) {
msgBody = msgCtx.getEnvelope().getBody().getFirstChildWithName(BaseConstants.DEFAULT_TEXT_WRAPPER).getText();
}
try {
// Keep message correlation empty will be deciding later on the process
Message message = new Message(msgBody != null ? msgBody : "", "", "");
return message;
} catch (UnsupportedEncodingException e) {
log.error("Unsported message has been received: ", e);
handleEexception("Unsported message has been received: ", e);
}
return null;
}
use of org.apache.axis2.transport.msmq.util.Message in project wso2-axis2-transports by wso2.
the class MSMQCamelClient method receive.
public Message receive(int timeOut) throws AxisFault {
try {
Message message = new Message("");
MsmqMessage msmqMessage = new MsmqMessage();
int initsize = 1;
boolean cont = true;
ByteArray recvbuffer = new ByteArray(initsize);
msmqMessage.setMsgBody(recvbuffer.cast());
msmqMessage.setBodySize(initsize);
while (cont) {
try {
msmqQueue.receiveMessage(msmqMessage, -1);
cont = false;
} catch (RuntimeException ex) {
if (ex.getMessage().equals("Message body too big")) {
initsize += 5;
recvbuffer = new ByteArray(initsize);
msmqMessage.setMsgBody(recvbuffer.cast());
msmqMessage.setBodySize(initsize);
} else {
throw ex;
}
}
}
Long messageSize = Long.valueOf(msmqMessage.getBodySize());
byte[] buffer = new byte[messageSize.intValue()];
for (int i = 0; i < messageSize; ++i) {
buffer[i] = recvbuffer.getitem(i);
}
message.setBody(new String(buffer).getBytes(Message._encoding));
byte[] cid = new byte[msmq_native_supportConstants.PROPID_M_CORRELATIONID_SIZE];
message.setCorrelationId(cid);
message.setLabel(CtypeMapClazz.getCtypeNameById(msmqMessage.getAppSpecific()));
if (log.isDebugEnabled()) {
log.info("Message Body size" + msmqMessage.getBodySize());
}
return (msmqMessage.getBodySize() == 0 || msmqMessage.getBodySize() == 1) ? null : message;
} catch (UnsupportedEncodingException e) {
log.error("Error while Reading the message received via destination", e);
throw new AxisFault("Error while Reading the message received via destination", e);
}
}
use of org.apache.axis2.transport.msmq.util.Message in project wso2-axis2-transports by wso2.
the class RabbitMQMessageReceiver method processThroughAxisEngine.
/**
* Process the new message through Axis2
*
* @param message the RabbitMQMessage
* @return true if the caller should commit
* @throws AxisFault on Axis2 errors
*/
private boolean processThroughAxisEngine(RabbitMQMessage message) throws AxisFault {
MessageContext msgContext = endpoint.createMessageContext();
String amqpCorrelationID = message.getCorrelationId();
if (amqpCorrelationID != null && amqpCorrelationID.length() > 0) {
msgContext.setProperty(RabbitMQConstants.CORRELATION_ID, amqpCorrelationID);
} else {
msgContext.setProperty(RabbitMQConstants.CORRELATION_ID, message.getMessageId());
}
String contentType = message.getContentType();
if (contentType == null) {
log.warn("Unable to determine content type for message " + msgContext.getMessageID() + " setting to text/plain");
contentType = RabbitMQConstants.DEFAULT_CONTENT_TYPE;
message.setContentType(contentType);
}
msgContext.setProperty(RabbitMQConstants.CONTENT_TYPE, contentType);
if (message.getContentEncoding() != null) {
msgContext.setProperty(RabbitMQConstants.CONTENT_ENCODING, message.getContentEncoding());
}
String soapAction = message.getSoapAction();
if (soapAction == null) {
soapAction = RabbitMQUtils.getSOAPActionHeader(message);
}
String replyTo = message.getReplyTo();
if (replyTo != null) {
msgContext.setProperty(Constants.OUT_TRANSPORT_INFO, new RabbitMQOutTransportInfo(rabbitMQConnectionFactory, replyTo, contentType));
}
RabbitMQUtils.setSOAPEnvelope(message, msgContext, contentType);
try {
listener.handleIncomingMessage(msgContext, RabbitMQUtils.getTransportHeaders(message), soapAction, contentType);
} catch (AxisFault axisFault) {
log.error("Error when trying to read incoming message ...", axisFault);
return false;
}
return true;
}
Aggregations