Added support for PATCH Request processing
This commit is contained in:
parent
7f3a4e7343
commit
ab8a4b879a
6 changed files with 37 additions and 24 deletions
|
@ -23,10 +23,10 @@ import com.rohitawate.restaurant.models.requests.DELETERequest;
|
|||
import com.rohitawate.restaurant.models.requests.DataDispatchRequest;
|
||||
import com.rohitawate.restaurant.models.requests.GETRequest;
|
||||
import com.rohitawate.restaurant.models.responses.RestaurantResponse;
|
||||
import com.rohitawate.restaurant.requestsmanager.DELETERequestManager;
|
||||
import com.rohitawate.restaurant.requestsmanager.DataDispatchRequestManager;
|
||||
import com.rohitawate.restaurant.requestsmanager.GETRequestManager;
|
||||
import com.rohitawate.restaurant.requestsmanager.RequestManager;
|
||||
import com.rohitawate.restaurant.requestmanager.DELETERequestManager;
|
||||
import com.rohitawate.restaurant.requestmanager.DataDispatchRequestManager;
|
||||
import com.rohitawate.restaurant.requestmanager.GETRequestManager;
|
||||
import com.rohitawate.restaurant.requestmanager.RequestManager;
|
||||
import com.rohitawate.restaurant.util.Services;
|
||||
import com.rohitawate.restaurant.util.settings.Settings;
|
||||
import com.rohitawate.restaurant.util.themes.ThemeManager;
|
||||
|
@ -122,8 +122,12 @@ public class DashboardController implements Initializable {
|
|||
addParamField(); // Adds a blank param field
|
||||
|
||||
snackBar = new JFXSnackbar(dashboard);
|
||||
bodyTab.disableProperty().bind(Bindings.and(httpMethodBox.valueProperty().isNotEqualTo("POST"),
|
||||
httpMethodBox.valueProperty().isNotEqualTo("PUT")));
|
||||
bodyTab.disableProperty().bind(
|
||||
Bindings.or(
|
||||
httpMethodBox.valueProperty().isEqualTo("GET"),
|
||||
httpMethodBox.valueProperty().isEqualTo("DELETE")
|
||||
)
|
||||
);
|
||||
|
||||
errorTitle.setText("Oops... That's embarrassing!");
|
||||
errorDetails.setText("Something went wrong. Try to make another request.\nRestart RESTaurant if that doesn't work.");
|
||||
|
@ -200,6 +204,7 @@ public class DashboardController implements Initializable {
|
|||
// DataDispatchRequestManager will generate appropriate request based on the type.
|
||||
case "POST":
|
||||
case "PUT":
|
||||
case "PATCH":
|
||||
if (requestManager == null || requestManager.getClass() != DataDispatchRequestManager.class)
|
||||
requestManager = new DataDispatchRequestManager();
|
||||
else if (requestManager.isRunning()) {
|
||||
|
@ -433,6 +438,7 @@ public class DashboardController implements Initializable {
|
|||
switch (httpMethodBox.getValue()) {
|
||||
case "POST":
|
||||
case "PUT":
|
||||
case "PATCH":
|
||||
dashboardState = new DashboardState(bodyTabController.getBasicRequest(httpMethodBox.getValue()));
|
||||
dashboardState.setHeaders(headerTabController.getHeaders());
|
||||
break;
|
||||
|
@ -472,7 +478,7 @@ public class DashboardController implements Initializable {
|
|||
for (Map.Entry entry : dashboardState.getParams().entrySet())
|
||||
addParamField(entry.getKey().toString(), entry.getValue().toString());
|
||||
|
||||
if (httpMethodBox.getValue().equals("POST") || httpMethodBox.getValue().equals("PUT"))
|
||||
if (!(httpMethodBox.getValue().equals("GET") || httpMethodBox.getValue().equals("DELETE")))
|
||||
bodyTabController.setState(dashboardState);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.rohitawate.restaurant.requestsmanager;
|
||||
package com.rohitawate.restaurant.requestmanager;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
@ -22,7 +22,6 @@ import com.fasterxml.jackson.databind.SerializationFeature;
|
|||
import com.rohitawate.restaurant.exceptions.UnreliableResponseException;
|
||||
import com.rohitawate.restaurant.models.requests.DELETERequest;
|
||||
import com.rohitawate.restaurant.models.responses.RestaurantResponse;
|
||||
import com.rohitawate.restaurant.util.Services;
|
||||
import javafx.concurrent.Task;
|
||||
|
||||
import javax.ws.rs.client.Invocation;
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.rohitawate.restaurant.requestsmanager;
|
||||
package com.rohitawate.restaurant.requestmanager;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
@ -22,7 +22,6 @@ import com.fasterxml.jackson.databind.SerializationFeature;
|
|||
import com.rohitawate.restaurant.exceptions.UnreliableResponseException;
|
||||
import com.rohitawate.restaurant.models.requests.DataDispatchRequest;
|
||||
import com.rohitawate.restaurant.models.responses.RestaurantResponse;
|
||||
import com.rohitawate.restaurant.util.Services;
|
||||
import javafx.concurrent.Task;
|
||||
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
|
||||
import org.glassfish.jersey.media.multipart.file.FileDataBodyPart;
|
||||
|
@ -68,7 +67,7 @@ public class DataDispatchRequestManager extends RequestManager {
|
|||
}
|
||||
|
||||
// Adds the request body based on the content type and generates an invocation.
|
||||
Invocation invocation;
|
||||
Invocation invocation = null;
|
||||
switch (dataDispatchRequest.getContentType()) {
|
||||
case MediaType.MULTIPART_FORM_DATA:
|
||||
FormDataMultiPart formData = new FormDataMultiPart();
|
||||
|
@ -124,12 +123,20 @@ public class DataDispatchRequestManager extends RequestManager {
|
|||
break;
|
||||
default:
|
||||
// Handles raw data types (JSON, Plain text, XML, HTML)
|
||||
if (requestType.equals("POST"))
|
||||
switch (requestType) {
|
||||
case "POST":
|
||||
invocation = requestBuilder
|
||||
.buildPost(Entity.entity(dataDispatchRequest.getBody(), dataDispatchRequest.getContentType()));
|
||||
else
|
||||
break;
|
||||
case "PUT":
|
||||
invocation = requestBuilder
|
||||
.buildPut(Entity.entity(dataDispatchRequest.getBody(), dataDispatchRequest.getContentType()));
|
||||
break;
|
||||
case "PATCH":
|
||||
invocation = requestBuilder
|
||||
.build("PATCH", Entity.entity(dataDispatchRequest.getBody(), dataDispatchRequest.getContentType()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
long initialTime = System.currentTimeMillis();
|
|
@ -14,14 +14,13 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.rohitawate.restaurant.requestsmanager;
|
||||
package com.rohitawate.restaurant.requestmanager;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.rohitawate.restaurant.exceptions.UnreliableResponseException;
|
||||
import com.rohitawate.restaurant.models.responses.RestaurantResponse;
|
||||
import com.rohitawate.restaurant.util.Services;
|
||||
import javafx.concurrent.Task;
|
||||
|
||||
import javax.ws.rs.client.Invocation.Builder;
|
|
@ -13,13 +13,14 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.rohitawate.restaurant.requestsmanager;
|
||||
package com.rohitawate.restaurant.requestmanager;
|
||||
|
||||
import com.rohitawate.restaurant.models.requests.RestaurantRequest;
|
||||
import com.rohitawate.restaurant.models.responses.RestaurantResponse;
|
||||
import com.rohitawate.restaurant.util.settings.Settings;
|
||||
import javafx.concurrent.Service;
|
||||
import org.glassfish.jersey.client.ClientProperties;
|
||||
import org.glassfish.jersey.client.HttpUrlConnectorProvider;
|
||||
import org.glassfish.jersey.media.multipart.MultiPartFeature;
|
||||
|
||||
import javax.ws.rs.client.Client;
|
||||
|
@ -34,6 +35,7 @@ public abstract class RequestManager extends Service<RestaurantResponse> {
|
|||
.register(MultiPartFeature.class)
|
||||
.build();
|
||||
|
||||
client.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
|
||||
if (Settings.connectionTimeOutEnable)
|
||||
client.property(ClientProperties.CONNECT_TIMEOUT, Settings.connectionTimeOut);
|
||||
if (Settings.connectionReadTimeOutEnable)
|
|
@ -134,7 +134,7 @@ public class HistoryManager {
|
|||
}
|
||||
}
|
||||
|
||||
if (state.getHttpMethod().equals("POST") || state.getHttpMethod().equals("PUT")) {
|
||||
if (!(state.getHttpMethod().equals("GET") || state.getHttpMethod().equals("DELETE"))) {
|
||||
// Maps the request to its ContentType for faster recovery
|
||||
statement = conn.prepareStatement(MiscUtils.trimString(queries.get("saveRequestContentPair").toString()));
|
||||
statement.setInt(1, requestID);
|
||||
|
@ -235,7 +235,7 @@ public class HistoryManager {
|
|||
state.setParams(getTuples(requestID, "Param"));
|
||||
state.setHttpMethod(resultSet.getString("Type"));
|
||||
|
||||
if (state.getHttpMethod().equals("POST") || state.getHttpMethod().equals("PUT")) {
|
||||
if (!(state.getHttpMethod().equals("GET") || state.getHttpMethod().equals("DELETE"))) {
|
||||
// Retrieves request body ContentType for querying corresponding table
|
||||
statement = conn.prepareStatement(MiscUtils.trimString(queries.get("selectRequestContentType").toString()));
|
||||
statement.setInt(1, requestID);
|
||||
|
@ -371,7 +371,7 @@ public class HistoryManager {
|
|||
if (!areMapsIdentical(map, newState.getParams()))
|
||||
return false;
|
||||
|
||||
if (newState.getHttpMethod().equals("POST") || newState.getHttpMethod().equals("PUT")) {
|
||||
if (!(newState.getHttpMethod().equals("GET") || newState.getHttpMethod().equals("DELETE"))) {
|
||||
switch (newState.getContentType()) {
|
||||
case MediaType.TEXT_PLAIN:
|
||||
case MediaType.APPLICATION_JSON:
|
||||
|
|
Loading…
Reference in a new issue