Project-wide rename-refactoring for DataRequest and remove redundant and useless constructors
This commit is contained in:
parent
6825b135ec
commit
2e8cb06cb7
10 changed files with 39 additions and 92 deletions
|
@ -33,12 +33,12 @@ import com.rohitawate.everest.misc.EverestUtilities;
|
||||||
import com.rohitawate.everest.misc.Services;
|
import com.rohitawate.everest.misc.Services;
|
||||||
import com.rohitawate.everest.misc.ThemeManager;
|
import com.rohitawate.everest.misc.ThemeManager;
|
||||||
import com.rohitawate.everest.models.requests.DELETERequest;
|
import com.rohitawate.everest.models.requests.DELETERequest;
|
||||||
import com.rohitawate.everest.models.requests.DataDispatchRequest;
|
import com.rohitawate.everest.models.requests.DataRequest;
|
||||||
import com.rohitawate.everest.models.requests.GETRequest;
|
import com.rohitawate.everest.models.requests.GETRequest;
|
||||||
import com.rohitawate.everest.models.responses.EverestResponse;
|
import com.rohitawate.everest.models.responses.EverestResponse;
|
||||||
import com.rohitawate.everest.requestmanager.DataDispatchRequestManager;
|
import com.rohitawate.everest.requestmanager.DataRequestManager;
|
||||||
import com.rohitawate.everest.requestmanager.RequestManager;
|
import com.rohitawate.everest.requestmanager.RequestManager;
|
||||||
import com.rohitawate.everest.requestmanager.RequestManagersFactory;
|
import com.rohitawate.everest.requestmanager.RequestManagersPool;
|
||||||
import javafx.beans.binding.Bindings;
|
import javafx.beans.binding.Bindings;
|
||||||
import javafx.beans.property.IntegerProperty;
|
import javafx.beans.property.IntegerProperty;
|
||||||
import javafx.beans.property.SimpleIntegerProperty;
|
import javafx.beans.property.SimpleIntegerProperty;
|
||||||
|
@ -104,7 +104,7 @@ public class DashboardController implements Initializable {
|
||||||
private ResponseHeadersViewer responseHeadersViewer;
|
private ResponseHeadersViewer responseHeadersViewer;
|
||||||
|
|
||||||
private GETRequest getRequest;
|
private GETRequest getRequest;
|
||||||
private DataDispatchRequest dataRequest;
|
private DataRequest dataRequest;
|
||||||
private DELETERequest deleteRequest;
|
private DELETERequest deleteRequest;
|
||||||
private HashMap<String, String> params;
|
private HashMap<String, String> params;
|
||||||
private EverestCodeArea responseArea;
|
private EverestCodeArea responseArea;
|
||||||
|
@ -239,14 +239,14 @@ public class DashboardController implements Initializable {
|
||||||
getRequest.setTarget(address);
|
getRequest.setTarget(address);
|
||||||
getRequest.setHeaders(headerTabController.getHeaders());
|
getRequest.setHeaders(headerTabController.getHeaders());
|
||||||
|
|
||||||
requestManager = RequestManagersFactory.get();
|
requestManager = RequestManagersPool.get();
|
||||||
requestManager.setRequest(getRequest);
|
requestManager.setRequest(getRequest);
|
||||||
break;
|
break;
|
||||||
case "POST":
|
case "POST":
|
||||||
case "PUT":
|
case "PUT":
|
||||||
case "PATCH":
|
case "PATCH":
|
||||||
if (dataRequest == null)
|
if (dataRequest == null)
|
||||||
dataRequest = new DataDispatchRequest();
|
dataRequest = new DataRequest();
|
||||||
|
|
||||||
dataRequest.setRequestType(httpMethodBox.getValue());
|
dataRequest.setRequestType(httpMethodBox.getValue());
|
||||||
dataRequest.setTarget(address);
|
dataRequest.setTarget(address);
|
||||||
|
@ -284,7 +284,7 @@ public class DashboardController implements Initializable {
|
||||||
dataRequest.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
dataRequest.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
||||||
}
|
}
|
||||||
|
|
||||||
requestManager = RequestManagersFactory.data();
|
requestManager = RequestManagersPool.data();
|
||||||
requestManager.setRequest(dataRequest);
|
requestManager.setRequest(dataRequest);
|
||||||
break;
|
break;
|
||||||
case "DELETE":
|
case "DELETE":
|
||||||
|
@ -294,7 +294,7 @@ public class DashboardController implements Initializable {
|
||||||
deleteRequest.setTarget(address);
|
deleteRequest.setTarget(address);
|
||||||
deleteRequest.setHeaders(headerTabController.getHeaders());
|
deleteRequest.setHeaders(headerTabController.getHeaders());
|
||||||
|
|
||||||
requestManager = RequestManagersFactory.delete();
|
requestManager = RequestManagersPool.delete();
|
||||||
requestManager.setRequest(deleteRequest);
|
requestManager.setRequest(deleteRequest);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -338,7 +338,7 @@ public class DashboardController implements Initializable {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (requestManager.getClass() == DataDispatchRequestManager.class) {
|
if (requestManager.getClass() == DataRequestManager.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 a body for your " + httpMethodBox.getValue() + " request.");
|
errorDetails.setText("Please specify a body for your " + httpMethodBox.getValue() + " request.");
|
||||||
|
|
|
@ -24,7 +24,7 @@ import com.rohitawate.everest.exceptions.UnreliableResponseException;
|
||||||
import com.rohitawate.everest.logging.LoggingService;
|
import com.rohitawate.everest.logging.LoggingService;
|
||||||
import com.rohitawate.everest.models.requests.EverestRequest;
|
import com.rohitawate.everest.models.requests.EverestRequest;
|
||||||
import com.rohitawate.everest.models.responses.EverestResponse;
|
import com.rohitawate.everest.models.responses.EverestResponse;
|
||||||
import com.rohitawate.everest.requestmanager.DataDispatchRequestManager;
|
import com.rohitawate.everest.requestmanager.DataRequestManager;
|
||||||
import com.rohitawate.everest.requestmanager.RequestManager;
|
import com.rohitawate.everest.requestmanager.RequestManager;
|
||||||
import javafx.event.Event;
|
import javafx.event.Event;
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ public class DashboardState {
|
||||||
errorDetails = "Something went wrong. Try to make another request.Restart Everest if that doesn't work.";
|
errorDetails = "Something went wrong. Try to make another request.Restart Everest if that doesn't work.";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (requestManager.getClass() == DataDispatchRequestManager.class) {
|
if (requestManager.getClass() == DataRequestManager.class) {
|
||||||
if (throwable.getCause() != null && throwable.getCause().getClass() == IllegalArgumentException.class) {
|
if (throwable.getCause() != null && throwable.getCause().getClass() == IllegalArgumentException.class) {
|
||||||
errorTitle = "Did you forget something?";
|
errorTitle = "Did you forget something?";
|
||||||
errorDetails = "Please specify a body for your " + this.composer.httpMethod + " request.";
|
errorDetails = "Please specify a body for your " + this.composer.httpMethod + " request.";
|
||||||
|
|
|
@ -16,18 +16,9 @@
|
||||||
|
|
||||||
package com.rohitawate.everest.models.requests;
|
package com.rohitawate.everest.models.requests;
|
||||||
|
|
||||||
import java.net.MalformedURLException;
|
/**
|
||||||
import java.net.URL;
|
* Convenience class to represent an HTTP request which uses the HTTP DELETE method.
|
||||||
|
*/
|
||||||
public class DELETERequest extends EverestRequest {
|
public class DELETERequest extends EverestRequest {
|
||||||
public DELETERequest() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public DELETERequest(String target) throws MalformedURLException {
|
|
||||||
super(target);
|
|
||||||
}
|
|
||||||
|
|
||||||
public DELETERequest(URL target) {
|
|
||||||
super(target);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,26 +16,18 @@
|
||||||
|
|
||||||
package com.rohitawate.everest.models.requests;
|
package com.rohitawate.everest.models.requests;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents HTTP requests which contain data viz. POST and PUT.
|
* Represents HTTP requests which use the HTTP POST, PUT and PATCH methods.
|
||||||
*/
|
*/
|
||||||
public class DataDispatchRequest extends EverestRequest implements Serializable {
|
public class DataRequest extends EverestRequest {
|
||||||
private String requestType;
|
private String requestType;
|
||||||
private String body;
|
private String body;
|
||||||
private String contentType;
|
private String contentType;
|
||||||
private HashMap<String, String> stringTuples;
|
private HashMap<String, String> stringTuples;
|
||||||
private HashMap<String, String> fileTuples;
|
private HashMap<String, String> fileTuples;
|
||||||
|
|
||||||
public DataDispatchRequest() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public DataDispatchRequest(String requestType) {
|
|
||||||
this.requestType = requestType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getBody() {
|
public String getBody() {
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
|
@ -25,17 +25,6 @@ public abstract class EverestRequest implements Serializable {
|
||||||
private URL target;
|
private URL target;
|
||||||
private HashMap<String, String> headers;
|
private HashMap<String, String> headers;
|
||||||
|
|
||||||
EverestRequest() {
|
|
||||||
}
|
|
||||||
|
|
||||||
EverestRequest(String target) throws MalformedURLException {
|
|
||||||
this.target = new URL(target);
|
|
||||||
}
|
|
||||||
|
|
||||||
EverestRequest(URL target) {
|
|
||||||
this.target = target;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTarget(String target) throws MalformedURLException {
|
public void setTarget(String target) throws MalformedURLException {
|
||||||
this.target = new URL(target);
|
this.target = new URL(target);
|
||||||
}
|
}
|
||||||
|
@ -44,10 +33,6 @@ public abstract class EverestRequest implements Serializable {
|
||||||
return this.target;
|
return this.target;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addHeader(String key, String value) {
|
|
||||||
headers.put(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHeaders(HashMap<String, String> headers) {
|
public void setHeaders(HashMap<String, String> headers) {
|
||||||
this.headers = headers;
|
this.headers = headers;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,18 +16,9 @@
|
||||||
|
|
||||||
package com.rohitawate.everest.models.requests;
|
package com.rohitawate.everest.models.requests;
|
||||||
|
|
||||||
import java.net.MalformedURLException;
|
/**
|
||||||
import java.net.URL;
|
* Convenience class to represent an HTTP request which uses the HTTP GET method.
|
||||||
|
*/
|
||||||
public class GETRequest extends EverestRequest {
|
public class GETRequest extends EverestRequest {
|
||||||
public GETRequest() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public GETRequest(URL target) {
|
|
||||||
super(target);
|
|
||||||
}
|
|
||||||
|
|
||||||
public GETRequest(String target) throws MalformedURLException {
|
|
||||||
super(target);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,10 +25,6 @@ import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
public class DELETERequestManager extends RequestManager {
|
public class DELETERequestManager extends RequestManager {
|
||||||
|
|
||||||
DELETERequestManager() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Task<EverestResponse> createTask() throws ProcessingException {
|
protected Task<EverestResponse> createTask() throws ProcessingException {
|
||||||
return new Task<EverestResponse>() {
|
return new Task<EverestResponse>() {
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
package com.rohitawate.everest.requestmanager;
|
package com.rohitawate.everest.requestmanager;
|
||||||
|
|
||||||
import com.rohitawate.everest.models.requests.DataDispatchRequest;
|
import com.rohitawate.everest.models.requests.DataRequest;
|
||||||
import com.rohitawate.everest.models.responses.EverestResponse;
|
import com.rohitawate.everest.models.responses.EverestResponse;
|
||||||
import javafx.concurrent.Task;
|
import javafx.concurrent.Task;
|
||||||
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
|
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
|
||||||
|
@ -35,24 +35,20 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes DataDispatchRequest by automatically determining whether it
|
* Processes DataRequest by automatically determining whether it
|
||||||
* is a POST, PUT or PATCH request.
|
* is a POST, PUT or PATCH request.
|
||||||
*/
|
*/
|
||||||
public class DataDispatchRequestManager extends RequestManager {
|
public class DataRequestManager extends RequestManager {
|
||||||
private DataDispatchRequest dataDispatchRequest;
|
private DataRequest dataRequest;
|
||||||
private String requestType;
|
private String requestType;
|
||||||
|
|
||||||
DataDispatchRequestManager() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Task<EverestResponse> createTask() throws ProcessingException {
|
protected Task<EverestResponse> createTask() throws ProcessingException {
|
||||||
return new Task<EverestResponse>() {
|
return new Task<EverestResponse>() {
|
||||||
@Override
|
@Override
|
||||||
protected EverestResponse call() throws Exception {
|
protected EverestResponse call() throws Exception {
|
||||||
dataDispatchRequest = (DataDispatchRequest) request;
|
dataRequest = (DataRequest) request;
|
||||||
requestType = dataDispatchRequest.getRequestType();
|
requestType = dataRequest.getRequestType();
|
||||||
|
|
||||||
Invocation invocation = appendBody();
|
Invocation invocation = appendBody();
|
||||||
initialTime = System.currentTimeMillis();
|
initialTime = System.currentTimeMillis();
|
||||||
|
@ -81,12 +77,12 @@ public class DataDispatchRequestManager extends RequestManager {
|
||||||
Invocation invocation = null;
|
Invocation invocation = null;
|
||||||
Map.Entry<String, String> mapEntry;
|
Map.Entry<String, String> mapEntry;
|
||||||
|
|
||||||
switch (dataDispatchRequest.getContentType()) {
|
switch (dataRequest.getContentType()) {
|
||||||
case MediaType.MULTIPART_FORM_DATA:
|
case MediaType.MULTIPART_FORM_DATA:
|
||||||
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 = dataDispatchRequest.getStringTuples();
|
HashMap<String, String> pairs = dataRequest.getStringTuples();
|
||||||
for (Map.Entry entry : pairs.entrySet()) {
|
for (Map.Entry entry : pairs.entrySet()) {
|
||||||
mapEntry = (Map.Entry) entry;
|
mapEntry = (Map.Entry) entry;
|
||||||
formData.field(mapEntry.getKey(), mapEntry.getValue());
|
formData.field(mapEntry.getKey(), mapEntry.getValue());
|
||||||
|
@ -96,7 +92,7 @@ public class DataDispatchRequestManager extends RequestManager {
|
||||||
File file;
|
File file;
|
||||||
boolean fileException = false;
|
boolean fileException = false;
|
||||||
String fileExceptionMessage = null;
|
String fileExceptionMessage = null;
|
||||||
pairs = dataDispatchRequest.getFileTuples();
|
pairs = dataRequest.getFileTuples();
|
||||||
|
|
||||||
// Adding the file tuples to the request
|
// Adding the file tuples to the request
|
||||||
for (Map.Entry entry : pairs.entrySet()) {
|
for (Map.Entry entry : pairs.entrySet()) {
|
||||||
|
@ -128,7 +124,7 @@ public class DataDispatchRequestManager extends RequestManager {
|
||||||
case MediaType.APPLICATION_OCTET_STREAM:
|
case MediaType.APPLICATION_OCTET_STREAM:
|
||||||
if (overriddenContentType == null)
|
if (overriddenContentType == null)
|
||||||
overriddenContentType = MediaType.APPLICATION_OCTET_STREAM;
|
overriddenContentType = MediaType.APPLICATION_OCTET_STREAM;
|
||||||
filePath = dataDispatchRequest.getBody();
|
filePath = dataRequest.getBody();
|
||||||
|
|
||||||
File check = new File(filePath);
|
File check = new File(filePath);
|
||||||
|
|
||||||
|
@ -149,7 +145,7 @@ public class DataDispatchRequestManager extends RequestManager {
|
||||||
|
|
||||||
Form form = new Form();
|
Form form = new Form();
|
||||||
|
|
||||||
for (Map.Entry entry : dataDispatchRequest.getStringTuples().entrySet()) {
|
for (Map.Entry entry : dataRequest.getStringTuples().entrySet()) {
|
||||||
mapEntry = (Map.Entry) entry;
|
mapEntry = (Map.Entry) entry;
|
||||||
form.param(mapEntry.getKey(), mapEntry.getValue());
|
form.param(mapEntry.getKey(), mapEntry.getValue());
|
||||||
}
|
}
|
||||||
|
@ -161,21 +157,21 @@ public class DataDispatchRequestManager extends RequestManager {
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// Handles raw data types (JSON, Plain text, XML, HTML)
|
// Handles raw data types (JSON, Plain text, XML, HTML)
|
||||||
String originalContentType = dataDispatchRequest.getContentType();
|
String originalContentType = dataRequest.getContentType();
|
||||||
if (overriddenContentType == null)
|
if (overriddenContentType == null)
|
||||||
overriddenContentType = originalContentType;
|
overriddenContentType = originalContentType;
|
||||||
switch (requestType) {
|
switch (requestType) {
|
||||||
case "POST":
|
case "POST":
|
||||||
invocation = requestBuilder
|
invocation = requestBuilder
|
||||||
.buildPost(Entity.entity(dataDispatchRequest.getBody(), overriddenContentType));
|
.buildPost(Entity.entity(dataRequest.getBody(), overriddenContentType));
|
||||||
break;
|
break;
|
||||||
case "PUT":
|
case "PUT":
|
||||||
invocation = requestBuilder
|
invocation = requestBuilder
|
||||||
.buildPut(Entity.entity(dataDispatchRequest.getBody(), overriddenContentType));
|
.buildPut(Entity.entity(dataRequest.getBody(), overriddenContentType));
|
||||||
break;
|
break;
|
||||||
case "PATCH":
|
case "PATCH":
|
||||||
invocation = requestBuilder
|
invocation = requestBuilder
|
||||||
.build("PATCH", Entity.entity(dataDispatchRequest.getBody(), overriddenContentType));
|
.build("PATCH", Entity.entity(dataRequest.getBody(), overriddenContentType));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -24,10 +24,6 @@ import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
public class GETRequestManager extends RequestManager {
|
public class GETRequestManager extends RequestManager {
|
||||||
|
|
||||||
GETRequestManager() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Task<EverestResponse> createTask() throws ProcessingException {
|
protected Task<EverestResponse> createTask() throws ProcessingException {
|
||||||
return new Task<EverestResponse>() {
|
return new Task<EverestResponse>() {
|
||||||
|
|
|
@ -31,9 +31,9 @@ import java.util.ArrayList;
|
||||||
* returned to the caller. If all the managers in the pool are running,
|
* returned to the caller. If all the managers in the pool are running,
|
||||||
* a new one is created, added to the pool, and returned.
|
* a new one is created, added to the pool, and returned.
|
||||||
*/
|
*/
|
||||||
public class RequestManagersFactory {
|
public class RequestManagersPool {
|
||||||
private static ArrayList<GETRequestManager> getManagers;
|
private static ArrayList<GETRequestManager> getManagers;
|
||||||
private static ArrayList<DataDispatchRequestManager> dataManagers;
|
private static ArrayList<DataRequestManager> dataManagers;
|
||||||
private static ArrayList<DELETERequestManager> deleteManagers;
|
private static ArrayList<DELETERequestManager> deleteManagers;
|
||||||
|
|
||||||
public static GETRequestManager get() {
|
public static GETRequestManager get() {
|
||||||
|
@ -53,18 +53,18 @@ public class RequestManagersFactory {
|
||||||
return newManager;
|
return newManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DataDispatchRequestManager data() {
|
public static DataRequestManager data() {
|
||||||
if (dataManagers == null)
|
if (dataManagers == null)
|
||||||
dataManagers = new ArrayList<>();
|
dataManagers = new ArrayList<>();
|
||||||
|
|
||||||
for (DataDispatchRequestManager dataManager : dataManagers) {
|
for (DataRequestManager dataManager : dataManagers) {
|
||||||
if (!dataManager.isRunning()) {
|
if (!dataManager.isRunning()) {
|
||||||
dataManager.reset();
|
dataManager.reset();
|
||||||
return dataManager;
|
return dataManager;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DataDispatchRequestManager newManager = new DataDispatchRequestManager();
|
DataRequestManager newManager = new DataRequestManager();
|
||||||
dataManagers.add(newManager);
|
dataManagers.add(newManager);
|
||||||
|
|
||||||
return newManager;
|
return newManager;
|
Loading…
Reference in a new issue