use of org.apache.axis2.builder.Builder in project wso2-synapse by wso2.
the class BuilderFormatterTest method testCase9.
public void testCase9() {
try {
MessageContext message = Util.newMessageContext();
Builder jsonBuilder = Util.newJsonBuilder();
InputStream inputStream = Util.getJson(1);
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();
MessageFormatter formatter = Util.newJsonFormatter();
formatter.writeTo(message, null, out, false);
// String outStr = new String(((ByteArrayOutputStream) out).toByteArray());
// assertTrue(jsonIn.equals(outStr));
} catch (AxisFault axisFault) {
axisFault.printStackTrace();
assertTrue(false);
} catch (FileNotFoundException e) {
e.printStackTrace();
assertFalse(true);
}
}
use of org.apache.axis2.builder.Builder in project wso2-synapse by wso2.
the class ResponseMessageBuilderTest method testRenewResponse.
public void testRenewResponse() {
String id = UIDGenerator.generateURNString();
String addressUrl = "http://synapse.test.com/eventing/sunscriptions";
Date date = new Date(System.currentTimeMillis() + 3600000);
Calendar cal = Calendar.getInstance();
cal.setTime(date);
SynapseSubscription sub = new SynapseSubscription();
sub.setId(id);
sub.setSubManUrl(addressUrl);
sub.setExpires(cal);
String expected = "<wse:RenewResponse xmlns:wse=\"http://schemas.xmlsoap.org/ws/2004/08/eventing\">" + "<wse:Expires>" + ConverterUtil.convertToString(cal) + "</wse:Expires>" + "</wse:RenewResponse>";
try {
MessageContext msgCtx = TestUtils.getAxis2MessageContext("<empty/>", null).getAxis2MessageContext();
ResponseMessageBuilder builder = new ResponseMessageBuilder(msgCtx);
SOAPEnvelope env = builder.genRenewSubscriptionResponse(sub);
OMElement resultOm = env.getBody().getFirstElement();
OMElement expectedOm = AXIOMUtil.stringToOM(expected);
assertTrue(compare(expectedOm, resultOm));
} catch (Exception e) {
fail("Error while constructing the test message context: " + e.getMessage());
}
}
use of org.apache.axis2.builder.Builder in project wso2-synapse by wso2.
the class ResponseMessageBuilderTest method testGetStatusResponse.
public void testGetStatusResponse() {
String id = UIDGenerator.generateURNString();
String addressUrl = "http://synapse.test.com/eventing/sunscriptions";
Date date = new Date(System.currentTimeMillis() + 3600000);
Calendar cal = Calendar.getInstance();
cal.setTime(date);
SynapseSubscription sub = new SynapseSubscription();
sub.setId(id);
sub.setSubManUrl(addressUrl);
sub.setExpires(cal);
String expected = "<wse:GetStatusResponse xmlns:wse=\"http://schemas.xmlsoap.org/ws/2004/08/eventing\">" + "<wse:Expires>" + ConverterUtil.convertToString(cal) + "</wse:Expires>" + "</wse:GetStatusResponse>";
try {
MessageContext msgCtx = TestUtils.getAxis2MessageContext("<empty/>", null).getAxis2MessageContext();
ResponseMessageBuilder builder = new ResponseMessageBuilder(msgCtx);
SOAPEnvelope env = builder.genGetStatusResponse(sub);
OMElement resultOm = env.getBody().getFirstElement();
OMElement expectedOm = AXIOMUtil.stringToOM(expected);
assertTrue(compare(expectedOm, resultOm));
} catch (Exception e) {
fail("Error while constructing the test message context: " + e.getMessage());
}
}
use of org.apache.axis2.builder.Builder in project wso2-synapse by wso2.
the class CacheMessageBuilderDispatchandler method invoke.
@Override
public InvocationResponse invoke(MessageContext messageContext) throws AxisFault {
InvocationResponse invocationResponse = super.invoke(messageContext);
EndpointReference toEPR = messageContext.getTo();
Pipe pipe = (Pipe) messageContext.getProperty(PassThroughConstants.PASS_THROUGH_PIPE);
if ((pipe != null || RequestResponseUtils.isHttpCarbonMessagePresent(messageContext)) && messageContext.getAxisMessage() != null) {
CacheConfiguration cacheCfg = null;
Parameter ccfgParam = messageContext.getAxisMessage().getParameter(CachingConstants.CACHE_CONFIGURATION);
if (ccfgParam != null && ccfgParam.getValue() instanceof CacheConfiguration) {
cacheCfg = (CacheConfiguration) ccfgParam.getValue();
// even though we found a cache config, if the timeout is <= 0, caching is disabled
if (cacheCfg.getTimeout() <= 0) {
return invocationResponse;
}
try {
MessageHandlerProvider.getMessageHandler(messageContext).buildMessage(messageContext, false);
} catch (Exception e) {
log.error("Error while executing the message at cache message builder handler", e);
}
}
}
return invocationResponse;
}
use of org.apache.axis2.builder.Builder in project wso2-synapse by wso2.
the class HttpCoreNIOListenerTest method suite.
public static TestSuite suite() throws Exception {
ManagedTestSuite suite = new ManagedTestSuite(HttpCoreNIOListenerTest.class);
// These tests don't work because of a problem similar to SYNAPSE-418
suite.addExclude("(test=EchoXML)");
TransportDescriptionFactory tdfNIO = new HttpTransportDescriptionFactory();
HttpTransportTestSuiteBuilder builder = new HttpTransportTestSuiteBuilder(suite, tdfNIO);
builder.addAxisTestClientConfigurator(new HttpAxisTestClientConfigurator(false));
builder.addAxisTestClientConfigurator(new HttpAxisTestClientConfigurator(true));
return suite;
}
Aggregations