Search in sources :

Example 16 with MessageContext

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);
}
Also used : MessageContext(org.apache.axis2.context.MessageContext)

Example 17 with MessageContext

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;
}
Also used : AxisRequestResponseTestClient(org.apache.axis2.transport.testkit.axis2.client.AxisRequestResponseTestClient) AxisAsyncEndpoint(org.apache.axis2.transport.testkit.axis2.endpoint.AxisAsyncEndpoint) AxisTestClientConfigurator(org.apache.axis2.transport.testkit.axis2.client.AxisTestClientConfigurator) AsyncChannel(org.apache.axis2.transport.testkit.channel.AsyncChannel) ManagedTestSuite(org.apache.axis2.transport.testkit.ManagedTestSuite) AxisAsyncTestClient(org.apache.axis2.transport.testkit.axis2.client.AxisAsyncTestClient) AxisEchoEndpoint(org.apache.axis2.transport.testkit.axis2.endpoint.AxisEchoEndpoint) MinConcurrencyTest(org.apache.axis2.transport.testkit.tests.misc.MinConcurrencyTest) MessageContext(org.apache.axis2.context.MessageContext) TransportTestSuiteBuilder(org.apache.axis2.transport.testkit.TransportTestSuiteBuilder)

Example 18 with MessageContext

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));
}
Also used : ContentType(javax.mail.internet.ContentType) DataSourceMessageBuilder(org.apache.axis2.format.DataSourceMessageBuilder) Builder(org.apache.axis2.builder.Builder) TextMessageBuilder(org.apache.axis2.format.TextMessageBuilder) SOAPBuilder(org.apache.axis2.builder.SOAPBuilder) MapMessage(javax.jms.MapMessage) OMElement(org.apache.axiom.om.OMElement) BytesMessage(javax.jms.BytesMessage) TextMessageBuilder(org.apache.axis2.format.TextMessageBuilder) TextMessageBuilderAdapter(org.apache.axis2.format.TextMessageBuilderAdapter) BytesMessageDataSource(org.apache.axis2.transport.jms.iowrappers.BytesMessageDataSource) SOAPBuilder(org.apache.axis2.builder.SOAPBuilder) ParseException(javax.mail.internet.ParseException) BytesMessageInputStream(org.apache.axis2.transport.jms.iowrappers.BytesMessageInputStream) TextMessage(javax.jms.TextMessage) DataSourceMessageBuilder(org.apache.axis2.format.DataSourceMessageBuilder)

Example 19 with MessageContext

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));
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) AxisFault(org.apache.axis2.AxisFault) InputStreamReader(java.io.InputStreamReader) QName(javax.xml.namespace.QName) WrappedTextNodeOMDataSourceFromReader(org.apache.axiom.om.ds.WrappedTextNodeOMDataSourceFromReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) WrappedTextNodeOMDataSourceFromReader(org.apache.axiom.om.ds.WrappedTextNodeOMDataSourceFromReader) OMSourcedElementImpl(org.apache.axiom.om.impl.llom.OMSourcedElementImpl)

Example 20 with MessageContext

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");
    }
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

MessageContext (org.apache.axis2.context.MessageContext)35 AxisFault (org.apache.axis2.AxisFault)25 OMElement (org.apache.axiom.om.OMElement)13 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)12 IOException (java.io.IOException)11 OMOutputFormat (org.apache.axiom.om.OMOutputFormat)11 XMLStreamException (javax.xml.stream.XMLStreamException)9 QName (javax.xml.namespace.QName)8 MessageFormatter (org.apache.axis2.transport.MessageFormatter)8 AxisOperation (org.apache.axis2.description.AxisOperation)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 InputStream (java.io.InputStream)5 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)5 SOAPFactory (org.apache.axiom.soap.SOAPFactory)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 OMFactory (org.apache.axiom.om.OMFactory)4 Options (org.apache.axis2.client.Options)4 Message (org.jivesoftware.smack.packet.Message)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 OutputStream (java.io.OutputStream)3