本文整理匯總了Java中org.springframework.http.client.SimpleClientHttpRequestFactory.createRequest方法的典型用法代碼示例。如果您正苦於以下問題:Java SimpleClientHttpRequestFactory.createRequest方法的具體用法?Java SimpleClientHttpRequestFactory.createRequest怎麽用?Java SimpleClientHttpRequestFactory.createRequest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.http.client.SimpleClientHttpRequestFactory
的用法示例。
在下文中一共展示了SimpleClientHttpRequestFactory.createRequest方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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();
}
}
示例3: hasHeader
import org.springframework.http.client.SimpleClientHttpRequestFactory; //導入方法依賴的package包/類
public boolean hasHeader(String url, int port, String header) throws Exception {
SimpleClientHttpRequestFactory clientHttpRequestFactory = new SimpleClientHttpRequestFactory();
ClientHttpRequest request = clientHttpRequestFactory
.createRequest(new URI("http://localhost:" + port + url), HttpMethod.GET);
ClientHttpResponse response = request.execute();
return response.getHeaders().containsKey(header);
}
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:8,代碼來源:EndpointWebMvcAutoConfigurationTests.java
示例4: assertContent
import org.springframework.http.client.SimpleClientHttpRequestFactory; //導入方法依賴的package包/類
public void assertContent(String url, int port, Object expected) throws Exception {
SimpleClientHttpRequestFactory clientHttpRequestFactory = new SimpleClientHttpRequestFactory();
ClientHttpRequest request = clientHttpRequestFactory
.createRequest(new URI("http://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;
}
}
示例5: assertContent
import org.springframework.http.client.SimpleClientHttpRequestFactory; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public void assertContent(String url, int port, Object expected) throws Exception {
SimpleClientHttpRequestFactory clientHttpRequestFactory = new SimpleClientHttpRequestFactory();
ClientHttpRequest request = clientHttpRequestFactory
.createRequest(new URI("http://localhost:" + port + url), HttpMethod.GET);
try {
ClientHttpResponse response = request.execute();
try {
String actual = StreamUtils.copyToString(response.getBody(),
Charset.forName("UTF-8"));
if (expected instanceof Matcher) {
assertThat(actual, is((Matcher<String>) expected));
}
else {
assertThat(actual, equalTo(expected));
}
}
finally {
response.close();
}
}
catch (Exception ex) {
if (expected == null) {
if (SocketException.class.isInstance(ex)
|| FileNotFoundException.class.isInstance(ex)) {
return;
}
}
throw ex;
}
}