I'm obviously missing something but I don't know what...
It's stupid how much little things make you go crazy more than complicate ones...
This is the controller's code:
@RequestMapping(value = "/getClienteNomeCognome", method = RequestMethod.GET)
public ResponseEntity<List<Object>> getClienteNomeCognome(@RequestParam("nomeCliente") String nomeCliente,
@RequestParam("cognomeCliente") String cognomeCliente) {
List<Object> listaRisultati = new ArrayList<Object>();
try {
listaRisultati = serviziDocumentaleService.getClienteNomeCognome(nomeCliente, cognomeCliente);
} catch (Exception e) {
LOGGER.warn(String.format("Errore inatteso sulla chiamata del servizio: [%s]", e.toString()));
}
LOGGER.info(String.format("Avvio ricerca cliente con nome: %s, cognome: %s)", nomeCliente, cognomeCliente));
return new ResponseEntity<List<Object>>(listaRisultati, HttpStatus.OK);
}
And this is getClienteNomeCognome:
public List<Object> getClienteNomeCognome(String nome, String cognome) throws Exception {
try {
final RestTemplate restTemplate = new RestTemplate();
final String url = "somelink?cognome=%25"+cognome+"%25&nome=%25"+nome+"%25";
final ResponseEntity<List> response = (ResponseEntity<List>) restTemplate.getForObject(url, List.class);
if (response.getBody() != null && response.getBody().toString().contains("<error>")) {
throw new Exception(String.format(
"La risposta del servizio contiene degli errori: %s",
response.getBody()));
} else {
LOGGER.debug("Fine chiamata al servizio di ricerca cliente");
return response.getBody();
}
} catch (HttpClientErrorException hcee) {
throw new Exception(String.format(
"Errore durante la chiamata. Error: %s",
hcee.getMessage()));
} catch (Exception e) {
throw new Exception(String.format(
"Errore generico durante la chiamata al servizio. Error: %s"
+ e.getMessage()));
}
}
%d means number. %0nd means zero-padded number with a length. You build n by subtraction in your example. %s is a string. Your format string ends up being this: "%03d%s", 0, "Apple"
The %d specifier is used for integer types, while %f is only used with a Java float or double.
throw new Exception(String.format("Errore generico durante la chiamata al servizio. Error: %s" + e.getMessage()));
should be
throw new Exception(String.format("Errore generico durante la chiamata al servizio. Error: %s", e.getMessage()));
I can't be 100% sure of the issue, since its missing code so I can emulate it from here. But it looks like:
LOGGER.info(String.format("Avvio ricerca cliente con nome: %s, cognome: %s)", nomeCliente, cognomeCliente));
has an extra )
after the last %s
, so maybe its just not reading it correctly? Unless that's just a mistake when copy-pasting the code here.
Let us know if that works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With