當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。