2
I’m trying to consume a webservice of ceps but always returns me 403 and it is public.
Testing the Working Webservice :
http://apps.widenet.com.br/busca-cep/api/cep.json?code=01001000
My Controller
@Controller
@RequestMapping("/busca-cep")
public class BuscaCEPController {
private static final Logger LOG = LoggerFactory.getLogger(BuscaCEPController.class);
@Autowired
private LogService logService;
@Autowired
private BuscaCEPService buscaCEPService;
@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<CEPResult> buscaCEP(String code) {
try {
logService.info(LOG, "action=buscaCEPIniciado, cep={}", code);
CEPResult result = buscaCEPService.buscarCEP(code);
logService.info(LOG, "action=buscaCEPConcluido, cep={}", code);
return new ResponseEntity<CEPResult>(result, HttpStatus.OK);
} catch (Exception e) {
logService.error(LOG, "action=buscaCEPErro, cep={}, e={}", code, e.getMessage());
return new ResponseEntity<CEPResult>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}
My Consumer Service
@Service
public class BuscaCEPService {
public CEPResult buscarCEP(String code) {
RestTemplate restTemplate = new RestTemplate();
CEPResult result = restTemplate.getForObject("http://apps.widenet.com.br/busca-cep/api/cep.json?code=" + code, CEPResult.class);
return result;
}
}
Thank you , worked perfectly !
– Jose Vieira Neto
just out of curiosity as you discovered that you would need to pass the user-agent header?
– Jose Vieira Neto
@Josevieiraneto as is GET, so I tested by the browser first. As the browser always puts this header (and others), hence I inferred that it was absence of some header (must be WS server configuration), so I tested and bingo :)
– Bruno César
Got it, thanks for the return
– Jose Vieira Neto