当前位置: 首页>>代码示例>>Java>>正文


Java HttpComponentsClientHttpRequestFactory类代码示例

本文整理汇总了Java中org.springframework.http.client.HttpComponentsClientHttpRequestFactory的典型用法代码示例。如果您正苦于以下问题:Java HttpComponentsClientHttpRequestFactory类的具体用法?Java HttpComponentsClientHttpRequestFactory怎么用?Java HttpComponentsClientHttpRequestFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HttpComponentsClientHttpRequestFactory类属于org.springframework.http.client包,在下文中一共展示了HttpComponentsClientHttpRequestFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testHome

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //导入依赖的package包/类
@Test
public void testHome() throws Exception {
    SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
            new SSLContextBuilder()
                    .loadTrustMaterial(null, new TrustSelfSignedStrategy()).build());

    HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory)
            .build();

    TestRestTemplate testRestTemplate = new TestRestTemplate();
    ((HttpComponentsClientHttpRequestFactory) testRestTemplate.getRequestFactory())
            .setHttpClient(httpClient);
    ResponseEntity<String> entity = testRestTemplate
            .getForEntity("https://localhost:" + this.port, String.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    assertTrue( "Result is not Matched with Server Response",entity.getBody().contains("welcome to the application"));
}
 
开发者ID:adarshkumarsingh83,项目名称:spring_boot,代码行数:18,代码来源:TomcatSSLApplicationTests.java

示例2: restTemplate

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //导入依赖的package包/类
@Bean
public RestTemplate restTemplate() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {

    SSLContext sslContext = SSLContexts.custom()
            .loadTrustMaterial(null, new TrustSelfSignedStrategy())
            .build();

    SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);
    CloseableHttpClient httpClient = HttpClients.custom()
            .setSSLSocketFactory(sslConnectionSocketFactory)
            .build();

    HttpComponentsClientHttpRequestFactory requestFactory =
            new HttpComponentsClientHttpRequestFactory();

    requestFactory.setHttpClient(httpClient);

    return new RestTemplate(requestFactory);
}
 
开发者ID:borysfan,项目名称:websocket-poc,代码行数:20,代码来源:App.java

示例3: getChecksum

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //导入依赖的package包/类
private String getChecksum(String defaultValue, String url,
		String version) {
	String result = defaultValue;
	if (result == null && StringUtils.hasText(url)) {
		CloseableHttpClient httpClient = HttpClients.custom()
				.setSSLHostnameVerifier(new NoopHostnameVerifier())
				.build();
		HttpComponentsClientHttpRequestFactory requestFactory
				= new HttpComponentsClientHttpRequestFactory();
		requestFactory.setHttpClient(httpClient);
		url = constructUrl(url, version);
		try {
			ResponseEntity<String> response
					= new RestTemplate(requestFactory).exchange(
					url, HttpMethod.GET, null, String.class);
			if (response.getStatusCode().equals(HttpStatus.OK)) {
				result = response.getBody();
			}
		}
		catch (HttpClientErrorException httpException) {
			// no action necessary set result to undefined
			logger.debug("Didn't retrieve checksum because", httpException);
		}
	}
	return result;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:27,代码来源:AboutController.java

示例4: testLogin

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //导入依赖的package包/类
@Test
public void testLogin() {
	try {
		String authUrl = String.format(AUTH_URL_BASE, port);
		JsonObject request = Json.createObjectBuilder()
				.add("id", DEFAULT_ID)
				.add("key", DEFAULT_KEY)
				.build();

		HttpHeaders headers = new HttpHeaders();
		headers.setContentType(MediaType.APPLICATION_JSON);
		HttpEntity<String> entity = new HttpEntity<>(request.toString(), headers);
		RestTemplate rest = new RestTemplate(new HttpComponentsClientHttpRequestFactory());
		ResponseEntity<String> response = rest.exchange(authUrl, HttpMethod.POST, entity, String.class);

		assertEquals(200, response.getStatusCodeValue());
		JsonReader reader = Json.createReader(new StringReader(response.getBody()));
		JsonObject o = reader.readObject();
		String token = o.getString("token");
		assertTrue(!StringUtils.isEmpty(token));
		logger.info(token);
	} catch (Exception e) {
		logger.error(e.getMessage(), e);
		fail(e.getMessage());
	}
}
 
开发者ID:kinota,项目名称:kinota-server,代码行数:27,代码来源:AgentLoginTest.java

示例5: requestFactory

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //导入依赖的package包/类
@Bean
public ClientHttpRequestFactory requestFactory() {

	// Disable auto redirect on 3xx HTTP responses
	CloseableHttpClient httpClient = HttpClientBuilder.create().disableRedirectHandling().build();

	HttpComponentsClientHttpRequestFactory rf = new HttpComponentsClientHttpRequestFactory(httpClient);

	// read timeout
	if(!StringUtils.isEmpty(readTimeout)) {
		rf.setReadTimeout(Integer.valueOf(readTimeout) * 1000);
	}

	// connect timeout
	if(!StringUtils.isEmpty(connectTimeout)) {
		rf.setConnectTimeout(Integer.valueOf(connectTimeout) * 1000);
	}

	return rf;
}
 
开发者ID:vianneyfaivre,项目名称:Persephone,代码行数:21,代码来源:DefaultRestTemplateConfig.java

示例6: createTemplate

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //导入依赖的package包/类
public RestTemplate createTemplate(final String host, final Integer port, final String username, final String password)
{
	Preconditions.checkArgument(StringUtils.isNotBlank(host));
	Preconditions.checkArgument(port != null);
	Preconditions.checkArgument(StringUtils.isNotBlank(username));
	Preconditions.checkArgument(StringUtils.isNotBlank(password));

	final AuthScope authscope = new AuthScope(host, port.intValue());
	final Credentials credentials = new UsernamePasswordCredentials(username, password);
	final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
	credentialsProvider.setCredentials(authscope, credentials);

	final HttpClientBuilder clientBuilder = HttpClientBuilder.create();
	clientBuilder.setDefaultCredentialsProvider(credentialsProvider);
	final CloseableHttpClient httpClient = clientBuilder.build();

	final HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
	requestFactory.setHttpClient(httpClient);

	return new RestTemplate(requestFactory);
}
 
开发者ID:fredhopper,项目名称:hybris-connector,代码行数:22,代码来源:RestTemplateProvider.java

示例7: SmallTimeoutRestTemplateWorker

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //导入依赖的package包/类
public SmallTimeoutRestTemplateWorker(final String url, final MetricRegistry registry, final String name,
                                      final int timeout) {

    final HttpClient httpClient = HttpClientBuilder.create()
            .setMaxConnTotal(MAX_CONN_TOTAL)
            // .setMaxConnPerRoute(MAX_CONN_PER_ROUTE)
            .build();

    final HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(httpClient);
    factory.setReadTimeout(timeout);
    factory.setConnectionRequestTimeout(timeout);
    factory.setConnectTimeout(timeout);

    this.restTemplate = new RestTemplate(factory);
    this.url = url;
    this.registry = registry;
    this.name = name;
    this.timeout = timeout;
}
 
开发者ID:vosmann,项目名称:flechette,代码行数:20,代码来源:SmallTimeoutRestTemplateWorker.java

示例8: MovieRepository

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //导入依赖的package包/类
/**
 * Construct rest template with data app uri.
 *
 * @param builder    rest template builder
 * @param dataAppUri data app uri from application.properties
 */
public MovieRepository(RestTemplateBuilder builder, @Value("${moviedb.webapp.dataAppUri}") String dataAppUri) {
    logger.debug("data app:" + dataAppUri);

    String trimmedURL = dataAppUri.trim().toLowerCase();
    String dataAppApiUrl;
    if (trimmedURL.startsWith("http://") || trimmedURL.startsWith("https://")) {
        dataAppApiUrl = trimmedURL + "/api/v1";
    } else {
        dataAppApiUrl = "http://" + trimmedURL + "/api/v1";
    }

    logger.debug("data app api root url: " + dataAppApiUrl);
    restTemplate = builder.rootUri(dataAppApiUrl).build();
    restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory());
}
 
开发者ID:Microsoft,项目名称:movie-db-java-on-azure,代码行数:22,代码来源:MovieRepository.java

示例9: testLoginUpperCaseUUIDs

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //导入依赖的package包/类
@Test
public void testLoginUpperCaseUUIDs() {
	try {
		String authUrl = String.format(AUTH_URL_BASE, port);
		JsonObject request = Json.createObjectBuilder()
				.add("id", DEFAULT_ID_UPPER)
				.add("key", DEFAULT_KEY_UPPER)
				.build();

		HttpHeaders headers = new HttpHeaders();
		headers.setContentType(MediaType.APPLICATION_JSON);
		HttpEntity<String> entity = new HttpEntity<>(request.toString(), headers);
		RestTemplate rest = new RestTemplate(new HttpComponentsClientHttpRequestFactory());
		ResponseEntity<String> response = rest.exchange(authUrl, HttpMethod.POST, entity, String.class);

		assertEquals(200, response.getStatusCodeValue());
		JsonReader reader = Json.createReader(new StringReader(response.getBody()));
		JsonObject o = reader.readObject();
		String token = o.getString("token");
		assertTrue(!StringUtils.isEmpty(token));
		logger.info(token);
	} catch (Exception e) {
		logger.error(e.getMessage(), e);
		fail(e.getMessage());
	}
}
 
开发者ID:kinota,项目名称:kinota-server,代码行数:27,代码来源:AgentLoginTest.java

示例10: createSecurityRestTemplate

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //导入依赖的package包/类
/**
 * Creates the security rest template.
 *
 * @throws KeyManagementException the key management exception
 * @throws NoSuchAlgorithmException the no such algorithm exception
 * @throws KeyStoreException the key store exception
 */
private void createSecurityRestTemplate() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException{
	TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true;
	SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom()
	        .loadTrustMaterial(null, acceptingTrustStrategy)
	        .build();
	SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext);
	
	HttpComponentsClientHttpRequestFactory requestFactory =
	        new HttpComponentsClientHttpRequestFactory();
	
	 HttpClient httpClient = HttpClientBuilder.create()
               .disableCookieManagement()
               .useSystemProperties()
               .setSSLSocketFactory(csf)
               .build();
	requestFactory.setHttpClient(httpClient);
	this.restTemplate = new RestTemplate(requestFactory);
}
 
开发者ID:ac-silva,项目名称:desafio-pagarme,代码行数:26,代码来源:Client.java

示例11: usingHttpComponents

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //导入依赖的package包/类
static ClientHttpRequestFactory usingHttpComponents(ClientOptions options)
		throws GeneralSecurityException, IOException {

	HttpClientBuilder httpClientBuilder = HttpClients.custom()
			.setSSLContext(SSLContext.getDefault())
			.useSystemProperties();

	RequestConfig.Builder requestConfigBuilder = RequestConfig.custom()
			.setAuthenticationEnabled(true);

	if (options.getConnectionTimeout() != null) {
		requestConfigBuilder.setConnectTimeout(options.getConnectionTimeout());
	}
	if (options.getReadTimeout() != null) {
		requestConfigBuilder.setSocketTimeout(options.getReadTimeout());
	}

	httpClientBuilder.setDefaultRequestConfig(requestConfigBuilder.build());

	return new HttpComponentsClientHttpRequestFactory(httpClientBuilder.build());
}
 
开发者ID:spring-projects,项目名称:spring-credhub,代码行数:22,代码来源:ClientHttpRequestFactoryFactory.java

示例12: afterPropertiesSet

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //导入依赖的package包/类
public void afterPropertiesSet() throws UnsupportedEncodingException {
  Collection<Header> defaultHeaders = new ArrayList<Header>();
  Header header = new BasicHeader("Authorization",
      "Basic " + BaseEncoding.base64().encode("apollo:".getBytes("UTF-8")));
  defaultHeaders.add(header);

  BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
  credentialsProvider.setCredentials(AuthScope.ANY,
      new UsernamePasswordCredentials("apollo", ""));
  CloseableHttpClient httpClient =
      HttpClientBuilder.create().setDefaultCredentialsProvider(credentialsProvider)
          .setDefaultHeaders(defaultHeaders).build();


  restTemplate = new RestTemplate(httpMessageConverters.getConverters());
  HttpComponentsClientHttpRequestFactory requestFactory =
      new HttpComponentsClientHttpRequestFactory(httpClient);
  requestFactory.setConnectTimeout(portalConfig.connectTimeout());
  requestFactory.setReadTimeout(portalConfig.readTimeout());

  restTemplate.setRequestFactory(requestFactory);
}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:23,代码来源:RestTemplateFactory.java

示例13: contextLoads

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //导入依赖的package包/类
@Test
public void contextLoads() throws Exception {

  SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
      new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build());

  CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory).build();


  ((HttpComponentsClientHttpRequestFactory) restTemplate.getRestTemplate().getRequestFactory())
      .setHttpClient(httpClient);
  HttpHeaders headers = new HttpHeaders();
  headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));

  HttpEntity<String> entity = new HttpEntity<>(headers);
  ResponseEntity<ExecutionStatus> response = restTemplate.exchange("https://localhost:"
      + this.port + this.contextRoot + this.jerseycontextRoot + "/execute?env=stage&key=PING",
      HttpMethod.GET, entity, ExecutionStatus.class);
  Assert.assertEquals(HttpStatus.OK, response.getStatusCode());
  Assert.assertEquals(new Integer(0), response.getBody().getCode());
  Assert.assertNotNull(response.getBody().getOutput());
  httpClient.close();

}
 
开发者ID:januslabs,项目名称:ansible-http,代码行数:25,代码来源:AnsibleHttpApplicationTests.java

示例14: hello

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //导入依赖的package包/类
@Test
public void hello() throws Exception {

  SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
      new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build());

  CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory).build();


  ((HttpComponentsClientHttpRequestFactory) restTemplate.getRestTemplate().getRequestFactory())
      .setHttpClient(httpClient);
  HttpHeaders headers = new HttpHeaders();
  headers.setAccept(Arrays.asList(MediaType.TEXT_PLAIN));

  HttpEntity<String> entity = new HttpEntity<>(headers);
  ResponseEntity<String> response = restTemplate.exchange("https://localhost:"
      + this.port + this.contextRoot + this.jerseycontextRoot + "/execute/hello",
      HttpMethod.GET, entity, String.class);
  Assert.assertEquals(HttpStatus.OK, response.getStatusCode());
  Assert.assertNotNull(response.getBody());
  httpClient.close();

}
 
开发者ID:januslabs,项目名称:ansible-http,代码行数:24,代码来源:AnsibleHttpApplicationTests.java

示例15: executeCommands

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //导入依赖的package包/类
@Test
public void executeCommands() throws Exception {
  SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
      new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build());

  CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory).build();


  ((HttpComponentsClientHttpRequestFactory) restTemplate.getRestTemplate().getRequestFactory())
      .setHttpClient(httpClient);
  HttpHeaders headers = new HttpHeaders();
  headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));


  HttpEntity<HashMap<String, String>> requestEntity =
      new HttpEntity<>(headers);


  ResponseEntity<ExecutionStatus> response = restTemplate.exchange(
      "https://localhost:" + this.port + this.contextRoot + this.jerseycontextRoot + "/execute"
          + "?key=DEPLOY&groupId=service.registration&name=assurantregistrationservice&version=2.1.6&clusterName=aebedx&env=stage",
      HttpMethod.POST, requestEntity, ExecutionStatus.class);
  Assert.assertEquals(HttpStatus.OK, response.getStatusCode());
  httpClient.close();

}
 
开发者ID:januslabs,项目名称:ansible-http,代码行数:27,代码来源:AnsibleHttpApplicationTests.java


注:本文中的org.springframework.http.client.HttpComponentsClientHttpRequestFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。