本文整理匯總了Java中org.springframework.http.client.SimpleClientHttpRequestFactory類的典型用法代碼示例。如果您正苦於以下問題:Java SimpleClientHttpRequestFactory類的具體用法?Java SimpleClientHttpRequestFactory怎麽用?Java SimpleClientHttpRequestFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SimpleClientHttpRequestFactory類屬於org.springframework.http.client包,在下文中一共展示了SimpleClientHttpRequestFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doTest
import org.springframework.http.client.SimpleClientHttpRequestFactory; //導入依賴的package包/類
private void doTest(AnnotationConfigEmbeddedWebApplicationContext context,
String resourcePath) throws Exception {
SimpleClientHttpRequestFactory clientHttpRequestFactory = new SimpleClientHttpRequestFactory();
ClientHttpRequest request = clientHttpRequestFactory.createRequest(
new URI("http://localhost:"
+ context.getEmbeddedServletContainer().getPort() + resourcePath),
HttpMethod.GET);
ClientHttpResponse response = request.execute();
try {
String actual = StreamUtils.copyToString(response.getBody(),
Charset.forName("UTF-8"));
assertThat(actual).isEqualTo("Hello World");
}
finally {
response.close();
}
}
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:18,代碼來源:EmbeddedServletContainerMvcIntegrationTests.java
示例2: getTemplate
import org.springframework.http.client.SimpleClientHttpRequestFactory; //導入依賴的package包/類
public static RestTemplate getTemplate(ClientHttpRequestInterceptor interceptor) {
RestTemplate restTemplate = new RestTemplate();
List<ClientHttpRequestInterceptor> ris = new ArrayList<>();
ris.add(interceptor);
restTemplate.setInterceptors(ris);
SimpleClientHttpRequestFactory httpFactory = new SimpleClientHttpRequestFactory();
httpFactory.setOutputStreaming(false);
restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(httpFactory));
restTemplate.getMessageConverters().add(0, new StringHttpMessageConverter(Charset.forName("UTF-8")));
return restTemplate;
}
示例3: sendPostForUpload
import org.springframework.http.client.SimpleClientHttpRequestFactory; //導入依賴的package包/類
/**
*
* /** sendPostCommand
*
* @param url
* @param parameters
* @return
* @throws ClientProtocolException
*/
public Map<String, Object> sendPostForUpload(String url, Map<String, Object> parameters) {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
requestFactory.setBufferRequestBody(false);
RestTemplate restTemplate = new RestTemplate(requestFactory);
List<HttpMessageConverter<?>> mc = restTemplate.getMessageConverters();
mc.add(new MappingJackson2HttpMessageConverter());
restTemplate.setMessageConverters(mc);
MultiValueMap<String, Object> postParams = new LinkedMultiValueMap<String, Object>();
postParams.setAll(parameters);
Map<String, Object> response = new HashMap<String, Object>();
HttpHeaders headers = new HttpHeaders();
headers.set("Content-Type", "multipart/form-data");
headers.set("Accept", "application/json");
headers.add("Cookie", "JSESSIONID=" + localContext.getCookieStore().getCookies().get(0).getValue());
HttpEntity<Object> request = new HttpEntity<Object>(postParams, headers);
ResponseEntity<?> result = restTemplate.exchange(url, HttpMethod.POST, request, String.class);
String body = result.getBody().toString();
MediaType contentType = result.getHeaders().getContentType();
HttpStatus statusCode = result.getStatusCode();
response.put(CONTENT_TYPE, contentType);
response.put(STATUS_CODE, statusCode);
response.put(BODY, body);
return response;
}
示例4: 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
示例5: createHttpFactory
import org.springframework.http.client.SimpleClientHttpRequestFactory; //導入依賴的package包/類
/**
* Extension point for plugging in different HTTP factories.
* @return Default is a {@link BufferingClientHttpRequestFactory}
*/
protected ClientHttpRequestFactory createHttpFactory(
int connectTimeout,
int requestTimeout)
{
SimpleClientHttpRequestFactory scrf = new SimpleClientHttpRequestFactory();
scrf.setConnectTimeout(connectTimeout);
scrf.setReadTimeout(requestTimeout);
//
// Wrap the default request factory in a BufferingClientHttpRequestFactory
// which allows us to read response bodies multiple times. This is needed
// because some interceptors will need to consume the body before the final
// response gets to the caller.
//
return new BufferingClientHttpRequestFactory(scrf);
}
示例6: 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);
}
示例7: execute
import org.springframework.http.client.SimpleClientHttpRequestFactory; //導入依賴的package包/類
@Override
public void execute(final String baseUrl, final UrlResolution resolution, final String uri,
final HttpMethod method, final Consumer<Http> tester) {
try {
final Http unit = Http.builder()
.baseUrl(baseUrl)
.urlResolution(resolution)
.requestFactory(new SimpleClientHttpRequestFactory())
.build();
tester.accept(unit);
fail("Expected exception");
} catch (final Exception e) {
assertThat(e, is(instanceOf(IllegalArgumentException.class)));
assertThat(e.getMessage(), is(message));
}
}
示例8: doTest
import org.springframework.http.client.SimpleClientHttpRequestFactory; //導入依賴的package包/類
private void doTest(AnnotationConfigEmbeddedWebApplicationContext context,
String resourcePath) throws Exception {
SimpleClientHttpRequestFactory clientHttpRequestFactory = new SimpleClientHttpRequestFactory();
ClientHttpRequest request = clientHttpRequestFactory.createRequest(
new URI("http://localhost:"
+ context.getEmbeddedServletContainer().getPort() + resourcePath),
HttpMethod.GET);
ClientHttpResponse response = request.execute();
try {
String actual = StreamUtils.copyToString(response.getBody(),
Charset.forName("UTF-8"));
assertThat(actual, equalTo("Hello World"));
}
finally {
response.close();
}
}
示例9: etcdClient
import org.springframework.http.client.SimpleClientHttpRequestFactory; //導入依賴的package包/類
@Bean
public EtcdClient etcdClient() throws NamingException {
List<String> locations = discoverNodes("_etcd-server._tcp." + properties.getServiceName());
EtcdClient client = new EtcdClient(locations.get(0));
client.setRetryCount(properties.getRetryCount());
client.setRetryDuration(properties.getRetryDuration());
client.setLocationUpdaterEnabled(properties.isUpdateLocations());
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
requestFactory.setConnectTimeout(properties.getConnectTimeout());
requestFactory.setReadTimeout(properties.getReadTimeout());
client.setRequestFactory(requestFactory);
return client;
}
示例10: initialize
import org.springframework.http.client.SimpleClientHttpRequestFactory; //導入依賴的package包/類
@PostConstruct
public void initialize() {
restTemplate = new RestTemplate();
// Loose JSON serialization defaults
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.setSerializationInclusion(Include.NON_NULL);
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(objectMapper);
restTemplate.setMessageConverters(Arrays.asList(converter));
// Timeout settings
SimpleClientHttpRequestFactory requestFactory = (SimpleClientHttpRequestFactory) restTemplate.getRequestFactory();
int tenSeconds = 10000;
requestFactory.setReadTimeout(tenSeconds);
requestFactory.setConnectTimeout(tenSeconds);
}
示例11: 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;
}
示例12: 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;
}
示例13: UrlResourceServiceRegistry
import org.springframework.http.client.SimpleClientHttpRequestFactory; //導入依賴的package包/類
public UrlResourceServiceRegistry(
String username,
String password,
String idpRemotePath,
String spRemotePath,
int refreshInMinutes) throws MalformedURLException {
super(false);
this.idpUrlResource = new BasicAuthenticationUrlResource(idpRemotePath, username, password);
this.spUrlResource = new BasicAuthenticationUrlResource(spRemotePath, username, password);
this.idpRemotePath = idpRemotePath;
this.spRemotePath = spRemotePath;
this.refreshInMinutes = refreshInMinutes;
SimpleClientHttpRequestFactory requestFactory = (SimpleClientHttpRequestFactory) restTemplate.getRequestFactory();
requestFactory.setConnectTimeout(5 * 1000);
schedule(this.refreshInMinutes, TimeUnit.MINUTES);
doInitializeMetadata(true);
}
示例14: 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);
}
示例15: ContainerizedSynchronizationService
import org.springframework.http.client.SimpleClientHttpRequestFactory; //導入依賴的package包/類
@Autowired
protected ContainerizedSynchronizationService(EnvironmentRepository environmentRepository,
EnvironmentConfigRepository environmentConfigRepository,
VersionRepository versionRepository,
EnvironmentService environmentService,
ImageManager imageManager,
ContainerManager containerManager,
NamingStrategy namingStrategy,
VersionService versionManager,
ContainerVersioningPolicy versioningPolicy) {
super(environmentRepository, environmentConfigRepository, versionRepository);
this.environmentService = environmentService;
this.imageManager = imageManager;
this.containerManager = containerManager;
this.namingStrategy = namingStrategy;
this.versionManager = versionManager;
this.versioningPolicy = versioningPolicy;
this.clientHttpRequestFactory = new SimpleClientHttpRequestFactory();
}