I have an architecture where my server component will be deployed on separate host and client component (UI) will be deployed on separate.
I am stuck with RestTemplate Proxy, can someone please help me how can I achieve it.
Below is the example, I am trying to follow, but not sure if its the right approach.
@Value("${generic.proxyHost}")
private String proxyHost;
@Value("${generic.proxyPort}")
private Integer proxyPort;
@Bean
public RestTemplate restTemplate() {
LOGGER.info("Setting up proxy with HOSTNAME => " + proxyHost + " and PORT => " + proxyPort);
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
Proxy proxy= new Proxy(Type.HTTP, new InetSocketAddress(proxyHost, proxyPort));
requestFactory.setProxy(proxy);
return new RestTemplate(requestFactory);
}
Also it would be help if I can know how to handle multipart file request.
Any help will be greatly appericiated.
I need to consume REST API on separate host and I am just looking for an example. I just googled around the stuff but no luck
There's a nice tutorial about Rest Template
at Baeldung's blog .
You could use this simple example to understand how to use it:
RestTemplate restTemplate = new RestTemplate();
String fooResourceUrl = "http://localhost:8080/spring-rest/foos";
ResponseEntity<String> response = restTemplate.getForEntity(fooResourceUrl + "/1", String.class);
assertThat(response.getStatusCode(), equalTo(HttpStatus.OK));
There's a plenty of examples in the article I linked above that will help you during your learn path.
Also it would be help if I can know how to handle multipart file request.
I believe that this other question has the information you need to start implementing this use case.
Cheers!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.