use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer in project ballerina by ballerina-lang.
the class UriTemplateDefaultDispatcherTest method testServiceNameDispatchingWhenAnnotationUnavailable.
@Test(description = "Test dispatching with Service name when annotation is not available")
public void testServiceNameDispatchingWhenAnnotationUnavailable() {
String path = "/serviceWithNoAnnotation/test1";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET");
HTTPCarbonMessage response = Services.invokeNew(application, TEST_EP, cMsg);
Assert.assertNotNull(response, "Response message not found");
BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get("echo").asText(), "dispatched to a service without an annotation", "Resource dispatched to wrong template");
}
use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer in project ballerina by ballerina-lang.
the class ConnectionAction method getOutputStream.
private OutputStream getOutputStream(HTTPCarbonMessage responseMessage, HttpResponseFuture outboundResponseStatusFuture) {
HttpMessageDataStreamer outboundMsgDataStreamer = new HttpMessageDataStreamer(responseMessage);
HttpConnectorListener outboundResStatusConnectorListener = new HttpResponseConnectorListener(outboundMsgDataStreamer);
outboundResponseStatusFuture.setHttpConnectorListener(outboundResStatusConnectorListener);
return outboundMsgDataStreamer.getOutputStream();
}
use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer in project ballerina by ballerina-lang.
the class ResponseReader method getReturnValue.
/**
* Get the response value from input stream.
*
* @param response carbon response
* @return return value from input stream as a string
*/
public static String getReturnValue(HTTPCarbonMessage response) {
Reader reader;
final int bufferSize = 1024;
final char[] buffer = new char[bufferSize];
final StringBuilder out = new StringBuilder();
try {
reader = new InputStreamReader(new HttpMessageDataStreamer(response).getInputStream(), UTF_8);
while (true) {
int size = reader.read(buffer, 0, buffer.length);
if (size < 0) {
break;
}
out.append(buffer, 0, size);
}
} catch (IOException e) {
LOG.error("Error occured while reading the response value in getReturnValue", e.getMessage());
}
return out.toString();
}
use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer in project ballerina by ballerina-lang.
the class GlobalVarServicePkgTest method testAccessingGlobalVarInOtherPackages.
@Test(description = "Test accessing global variables in other packages", enabled = false)
public void testAccessingGlobalVarInOtherPackages() {
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/globalvar-pkg/defined", "GET");
HTTPCarbonMessage response = Services.invokeNew(result, cMsg);
Assert.assertNotNull(response);
// Expected Json message : {"glbVarInt":22343, "glbVarString":"stringval", "glbVarFloat":6342.234234}
BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get("glbVarInt").asText(), "22343");
Assert.assertEquals(bJson.value().get("glbVarString").asText(), "stringval");
Assert.assertEquals(bJson.value().get("glbVarFloat").asText(), "6342.234234");
}
use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer in project ballerina by ballerina-lang.
the class GlobalVarServicePkgTest method testAssignGlobalVarFromOtherPkgWhenDefining.
@Test(description = "Test assigning global variable from other package when defining", enabled = false)
public void testAssignGlobalVarFromOtherPkgWhenDefining() {
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/globalvar-pkg/assign-from-other-pkg", "GET");
HTTPCarbonMessage response = Services.invokeNew(result, cMsg);
Assert.assertNotNull(response);
// Expected Json message : {"glbVarFloat1":6342.234234}
BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get("glbVarFloat1").asText(), "6342.234234");
}
Aggregations