Search in sources :

Example 71 with MessageContext

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

the class XFormURLEncodedBuilderTest method testProcessDocumentPostMethod.

/**
 * Test XFormURLEncodedBuilder with HTTP POST method
 * @throws AxisFault
 */
public void testProcessDocumentPostMethod() throws AxisFault {
    String expectedSoapEnvelope = "<?xml version='1.0' encoding='utf-8'?>" + "<soapenv:Envelope xmlns:soapenv=\"http://www.w3.org/2003/05/soap-envelope\">" + "<soapenv:Body>" + "<xformValues>" + "<price>10</price>" + "<symbol>WSO2</symbol>" + "</xformValues>" + "</soapenv:Body>" + "</soapenv:Envelope>";
    String expectedSoapEnvelope2 = "<?xml version='1.0' encoding='utf-8'?>" + "<soapenv:Envelope xmlns:soapenv=\"http://www.w3.org/2003/05/soap-envelope\">" + "<soapenv:Body>" + "<xformValues>" + "<symbol>WSO2</symbol>" + "<price>10</price>" + "</xformValues>" + "</soapenv:Body>" + "</soapenv:Envelope>";
    MessageContext messageContext = Util.newMessageContext();
    messageContext.setTo(new EndpointReference("http://localhost:9000/stockquote/test?symbol=WSO2&price=10"));
    messageContext.setProperty(HTTPConstants.HTTP_METHOD, "POST");
    XFormURLEncodedBuilder urlEncodedBuilder = new XFormURLEncodedBuilder();
    OMElement element = urlEncodedBuilder.processDocument(null, "", messageContext);
    boolean assertion = expectedSoapEnvelope.equals(element.toString()) || expectedSoapEnvelope2.equals(element.toString());
    assertTrue("Invalid SOAPEnvelope received", assertion);
}
Also used : OMElement(org.apache.axiom.om.OMElement) MessageContext(org.apache.axis2.context.MessageContext) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 72 with MessageContext

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

the class ContextAwareLoggerTest method testGetMDCAwareLogger.

public void testGetMDCAwareLogger() {
    // Not removing from mdc after logging
    // Axis2 Message Context
    MessageContext messageContext = getCorrelationIdAwareAxis2Context();
    ContextAwareLogger.setCorrelationLoggingEnabled(true);
    Log contextAwareLogger = ContextAwareLogger.getLogger(messageContext, log, false);
    validateMDCAwareLogger(contextAwareLogger);
    // HTTPContext
    HttpContext httpContext = getCorrelationIdAwareHTTPContext();
    contextAwareLogger = ContextAwareLogger.getLogger(httpContext, log, false);
    validateMDCAwareLogger(contextAwareLogger);
}
Also used : Log(org.apache.commons.logging.Log) BasicHttpContext(org.apache.http.protocol.BasicHttpContext) HttpContext(org.apache.http.protocol.HttpContext) MessageContext(org.apache.axis2.context.MessageContext)

Example 73 with MessageContext

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

the class ContextAwareLoggerTest method testGetMDCImmediateLogger.

public void testGetMDCImmediateLogger() {
    // Removing from mdc after logging
    // Axis2 MessageContext
    MessageContext messageContext = getCorrelationIdAwareAxis2Context();
    ContextAwareLogger.setCorrelationLoggingEnabled(true);
    Log contextAwareLogger = ContextAwareLogger.getLogger(messageContext, log, true);
    validateMDCImmediateLogger(contextAwareLogger);
    // HTTP Context
    HttpContext httpContext = getCorrelationIdAwareHTTPContext();
    contextAwareLogger = ContextAwareLogger.getLogger(httpContext, log, true);
    validateMDCImmediateLogger(contextAwareLogger);
}
Also used : Log(org.apache.commons.logging.Log) BasicHttpContext(org.apache.http.protocol.BasicHttpContext) HttpContext(org.apache.http.protocol.HttpContext) MessageContext(org.apache.axis2.context.MessageContext)

Example 74 with MessageContext

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

the class ContextAwareLoggerTest method testLogWarnForMDCImmediateLogger.

public void testLogWarnForMDCImmediateLogger() {
    String logMessage = "Testing WARN log For CorrelationMDCImmediateLogger";
    HttpContext httpContext = getCorrelationIdAwareHTTPContext();
    Log contextAwareLogger = ContextAwareLogger.getLogger(httpContext, log, true);
    contextAwareLogger.info(logMessage);
    validateMDCPropertyForMDCImmediateLogger();
    MessageContext messageContext = getCorrelationIdAwareAxis2Context();
    contextAwareLogger = ContextAwareLogger.getLogger(messageContext, log, true);
    contextAwareLogger.warn(logMessage);
    validateMDCPropertyForMDCImmediateLogger();
}
Also used : Log(org.apache.commons.logging.Log) BasicHttpContext(org.apache.http.protocol.BasicHttpContext) HttpContext(org.apache.http.protocol.HttpContext) MessageContext(org.apache.axis2.context.MessageContext)

Example 75 with MessageContext

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

the class ContextAwareLoggerTest method testLogInfoForMDCAwareLogger.

public void testLogInfoForMDCAwareLogger() {
    String logMessage = "Testing INFO log For CorrelationMDCAwareLogger";
    HttpContext httpContext = getCorrelationIdAwareHTTPContext();
    Log contextAwareLogger = ContextAwareLogger.getLogger(httpContext, log, false);
    contextAwareLogger.info(logMessage);
    validateMDCPropertyForMDCAwareLogger();
    MessageContext messageContext = getCorrelationIdAwareAxis2Context();
    contextAwareLogger = ContextAwareLogger.getLogger(messageContext, log, false);
    contextAwareLogger.info(logMessage);
    validateMDCPropertyForMDCAwareLogger();
}
Also used : Log(org.apache.commons.logging.Log) BasicHttpContext(org.apache.http.protocol.BasicHttpContext) HttpContext(org.apache.http.protocol.HttpContext) MessageContext(org.apache.axis2.context.MessageContext)

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