Re-organized the project
This commit is contained in:
parent
850a74cd11
commit
2c05263202
7 changed files with 141 additions and 156 deletions
|
@ -1,17 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<actions>
|
||||
<action>
|
||||
<actionName>run</actionName>
|
||||
<packagings>
|
||||
<packaging>jar</packaging>
|
||||
</packagings>
|
||||
<goals>
|
||||
<goal>process-classes</goal>
|
||||
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
|
||||
</goals>
|
||||
<properties>
|
||||
<exec.args>-classpath %classpath com.rohitawate.restaurant.main.Main</exec.args>
|
||||
<exec.executable>java</exec.executable>
|
||||
</properties>
|
||||
</action>
|
||||
</actions>
|
6
pom.xml
6
pom.xml
|
@ -14,14 +14,16 @@
|
|||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>com.rohitawate.restaurant.main.Main</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
|
@ -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<String> httpMethodBox;
|
||||
@FXML
|
||||
@FXML
|
||||
private TextField addressField;
|
||||
@FXML
|
||||
private ComboBox<String> 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;
|
||||
private JFXSnackbar snackBar;
|
||||
private final String[] httpMethods = {"GET", "POST", "PUT", "DELETE", "PATCH"};
|
||||
private RequestManager requestManager;
|
||||
|
||||
@Override
|
||||
public void initialize(URL url, ResourceBundle rb) {
|
||||
@Override
|
||||
public void initialize(URL url, ResourceBundle rb) {
|
||||
responseBox.getChildren().remove(0);
|
||||
httpMethodBox.getItems().addAll(httpMethods);
|
||||
httpMethodBox.setValue("GET");
|
||||
httpMethodBox.setValue("GET");
|
||||
|
||||
requestManager = new RequestManager();
|
||||
snackBar = new JFXSnackbar(dashboard);
|
||||
}
|
||||
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;
|
||||
}
|
||||
@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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
|
@ -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;
|
|
@ -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;
|
||||
|
|
@ -13,13 +13,13 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.rohitawate.restaurant.requests;
|
||||
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.GETRequest;
|
||||
import com.rohitawate.restaurant.models.RestaurantResponse;
|
||||
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;
|
||||
|
@ -35,9 +35,9 @@ public class RequestManager {
|
|||
client = ClientBuilder.newClient();
|
||||
}
|
||||
|
||||
public RestaurantResponse get(GETRequest GETRequest) throws IOException {
|
||||
public RestaurantResponse get(GETRequest request) throws IOException {
|
||||
RestaurantResponse response = new RestaurantResponse();
|
||||
WebTarget target = client.target(GETRequest.getTarget().toString());
|
||||
WebTarget target = client.target(request.getTarget().toString());
|
||||
|
||||
long initialTime = System.currentTimeMillis();
|
||||
Response serverResponse = target.request().get();
|
Loading…
Reference in a new issue