diff --git a/nbactions.xml b/nbactions.xml
deleted file mode 100644
index 5f657da..0000000
--- a/nbactions.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
- run
-
- jar
-
-
- process-classes
- org.codehaus.mojo:exec-maven-plugin:1.2.1:exec
-
-
- -classpath %classpath com.rohitawate.restaurant.main.Main
- java
-
-
-
diff --git a/pom.xml b/pom.xml
index e871f41..89cd331 100644
--- a/pom.xml
+++ b/pom.xml
@@ -14,14 +14,16 @@
- org.apache.maven.plugins
- maven-jar-plugin
+ maven-assembly-plugin
com.rohitawate.restaurant.main.Main
+
+ jar-with-dependencies
+
diff --git a/src/main/java/com/rohitawate/restaurant/dashboard/DashboardController.java b/src/main/java/com/rohitawate/restaurant/dashboard/DashboardController.java
index bf6e965..0cc64ad 100644
--- a/src/main/java/com/rohitawate/restaurant/dashboard/DashboardController.java
+++ b/src/main/java/com/rohitawate/restaurant/dashboard/DashboardController.java
@@ -16,9 +16,9 @@
package com.rohitawate.restaurant.dashboard;
import com.jfoenix.controls.JFXSnackbar;
-import com.rohitawate.restaurant.models.GETRequest;
-import com.rohitawate.restaurant.models.RestaurantResponse;
-import com.rohitawate.restaurant.requests.RequestManager;
+import com.rohitawate.restaurant.models.requests.GETRequest;
+import com.rohitawate.restaurant.models.responses.RestaurantResponse;
+import com.rohitawate.restaurant.requestsmanager.RequestManager;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ComboBox;
@@ -36,13 +36,13 @@ import java.net.URL;
import java.util.ResourceBundle;
public class DashboardController implements Initializable {
- @FXML
+ @FXML
private BorderPane dashboard;
- @FXML
- private TextField addressField;
- @FXML
- private ComboBox httpMethodBox;
- @FXML
+ @FXML
+ private TextField addressField;
+ @FXML
+ private ComboBox httpMethodBox;
+ @FXML
private VBox responseBox;
@FXML
private HBox responseDetails;
@@ -51,37 +51,37 @@ public class DashboardController implements Initializable {
@FXML
private Label statusCode, statusCodeDescription, responseTime, responseSize;
- private JFXSnackbar snackBar;
- private final String[] httpMethods = {"GET", "POST", "PUT", "DELETE", "PATCH"};
- private RequestManager requestManager;
-
- @Override
- public void initialize(URL url, ResourceBundle rb) {
+ private JFXSnackbar snackBar;
+ private final String[] httpMethods = {"GET", "POST", "PUT", "DELETE", "PATCH"};
+ private RequestManager requestManager;
+
+ @Override
+ public void initialize(URL url, ResourceBundle rb) {
responseBox.getChildren().remove(0);
httpMethodBox.getItems().addAll(httpMethods);
- httpMethodBox.setValue("GET");
-
- requestManager = new RequestManager();
- snackBar = new JFXSnackbar(dashboard);
- }
+ httpMethodBox.setValue("GET");
- @FXML
- private void sendAction() {
- try {
- String address = addressField.getText();
- if (address.equals("")) {
- snackBar.show("Please enter a valid address", 7000);
- return;
- }
+ requestManager = new RequestManager();
+ snackBar = new JFXSnackbar(dashboard);
+ }
+
+ @FXML
+ private void sendAction() {
+ try {
+ String address = addressField.getText();
+ if (address.equals("")) {
+ snackBar.show("Please enter a valid address", 7000);
+ return;
+ }
RestaurantResponse response;
- switch (httpMethodBox.getValue()) {
- case "GET":
- GETRequest GETRequest = new GETRequest(addressField.getText());
- response = requestManager.get(GETRequest);
- break;
+ switch (httpMethodBox.getValue()) {
+ case "GET":
+ GETRequest request = new GETRequest(addressField.getText());
+ response = requestManager.get(request);
+ break;
default:
response = new RestaurantResponse();
- }
+ }
responseArea.setText(response.getBody());
if (responseBox.getChildren().size() != 2)
responseBox.getChildren().add(0, responseDetails);
@@ -89,11 +89,11 @@ public class DashboardController implements Initializable {
statusCodeDescription.setText(Response.Status.fromStatusCode(response.getStatusCode()).getReasonPhrase());
responseTime.setText(Long.toString(response.getTime()) + " ms");
responseSize.setText(Integer.toString(response.getSize()) + " B");
- } catch (MalformedURLException ex) {
- snackBar.show("Invalid URL. Please verify and try again.", 7000);
- } catch (IOException ex) {
- snackBar.show("Server did not respond", 7000);
- }
-
- }
+ } catch (MalformedURLException ex) {
+ snackBar.show("Invalid URL. Please verify and try again.", 7000);
+ } catch (IOException ex) {
+ snackBar.show("Server did not respond", 7000);
+ }
+
+ }
}
diff --git a/src/main/java/com/rohitawate/restaurant/models/GETRequest.java b/src/main/java/com/rohitawate/restaurant/models/requests/GETRequest.java
similarity index 94%
rename from src/main/java/com/rohitawate/restaurant/models/GETRequest.java
rename to src/main/java/com/rohitawate/restaurant/models/requests/GETRequest.java
index 1f69c68..6745cbe 100644
--- a/src/main/java/com/rohitawate/restaurant/models/GETRequest.java
+++ b/src/main/java/com/rohitawate/restaurant/models/requests/GETRequest.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.rohitawate.restaurant.models;
+package com.rohitawate.restaurant.models.requests;
import java.net.MalformedURLException;
import java.net.URL;
diff --git a/src/main/java/com/rohitawate/restaurant/models/RestaurantRequest.java b/src/main/java/com/rohitawate/restaurant/models/requests/RestaurantRequest.java
similarity index 95%
rename from src/main/java/com/rohitawate/restaurant/models/RestaurantRequest.java
rename to src/main/java/com/rohitawate/restaurant/models/requests/RestaurantRequest.java
index 95d45f3..371f617 100644
--- a/src/main/java/com/rohitawate/restaurant/models/RestaurantRequest.java
+++ b/src/main/java/com/rohitawate/restaurant/models/requests/RestaurantRequest.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.rohitawate.restaurant.models;
+package com.rohitawate.restaurant.models.requests;
import java.net.MalformedURLException;
import java.net.URL;
diff --git a/src/main/java/com/rohitawate/restaurant/models/RestaurantResponse.java b/src/main/java/com/rohitawate/restaurant/models/responses/RestaurantResponse.java
similarity index 96%
rename from src/main/java/com/rohitawate/restaurant/models/RestaurantResponse.java
rename to src/main/java/com/rohitawate/restaurant/models/responses/RestaurantResponse.java
index 7f15312..27b37be 100644
--- a/src/main/java/com/rohitawate/restaurant/models/RestaurantResponse.java
+++ b/src/main/java/com/rohitawate/restaurant/models/responses/RestaurantResponse.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.rohitawate.restaurant.models;
+package com.rohitawate.restaurant.models.responses;
import javax.ws.rs.core.MediaType;
diff --git a/src/main/java/com/rohitawate/restaurant/requests/RequestManager.java b/src/main/java/com/rohitawate/restaurant/requestsmanager/RequestManager.java
similarity index 89%
rename from src/main/java/com/rohitawate/restaurant/requests/RequestManager.java
rename to src/main/java/com/rohitawate/restaurant/requestsmanager/RequestManager.java
index 9bb872f..aa4a9f5 100644
--- a/src/main/java/com/rohitawate/restaurant/requests/RequestManager.java
+++ b/src/main/java/com/rohitawate/restaurant/requestsmanager/RequestManager.java
@@ -1,93 +1,93 @@
-/*
- * Copyright 2018 Rohit Awate.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.rohitawate.restaurant.requests;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.SerializationFeature;
-import com.rohitawate.restaurant.models.GETRequest;
-import com.rohitawate.restaurant.models.RestaurantResponse;
-
-import javax.ws.rs.client.Client;
-import javax.ws.rs.client.ClientBuilder;
-import javax.ws.rs.client.WebTarget;
-import javax.ws.rs.core.Response;
-import java.io.IOException;
-
-public class RequestManager {
-
- private final Client client;
-
- public RequestManager() {
- client = ClientBuilder.newClient();
- }
-
- public RestaurantResponse get(GETRequest GETRequest) throws IOException {
- RestaurantResponse response = new RestaurantResponse();
- WebTarget target = client.target(GETRequest.getTarget().toString());
-
- long initialTime = System.currentTimeMillis();
- Response serverResponse = target.request().get();
- response.setTime(initialTime, System.currentTimeMillis());
-
- if (serverResponse == null)
- throw new IOException();
- else if (serverResponse.getStatus() == 301) {
- response.setStatusCode(301);
- String newLocation = serverResponse.getHeaderString("location");
- String responseHelpText;
-
- if (newLocation == null)
- responseHelpText = "The resource has been permanently moved to another location.\n\n" +
- "Here's what you can do:\n" +
- "- Find the new URL from the API documentation.\n" +
- "- Try using https instead of http if you're not already.";
- else
- responseHelpText = "The resource has been permanently moved to: " + newLocation;
-
- response.setBody(responseHelpText);
- return response;
- }
-
- String type = (String) serverResponse.getHeaders().getFirst("Content-type");
- String responseBody = serverResponse.readEntity(String.class);
-
- ObjectMapper mapper = new ObjectMapper();
- mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
-
- switch (type.toLowerCase()) {
- case "application/json; charset=utf-8":
- case "application/json":
- JsonNode node = mapper.readTree(responseBody);
- response.setBody(mapper.writeValueAsString(node));
- break;
- case "application/xml; charset=utf-8":
- case "application/xml":
- response.setBody(mapper.writeValueAsString(responseBody));
- break;
- case "text/html":
- case "text/html; charset=utf-8":
- response.setBody(responseBody);
- break;
- }
-
- response.setMediaType(serverResponse.getMediaType());
- response.setStatusCode(serverResponse.getStatus());
- response.setSize(responseBody.length());
-
- return response;
- }
-}
+/*
+ * Copyright 2018 Rohit Awate.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.rohitawate.restaurant.requestsmanager;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.rohitawate.restaurant.models.requests.GETRequest;
+import com.rohitawate.restaurant.models.responses.RestaurantResponse;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+
+public class RequestManager {
+
+ private final Client client;
+
+ public RequestManager() {
+ client = ClientBuilder.newClient();
+ }
+
+ public RestaurantResponse get(GETRequest request) throws IOException {
+ RestaurantResponse response = new RestaurantResponse();
+ WebTarget target = client.target(request.getTarget().toString());
+
+ long initialTime = System.currentTimeMillis();
+ Response serverResponse = target.request().get();
+ response.setTime(initialTime, System.currentTimeMillis());
+
+ if (serverResponse == null)
+ throw new IOException();
+ else if (serverResponse.getStatus() == 301) {
+ response.setStatusCode(301);
+ String newLocation = serverResponse.getHeaderString("location");
+ String responseHelpText;
+
+ if (newLocation == null)
+ responseHelpText = "The resource has been permanently moved to another location.\n\n" +
+ "Here's what you can do:\n" +
+ "- Find the new URL from the API documentation.\n" +
+ "- Try using https instead of http if you're not already.";
+ else
+ responseHelpText = "The resource has been permanently moved to: " + newLocation;
+
+ response.setBody(responseHelpText);
+ return response;
+ }
+
+ String type = (String) serverResponse.getHeaders().getFirst("Content-type");
+ String responseBody = serverResponse.readEntity(String.class);
+
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
+
+ switch (type.toLowerCase()) {
+ case "application/json; charset=utf-8":
+ case "application/json":
+ JsonNode node = mapper.readTree(responseBody);
+ response.setBody(mapper.writeValueAsString(node));
+ break;
+ case "application/xml; charset=utf-8":
+ case "application/xml":
+ response.setBody(mapper.writeValueAsString(responseBody));
+ break;
+ case "text/html":
+ case "text/html; charset=utf-8":
+ response.setBody(responseBody);
+ break;
+ }
+
+ response.setMediaType(serverResponse.getMediaType());
+ response.setStatusCode(serverResponse.getStatus());
+ response.setSize(responseBody.length());
+
+ return response;
+ }
+}