+ remove (Ride)(Request) from GET(Request) to App.

pull/1/head
Ivan Olexyn 5 years ago
parent 30f32fb4d4
commit 515f7054a5

@ -83,9 +83,8 @@ public class ClientServlet extends HttpServlet {
*/ */
final void sendGetRequest(Ride ride) throws IOException, ServletException, InterruptedException { final void sendGetRequest(Ride ride) throws IOException, ServletException, InterruptedException {
Ride parsedRide = doSendGetRequest(ride);
ride.setData(parsedRide.getData()); ride.setData(doSendGetRequest(ride.getRequest()));
synchronized (booked) { synchronized (booked) {
booked.remove(ride.getID()); booked.remove(ride.getID());
@ -102,18 +101,18 @@ public class ClientServlet extends HttpServlet {
* Send GET (Request) to App. * Send GET (Request) to App.
* Parse response. * Parse response.
*/ */
protected Ride doSendGetRequest(Ride ride) throws IOException, InterruptedException { protected String doSendGetRequest(String request) throws IOException, InterruptedException {
// send GET (Ride) // send GET (Ride)
final HttpURLConnection connection = ConnectionHelper.make("GET", APP_URL); final HttpURLConnection connection = ConnectionHelper.make("GET", APP_URL);
connection.setDoOutput(true); connection.setDoOutput(true);
DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream()); DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
outputStream.writeBytes(ride.getRequest()); outputStream.writeBytes(request);
outputStream.flush(); outputStream.flush();
outputStream.close(); outputStream.close();
return ConnectionHelper.parseRide(connection); return ConnectionHelper.parseString(connection);
} }

@ -36,16 +36,12 @@ public class AppMock extends ActorRunnable {
synchronized (exchange) { synchronized (exchange) {
String parsedRequest = IOUtils.toString(request.getReader()); String parsedRequest = IOUtils.toString(request.getReader());
JSONObject obj = new JSONObject(parsedRequest);
parsedRequest = obj.getString("request");
String dataString = "DATA-" + parsedRequest.split("-")[1]; String dataString = "DATA-" + parsedRequest.split("-")[1];
JSONObject dataObj = new JSONObject();
dataObj.put("data", dataString);
exchange.response.setStatus(200); exchange.response.setStatus(200);
PrintWriter writer = exchange.response.getWriter(); PrintWriter writer = exchange.response.getWriter();
writer.write(dataObj.toString()); writer.write(dataString);
writer.flush(); writer.flush();
writer.close(); writer.close();

@ -51,14 +51,13 @@ public class ClientMock extends ClientServlet {
* Parse response. * Parse response.
*/ */
@Override @Override
protected Ride doSendGetRequest(Ride ride) throws IOException, InterruptedException { protected String doSendGetRequest(String request) throws IOException, InterruptedException {
// Mock Exchange // Mock Exchange
final ExchangeMock exchange = new ExchangeMock(); final ExchangeMock exchange = new ExchangeMock();
exchange.request.setMethod("GET"); exchange.request.setMethod("GET");
exchange.request.setContentType("application/json"); exchange.request.setContent(request.getBytes());
exchange.request.setContent(ride.json().getBytes());
synchronized (exchange) { synchronized (exchange) {
// Mock GET (Request) // Mock GET (Request)
@ -69,7 +68,7 @@ public class ClientMock extends ClientServlet {
exchange.notify(); exchange.notify();
} }
return new Ride(exchange.response.getContentAsString()); return exchange.response.getContentAsString();
} }

Loading…
Cancel
Save