-1

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.

Manish Sharma
  • 87
  • 2
  • 11
  • What’s your doubt? You need to consume an REST API on a separate server? Is there any error or are you just looking for an example? – Ricardo Zanini Dec 04 '17 at 19:17
  • Hi @Ricardo yes 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 – Manish Sharma Dec 05 '17 at 04:28
  • you can refer to this https://stackoverflow.com/questions/31273236/spring-resttemplate-and-proxy-auth – Azanul Khairi6 Aug 14 '19 at 07:19

1 Answers1

0

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!

Ricardo Zanini
  • 1,041
  • 7
  • 12