4
Correction
I have an accentuation problem 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 outside of Netbeans. That is, if run outside in any environment it saves the wrong characters, but if run inside Netbeans (Debugging or Running only) it saves the normal characters.
web service code
@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!");
}
Configuration of the Postgres database
Thank you so much for your help.
Someone would have a hint?
– João Paulo
Have you looked at the postgree settings?
– DiegoAugusto
I’m sorry, because the error happens when I run outside of Netbeans. That is, if I run out in any environment it goes with the wrong characters, but if I run inside Netbeans (Debugging or just Running) it sends the normal characters. And I still have no solution for this error...
– João Paulo
Yes, but your postgree table is UTF-8 ?
– DiegoAugusto
Yes it this UTF-8, I put up an image with the settings of the bank.
– João Paulo
I’m thinking about what it might be.
– DiegoAugusto
Try to use
ISO-8859-1
and see what– DiegoAugusto
With ISO-8859-1 it worked perfectly outside of the Netbeans IDE but inside (Debugging or simply Running) it stopped working. Crazy thing... Programmer thing...kkkk
– João Paulo
Strange... Something is going unnoticed, rs
– DiegoAugusto
Maybe Netbeans is set to UTF-8
– DiegoAugusto
I’m going to leave ISO-8859-1 because it’s more important to work on the separate executable than it is in Netbeans. So I’ve partially solved it. Thank you Techies. May God reward you.
– João Paulo
For nothing, Since you solved partially wait a while and see if another person responds with a better solution, in case it happens do not forget to put as solved your problem, so it can help other people.
– DiegoAugusto
@Joãopaulo you can post your problem solution as an answer below and mark as accepted. The site works different from forums.
– user28595