use of org.apache.axis2.context.MessageContext in project wso2-axis2-transports by wso2.
the class JMSSender method processSyncResponse.
/**
* Creates an Axis MessageContext for the received JMS message and
* sets up the transports and various properties
*
* @param outMsgCtx the outgoing message for which we are expecting the response
* @param message the JMS response message received
* @param contentTypeProperty the message property used to determine the content type
* of the response message
* @throws AxisFault on error
*/
private void processSyncResponse(MessageContext outMsgCtx, Message message, String contentTypeProperty) throws AxisFault {
MessageContext responseMsgCtx = createResponseMessageContext(outMsgCtx);
// load any transport headers from received message
JMSUtils.loadTransportHeaders(message, responseMsgCtx);
String contentType = contentTypeProperty == null ? null : JMSUtils.getProperty(message, contentTypeProperty);
try {
JMSUtils.setSOAPEnvelope(message, responseMsgCtx, contentType);
} catch (JMSException ex) {
throw AxisFault.makeFault(ex);
}
handleIncomingMessage(responseMsgCtx, JMSUtils.getTransportHeaders(message, responseMsgCtx), JMSUtils.getProperty(message, BaseConstants.SOAPACTION), contentType);
}
use of org.apache.axis2.context.MessageContext in project wso2-axis2-transports by wso2.
the class JMSTransportTest method suite.
public static TestSuite suite() throws Exception {
ManagedTestSuite suite = new ManagedTestSuite(JMSTransportTest.class);
// SwA doesn't make sense with text messages
suite.addExclude("(&(test=AsyncSwA)(client=jms)(jmsType=text))");
// Don't execute all possible test combinations:
// * Use a single setup to execute tests with all message types.
// * Only use a small set of message types for the other setups.
suite.addExclude("(!(|(&(broker=qpid)(singleCF=false)(cfOnSender=false)(!(|(destType=topic)(replyDestType=topic))))" + "(&(test=AsyncXML)(messageType=SOAP11)(data=ASCII))" + "(&(test=EchoXML)(messageType=POX)(data=ASCII))" + "(test=MinConcurrency)))");
// SYNAPSE-436:
suite.addExclude("(&(test=EchoXML)(replyDestType=topic)(endpoint=axis))");
// Example to run a few use cases.. please leave these commented out - asankha
// suite.addExclude("(|(test=AsyncXML)(test=MinConcurrency)(destType=topic)(broker=qpid)(destType=topic)(replyDestType=topic)(client=jms)(endpoint=mock)(cfOnSender=true))");
// suite.addExclude("(|(test=EchoXML)(destType=queue)(broker=qpid)(cfOnSender=true)(singleCF=false)(destType=queue)(client=jms)(endpoint=mock))");
// suite.addExclude("(|(test=EchoXML)(test=AsyncXML)(test=AsyncSwA)(test=AsyncTextPlain)(test=AsyncBinary)(test=AsyncSOAPLarge)(broker=qpid))");
TransportTestSuiteBuilder builder = new TransportTestSuiteBuilder(suite);
JMSTestEnvironment[] environments = new JMSTestEnvironment[] { new QpidTestEnvironment(), new ActiveMQTestEnvironment() };
for (boolean singleCF : new boolean[] { false, true }) {
for (boolean cfOnSender : new boolean[] { false, true }) {
for (JMSTestEnvironment env : environments) {
builder.addEnvironment(env, new JMSTransportDescriptionFactory(singleCF, cfOnSender, 1));
}
}
}
builder.addAsyncChannel(new JMSAsyncChannel(JMSConstants.DESTINATION_TYPE_QUEUE, ContentTypeMode.TRANSPORT));
builder.addAsyncChannel(new JMSAsyncChannel(JMSConstants.DESTINATION_TYPE_TOPIC, ContentTypeMode.TRANSPORT));
builder.addAxisAsyncTestClient(new AxisAsyncTestClient());
builder.addAxisAsyncTestClient(new AxisAsyncTestClient(), new JMSAxisTestClientConfigurator(JMSConstants.JMS_BYTE_MESSAGE));
builder.addAxisAsyncTestClient(new AxisAsyncTestClient(), new JMSAxisTestClientConfigurator(JMSConstants.JMS_TEXT_MESSAGE));
builder.addByteArrayAsyncTestClient(new JMSAsyncClient<byte[]>(JMSBytesMessageFactory.INSTANCE));
builder.addStringAsyncTestClient(new JMSAsyncClient<String>(JMSTextMessageFactory.INSTANCE));
builder.addAxisAsyncEndpoint(new AxisAsyncEndpoint());
builder.addRequestResponseChannel(new JMSRequestResponseChannel(JMSConstants.DESTINATION_TYPE_QUEUE, JMSConstants.DESTINATION_TYPE_QUEUE, ContentTypeMode.TRANSPORT));
AxisTestClientConfigurator timeoutConfigurator = new AxisTestClientConfigurator() {
public void setupRequestMessageContext(MessageContext msgContext) throws AxisFault {
msgContext.setProperty(JMSConstants.JMS_WAIT_REPLY, "5000");
}
};
builder.addAxisRequestResponseTestClient(new AxisRequestResponseTestClient(), timeoutConfigurator);
builder.addStringRequestResponseTestClient(new JMSRequestResponseClient<String>(JMSTextMessageFactory.INSTANCE));
builder.addEchoEndpoint(new MockEchoEndpoint());
builder.addEchoEndpoint(new AxisEchoEndpoint());
for (JMSTestEnvironment env : new JMSTestEnvironment[] { new QpidTestEnvironment(), new ActiveMQTestEnvironment() }) {
suite.addTest(new MinConcurrencyTest(new AsyncChannel[] { new JMSAsyncChannel("endpoint1", JMSConstants.DESTINATION_TYPE_QUEUE, ContentTypeMode.TRANSPORT), new JMSAsyncChannel("endpoint2", JMSConstants.DESTINATION_TYPE_QUEUE, ContentTypeMode.TRANSPORT) }, 2, false, env, new JMSTransportDescriptionFactory(false, false, 2)));
}
builder.build();
return suite;
}
use of org.apache.axis2.context.MessageContext 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.context.MessageContext in project wso2-axis2-transports by wso2.
the class PlainTextBuilder method processDocument.
public OMElement processDocument(InputStream inputStream, String contentType, MessageContext msgContext) throws AxisFault {
OMFactory factory = OMAbstractFactory.getOMFactory();
String charSetEnc = BuilderUtil.getCharSetEncoding(contentType);
QName wrapperQName = getWrapperQName(msgContext);
Reader reader;
try {
reader = new InputStreamReader(inputStream, charSetEnc);
} catch (UnsupportedEncodingException ex) {
throw new AxisFault("Unsupported encoding: " + charSetEnc, ex);
}
return new OMSourcedElementImpl(wrapperQName, factory, new WrappedTextNodeOMDataSourceFromReader(wrapperQName, reader));
}
use of org.apache.axis2.context.MessageContext 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");
}
}
Aggregations