Add ability to make DataRequests with empty bodies
This commit is contained in:
parent
7b631a019b
commit
8082f002fe
4 changed files with 27 additions and 27 deletions
|
@ -346,10 +346,7 @@ public class DashboardController implements Initializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (requestManager.getRequest().getClass().equals(DataRequest.class)) {
|
if (requestManager.getRequest().getClass().equals(DataRequest.class)) {
|
||||||
if (throwable.getCause() != null && throwable.getCause().getClass() == IllegalArgumentException.class) {
|
if (throwable.getClass() == FileNotFoundException.class) {
|
||||||
errorTitle.setText("Did you forget something?");
|
|
||||||
errorDetails.setText("Please specify a body for your " + httpMethodBox.getValue() + " request.");
|
|
||||||
} else if (throwable.getClass() == FileNotFoundException.class) {
|
|
||||||
errorTitle.setText("File(s) not found:");
|
errorTitle.setText("File(s) not found:");
|
||||||
errorDetails.setText(throwable.getMessage());
|
errorDetails.setText(throwable.getMessage());
|
||||||
}
|
}
|
||||||
|
|
|
@ -189,18 +189,22 @@ public class RequestManager extends Service<EverestResponse> {
|
||||||
*/
|
*/
|
||||||
String overriddenContentType = request.getHeaders().get("Content-Type");
|
String overriddenContentType = request.getHeaders().get("Content-Type");
|
||||||
Invocation invocation = null;
|
Invocation invocation = null;
|
||||||
Map.Entry<String, String> mapEntry;
|
|
||||||
String requestType = dataRequest.getRequestType();
|
String requestType = dataRequest.getRequestType();
|
||||||
|
|
||||||
switch (dataRequest.getContentType()) {
|
switch (dataRequest.getContentType()) {
|
||||||
case MediaType.MULTIPART_FORM_DATA:
|
case MediaType.MULTIPART_FORM_DATA:
|
||||||
|
// This enables Everest to make requests with an empty body.
|
||||||
|
if (dataRequest.getStringTuples().size() == 0 && dataRequest.getFileTuples().size() == 0) {
|
||||||
|
invocation = getInvocation(MediaType.MULTIPART_FORM_DATA, requestType, null, requestBuilder);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
FormDataMultiPart formData = new FormDataMultiPart();
|
FormDataMultiPart formData = new FormDataMultiPart();
|
||||||
|
|
||||||
// Adding the string tuples to the request
|
// Adding the string tuples to the request
|
||||||
HashMap<String, String> pairs = dataRequest.getStringTuples();
|
HashMap<String, String> pairs = dataRequest.getStringTuples();
|
||||||
for (Map.Entry<String, String> entry : pairs.entrySet()) {
|
for (Map.Entry<String, String> entry : pairs.entrySet()) {
|
||||||
mapEntry = entry;
|
formData.field(entry.getKey(), entry.getValue());
|
||||||
formData.field(mapEntry.getKey(), mapEntry.getValue());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String filePath;
|
String filePath;
|
||||||
|
@ -211,12 +215,11 @@ public class RequestManager extends Service<EverestResponse> {
|
||||||
|
|
||||||
// Adding the file tuples to the request
|
// Adding the file tuples to the request
|
||||||
for (Map.Entry<String, String> entry : pairs.entrySet()) {
|
for (Map.Entry<String, String> entry : pairs.entrySet()) {
|
||||||
mapEntry = entry;
|
filePath = entry.getValue();
|
||||||
filePath = mapEntry.getValue();
|
|
||||||
file = new File(filePath);
|
file = new File(filePath);
|
||||||
|
|
||||||
if (file.exists())
|
if (file.exists())
|
||||||
formData.bodyPart(new FileDataBodyPart(mapEntry.getKey(),
|
formData.bodyPart(new FileDataBodyPart(entry.getKey(),
|
||||||
file, MediaType.APPLICATION_OCTET_STREAM_TYPE));
|
file, MediaType.APPLICATION_OCTET_STREAM_TYPE));
|
||||||
else {
|
else {
|
||||||
fileException = true;
|
fileException = true;
|
||||||
|
@ -238,8 +241,10 @@ public class RequestManager extends Service<EverestResponse> {
|
||||||
overriddenContentType = MediaType.APPLICATION_OCTET_STREAM;
|
overriddenContentType = MediaType.APPLICATION_OCTET_STREAM;
|
||||||
filePath = dataRequest.getBody();
|
filePath = dataRequest.getBody();
|
||||||
|
|
||||||
|
// This enables Everest to make requests with empty bodies.
|
||||||
if (filePath.equals("")) {
|
if (filePath.equals("")) {
|
||||||
throw new FileNotFoundException("No file selected");
|
invocation = getInvocation(overriddenContentType, requestType, null, requestBuilder);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
File check = new File(filePath);
|
File check = new File(filePath);
|
||||||
|
@ -259,8 +264,7 @@ public class RequestManager extends Service<EverestResponse> {
|
||||||
Form form = new Form();
|
Form form = new Form();
|
||||||
|
|
||||||
for (Map.Entry<String, String> entry : dataRequest.getStringTuples().entrySet()) {
|
for (Map.Entry<String, String> entry : dataRequest.getStringTuples().entrySet()) {
|
||||||
mapEntry = entry;
|
form.param(entry.getKey(), entry.getValue());
|
||||||
form.param(mapEntry.getKey(), mapEntry.getValue());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
invocation = getInvocation(overriddenContentType, requestType, form, requestBuilder);
|
invocation = getInvocation(overriddenContentType, requestType, form, requestBuilder);
|
||||||
|
|
|
@ -18,8 +18,7 @@ package com.rohitawate.everest.state;
|
||||||
|
|
||||||
import com.rohitawate.everest.models.requests.HTTPConstants;
|
import com.rohitawate.everest.models.requests.HTTPConstants;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the state of the Composer.
|
* Represents the state of the Composer.
|
||||||
|
@ -28,8 +27,8 @@ public class ComposerState {
|
||||||
public String target;
|
public String target;
|
||||||
public String httpMethod;
|
public String httpMethod;
|
||||||
|
|
||||||
public ArrayList<FieldState> params;
|
public List<FieldState> params;
|
||||||
public ArrayList<FieldState> headers;
|
public List<FieldState> headers;
|
||||||
public String contentType;
|
public String contentType;
|
||||||
|
|
||||||
// Body and content-type of requests with raw bodies
|
// Body and content-type of requests with raw bodies
|
||||||
|
@ -37,11 +36,11 @@ public class ComposerState {
|
||||||
public String rawBodyBoxValue;
|
public String rawBodyBoxValue;
|
||||||
|
|
||||||
// Tuples of URL-encoded requests
|
// Tuples of URL-encoded requests
|
||||||
public ArrayList<FieldState> urlStringTuples;
|
public List<FieldState> urlStringTuples;
|
||||||
|
|
||||||
// String and file tuples of multipart-form requests
|
// String and file tuples of multipart-form requests
|
||||||
public ArrayList<FieldState> formStringTuples;
|
public List<FieldState> formStringTuples;
|
||||||
public ArrayList<FieldState> formFileTuples;
|
public List<FieldState> formFileTuples;
|
||||||
|
|
||||||
// File path of application/octet-stream requests
|
// File path of application/octet-stream requests
|
||||||
public String binaryFilePath;
|
public String binaryFilePath;
|
||||||
|
|
|
@ -208,15 +208,15 @@ class SQLiteManager implements DataManager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param requestID Database ID of the request whose tuples are needed.
|
* @param requestID Database ID of the request whose tuples are needed.
|
||||||
* @param type Type of tuples needed ('String', 'File' or 'Param')
|
* @param type Type of tuples needed ('URLString', 'FormString', 'File', 'Header' or 'Param')
|
||||||
* @return tuples - Map of tuples of corresponding type
|
* @return fieldStates - List of FieldStates for the tuples
|
||||||
*/
|
*/
|
||||||
private ArrayList<FieldState> getTuples(int requestID, String type) throws SQLException {
|
private List<FieldState> getTuples(int requestID, String type) throws SQLException {
|
||||||
if (!(type.equals("FormString") || type.equals("URLString") ||
|
if (!(type.equals("FormString") || type.equals("URLString") ||
|
||||||
type.equals("File") || type.equals("Param") || type.equals("Header")))
|
type.equals("File") || type.equals("Param") || type.equals("Header")))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
ArrayList<FieldState> tuples = new ArrayList<>();
|
ArrayList<FieldState> fieldStates = new ArrayList<>();
|
||||||
|
|
||||||
PreparedStatement statement = conn.prepareStatement(Queries.selectTuplesByType);
|
PreparedStatement statement = conn.prepareStatement(Queries.selectTuplesByType);
|
||||||
statement.setInt(1, requestID);
|
statement.setInt(1, requestID);
|
||||||
|
@ -230,10 +230,10 @@ class SQLiteManager implements DataManager {
|
||||||
key = RS.getString("Key");
|
key = RS.getString("Key");
|
||||||
value = RS.getString("Value");
|
value = RS.getString("Value");
|
||||||
checked = RS.getBoolean("Checked");
|
checked = RS.getBoolean("Checked");
|
||||||
tuples.add(new FieldState(key, value, checked));
|
fieldStates.add(new FieldState(key, value, checked));
|
||||||
}
|
}
|
||||||
|
|
||||||
return tuples;
|
return fieldStates;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ComposerState getLastRequest() {
|
private ComposerState getLastRequest() {
|
||||||
|
@ -297,7 +297,7 @@ class SQLiteManager implements DataManager {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveTuple(ArrayList<FieldState> tuples, String tupleType, int requestID) {
|
private void saveTuple(List<FieldState> tuples, String tupleType, int requestID) {
|
||||||
if (tuples.size() > 0) {
|
if (tuples.size() > 0) {
|
||||||
try {
|
try {
|
||||||
for (FieldState fieldState : tuples) {
|
for (FieldState fieldState : tuples) {
|
||||||
|
|
Loading…
Reference in a new issue