0

I am trying to consume a (GET) rest service.

http://localhost:7010/abc/status?configFilePath=config%2Fconfig.properties

I am trying to use that using the Spring RestTemplate service

Below is the code which I have used for the restTemplate:

String configFile = "config/config.properties";
Map<String,String> restvars = new HashMap<String,String>();
restvars.put("configFilePath", configFile);

RestTemplate restTemplate = new RestTemplate();
String restUrl = http://localhost:7010/abc/status?          
String restCall = restTemplate.getForObject(restUrl, String.class, restvars);
System.out.println(restCall.toString());

It throws

Required String parameter 'configFilePath' is not present

Doesn't the Map actually pass the parameters ?

Betafish
  • 1,212
  • 3
  • 20
  • 45

1 Answers1

0

I was looking at it from wrong angle. The answer from this SO question helped.

HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);

UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url)
        .queryParam("configFilePath", configFile);

HttpEntity<?> entity = new HttpEntity<>(headers);
HttpEntity<String> response = restTemplate.exchange(builder.toUriString(),String.class);
Betafish
  • 1,212
  • 3
  • 20
  • 45