Search in sources :

Example 51 with HttpCarbonMessage

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

the class LocksInServicesTest method testServiceLvlVarLockComplex.

@Test(description = "Test locking service level variable complex", enabled = false)
public void testServiceLvlVarLockComplex() {
    Semaphore semaphore = new Semaphore(-11);
    ExecutorService executor = TestThreadPool.getInstance().getExecutor();
    for (int i = 0; i < 4; i++) {
        executor.submit(new TestRequestSender(compileResult, semaphore, "/sample1/echo"));
        executor.submit(new TestRequestSender(compileResult, semaphore, "/sample1/echo1"));
        executor.submit(new TestRequestSender(compileResult, semaphore, "/sample1/echo2"));
    }
    try {
        if (!semaphore.tryAcquire(10, TimeUnit.MINUTES)) {
            Assert.fail("request execution not finished within 2s");
        }
        String path = "/sample1/getResult";
        HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET");
        HTTPCarbonMessage response = Services.invokeNew(compileResult, cMsg);
        Assert.assertNotNull(response, "Response message not found");
        String responseMsgPayload = StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(response).getInputStream());
        Assert.assertEquals(responseMsgPayload, "3333333333331224.01455555555555513.026.0777777777777", "incorrect request count");
    } catch (InterruptedException e) {
        Assert.fail("thread interrupted before request execution finished - " + e.getMessage(), e);
    }
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) ExecutorService(java.util.concurrent.ExecutorService) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) Semaphore(java.util.concurrent.Semaphore) Test(org.testng.annotations.Test)

Example 52 with HttpCarbonMessage

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

the class LocksInServicesTest method testServiceLvlVarLockBasic.

@Test(description = "Test locking service level variable basic", enabled = false)
public void testServiceLvlVarLockBasic() {
    Semaphore semaphore = new Semaphore(-9999);
    ExecutorService executor = TestThreadPool.getInstance().getExecutor();
    for (int i = 0; i < 10000; i++) {
        executor.submit(new TestRequestSender(compileResult, semaphore, "/sample/echo"));
    }
    try {
        if (!semaphore.tryAcquire(20, TimeUnit.MINUTES)) {
            Assert.fail("request execution not finished within 2s");
        }
        String path = "/sample/getCount";
        HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET");
        HTTPCarbonMessage response = Services.invokeNew(compileResult, cMsg);
        Assert.assertNotNull(response, "Response message not found");
        String responseMsgPayload = StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(response).getInputStream());
        Assert.assertEquals(responseMsgPayload, "count - 10000", "incorrect request count");
    } catch (InterruptedException e) {
        Assert.fail("thread interrupted before request execution finished - " + e.getMessage(), e);
    }
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) ExecutorService(java.util.concurrent.ExecutorService) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) Semaphore(java.util.concurrent.Semaphore) Test(org.testng.annotations.Test)

Example 53 with HttpCarbonMessage

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

the class MimeUtilityFunctionTest method testLargePayload.

@Test(description = "When the payload exceeds 2MB check whether the response received back matches  " + "the original content length")
public void testLargePayload() {
    String path = "/test/largepayload";
    try {
        ByteChannel byteChannel = TestUtil.openForReading("datafiles/io/text/fileThatExceeds2MB.txt");
        Channel channel = new MockByteChannel(byteChannel, 10);
        CharacterChannel characterChannel = new CharacterChannel(channel, StandardCharsets.UTF_8.name());
        String responseValue = characterChannel.readAll();
        characterChannel.close();
        HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "POST", responseValue);
        HTTPCarbonMessage response = Services.invokeNew(serviceResult, "mockEP", cMsg);
        Assert.assertNotNull(response, "Response message not found");
        InputStream inputStream = new HttpMessageDataStreamer(response).getInputStream();
        Assert.assertNotNull(inputStream, "Inputstream is null");
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        MimeUtil.writeInputToOutputStream(inputStream, outputStream);
        Assert.assertEquals(outputStream.size(), 2323779);
    } catch (IOException | URISyntaxException e) {
        log.error("Error occurred in testLargePayload", e.getMessage());
    }
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) InputStream(java.io.InputStream) Channel(org.ballerinalang.nativeimpl.io.channels.base.Channel) MockByteChannel(org.ballerinalang.test.nativeimpl.functions.io.MockByteChannel) ByteChannel(java.nio.channels.ByteChannel) CharacterChannel(org.ballerinalang.nativeimpl.io.channels.base.CharacterChannel) BString(org.ballerinalang.model.values.BString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) MockByteChannel(org.ballerinalang.test.nativeimpl.functions.io.MockByteChannel) MockByteChannel(org.ballerinalang.test.nativeimpl.functions.io.MockByteChannel) ByteChannel(java.nio.channels.ByteChannel) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) CharacterChannel(org.ballerinalang.nativeimpl.io.channels.base.CharacterChannel) Test(org.testng.annotations.Test)

Example 54 with HttpCarbonMessage

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

the class MultipartDecoderTest method testMultiplePartsForFormData.

@Test(description = "Test sending a multipart request as multipart/form-data with multiple body parts")
public void testMultiplePartsForFormData() {
    String path = "/test/multipleparts";
    List<Header> headers = new ArrayList<>();
    String multipartDataBoundary = MimeUtil.getNewMultipartDelimiter();
    headers.add(new Header(HttpHeaderNames.CONTENT_TYPE.toString(), "multipart/form-data; boundary=" + multipartDataBoundary));
    String multipartBody = "--" + multipartDataBoundary + "\r\n" + "Content-Disposition: form-data; name=\"foo\"" + "\r\n" + "Content-Type: text/plain; charset=UTF-8" + "\r\n" + "\r\n" + "Part1" + "\r\n" + "--" + multipartDataBoundary + "\r\n" + "Content-Disposition: form-data; name=\"filepart\"; filename=\"file-01.txt\"" + "\r\n" + "Content-Type: text/plain" + "\r\n" + "Content-Transfer-Encoding: binary" + "\r\n" + "\r\n" + "Part2" + StringUtil.NEWLINE + "\r\n" + "--" + multipartDataBoundary + "--" + "\r\n";
    HTTPTestRequest inRequestMsg = MessageUtils.generateHTTPMessage(path, HttpConstants.HTTP_METHOD_POST, headers, multipartBody);
    HTTPCarbonMessage response = Services.invokeNew(serviceResult, MOCK_ENDPOINT_NAME, inRequestMsg);
    Assert.assertNotNull(response, "Response message not found");
    Assert.assertEquals(ResponseReader.getReturnValue(response), " -- Part1 -- Part2" + StringUtil.NEWLINE);
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) Header(org.wso2.carbon.messaging.Header) ArrayList(java.util.ArrayList) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) Test(org.testng.annotations.Test)

Example 55 with HttpCarbonMessage

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

the class MultipartEncoderTest method testNestedPartsInOutResponse.

@Test(description = "Retrieve body parts from the Request and send it across Response")
public void testNestedPartsInOutResponse() {
    String path = "/multipart/nested_parts_in_outresponse";
    HTTPTestRequest inRequestMsg = Util.createNestedPartRequest(path);
    HTTPCarbonMessage response = Services.invokeNew(serviceResult, MOCK_ENDPOINT_NAME, inRequestMsg);
    Assert.assertNotNull(response, "Response message not found");
    InputStream inputStream = new HttpMessageDataStreamer(response).getInputStream();
    try {
        List<MIMEPart> mimeParts = MultipartDecoder.decodeBodyParts(inRequestMsg.getHeader(HttpHeaderNames.CONTENT_TYPE.toString()), inputStream);
        Assert.assertEquals(mimeParts.size(), 2);
        List<MIMEPart> childParts = MultipartDecoder.decodeBodyParts(mimeParts.get(1).getContentType(), mimeParts.get(1).readOnce());
        Assert.assertEquals(childParts.size(), 2);
    } catch (MimeTypeParseException e) {
        log.error("Error occurred while testing mulitpart/mixed encoding", e.getMessage());
    }
}
Also used : MimeTypeParseException(javax.activation.MimeTypeParseException) HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) MIMEPart(org.jvnet.mimepull.MIMEPart) Test(org.testng.annotations.Test)

Aggregations

HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)308 Test (org.testng.annotations.Test)247 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)233 HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)179 BJSON (org.ballerinalang.model.values.BJSON)108 BString (org.ballerinalang.model.values.BString)45 BStruct (org.ballerinalang.model.values.BStruct)43 Request (org.wso2.msf4j.Request)34 ArrayList (java.util.ArrayList)25 BValue (org.ballerinalang.model.values.BValue)19 Header (org.wso2.carbon.messaging.Header)14 Tracer (org.ballerinalang.util.tracer.Tracer)11 HttpCarbonMessage (org.wso2.transport.http.netty.message.HttpCarbonMessage)10 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)9 IOException (java.io.IOException)8 ResponseCacheControlStruct (org.ballerinalang.net.http.caching.ResponseCacheControlStruct)7 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)5 Semaphore (java.util.concurrent.Semaphore)5 APIMgtSecurityException (org.wso2.carbon.apimgt.rest.api.common.exception.APIMgtSecurityException)5 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)4