From 8db05946603a8888e19d1f765e3b371ae9cea2bd Mon Sep 17 00:00:00 2001 From: Rohit Awate Date: Thu, 1 Feb 2018 12:13:15 +0530 Subject: [PATCH] Added application/octet-stream support in POST requests --- .../rohitawate/restaurant/dashboard/BodyTabController.java | 7 ++++++- .../rohitawate/restaurant/models/requests/POSTRequest.java | 1 - .../restaurant/requestsmanager/POSTRequestManager.java | 6 ++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/rohitawate/restaurant/dashboard/BodyTabController.java b/src/main/java/com/rohitawate/restaurant/dashboard/BodyTabController.java index 82bee99..b8b0922 100644 --- a/src/main/java/com/rohitawate/restaurant/dashboard/BodyTabController.java +++ b/src/main/java/com/rohitawate/restaurant/dashboard/BodyTabController.java @@ -59,7 +59,9 @@ public class BodyTabController implements Initializable { } } - // Returns a RestaurantRequest with only the body data. + /** + * Returns a RestaurantRequest object initialized with the request body. + */ public POSTRequest getBasicRequest() { POSTRequest request = new POSTRequest(); if (rawTab.isSelected()) { @@ -87,6 +89,9 @@ public class BodyTabController implements Initializable { request.setFileTuples(urlTabController.getFileTuples()); request.setContentType(MediaType.MULTIPART_FORM_DATA); + } else if (binaryTab.isSelected()) { + request.setBody(filePathField.getText()); + request.setContentType(MediaType.APPLICATION_OCTET_STREAM); } return request; } diff --git a/src/main/java/com/rohitawate/restaurant/models/requests/POSTRequest.java b/src/main/java/com/rohitawate/restaurant/models/requests/POSTRequest.java index 805cd13..eecbbd9 100644 --- a/src/main/java/com/rohitawate/restaurant/models/requests/POSTRequest.java +++ b/src/main/java/com/rohitawate/restaurant/models/requests/POSTRequest.java @@ -26,7 +26,6 @@ public class POSTRequest extends RestaurantRequest { private HashMap stringTuples; private HashMap fileTuples; - public POSTRequest() { } diff --git a/src/main/java/com/rohitawate/restaurant/requestsmanager/POSTRequestManager.java b/src/main/java/com/rohitawate/restaurant/requestsmanager/POSTRequestManager.java index adb36d9..6b8b6b3 100644 --- a/src/main/java/com/rohitawate/restaurant/requestsmanager/POSTRequestManager.java +++ b/src/main/java/com/rohitawate/restaurant/requestsmanager/POSTRequestManager.java @@ -32,7 +32,9 @@ import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStream; import java.util.HashMap; import java.util.Map; @@ -83,6 +85,10 @@ public class POSTRequestManager extends RequestManager { invocation = requestBuilder.buildPost(Entity.entity(formData, MediaType.MULTIPART_FORM_DATA_TYPE)); break; + case MediaType.APPLICATION_OCTET_STREAM: + InputStream stream = new FileInputStream(postRequest.getBody()); + invocation = requestBuilder.buildPost(Entity.entity(stream, MediaType.APPLICATION_OCTET_STREAM_TYPE)); + break; default: // Handles raw data types (JSON, Plain text, XML, HTML) invocation = requestBuilder