@Override public AgentResponse process(AgentRequest request) { AgentResponse response; String json = gson.toJson(request); HttpRequest httpRequest = new HttpRequest(HttpMethod.POST, requestUrl).setBody(json, ContentType.APPLICATION_JSON); HttpResponse httpResponse = client.execute(httpRequest); if (httpResponse != null) { String text = httpResponse.asString(); try { response = gson.fromJson(text, AgentResponse.class); // the gson deserialization code is very permissive so we verify if (!response.isValid()) { response = new AgentResponse(ResponseStatus.Code.INVALID_RESPONSE_FROM_AGENT); logger.warn("Invalid json for request: " + text); } } catch (JsonSyntaxException e) { response = new AgentResponse(ResponseStatus.Code.INVALID_RESPONSE_FROM_AGENT); logger.warn("Invalid json for request: " + text); } } else { response = new AgentResponse(ResponseStatus.Code.NO_RESPONSE_FROM_AGENT); } return response; }