当前位置: 首页>>代码示例>>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;未经允许,请勿转载。