Search in sources :

Example 76 with MessageContext

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

the class ContextAwareLoggerTest method testLogInfoForMDCImmediateLogger.

public void testLogInfoForMDCImmediateLogger() {
    String logMessage = "Testing INFO 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.info(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 77 with MessageContext

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

the class ContextAwareLoggerTest method getCorrelationIdAwareAxis2Context.

private MessageContext getCorrelationIdAwareAxis2Context() {
    MessageContext messageContext = new MessageContext();
    messageContext.setProperty(CorrelationConstants.CORRELATION_ID, correlationId);
    return messageContext;
}
Also used : MessageContext(org.apache.axis2.context.MessageContext)

Example 78 with MessageContext

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

the class JsonFormatterTest method testWriteTo.

public void testWriteTo() throws AxisFault, XMLStreamException {
    JsonFormatter formatter = new JsonFormatter();
    MessageContext messageContext = Util.newMessageContext("<jsonArray><jsonElement>10</jsonElement><jsonElement>20</jsonElement></jsonArray>");
    OutputStream out = new ByteArrayOutputStream();
    formatter.writeTo(messageContext, null, out, true);
    assertEquals("Formatter output is invalid", "[10,20]", out.toString());
}
Also used : OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MessageContext(org.apache.axis2.context.MessageContext) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 79 with MessageContext

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

the class JsonFormatterTest method testCase.

/**
 * NOTE: Under this test class, we cannot test the creation of JSON arrays by giving xml processing instructions to the
 * xml input string object. The reason is that when doing stringToOm and setting the SOAP child with addChild() method,
 * the addChild() method throws an exception saying that it does not support the xml PI node type.
 */
public void testCase() {
    try {
        InputStream inputStream = Util.getJson(0);
        MessageFormatter formatter = Util.newJsonFormatter();
        MessageContext messageContext = Util.newMessageContext();
        JsonUtil.getNewJsonPayload(messageContext, inputStream, false, false);
        OutputStream out = Util.newOutputStream();
        formatter.writeTo(messageContext, null, out, false);
        assertTrue(JsonDataSourceTest.expectedJSON.equals(out.toString()));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        assertTrue(false);
    } catch (AxisFault axisFault) {
        axisFault.printStackTrace();
        assertTrue(false);
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileNotFoundException(java.io.FileNotFoundException) MessageFormatter(org.apache.axis2.transport.MessageFormatter) MessageContext(org.apache.axis2.context.MessageContext)

Example 80 with MessageContext

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

the class JsonFormatterTest method testGetBytesXML.

public void testGetBytesXML() throws AxisFault, XMLStreamException {
    JsonFormatter formatter = new JsonFormatter();
    MessageContext messageContext = Util.newMessageContext("<name>WSO2</name>");
    byte[] bytes = formatter.getBytes(messageContext, null);
    assertEquals("Invalid content received", "{\"name\":\"WSO2\"}", new String(bytes));
}
Also used : 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