Search in sources :

Example 66 with MessageContext

use of org.apache.axis2.context.MessageContext in project wso2-synapse by wso2.

the class SourceTextRetrieverTest method testSOAPEnvelopeTextRetriever.

public void testSOAPEnvelopeTextRetriever() throws Exception {
    SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
    SOAPEnvelope env = fac.getDefaultEnvelope();
    OMElement payload = AXIOMUtil.stringToOM(fac, "<getQuote id=\"attr\"><symbol>TEST</symbol><property>1</property>" + "<property>2</property></getQuote>");
    env.getBody().addChild(payload);
    MessageContext msgCtx = new MessageContext();
    msgCtx.setEnvelope(env);
    EvaluatorContext context = new EvaluatorContext(null, null);
    context.setMessageContext(msgCtx);
    SOAPEnvelopeTextRetriever txtRtvr = new SOAPEnvelopeTextRetriever("//symbol");
    assertEquals("TEST", txtRtvr.getSourceText(context));
    txtRtvr = new SOAPEnvelopeTextRetriever("//getQuote/@id");
    assertEquals("attr", txtRtvr.getSourceText(context));
    txtRtvr = new SOAPEnvelopeTextRetriever("//property[1]");
    assertEquals("1", txtRtvr.getSourceText(context));
    txtRtvr = new SOAPEnvelopeTextRetriever("//property[2]");
    assertEquals("2", txtRtvr.getSourceText(context));
}
Also used : EvaluatorContext(org.apache.synapse.commons.evaluators.EvaluatorContext) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) MessageContext(org.apache.axis2.context.MessageContext) SOAPFactory(org.apache.axiom.soap.SOAPFactory)

Example 67 with MessageContext

use of org.apache.axis2.context.MessageContext in project wso2-synapse by wso2.

the class XFormURLEncodedFormatterTest method testGetBytes.

public void testGetBytes() throws AxisFault, XMLStreamException {
    XFormURLEncodedFormatter formatter = new XFormURLEncodedFormatter();
    MessageContext messageContext = Util.newMessageContext("<test><test>123</test></test>");
    byte[] bytes = formatter.getBytes(messageContext, new OMOutputFormat());
    assertEquals("Invalid X-form URL Encoded string", "test=123", new String(bytes));
}
Also used : MessageContext(org.apache.axis2.context.MessageContext) OMOutputFormat(org.apache.axiom.om.OMOutputFormat)

Example 68 with MessageContext

use of org.apache.axis2.context.MessageContext in project wso2-synapse by wso2.

the class XFormURLEncodedFormatterTest method testGetContentTypeWithSoapAction.

public void testGetContentTypeWithSoapAction() throws AxisFault, XMLStreamException {
    XFormURLEncodedFormatter formatter = new XFormURLEncodedFormatter();
    MessageContext messageContext = Util.newMessageContext();
    String contentType = formatter.getContentType(messageContext, new OMOutputFormat(), "urn:mediate");
    assertEquals("Invalid content type", "application/x-www-form-urlencoded;action=\"urn:mediate\";", contentType);
}
Also used : MessageContext(org.apache.axis2.context.MessageContext) OMOutputFormat(org.apache.axiom.om.OMOutputFormat)

Example 69 with MessageContext

use of org.apache.axis2.context.MessageContext in project wso2-synapse by wso2.

the class XFormURLEncodedFormatterTest method testGetContentType.

public void testGetContentType() throws AxisFault, XMLStreamException {
    XFormURLEncodedFormatter formatter = new XFormURLEncodedFormatter();
    MessageContext messageContext = Util.newMessageContext();
    String contentType = formatter.getContentType(messageContext, new OMOutputFormat(), "");
    assertEquals("Invalid content type", "application/x-www-form-urlencoded", contentType);
}
Also used : MessageContext(org.apache.axis2.context.MessageContext) OMOutputFormat(org.apache.axiom.om.OMOutputFormat)

Example 70 with MessageContext

use of org.apache.axis2.context.MessageContext in project wso2-synapse by wso2.

the class VFSUtils method getFileName.

public static String getFileName(MessageContext msgCtx, VFSOutTransportInfo vfsOutInfo) {
    String fileName = null;
    // first preference to a custom filename set on the current message context
    Map transportHeaders = (Map) msgCtx.getProperty(MessageContext.TRANSPORT_HEADERS);
    if (transportHeaders != null) {
        fileName = (String) transportHeaders.get(VFSConstants.REPLY_FILE_NAME);
    }
    // if not, does the service (in its service.xml) specify one?
    if (fileName == null) {
        Parameter param = msgCtx.getAxisService().getParameter(VFSConstants.REPLY_FILE_NAME);
        if (param != null) {
            fileName = (String) param.getValue();
        }
    }
    // next check if the OutTransportInfo specifies one
    if (fileName == null) {
        fileName = vfsOutInfo.getOutFileName();
    }
    // if none works.. use default
    if (fileName == null) {
        fileName = VFSConstants.DEFAULT_RESPONSE_FILE;
    }
    return fileName;
}
Also used : Parameter(org.apache.axis2.description.Parameter) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

MessageContext (org.apache.axis2.context.MessageContext)218 AxisFault (org.apache.axis2.AxisFault)126 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)84 EndpointReference (org.apache.axis2.addressing.EndpointReference)79 OMElement (org.apache.axiom.om.OMElement)75 MessageContext (org.apache.synapse.MessageContext)71 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)62 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)56 IOException (java.io.IOException)55 Map (java.util.Map)52 Test (org.junit.Test)45 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)44 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)36 MessageFormatter (org.apache.axis2.transport.MessageFormatter)35 OMOutputFormat (org.apache.axiom.om.OMOutputFormat)34 Options (org.apache.axis2.client.Options)30 HashMap (java.util.HashMap)29 AxisService (org.apache.axis2.description.AxisService)29 QName (javax.xml.namespace.QName)28 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)28