Search in sources :

Example 56 with HTTPCarbonMessage

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

the class MultipartEncoderTest method testMultipartsInOutResponse.

@Test(description = "Test whether the encoded body parts can be sent through Response, with a given boundary")
public void testMultipartsInOutResponse() {
    String path = "/multipart/encode_out_response";
    HTTPTestRequest inRequestMsg = MessageUtils.generateHTTPMessage(path, HttpConstants.HTTP_METHOD_GET);
    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("multipart/mixed; boundary=" + "e3a0b9ad7b4e7cdb", inputStream);
        Assert.assertEquals(mimeParts.size(), 4);
        BStruct bodyPart = Util.getEntityStruct(result);
        validateBodyPartContent(mimeParts, bodyPart);
    } catch (MimeTypeParseException e) {
        log.error("Error occurred while testing mulitpart/mixed encoding", e.getMessage());
    } catch (IOException e) {
        log.error("Error occurred while decoding binary part", e.getMessage());
    }
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) 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) IOException(java.io.IOException) MIMEPart(org.jvnet.mimepull.MIMEPart) Test(org.testng.annotations.Test)

Example 57 with HTTPCarbonMessage

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

the class MultipartFormDataDecoderTest method testXmlBodyPartAsFileUpload.

@Test(description = "Test sending a multipart request with a json body part where the content is kept in a file")
public void testXmlBodyPartAsFileUpload() {
    String path = "/test/xmlbodypart";
    Map<String, Object> messageMap = Util.createPrerequisiteMessages(path, MULTIPART_FORM_DATA, result);
    ArrayList<BStruct> bodyParts = new ArrayList<>();
    bodyParts.add(Util.getXmlFilePart(result));
    HTTPTestRequest cMsg = Util.getCarbonMessageWithBodyParts(messageMap, Util.getArrayOfBodyParts(bodyParts));
    HTTPCarbonMessage response = Services.invokeNew(serviceResult, MOCK_ENDPOINT_NAME, cMsg);
    Assert.assertNotNull(response, "Response message not found");
    Assert.assertEquals(new BXMLItem(ResponseReader.getReturnValue(response)).getTextValue().stringValue(), "Ballerina" + " xml file part");
}
Also used : BXMLItem(org.ballerinalang.model.values.BXMLItem) BStruct(org.ballerinalang.model.values.BStruct) HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) ArrayList(java.util.ArrayList) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) Test(org.testng.annotations.Test)

Example 58 with HTTPCarbonMessage

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

the class MultipartFormDataDecoderTest method testBinaryBodyPart.

@Test(description = "Test sending a multipart request with a binary body part which is kept in memory")
public void testBinaryBodyPart() {
    String path = "/test/binarybodypart";
    Map<String, Object> messageMap = Util.createPrerequisiteMessages(path, MULTIPART_FORM_DATA, result);
    ArrayList<BStruct> bodyParts = new ArrayList<>();
    bodyParts.add(Util.getBinaryBodyPart(result));
    HTTPTestRequest cMsg = Util.getCarbonMessageWithBodyParts(messageMap, Util.getArrayOfBodyParts(bodyParts));
    HTTPCarbonMessage response = Services.invokeNew(serviceResult, MOCK_ENDPOINT_NAME, cMsg);
    Assert.assertNotNull(response, "Response message not found");
    Assert.assertEquals(ResponseReader.getReturnValue(response), "Ballerina binary part");
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) ArrayList(java.util.ArrayList) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) Test(org.testng.annotations.Test)

Example 59 with HTTPCarbonMessage

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

the class MultipartFormDataDecoderTest method testTextBodyPartAsFileUpload.

@Test(description = "Test sending a multipart request with a text body part where the content is kept in a file")
public void testTextBodyPartAsFileUpload() {
    String path = "/test/textbodypart";
    Map<String, Object> messageMap = Util.createPrerequisiteMessages(path, MULTIPART_FORM_DATA, result);
    ArrayList<BStruct> bodyParts = new ArrayList<>();
    bodyParts.add(Util.getTextFilePart(result));
    HTTPTestRequest cMsg = Util.getCarbonMessageWithBodyParts(messageMap, Util.getArrayOfBodyParts(bodyParts));
    HTTPCarbonMessage response = Services.invokeNew(serviceResult, MOCK_ENDPOINT_NAME, cMsg);
    Assert.assertNotNull(response, "Response message not found");
    Assert.assertEquals(ResponseReader.getReturnValue(response), "Ballerina text as a file part");
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) ArrayList(java.util.ArrayList) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) Test(org.testng.annotations.Test)

Example 60 with HTTPCarbonMessage

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

the class MultipartFormDataDecoderTest method testTextBodyPartWith8BitEncoding.

@Test(description = "Test sending a multipart request with a text body part that has 8 bit transfer encoding")
public void testTextBodyPartWith8BitEncoding() {
    String path = "/test/textbodypart";
    Map<String, Object> messageMap = Util.createPrerequisiteMessages(path, MULTIPART_FORM_DATA, result);
    ArrayList<BStruct> bodyParts = new ArrayList<>();
    bodyParts.add(Util.getTextFilePartWithEncoding(CONTENT_TRANSFER_ENCODING_8_BIT, "èlllll", result));
    HTTPTestRequest cMsg = Util.getCarbonMessageWithBodyParts(messageMap, Util.getArrayOfBodyParts(bodyParts));
    HTTPCarbonMessage response = Services.invokeNew(serviceResult, MOCK_ENDPOINT_NAME, cMsg);
    Assert.assertNotNull(response, "Response message not found");
    Assert.assertEquals(ResponseReader.getReturnValue(response), "èlllll");
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) ArrayList(java.util.ArrayList) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) 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