本文整理匯總了Java中org.springframework.http.client.SimpleClientHttpRequestFactory.setProxy方法的典型用法代碼示例。如果您正苦於以下問題:Java SimpleClientHttpRequestFactory.setProxy方法的具體用法?Java SimpleClientHttpRequestFactory.setProxy怎麽用?Java SimpleClientHttpRequestFactory.setProxy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.http.client.SimpleClientHttpRequestFactory
的用法示例。
在下文中一共展示了SimpleClientHttpRequestFactory.setProxy方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: clientHttpRequestFactory
import org.springframework.http.client.SimpleClientHttpRequestFactory; //導入方法依賴的package包/類
@Bean
public ClientHttpRequestFactory clientHttpRequestFactory() {
List<ClientHttpRequestInterceptor> interceptors = Arrays
.asList(getSecurityInterceptor());
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
Proxy proxy = this.properties.getRemote().getProxy();
if (proxy.getHost() != null && proxy.getPort() != null) {
requestFactory.setProxy(new java.net.Proxy(Type.HTTP,
new InetSocketAddress(proxy.getHost(), proxy.getPort())));
}
return new InterceptingClientHttpRequestFactory(requestFactory, interceptors);
}
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:13,代碼來源:RemoteClientConfiguration.java
示例2: init
import org.springframework.http.client.SimpleClientHttpRequestFactory; //導入方法依賴的package包/類
@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);
}
示例3: executeRestRequest
import org.springframework.http.client.SimpleClientHttpRequestFactory; //導入方法依賴的package包/類
public <T> T executeRestRequest(LinkDto link, String path, Class<T> clazz) {
SimpleClientHttpRequestFactory clientHttpRequestFactory = new SimpleClientHttpRequestFactory();
if (this.getItConfiguration().isUseHttpIgeProxy()) {
final String httpProxyHost = this.getItConfiguration().getHttpProxyHost();
final int httpProxyPort = this.getItConfiguration().getHttpProxyPort();
logger.info("Use proxy {}:{} to access Simple Probe", httpProxyHost, httpProxyPort);
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(httpProxyHost, httpProxyPort));
clientHttpRequestFactory.setProxy(proxy);
}
RestTemplate restTemplate = new RestTemplate(clientHttpRequestFactory);
T result = restTemplate.getForEntity(link.getUrl().toString()+path, clazz).getBody();
return result;
}
示例4: getRestTemplateForProbeFrom
import org.springframework.http.client.SimpleClientHttpRequestFactory; //導入方法依賴的package包/類
private String getRestTemplateForProbeFrom(LinkDto link,String path) {
logger.info("Querying endpoint: {}",link.getUrl().toString()+path);
SimpleClientHttpRequestFactory clientHttpRequestFactory = new SimpleClientHttpRequestFactory();
if (paasServicesEnvITHelper.getItConfiguration().isUseHttpIgeProxy()) {
final String httpProxyHost = paasServicesEnvITHelper.getItConfiguration().getHttpProxyHost();
final int httpProxyPort = paasServicesEnvITHelper.getItConfiguration().getHttpProxyPort();
logger.info("Use proxy {}:{} to access Simple Probe", httpProxyHost, httpProxyPort);
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(httpProxyHost, httpProxyPort));
clientHttpRequestFactory.setProxy(proxy);
}
RestTemplate restTemplate = new RestTemplate(clientHttpRequestFactory);
HttpHeaders customHeaders = new HttpHeaders();
customHeaders.add(HEADER_ELPAASO_UNIVERSAL_ID, HEADER_ELPAASO_UNIVERSAL_ID_DEFAULT_VALUE);
HttpEntity<String> entity = new HttpEntity<>("parameters", customHeaders);
ResponseEntity<String> response = restTemplate.exchange(link.getUrl().toString()+path,
HttpMethod.GET,
entity,
String.class);
String result = response.getBody();
return result;
}
示例5: request
import org.springframework.http.client.SimpleClientHttpRequestFactory; //導入方法依賴的package包/類
private ResponseEntity<String> request(UriComponentsBuilder uriComponentsBuilder, HttpMethod method, int connectTimeout, int readTimeout) throws RestClientException
{
LOGGER.info(uriComponentsBuilder.build(false).encode().toUriString()+" (ConenectTimeout="+connectTimeout+" ReadTimeout="+readTimeout+")");
//proxy support
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
if (LOGGER.isDebugEnabled()) LOGGER.debug("Http PROXY settings:"+HttpProxyGlobalConfigReader.getHttpProxy());
if (HttpProxyGlobalConfigReader.getHttpProxy()!=null)
factory.setProxy(HttpProxyGlobalConfigReader.getHttpProxy());
factory.setConnectTimeout(connectTimeout);
factory.setReadTimeout(readTimeout);
RestTemplate restTemplate = new RestTemplate();
restTemplate.setRequestFactory(factory);
HttpHeaders requestHeaders = new HttpHeaders();
HttpEntity<String> requestEntity = new HttpEntity<String>(requestHeaders);
return restTemplate.exchange(uriComponentsBuilder.build(false).encode().toUriString(), method, requestEntity, String.class);
}
示例6: restTemplate
import org.springframework.http.client.SimpleClientHttpRequestFactory; //導入方法依賴的package包/類
@Bean
public RestTemplate restTemplate() {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
Proxy proxy= new Proxy(Type.HTTP, new InetSocketAddress("vip-px.main.aviva.eu.corp", 8080));
requestFactory.setProxy(proxy);
return new RestTemplate(requestFactory);
// return new RestTemplate();
}
示例7: setHttpProxy
import org.springframework.http.client.SimpleClientHttpRequestFactory; //導入方法依賴的package包/類
public void setHttpProxy(String host, int port) {
if (host != null && !host.isEmpty()) {
// Debug
logger.debug("Using HTTP proxy for REST connection: " + host + ":" + port);
// Set proxy
SimpleClientHttpRequestFactory requestFactory = (SimpleClientHttpRequestFactory) getRequestFactory();
Proxy proxy = new Proxy(Type.HTTP, new InetSocketAddress(host, port));
requestFactory.setProxy(proxy);
}
}
示例8: abstractServiceSetUp
import org.springframework.http.client.SimpleClientHttpRequestFactory; //導入方法依賴的package包/類
public void abstractServiceSetUp() throws Exception, Throwable {
String hostname = GeneralUtils.getProperty("test.server.hostname", System.getProperty("test.server.hostname"));
String port = GeneralUtils.getProperty("test.server.port", System.getProperty("test.server.port"));
String baseUrl = GeneralUtils.getProperty("test.server.baseUrl", System.getProperty("test.server.baseUrl"));
this.baseUri = URI.create("http://" + hostname + ":" + port + baseUrl + "odktables/" + appId + "/");
// RestTemplate
try {
this.rt = new RestTemplate();
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
InetSocketAddress address =
new InetSocketAddress(proxy.getClientBindAddress().getHostAddress(), proxyPort);
Proxy proxyRef = new Proxy(Proxy.Type.HTTP, address);
factory.setProxy(proxyRef);
factory.setOutputStreaming(false);
rt.setRequestFactory(factory);
} catch (Throwable t) {
t.printStackTrace();
throw t;
}
this.rt.setErrorHandler(new ErrorHandler());
List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
converters.add(new MappingJackson2HttpMessageConverter());
// converters.add(new AllEncompassingFormHttpMessageConverter());
this.rt.setMessageConverters(converters);
// HttpHeaders
List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>();
acceptableMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
this.reqHeaders = new HttpHeaders();
reqHeaders.setAccept(acceptableMediaTypes);
reqHeaders.setContentType(MediaType.APPLICATION_JSON_UTF8);
}
示例9: submitSearchRequest
import org.springframework.http.client.SimpleClientHttpRequestFactory; //導入方法依賴的package包/類
private ResponseEntity<LegacySearchResponse> submitSearchRequest(String url, String parameterValue, int page) {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
requestFactory.setProxy(new Proxy(Type.HTTP, new InetSocketAddress(proxyHost, proxyPort)));
try {
RestTemplate restTemplate = new RestTemplate(requestFactory);
ResponseEntity<LegacySearchResponse> entityResponse = restTemplate.getForEntity(legacySystemHostUrl + url,
LegacySearchResponse.class, page, parameterValue);
return entityResponse;
} catch (Exception e) {
logger.error(".getLegacyCategoriesForCatDocRef : exception occured", e);
return null;
}
}