Java Code Examples for org.springframework.http.client.SimpleClientHttpRequestFactory#setProxy()

The following examples show how to use org.springframework.http.client.SimpleClientHttpRequestFactory#setProxy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RestProxyTemplate.java    From orders with Apache License 2.0 6 votes vote down vote up
@PostConstruct
public void init() {
    if (host.isEmpty() || port.isEmpty()) {
        return;
    }
    int portNr = -1;
    try {
        portNr = Integer.parseInt(port);
    } catch (NumberFormatException e) {
        logger.error("Unable to parse the proxy port number");
    }
    SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
    InetSocketAddress address = new InetSocketAddress(host, portNr);
    Proxy proxy = new Proxy(Proxy.Type.HTTP, address);
    factory.setProxy(proxy);

    restTemplate.setRequestFactory(factory);
}
 
Example 2
Source File: ApplicationE2E.java    From spring-boot-quickstart-archtype with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    // replace that with UAT server host
    this.baseURL = new URL("http://localhost:" + port + "/");
    // disable proxy if you wanna run locally
    SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
    Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("userproxy.glb.ebc.local", 8080));
    requestFactory.setProxy(proxy);
    restTemplate = new RestTemplate();


}
 
Example 3
Source File: ApplicationSanityCheck_ITT.java    From spring-boot-quickstart-archtype with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    this.base = new URL("http://localhost:" + port + "/");
    // disable proxy if you wanna run locally
    SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
    Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("userproxy.glb.ebc.local", 8080));
    requestFactory.setProxy(proxy);
    template = new RestTemplate(requestFactory);


}
 
Example 4
Source File: YandexSearchProvider.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
@PostConstruct
private void init() {
    SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
    requestFactory.setConnectTimeout((int) HTTP_TIMEOUT_DURATION.toMillis());
    requestFactory.setReadTimeout((int) HTTP_TIMEOUT_DURATION.toMillis());

    var yandexProxy = workerProperties.getAudio().getYandexProxy();
    if (StringUtils.isNotEmpty(yandexProxy.getHost())) {
        requestFactory.setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(yandexProxy.getHost(), yandexProxy.getPort())));
    }

    this.restTemplate = new RestTemplate(requestFactory);
}
 
Example 5
Source File: AdminServerNotifierAutoConfiguration.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
private static RestTemplate createNotifierRestTemplate(NotifierProxyProperties proxyProperties) {
	RestTemplate restTemplate = new RestTemplate();
	if (proxyProperties.getHost() != null) {
		SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
		Proxy proxy = new Proxy(Proxy.Type.HTTP,
				new InetSocketAddress(proxyProperties.getHost(), proxyProperties.getPort()));
		requestFactory.setProxy(proxy);
		restTemplate.setRequestFactory(requestFactory);
	}
	return restTemplate;
}
 
Example 6
Source File: RequestFactoryLiveTest.java    From tutorials with MIT License 5 votes vote down vote up
@Before
public void setUp() {
    Proxy proxy = new Proxy(Type.HTTP, new InetSocketAddress(PROXY_SERVER_HOST, PROXY_SERVER_PORT));

    SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
    requestFactory.setProxy(proxy);

    restTemplate = new RestTemplate(requestFactory);
}