Added application/octet-stream support in POST requests

This commit is contained in:
Rohit Awate 2018-02-01 12:13:15 +05:30
parent 4879a5ce9f
commit 8db0594660
3 changed files with 12 additions and 2 deletions

View file

@ -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;
}

View file

@ -26,7 +26,6 @@ public class POSTRequest extends RestaurantRequest {
private HashMap<String, String> stringTuples;
private HashMap<String, String> fileTuples;
public POSTRequest() {
}

View file

@ -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