diff --git a/src/main/java/com/rohitawate/everest/controllers/DashboardController.java b/src/main/java/com/rohitawate/everest/controllers/DashboardController.java index da4a61e..e03236d 100644 --- a/src/main/java/com/rohitawate/everest/controllers/DashboardController.java +++ b/src/main/java/com/rohitawate/everest/controllers/DashboardController.java @@ -33,12 +33,12 @@ import com.rohitawate.everest.misc.EverestUtilities; import com.rohitawate.everest.misc.Services; import com.rohitawate.everest.misc.ThemeManager; 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.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.RequestManagersFactory; +import com.rohitawate.everest.requestmanager.RequestManagersPool; import javafx.beans.binding.Bindings; import javafx.beans.property.IntegerProperty; import javafx.beans.property.SimpleIntegerProperty; @@ -104,7 +104,7 @@ public class DashboardController implements Initializable { private ResponseHeadersViewer responseHeadersViewer; private GETRequest getRequest; - private DataDispatchRequest dataRequest; + private DataRequest dataRequest; private DELETERequest deleteRequest; private HashMap params; private EverestCodeArea responseArea; @@ -239,14 +239,14 @@ public class DashboardController implements Initializable { getRequest.setTarget(address); getRequest.setHeaders(headerTabController.getHeaders()); - requestManager = RequestManagersFactory.get(); + requestManager = RequestManagersPool.get(); requestManager.setRequest(getRequest); break; case "POST": case "PUT": case "PATCH": if (dataRequest == null) - dataRequest = new DataDispatchRequest(); + dataRequest = new DataRequest(); dataRequest.setRequestType(httpMethodBox.getValue()); dataRequest.setTarget(address); @@ -284,7 +284,7 @@ public class DashboardController implements Initializable { dataRequest.setContentType(MediaType.APPLICATION_FORM_URLENCODED); } - requestManager = RequestManagersFactory.data(); + requestManager = RequestManagersPool.data(); requestManager.setRequest(dataRequest); break; case "DELETE": @@ -294,7 +294,7 @@ public class DashboardController implements Initializable { deleteRequest.setTarget(address); deleteRequest.setHeaders(headerTabController.getHeaders()); - requestManager = RequestManagersFactory.delete(); + requestManager = RequestManagersPool.delete(); requestManager.setRequest(deleteRequest); break; default: @@ -338,7 +338,7 @@ public class DashboardController implements Initializable { return; } - if (requestManager.getClass() == DataDispatchRequestManager.class) { + if (requestManager.getClass() == DataRequestManager.class) { if (throwable.getCause() != null && throwable.getCause().getClass() == IllegalArgumentException.class) { errorTitle.setText("Did you forget something?"); errorDetails.setText("Please specify a body for your " + httpMethodBox.getValue() + " request."); diff --git a/src/main/java/com/rohitawate/everest/controllers/state/DashboardState.java b/src/main/java/com/rohitawate/everest/controllers/state/DashboardState.java index bc72fb1..b6ad258 100644 --- a/src/main/java/com/rohitawate/everest/controllers/state/DashboardState.java +++ b/src/main/java/com/rohitawate/everest/controllers/state/DashboardState.java @@ -24,7 +24,7 @@ import com.rohitawate.everest.exceptions.UnreliableResponseException; import com.rohitawate.everest.logging.LoggingService; import com.rohitawate.everest.models.requests.EverestRequest; 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 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."; } - if (requestManager.getClass() == DataDispatchRequestManager.class) { + if (requestManager.getClass() == DataRequestManager.class) { if (throwable.getCause() != null && throwable.getCause().getClass() == IllegalArgumentException.class) { errorTitle = "Did you forget something?"; errorDetails = "Please specify a body for your " + this.composer.httpMethod + " request."; diff --git a/src/main/java/com/rohitawate/everest/models/requests/DELETERequest.java b/src/main/java/com/rohitawate/everest/models/requests/DELETERequest.java index c7fbf5f..e9981ce 100644 --- a/src/main/java/com/rohitawate/everest/models/requests/DELETERequest.java +++ b/src/main/java/com/rohitawate/everest/models/requests/DELETERequest.java @@ -16,18 +16,9 @@ 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 DELETERequest() { - } - public DELETERequest(String target) throws MalformedURLException { - super(target); - } - - public DELETERequest(URL target) { - super(target); - } } diff --git a/src/main/java/com/rohitawate/everest/models/requests/DataDispatchRequest.java b/src/main/java/com/rohitawate/everest/models/requests/DataRequest.java similarity index 84% rename from src/main/java/com/rohitawate/everest/models/requests/DataDispatchRequest.java rename to src/main/java/com/rohitawate/everest/models/requests/DataRequest.java index 2638b3b..74c866c 100644 --- a/src/main/java/com/rohitawate/everest/models/requests/DataDispatchRequest.java +++ b/src/main/java/com/rohitawate/everest/models/requests/DataRequest.java @@ -16,26 +16,18 @@ package com.rohitawate.everest.models.requests; -import java.io.Serializable; 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 body; private String contentType; private HashMap stringTuples; private HashMap fileTuples; - public DataDispatchRequest() { - } - - public DataDispatchRequest(String requestType) { - this.requestType = requestType; - } - public String getBody() { return body; } diff --git a/src/main/java/com/rohitawate/everest/models/requests/EverestRequest.java b/src/main/java/com/rohitawate/everest/models/requests/EverestRequest.java index b8ac346..166397e 100644 --- a/src/main/java/com/rohitawate/everest/models/requests/EverestRequest.java +++ b/src/main/java/com/rohitawate/everest/models/requests/EverestRequest.java @@ -25,17 +25,6 @@ public abstract class EverestRequest implements Serializable { private URL target; private HashMap 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 { this.target = new URL(target); } @@ -44,10 +33,6 @@ public abstract class EverestRequest implements Serializable { return this.target; } - public void addHeader(String key, String value) { - headers.put(key, value); - } - public void setHeaders(HashMap headers) { this.headers = headers; } diff --git a/src/main/java/com/rohitawate/everest/models/requests/GETRequest.java b/src/main/java/com/rohitawate/everest/models/requests/GETRequest.java index 91ee60e..b42e71c 100644 --- a/src/main/java/com/rohitawate/everest/models/requests/GETRequest.java +++ b/src/main/java/com/rohitawate/everest/models/requests/GETRequest.java @@ -16,18 +16,9 @@ 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 GETRequest() { - } - public GETRequest(URL target) { - super(target); - } - - public GETRequest(String target) throws MalformedURLException { - super(target); - } } diff --git a/src/main/java/com/rohitawate/everest/requestmanager/DELETERequestManager.java b/src/main/java/com/rohitawate/everest/requestmanager/DELETERequestManager.java index 01c4da1..bbe415d 100644 --- a/src/main/java/com/rohitawate/everest/requestmanager/DELETERequestManager.java +++ b/src/main/java/com/rohitawate/everest/requestmanager/DELETERequestManager.java @@ -25,10 +25,6 @@ import javax.ws.rs.core.Response; public class DELETERequestManager extends RequestManager { - DELETERequestManager() { - - } - @Override protected Task createTask() throws ProcessingException { return new Task() { diff --git a/src/main/java/com/rohitawate/everest/requestmanager/DataDispatchRequestManager.java b/src/main/java/com/rohitawate/everest/requestmanager/DataRequestManager.java similarity index 84% rename from src/main/java/com/rohitawate/everest/requestmanager/DataDispatchRequestManager.java rename to src/main/java/com/rohitawate/everest/requestmanager/DataRequestManager.java index 6cd35bd..0f3b323 100644 --- a/src/main/java/com/rohitawate/everest/requestmanager/DataDispatchRequestManager.java +++ b/src/main/java/com/rohitawate/everest/requestmanager/DataRequestManager.java @@ -16,7 +16,7 @@ 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 javafx.concurrent.Task; import org.glassfish.jersey.media.multipart.FormDataMultiPart; @@ -35,24 +35,20 @@ import java.util.HashMap; 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. */ -public class DataDispatchRequestManager extends RequestManager { - private DataDispatchRequest dataDispatchRequest; +public class DataRequestManager extends RequestManager { + private DataRequest dataRequest; private String requestType; - DataDispatchRequestManager() { - - } - @Override protected Task createTask() throws ProcessingException { return new Task() { @Override protected EverestResponse call() throws Exception { - dataDispatchRequest = (DataDispatchRequest) request; - requestType = dataDispatchRequest.getRequestType(); + dataRequest = (DataRequest) request; + requestType = dataRequest.getRequestType(); Invocation invocation = appendBody(); initialTime = System.currentTimeMillis(); @@ -81,12 +77,12 @@ public class DataDispatchRequestManager extends RequestManager { Invocation invocation = null; Map.Entry mapEntry; - switch (dataDispatchRequest.getContentType()) { + switch (dataRequest.getContentType()) { case MediaType.MULTIPART_FORM_DATA: FormDataMultiPart formData = new FormDataMultiPart(); // Adding the string tuples to the request - HashMap pairs = dataDispatchRequest.getStringTuples(); + HashMap pairs = dataRequest.getStringTuples(); for (Map.Entry entry : pairs.entrySet()) { mapEntry = (Map.Entry) entry; formData.field(mapEntry.getKey(), mapEntry.getValue()); @@ -96,7 +92,7 @@ public class DataDispatchRequestManager extends RequestManager { File file; boolean fileException = false; String fileExceptionMessage = null; - pairs = dataDispatchRequest.getFileTuples(); + pairs = dataRequest.getFileTuples(); // Adding the file tuples to the request for (Map.Entry entry : pairs.entrySet()) { @@ -128,7 +124,7 @@ public class DataDispatchRequestManager extends RequestManager { case MediaType.APPLICATION_OCTET_STREAM: if (overriddenContentType == null) overriddenContentType = MediaType.APPLICATION_OCTET_STREAM; - filePath = dataDispatchRequest.getBody(); + filePath = dataRequest.getBody(); File check = new File(filePath); @@ -149,7 +145,7 @@ public class DataDispatchRequestManager extends RequestManager { Form form = new Form(); - for (Map.Entry entry : dataDispatchRequest.getStringTuples().entrySet()) { + for (Map.Entry entry : dataRequest.getStringTuples().entrySet()) { mapEntry = (Map.Entry) entry; form.param(mapEntry.getKey(), mapEntry.getValue()); } @@ -161,21 +157,21 @@ public class DataDispatchRequestManager extends RequestManager { break; default: // Handles raw data types (JSON, Plain text, XML, HTML) - String originalContentType = dataDispatchRequest.getContentType(); + String originalContentType = dataRequest.getContentType(); if (overriddenContentType == null) overriddenContentType = originalContentType; switch (requestType) { case "POST": invocation = requestBuilder - .buildPost(Entity.entity(dataDispatchRequest.getBody(), overriddenContentType)); + .buildPost(Entity.entity(dataRequest.getBody(), overriddenContentType)); break; case "PUT": invocation = requestBuilder - .buildPut(Entity.entity(dataDispatchRequest.getBody(), overriddenContentType)); + .buildPut(Entity.entity(dataRequest.getBody(), overriddenContentType)); break; case "PATCH": invocation = requestBuilder - .build("PATCH", Entity.entity(dataDispatchRequest.getBody(), overriddenContentType)); + .build("PATCH", Entity.entity(dataRequest.getBody(), overriddenContentType)); break; } } diff --git a/src/main/java/com/rohitawate/everest/requestmanager/GETRequestManager.java b/src/main/java/com/rohitawate/everest/requestmanager/GETRequestManager.java index 4108dcd..aa4c731 100644 --- a/src/main/java/com/rohitawate/everest/requestmanager/GETRequestManager.java +++ b/src/main/java/com/rohitawate/everest/requestmanager/GETRequestManager.java @@ -24,10 +24,6 @@ import javax.ws.rs.core.Response; public class GETRequestManager extends RequestManager { - GETRequestManager() { - - } - @Override protected Task createTask() throws ProcessingException { return new Task() { diff --git a/src/main/java/com/rohitawate/everest/requestmanager/RequestManagersFactory.java b/src/main/java/com/rohitawate/everest/requestmanager/RequestManagersPool.java similarity index 89% rename from src/main/java/com/rohitawate/everest/requestmanager/RequestManagersFactory.java rename to src/main/java/com/rohitawate/everest/requestmanager/RequestManagersPool.java index d5fdade..fcc921e 100644 --- a/src/main/java/com/rohitawate/everest/requestmanager/RequestManagersFactory.java +++ b/src/main/java/com/rohitawate/everest/requestmanager/RequestManagersPool.java @@ -31,9 +31,9 @@ import java.util.ArrayList; * returned to the caller. If all the managers in the pool are running, * a new one is created, added to the pool, and returned. */ -public class RequestManagersFactory { +public class RequestManagersPool { private static ArrayList getManagers; - private static ArrayList dataManagers; + private static ArrayList dataManagers; private static ArrayList deleteManagers; public static GETRequestManager get() { @@ -53,18 +53,18 @@ public class RequestManagersFactory { return newManager; } - public static DataDispatchRequestManager data() { + public static DataRequestManager data() { if (dataManagers == null) dataManagers = new ArrayList<>(); - for (DataDispatchRequestManager dataManager : dataManagers) { + for (DataRequestManager dataManager : dataManagers) { if (!dataManager.isRunning()) { dataManager.reset(); return dataManager; } } - DataDispatchRequestManager newManager = new DataDispatchRequestManager(); + DataRequestManager newManager = new DataRequestManager(); dataManagers.add(newManager); return newManager;