Amigos,
Estou batendo cabeça com um problema que aparenta ser trivial, mas não estou evoluindo. Tenho uma aplicação cliente-servidor, onde o cliente faz uma requisição para o servidor, obtém um xml como resposta e executa o que tem que executar. Após a execução, deve devolver para o servidor alguns dados. É nesse retorno que estou tendo problemas.
O método no servidor está assim:
@GET
@RequestMapping("/alerts/{agentId}/{lastExecutionDate}/{lastResultSet}")
@Consumes(XML_CONTENT_TYPE)
public void updateAlertByAgentId(@PathVariable String agentId, @PathVariable String lastExecutionDate, @PathVariable String lastResultSet) {
System.out.println("update!");
... // do something!
}
No cliente a implementação está assim:
public void update(int resultSetRowCount) {
String date = timestamp.toString();
String uri = "http://" + serverIp + ":" + serverPort + "/hrm/alerts/" + agentId + "/" + date + "/" + resultSetRowCount;
System.out.println(uri);
try {
// create HTTP Client
HttpClient httpClient = HttpClientBuilder.create().build();
// Create new patchRequest with below mentioned URL
HttpGet getRequest = new HttpGet();
// Add additional header to patchRequest which accepts application/xml data
getRequest.addHeader("accept", "application/xml");
// Execute your request and catch response
HttpResponse response = httpClient.execute(getRequest);
// Check for HTTP response code: 200 = success
if (response.getStatusLine().getStatusCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : " + response.getStatusLine().getStatusCode());
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
Eu não sei se o problema está no cliente, no servidor ou em ambos. Mas essa implementação no cliente retornou:
http://127.0.0.1:8080/hrm/alerts/xpto1/20160412144546/10
Exception in thread “main” java.lang.NullPointerException
at org.apache.http.impl.client.CloseableHttpClient.determineTarget(CloseableHttpClient.java:91)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
at br.com.mentium.hrm.agent.service.UpdateServer.update(UpdateServer.java:63)
at br.com.mentium.hrm.agent.service.ProcessAlerts.execute(ProcessAlerts.java:37)
at br.com.mentium.hrm.agent.Agent.execute(Agent.java:90)
at br.com.mentium.hrm.agent.Agent.main(Agent.java:38)
Como fazer isso funcionar?
Obrigado!