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

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

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

Loading…
Cancel
Save