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.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<String, String> 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.");
|
||||
|
|
|
@ -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.";
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<String, String> stringTuples;
|
||||
private HashMap<String, String> fileTuples;
|
||||
|
||||
public DataDispatchRequest() {
|
||||
}
|
||||
|
||||
public DataDispatchRequest(String requestType) {
|
||||
this.requestType = requestType;
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return body;
|
||||
}
|
|
@ -25,17 +25,6 @@ public abstract class EverestRequest implements Serializable {
|
|||
private URL target;
|
||||
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 {
|
||||
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<String, String> headers) {
|
||||
this.headers = headers;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,10 +25,6 @@ import javax.ws.rs.core.Response;
|
|||
|
||||
public class DELETERequestManager extends RequestManager {
|
||||
|
||||
DELETERequestManager() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Task<EverestResponse> createTask() throws ProcessingException {
|
||||
return new Task<EverestResponse>() {
|
||||
|
|
|
@ -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<EverestResponse> createTask() throws ProcessingException {
|
||||
return new Task<EverestResponse>() {
|
||||
@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<String, String> mapEntry;
|
||||
|
||||
switch (dataDispatchRequest.getContentType()) {
|
||||
switch (dataRequest.getContentType()) {
|
||||
case MediaType.MULTIPART_FORM_DATA:
|
||||
FormDataMultiPart formData = new FormDataMultiPart();
|
||||
|
||||
// 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()) {
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -24,10 +24,6 @@ import javax.ws.rs.core.Response;
|
|||
|
||||
public class GETRequestManager extends RequestManager {
|
||||
|
||||
GETRequestManager() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Task<EverestResponse> createTask() throws ProcessingException {
|
||||
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,
|
||||
* 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<DataDispatchRequestManager> dataManagers;
|
||||
private static ArrayList<DataRequestManager> dataManagers;
|
||||
private static ArrayList<DELETERequestManager> 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;
|
Loading…
Reference in a new issue