Search code examples
javacontrollerresponseresttemplate

java.util.MissingFormatArgumentException: Format specifier '%s'


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()));
    }

}

Solution

  • 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()));