當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpComponentsClientHttpRequestFactory.createRequest方法代碼示例

本文整理匯總了Java中org.springframework.http.client.HttpComponentsClientHttpRequestFactory.createRequest方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpComponentsClientHttpRequestFactory.createRequest方法的具體用法?Java HttpComponentsClientHttpRequestFactory.createRequest怎麽用?Java HttpComponentsClientHttpRequestFactory.createRequest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.http.client.HttpComponentsClientHttpRequestFactory的用法示例。


在下文中一共展示了HttpComponentsClientHttpRequestFactory.createRequest方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getClientResponse

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //導入方法依賴的package包/類
protected ClientHttpResponse getClientResponse(String url, HttpMethod method,
		HttpComponentsClientHttpRequestFactory requestFactory, String... headers)
				throws IOException, URISyntaxException {
	ClientHttpRequest request = requestFactory.createRequest(new URI(url), method);
	request.getHeaders().add("Cookie", "JSESSIONID=" + "123");
	for (String header : headers) {
		String[] parts = header.split(":");
		request.getHeaders().add(parts[0], parts[1]);
	}
	ClientHttpResponse response = request.execute();
	return response;
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:13,代碼來源:AbstractEmbeddedServletContainerFactoryTests.java

示例2: verify404

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //導入方法依賴的package包/類
private void verify404() throws Exception {
	HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
	ClientHttpRequest request = requestFactory.createRequest(
			new URI("http://localhost:"
					+ this.context.getEmbeddedServletContainer().getPort() + "/"),
			HttpMethod.GET);
	ClientHttpResponse response = request.execute();
	assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:10,代碼來源:MultipartAutoConfigurationTests.java

示例3: assertContent

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //導入方法依賴的package包/類
private void assertContent(String scheme, String url, int port, Object expected)
		throws Exception {

	SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
			new SSLContextBuilder()
					.loadTrustMaterial(null, new TrustSelfSignedStrategy()).build());
	HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory)
			.build();
	HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(
			httpClient);
	ClientHttpRequest request = requestFactory.createRequest(
			new URI(scheme + "://localhost:" + port + url), HttpMethod.GET);
	try {
		ClientHttpResponse response = request.execute();
		if (HttpStatus.NOT_FOUND.equals(response.getStatusCode())) {
			throw new FileNotFoundException();
		}
		try {
			String actual = StreamUtils.copyToString(response.getBody(),
					Charset.forName("UTF-8"));
			if (expected instanceof Matcher) {
				assertThat(actual).is(Matched.by((Matcher<?>) expected));
			}
			else {
				assertThat(actual).isEqualTo(expected);
			}
		}
		finally {
			response.close();
		}
	}
	catch (Exception ex) {
		if (expected == null) {
			if (SocketException.class.isInstance(ex)
					|| FileNotFoundException.class.isInstance(ex)) {
				return;
			}
		}
		throw ex;
	}
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:42,代碼來源:EndpointWebMvcAutoConfigurationTests.java


注:本文中的org.springframework.http.client.HttpComponentsClientHttpRequestFactory.createRequest方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。