use of org.apache.axis2.transport.msmq.util.Message in project wso2-axis2-transports by wso2.
the class JMSUtils method setSOAPEnvelope.
/**
* Set the SOAPEnvelope to the Axis2 MessageContext, from the JMS Message passed in
* @param message the JMS message read
* @param msgContext the Axis2 MessageContext to be populated
* @param contentType content type for the message
* @throws AxisFault
* @throws JMSException
*/
public static void setSOAPEnvelope(Message message, MessageContext msgContext, String contentType) throws AxisFault, JMSException {
if (contentType == null) {
if (message instanceof TextMessage) {
contentType = "text/plain";
} else {
contentType = "application/octet-stream";
}
if (log.isDebugEnabled()) {
log.debug("No content type specified; assuming " + contentType);
}
}
int index = contentType.indexOf(';');
String type = index > 0 ? contentType.substring(0, index) : contentType;
Builder builder = BuilderUtil.getBuilderFromSelector(type, msgContext);
if (builder == null) {
if (log.isDebugEnabled()) {
log.debug("No message builder found for type '" + type + "'. Falling back to SOAP.");
}
builder = new SOAPBuilder();
}
OMElement documentElement;
if (message instanceof BytesMessage) {
// Extract the charset encoding from the content type and
// set the CHARACTER_SET_ENCODING property as e.g. SOAPBuilder relies on this.
String charSetEnc = null;
try {
if (contentType != null) {
charSetEnc = new ContentType(contentType).getParameter("charset");
}
} catch (ParseException ex) {
// ignore
}
msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEnc);
if (builder instanceof DataSourceMessageBuilder) {
documentElement = ((DataSourceMessageBuilder) builder).processDocument(new BytesMessageDataSource((BytesMessage) message), contentType, msgContext);
} else {
documentElement = builder.processDocument(new BytesMessageInputStream((BytesMessage) message), contentType, msgContext);
}
} else if (message instanceof TextMessage) {
TextMessageBuilder textMessageBuilder;
if (builder instanceof TextMessageBuilder) {
textMessageBuilder = (TextMessageBuilder) builder;
} else {
textMessageBuilder = new TextMessageBuilderAdapter(builder);
}
String content = ((TextMessage) message).getText();
documentElement = textMessageBuilder.processDocument(content, contentType, msgContext);
} else if (message instanceof MapMessage) {
documentElement = convertJMSMapToXML((MapMessage) message);
} else {
handleException("Unsupported JMS message type " + message.getClass().getName());
// Make compiler happy
return;
}
msgContext.setEnvelope(TransportUtils.createSOAPEnvelope(documentElement));
}
use of org.apache.axis2.transport.msmq.util.Message in project wso2-axis2-transports by wso2.
the class JMSRequestResponseClient method sendMessage.
public IncomingMessage<T> sendMessage(ClientOptions options, ContentType contentType, T message) throws Exception {
String correlationId = doSendMessage(options, contentType, message);
MessageConsumer consumer = replySession.createConsumer(replyDestination, "JMSCorrelationID = '" + correlationId + "'");
try {
Message replyMessage = consumer.receive(8000);
return new IncomingMessage<T>(new ContentType(replyMessage.getStringProperty("Content-Type")), jmsMessageFactory.parseMessage(replyMessage));
} finally {
consumer.close();
}
}
use of org.apache.axis2.transport.msmq.util.Message in project wso2-axis2-transports by wso2.
the class LogAspect method beforeSend.
@Before("(call(void javax.jms.MessageProducer.send(javax.jms.Message)) ||" + " call(void javax.jms.TopicPublisher.publish(javax.jms.Message))) && args(message)")
public void beforeSend(Message message) {
try {
OutputStream out = LogManager.INSTANCE.createLog("jms");
try {
PrintWriter pw = new PrintWriter(new OutputStreamWriter(out), false);
pw.println("Type: " + message.getClass().getName());
pw.println("JMS message ID: " + message.getJMSMessageID());
pw.println("JMS correlation ID: " + message.getJMSCorrelationID());
pw.println("JMS reply to: " + message.getJMSReplyTo());
for (Enumeration<?> e = message.getPropertyNames(); e.hasMoreElements(); ) {
String name = (String) e.nextElement();
pw.print(name);
pw.print(": ");
pw.println(message.getStringProperty(name));
}
pw.println();
pw.flush();
if (message instanceof BytesMessage) {
BytesMessage bytesMessage = (BytesMessage) message;
bytesMessage.reset();
IOUtils.copy(new BytesMessageInputStream(bytesMessage), out);
} else if (message instanceof TextMessage) {
pw.print(((TextMessage) message).getText());
pw.flush();
}
} finally {
out.close();
}
} catch (Throwable ex) {
log.error("Failed to dump JMS message", ex);
}
}
use of org.apache.axis2.transport.msmq.util.Message in project wso2-axis2-transports by wso2.
the class MailTransportSender method waitForReply.
private void waitForReply(MessageContext msgContext, String mailMessageID) throws AxisFault {
// message context in asnych model
if (!(msgContext.getAxisOperation() instanceof OutInAxisOperation) && (msgContext.getProperty(org.apache.axis2.Constants.PIGGYBACK_MESSAGE) == null)) {
return;
}
ConfigurationContext configContext = msgContext.getConfigurationContext();
// if the mail message listner has not started we need to start it
if (!configContext.getListenerManager().isListenerRunning(MailConstants.TRANSPORT_NAME)) {
TransportInDescription mailTo = configContext.getAxisConfiguration().getTransportIn(MailConstants.TRANSPORT_NAME);
if (mailTo == null) {
handleException("Could not find the transport receiver for " + MailConstants.TRANSPORT_NAME);
}
configContext.getListenerManager().addListener(mailTo, false);
}
SynchronousCallback synchronousCallback = new SynchronousCallback(msgContext);
Map callBackMap = (Map) msgContext.getConfigurationContext().getProperty(BaseConstants.CALLBACK_TABLE);
callBackMap.put(mailMessageID, synchronousCallback);
synchronized (synchronousCallback) {
try {
synchronousCallback.wait(msgContext.getOptions().getTimeOutInMilliSeconds());
} catch (InterruptedException e) {
handleException("Error occured while waiting ..", e);
}
}
if (!synchronousCallback.isComplete()) {
// when timeout occurs remove this entry.
callBackMap.remove(mailMessageID);
handleException("Timeout while waiting for a response");
}
}
use of org.apache.axis2.transport.msmq.util.Message in project wso2-axis2-transports by wso2.
the class MailRequestResponseClient method waitForReply.
private Message waitForReply(String msgId) throws Exception {
Thread.yield();
Thread.sleep(100);
Message reply = null;
boolean replyNotFound = true;
int retryCount = 50;
while (replyNotFound) {
log.debug("Checking for response ... with MessageID : " + msgId);
reply = getMessage(msgId);
if (reply != null) {
replyNotFound = false;
} else {
if (retryCount-- > 0) {
Thread.sleep(100);
} else {
break;
}
}
}
return reply;
}
Aggregations