Search code examples
springspring-bootspring-securityresttemplate

spring boot restTempalte call (get Data) with security handel


i want get data from another application by calling resttempalte in springboot .. how to set my header for security .. how to handel security of another application

RestTemplate restTemplate = new RestTemplate(); String result = restTemplate.getForObject(uri, String.class);

System.out.println("Rest--->"+result);



Solution

  • You can use like:

    final String uri = "http://localhost:9090/TicketingSystem/caselogcontroller/getAppIds";
    RestTemplate restTemplate = new RestTemplate();
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    headers.set("authorization", <your tokens>));
    String result = restTemplate.exchange(uri, HttpMethod.GET, new HttpEntity<>(headers) String.class);
    System.out.println("Rest--->"+result);