REST Service call with JAR as payload

174 Views Asked by At

How to read JAR file from src/main/resources folder & use it as payload for REST service call from Spring boot application using RestTemplate

Any code snippet would be helpful

Thanks

1

There are 1 best solutions below

0
On BEST ANSWER

You need to use LinkedMultiValueMap to send a file using RestTemplate, Code should be like below:

    ClassLoader classLoader = getClass().getClassLoader();
    File file = new File(classLoader.getResource("yourjarfile").getFile());

    LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
        map.add("file", new FileSystemResource(file));

    HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<MultiValueMap<String, Object>>(map,
                getHeaders());

    ResponseEntity<String> resp = new RestTemplate().exchange(
                    "REST_URL/", HttpMethod.POST, httpEntity,
                    String.class);