use of org.apache.axis2.context.MessageContext in project wso2-synapse by wso2.
the class JsonFormatterTest method runTest.
private void runTest(String xmlInput, String jsonOut, InputStream inputStream) {
try {
MessageFormatter formatter = Util.newJsonFormatter();
MessageContext messageContext = Util.newMessageContext(xmlInput);
JsonUtil.getNewJsonPayload(messageContext, inputStream, false, false);
OutputStream out = Util.newOutputStream();
formatter.writeTo(messageContext, null, out, false);
assertTrue(jsonOut.equals(out.toString()));
} catch (AxisFault axisFault) {
axisFault.printStackTrace();
assertTrue(false);
} catch (XMLStreamException e) {
e.printStackTrace();
assertTrue(false);
} catch (Exception e) {
System.out.println(e);
assertTrue(false);
}
}
use of org.apache.axis2.context.MessageContext in project wso2-synapse by wso2.
the class JsonStreamingFormatterTest method testGetBytes.
public void testGetBytes() {
String inputXML = "<test>123</test>";
String outputJSON = "{\"test\":123}";
try {
OMElement omElement = AXIOMUtil.stringToOM(inputXML);
MessageFormatter formatter = Util.newJsonStreamFormatter();
MessageContext messageContext = Util.newMessageContext();
messageContext.getEnvelope().getBody().addChild(omElement);
byte[] bytes = formatter.getBytes(messageContext, null);
String result = new String(bytes);
assertEquals(outputJSON, result);
} catch (Exception ex) {
ex.printStackTrace();
assertTrue(false);
}
}
use of org.apache.axis2.context.MessageContext in project wso2-synapse by wso2.
the class JsonStreamingFormatterTest method testCase.
public void testCase() {
try {
InputStream inputStream = Util.newInputStream(obj_1.getBytes());
MessageFormatter formatter = Util.newJsonStreamFormatter();
MessageContext messageContext = Util.newMessageContext();
JsonUtil.getNewJsonPayload(messageContext, inputStream, true, true);
OutputStream out = Util.newOutputStream();
formatter.writeTo(messageContext, null, out, false);
assertTrue(obj_1.equals(out.toString()));
} catch (AxisFault axisFault) {
axisFault.printStackTrace();
assertTrue(false);
}
}
use of org.apache.axis2.context.MessageContext in project wso2-synapse by wso2.
the class Util method newMessageContext.
public static MessageContext newMessageContext(String xmlpayload) throws AxisFault, XMLStreamException {
MessageContext messageContext = new MessageContext();
SOAPEnvelope envelope = factory.createSOAPEnvelope();
factory.createSOAPBody(envelope);
envelope.getBody().addChild(AXIOMUtil.stringToOM(xmlpayload));
messageContext.setEnvelope(envelope);
return messageContext;
}
use of org.apache.axis2.context.MessageContext in project wso2-synapse by wso2.
the class BuilderFormatterTest method runTest.
public void runTest(String jsonIn, String xmlOut) {
try {
MessageContext message = Util.newMessageContext();
InputStream inputStream = Util.newInputStream(jsonIn.getBytes());
OMElement element = jsonBuilder.processDocument(inputStream, "application/json", message);
message.getEnvelope().getBody().addChild(element);
// System.out.println(element.toString());
assertTrue(xmlOut.equals(element.toString()));
OutputStream out = Util.newOutputStream();
formatter.writeTo(message, null, out, false);
String outStr = new String(((ByteArrayOutputStream) out).toByteArray());
// System.out.println(outStr);
assertTrue(jsonIn.equals(outStr));
} catch (AxisFault axisFault) {
axisFault.printStackTrace();
assertTrue(false);
}
}
Aggregations