[英]How to configure spring boot resttemplate proxy for client and server
I have an architecture where my server component will be deployed on separate host and client component (UI) will be deployed on separate. 我有一个体系结构,其中我的服务器组件将部署在单独的主机上,而客户端组件(UI)将部署在单独的主机上。
I am stuck with RestTemplate Proxy, can someone please help me how can I achieve it. 我一直在使用RestTemplate代理,有人可以帮助我如何实现它。
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.
我需要在单独的主机上使用REST API,我只是在寻找示例。 I just googled around the stuff but no luck
我只是用谷歌搜索东西,但是没有运气
There's a nice tutorial about Rest Template
at Baeldung's blog . Baeldung的博客上有一个关于
Rest Template
的很好的教程。
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! 干杯!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.