Correction
I'm having an accent issue when consuming WebService on Windows Server. I have apache-tomcat-7.0.63 installed on windows server 2008, and as SGB, PostGres 9.4 and with Java 8. The error happens when I run out of NetBeans. That is, if you run outside in any environment it writes the wrong characters, but if you run inside NetBeans (Debugging or just Running) it writes the normal characters.
webservicecode
@POST@Path("cliente/sincronizar")
@Consumes("application/json;charset=utf-8")
public Response createClienteInJSON(String param) {
Gson gson = new Gson();
ContaCTR contaCTR = new ContaCTR();
ParamCliente paramCliente = gson.fromJson(param, ParamCliente.class);
Conta conta = contaCTR.carregar(paramCliente.getToken());
if (!paramCliente.getClientes().isEmpty() && conta != null) {
try {
WsAuxiliar.sincronizarCliente(paramCliente.getClientes(), conta);
ClienteCTR clienteCTR = new ClienteCTR();
List<Cliente> clientes = clienteCTR.listar(conta.getContaid(), "codigointerno");
WsAuxiliar.sincronizarEmail(paramCliente.getEmails(), conta, clientes);
WsAuxiliar.sincronizarEndereco(paramCliente.getEnderecos(), conta, clientes);
WsAuxiliar.sincronizarTelefone(paramCliente.getTelefones(), conta, clientes);
} catch (Exception e) {
throw new RuntimeException("Falha ao sincronizar Cliente. Erro: " + e.getMessage());
}
}
return Response.status(201).build();
}
client code consuming web service
public Retorno sendPostClientes(String token) throws Exception {
try {
ParamCliente paramCliente = new ParamCliente();
paramCliente.carregar();
paramCliente.setToken(token );
Gson gson = new Gson();
String input = gson.toJson(paramCliente);
URL url = new URL(Configuracao.carregar().getWebserv() + "cliente/sincronizar");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json;charset=utf-8");
OutputStream os = conn.getOutputStream();
os.write(input.getBytes());
os.flush();
if (conn.getResponseCode() != HttpURLConnection.HTTP_CREATED) {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader(
(conn.getInputStream())));
String output;
System.out.println("Output from Server .... \n");
while ((output = br.readLine()) != null) {
System.out.println(output);
}
conn.disconnect();
} catch (Exception e) {
return Retorno.criarRetorno(Boolean.TRUE, "Erro ao sincronizar clientes!\n" + e.getMessage());
}
return Retorno.criarRetorno(Boolean.FALSE, "Clientes Sincronizado com sucesso!");
}
Postgres database configuration
Thanks in advance for your help.