Search in sources :

Example 86 with HttpMessageDataStreamer

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");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 87 with HttpMessageDataStreamer

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();
}
Also used : HttpConnectorListener(org.wso2.transport.http.netty.contract.HttpConnectorListener) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer)

Example 88 with HttpMessageDataStreamer

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();
}
Also used : InputStreamReader(java.io.InputStreamReader) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException)

Example 89 with HttpMessageDataStreamer

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");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 90 with HttpMessageDataStreamer

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");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Aggregations

HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)176 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)172 Test (org.testng.annotations.Test)172 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)172 BJSON (org.ballerinalang.model.values.BJSON)104 BString (org.ballerinalang.model.values.BString)21 ArrayList (java.util.ArrayList)5 Header (org.wso2.carbon.messaging.Header)5 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 ExecutorService (java.util.concurrent.ExecutorService)4 Semaphore (java.util.concurrent.Semaphore)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 MimeTypeParseException (javax.activation.MimeTypeParseException)2 BStruct (org.ballerinalang.model.values.BStruct)2 StringDataSource (org.ballerinalang.runtime.message.StringDataSource)2 MIMEPart (org.jvnet.mimepull.MIMEPart)2 EncoderException (io.netty.handler.codec.EncoderException)1 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1