Added Request object recycling to DashboardController
This commit is contained in:
parent
4753d433b5
commit
b81b67cc6f
3 changed files with 68 additions and 19 deletions
|
@ -44,16 +44,16 @@ public class BodyTabController implements Initializable {
|
||||||
@FXML
|
@FXML
|
||||||
private TabPane bodyTabPane;
|
private TabPane bodyTabPane;
|
||||||
@FXML
|
@FXML
|
||||||
private ComboBox<String> rawInputTypeBox;
|
ComboBox<String> rawInputTypeBox;
|
||||||
@FXML
|
@FXML
|
||||||
private TextArea rawInputArea;
|
TextArea rawInputArea;
|
||||||
@FXML
|
@FXML
|
||||||
private Tab rawTab, binaryTab, formTab, urlTab;
|
Tab rawTab, binaryTab, formTab, urlTab;
|
||||||
@FXML
|
@FXML
|
||||||
private TextField filePathField;
|
TextField filePathField;
|
||||||
|
|
||||||
private FormDataTabController formDataTabController;
|
FormDataTabController formDataTabController;
|
||||||
private URLTabController urlTabController;
|
URLTabController urlTabController;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL location, ResourceBundle resources) {
|
public void initialize(URL location, ResourceBundle resources) {
|
||||||
|
|
|
@ -47,6 +47,7 @@ import javafx.scene.layout.StackPane;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
|
|
||||||
import javax.ws.rs.ProcessingException;
|
import javax.ws.rs.ProcessingException;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -73,7 +74,7 @@ public class DashboardController implements Initializable {
|
||||||
private Label statusCode, statusCodeDescription, responseTime,
|
private Label statusCode, statusCodeDescription, responseTime,
|
||||||
responseSize, errorTitle, errorDetails, responseType;
|
responseSize, errorTitle, errorDetails, responseType;
|
||||||
@FXML
|
@FXML
|
||||||
private JFXButton sendButton, cancelButton;
|
private JFXButton cancelButton;
|
||||||
@FXML
|
@FXML
|
||||||
TabPane requestOptionsTab;
|
TabPane requestOptionsTab;
|
||||||
@FXML
|
@FXML
|
||||||
|
@ -93,6 +94,10 @@ public class DashboardController implements Initializable {
|
||||||
private IntegerProperty paramsCountProperty;
|
private IntegerProperty paramsCountProperty;
|
||||||
private Accordion accordion;
|
private Accordion accordion;
|
||||||
|
|
||||||
|
private GETRequest getRequest;
|
||||||
|
private DataDispatchRequest dataRequest;
|
||||||
|
private DELETERequest deleteRequest;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL url, ResourceBundle rb) {
|
public void initialize(URL url, ResourceBundle rb) {
|
||||||
applyDashboardSettings();
|
applyDashboardSettings();
|
||||||
|
@ -142,7 +147,7 @@ public class DashboardController implements Initializable {
|
||||||
});
|
});
|
||||||
|
|
||||||
errorTitle.setText("Oops... That's embarrassing!");
|
errorTitle.setText("Oops... That's embarrassing!");
|
||||||
errorDetails.setText("Something went wrong. Try to make another request.\nRestart Everest if that doesn't work.");
|
errorDetails.setText("Something went wrong. Try to make another getRequest.\nRestart Everest if that doesn't work.");
|
||||||
|
|
||||||
setupVisualizer();
|
setupVisualizer();
|
||||||
}
|
}
|
||||||
|
@ -164,7 +169,10 @@ public class DashboardController implements Initializable {
|
||||||
}
|
}
|
||||||
switch (httpMethodBox.getValue()) {
|
switch (httpMethodBox.getValue()) {
|
||||||
case "GET":
|
case "GET":
|
||||||
GETRequest getRequest = new GETRequest(addressField.getText());
|
if (getRequest == null)
|
||||||
|
getRequest = new GETRequest();
|
||||||
|
|
||||||
|
getRequest.setTarget(addressField.getText());
|
||||||
getRequest.setHeaders(headerTabController.getHeaders());
|
getRequest.setHeaders(headerTabController.getHeaders());
|
||||||
|
|
||||||
requestManager = Services.pool.get();
|
requestManager = Services.pool.get();
|
||||||
|
@ -174,24 +182,61 @@ public class DashboardController implements Initializable {
|
||||||
configureRequestManager();
|
configureRequestManager();
|
||||||
requestManager.start();
|
requestManager.start();
|
||||||
break;
|
break;
|
||||||
// DataDispatchRequestManager will generate appropriate request based on the type.
|
// DataDispatchRequestManager will generate appropriate getRequest based on the type.
|
||||||
case "POST":
|
case "POST":
|
||||||
case "PUT":
|
case "PUT":
|
||||||
case "PATCH":
|
case "PATCH":
|
||||||
DataDispatchRequest dataDispatchRequest =
|
if (dataRequest == null)
|
||||||
bodyTabController.getBasicRequest(httpMethodBox.getValue());
|
dataRequest = new DataDispatchRequest();
|
||||||
dataDispatchRequest.setTarget(addressField.getText());
|
|
||||||
dataDispatchRequest.setHeaders(headerTabController.getHeaders());
|
dataRequest.setRequestType(httpMethodBox.getValue());
|
||||||
|
dataRequest.setTarget(addressField.getText());
|
||||||
|
dataRequest.setHeaders(headerTabController.getHeaders());
|
||||||
|
|
||||||
|
if (bodyTabController.rawTab.isSelected()) {
|
||||||
|
String contentType;
|
||||||
|
switch (bodyTabController.rawInputTypeBox.getValue()) {
|
||||||
|
case "PLAIN TEXT":
|
||||||
|
contentType = MediaType.TEXT_PLAIN;
|
||||||
|
break;
|
||||||
|
case "JSON":
|
||||||
|
contentType = MediaType.APPLICATION_JSON;
|
||||||
|
break;
|
||||||
|
case "XML":
|
||||||
|
contentType = MediaType.APPLICATION_XML;
|
||||||
|
break;
|
||||||
|
case "HTML":
|
||||||
|
contentType = MediaType.TEXT_HTML;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
contentType = MediaType.TEXT_PLAIN;
|
||||||
|
}
|
||||||
|
dataRequest.setContentType(contentType);
|
||||||
|
dataRequest.setBody(bodyTabController.rawInputArea.getText());
|
||||||
|
} else if (bodyTabController.formTab.isSelected()) {
|
||||||
|
dataRequest.setStringTuples(bodyTabController.formDataTabController.getStringTuples());
|
||||||
|
dataRequest.setFileTuples(bodyTabController.formDataTabController.getFileTuples());
|
||||||
|
dataRequest.setContentType(MediaType.MULTIPART_FORM_DATA);
|
||||||
|
} else if (bodyTabController.binaryTab.isSelected()) {
|
||||||
|
dataRequest.setBody(bodyTabController.filePathField.getText());
|
||||||
|
dataRequest.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
||||||
|
} else if (bodyTabController.urlTab.isSelected()) {
|
||||||
|
dataRequest.setStringTuples(bodyTabController.urlTabController.getStringTuples());
|
||||||
|
dataRequest.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
||||||
|
}
|
||||||
|
|
||||||
requestManager = Services.pool.data();
|
requestManager = Services.pool.data();
|
||||||
requestManager.setRequest(dataDispatchRequest);
|
requestManager.setRequest(dataRequest);
|
||||||
|
|
||||||
cancelButton.setOnAction(e -> requestManager.cancel());
|
cancelButton.setOnAction(e -> requestManager.cancel());
|
||||||
configureRequestManager();
|
configureRequestManager();
|
||||||
requestManager.start();
|
requestManager.start();
|
||||||
break;
|
break;
|
||||||
case "DELETE":
|
case "DELETE":
|
||||||
DELETERequest deleteRequest = new DELETERequest(addressField.getText());
|
if (deleteRequest == null)
|
||||||
|
deleteRequest = new DELETERequest();
|
||||||
|
|
||||||
|
deleteRequest.setTarget(addressField.getText());
|
||||||
deleteRequest.setHeaders(headerTabController.getHeaders());
|
deleteRequest.setHeaders(headerTabController.getHeaders());
|
||||||
|
|
||||||
requestManager = Services.pool.delete();
|
requestManager = Services.pool.delete();
|
||||||
|
@ -212,7 +257,7 @@ public class DashboardController implements Initializable {
|
||||||
Services.loggingService.logSevere("Request execution failed.", E, LocalDateTime.now());
|
Services.loggingService.logSevere("Request execution failed.", E, LocalDateTime.now());
|
||||||
errorLayer.setVisible(true);
|
errorLayer.setVisible(true);
|
||||||
errorTitle.setText("Oops... That's embarrassing!");
|
errorTitle.setText("Oops... That's embarrassing!");
|
||||||
errorDetails.setText("Something went wrong. Try to make another request.\nRestart Everest if that doesn't work.");
|
errorDetails.setText("Something went wrong. Try to make another getRequest.\nRestart Everest if that doesn't work.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,7 +273,7 @@ public class DashboardController implements Initializable {
|
||||||
promptLayer.setVisible(false);
|
promptLayer.setVisible(false);
|
||||||
Throwable throwable = requestManager.getException();
|
Throwable throwable = requestManager.getException();
|
||||||
Exception exception = (Exception) throwable;
|
Exception exception = (Exception) throwable;
|
||||||
Services.loggingService.logWarning(httpMethodBox.getValue() + " request could not be processed.", exception, LocalDateTime.now());
|
Services.loggingService.logWarning(httpMethodBox.getValue() + " getRequest could not be processed.", exception, LocalDateTime.now());
|
||||||
|
|
||||||
if (throwable.getClass() == UnreliableResponseException.class) {
|
if (throwable.getClass() == UnreliableResponseException.class) {
|
||||||
UnreliableResponseException URE = (UnreliableResponseException) throwable;
|
UnreliableResponseException URE = (UnreliableResponseException) throwable;
|
||||||
|
@ -249,7 +294,7 @@ public class DashboardController implements Initializable {
|
||||||
if (requestManager.getClass() == DataDispatchRequestManager.class) {
|
if (requestManager.getClass() == DataDispatchRequestManager.class) {
|
||||||
if (throwable.getCause() != null && throwable.getCause().getClass() == IllegalArgumentException.class) {
|
if (throwable.getCause() != null && throwable.getCause().getClass() == IllegalArgumentException.class) {
|
||||||
errorTitle.setText("Did you forget something?");
|
errorTitle.setText("Did you forget something?");
|
||||||
errorDetails.setText("Please specify at least one body part for your " + httpMethodBox.getValue() + " request.");
|
errorDetails.setText("Please specify at least one body part for your " + httpMethodBox.getValue() + " getRequest.");
|
||||||
} else if (throwable.getClass() == FileNotFoundException.class) {
|
} 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());
|
||||||
|
|
|
@ -71,4 +71,8 @@ public class DataDispatchRequest extends EverestRequest implements Serializable
|
||||||
public String getRequestType() {
|
public String getRequestType() {
|
||||||
return requestType;
|
return requestType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setRequestType(String requestType) {
|
||||||
|
this.requestType = requestType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue