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());
}
}
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");
}
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");
}
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");
}
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");
}
Aggregations