Search in sources :

Example 61 with HttpMessageDataStreamer

use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer in project ballerina by ballerina-lang.

the class HTTPCorsTest method testSimpleReqMultipleOrigins.

@Test(description = "Test simple request with multiple origins")
public void testSimpleReqMultipleOrigins() {
    String path = "/hello1/test3";
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "POST", "Hello there");
    cMsg.setHeader(HttpHeaderNames.ORIGIN.toString(), "http://www.wso2.com http://www.amazon.com");
    HTTPCarbonMessage response = Services.invokeNew(complieResult, TEST_EP, cMsg);
    Assert.assertNotNull(response);
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
    Assert.assertEquals(bJson.value().get("echo").asText(), "moreOrigins");
    Assert.assertEquals("http://www.wso2.com http://www.amazon.com", response.getHeader(HttpHeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN.toString()));
    Assert.assertEquals("true", response.getHeader(HttpHeaderNames.ACCESS_CONTROL_ALLOW_CREDENTIALS.toString()));
}
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 62 with HttpMessageDataStreamer

use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer in project ballerina by ballerina-lang.

the class HTTPCorsTest method testSimpleReqwithExtraWS.

@Test(description = "Test for values with extra white spaces")
public void testSimpleReqwithExtraWS() {
    String path = "/hello2/test1";
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "POST", "hello");
    cMsg.setHeader(HttpHeaderNames.ORIGIN.toString(), "http://www.facebook.com");
    HTTPCarbonMessage response = Services.invokeNew(complieResult, TEST_EP, cMsg);
    Assert.assertNotNull(response);
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
    Assert.assertEquals(bJson.value().get("echo").asText(), "resOnlyCors");
    Assert.assertEquals("http://www.facebook.com", response.getHeader(HttpHeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN.toString()));
}
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 63 with HttpMessageDataStreamer

use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer in project ballerina by ballerina-lang.

the class HTTPCorsTest method testSimpleReqInvalidOrigin.

@Test(description = "Test simple request for invalid origins")
public void testSimpleReqInvalidOrigin() {
    String path = "/hello1/test1";
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "POST", "Hello there");
    cMsg.setHeader(HttpHeaderNames.ORIGIN.toString(), "www.wso2.com");
    HTTPCarbonMessage response = Services.invokeNew(complieResult, TEST_EP, cMsg);
    Assert.assertNotNull(response);
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
    Assert.assertEquals(bJson.value().get("echo").asText(), "resCors");
    Assert.assertEquals(null, response.getHeader(HttpHeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN.toString()));
    Assert.assertNull(null, response.getHeader(HttpHeaderNames.ACCESS_CONTROL_ALLOW_CREDENTIALS.toString()));
}
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 64 with HttpMessageDataStreamer

use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer in project ballerina by ballerina-lang.

the class HTTPCorsTest method testSimpleReqServiceCors.

@Test(description = "Test for simple request service CORS")
public void testSimpleReqServiceCors() {
    String path = "/hello1/test2";
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET");
    cMsg.setHeader(HttpHeaderNames.ORIGIN.toString(), "http://www.hello.com");
    HTTPCarbonMessage response = Services.invokeNew(complieResult, TEST_EP, cMsg);
    Assert.assertNotNull(response);
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
    Assert.assertEquals(bJson.value().get("echo").asText(), "serCors");
    Assert.assertEquals(response.getHeader(HttpHeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN.toString()), "http://www.hello.com");
    Assert.assertEquals(response.getHeader(HttpHeaderNames.ACCESS_CONTROL_ALLOW_CREDENTIALS.toString()), "true");
}
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 65 with HttpMessageDataStreamer

use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer in project ballerina by ballerina-lang.

the class DataBindingTest method testDataBindingWithoutPayload.

@Test(description = "Test data binding without a payload")
public void testDataBindingWithoutPayload() {
    HTTPTestRequest requestMsg = MessageUtils.generateHTTPMessage("/echo/body1", "GET");
    HTTPCarbonMessage responseMsg = Services.invokeNew(compileResult, TEST_EP, requestMsg);
    Assert.assertNotNull(responseMsg, "responseMsg message not found");
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(responseMsg).getInputStream());
    Assert.assertEquals(bJson.value().get("Person").asText(), "", "Person variable not set properly.");
}
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