本文整理汇总了Java中org.eclipse.jetty.client.ContentExchange.waitForDone方法的典型用法代码示例。如果您正苦于以下问题:Java ContentExchange.waitForDone方法的具体用法?Java ContentExchange.waitForDone怎么用?Java ContentExchange.waitForDone使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jetty.client.ContentExchange
的用法示例。
在下文中一共展示了ContentExchange.waitForDone方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sentRequest
import org.eclipse.jetty.client.ContentExchange; //导入方法依赖的package包/类
public static int sentRequest(final String url, final String method, final String content) throws Exception {
HttpClient httpClient = new HttpClient();
try {
httpClient.start();
ContentExchange contentExchange = new ContentExchange();
contentExchange.setMethod(method);
contentExchange.setRequestContentType(MediaType.APPLICATION_JSON);
contentExchange.setRequestContent(new ByteArrayBuffer(content.getBytes("UTF-8")));
httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
contentExchange.setURL(url);
httpClient.send(contentExchange);
contentExchange.waitForDone();
return contentExchange.getResponseStatus();
} finally {
httpClient.stop();
}
}
示例2: sentGetRequest
import org.eclipse.jetty.client.ContentExchange; //导入方法依赖的package包/类
public static String sentGetRequest(final String url) throws Exception {
HttpClient httpClient = new HttpClient();
try {
httpClient.start();
ContentExchange contentExchange = new ContentExchange();
contentExchange.setMethod("GET");
contentExchange.setRequestContentType(MediaType.APPLICATION_JSON);
httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
contentExchange.setURL(url);
httpClient.send(contentExchange);
contentExchange.waitForDone();
return contentExchange.getResponseContent();
} finally {
httpClient.stop();
}
}
示例3: sentRequest
import org.eclipse.jetty.client.ContentExchange; //导入方法依赖的package包/类
private static ContentExchange sentRequest(final String content) throws Exception {
HttpClient httpClient = new HttpClient();
try {
httpClient.start();
ContentExchange result = new ContentExchange();
result.setMethod("POST");
result.setRequestContentType(MediaType.APPLICATION_JSON);
result.setRequestContent(new ByteArrayBuffer(content.getBytes("UTF-8")));
httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
result.setURL(URL);
httpClient.send(result);
result.waitForDone();
return result;
} finally {
httpClient.stop();
}
}
示例4: sendRequestWithHeaders
import org.eclipse.jetty.client.ContentExchange; //导入方法依赖的package包/类
private ContentExchange sendRequestWithHeaders(String url, Map<String, List<String>> headers, String method, String payload) throws IOException, InterruptedException {
ContentExchange exchange = new ContentExchange(true);
exchange.setURL(url);
if (null != method) {
exchange.setMethod(method);
}
if (null != payload) {
exchange.setRequestContentSource(new ByteArrayInputStream(payload.getBytes()));
}
for (Entry<String, List<String>> e : headers.entrySet()) {
for (String val : e.getValue()) {
exchange.addRequestHeader(e.getKey(), val);
}
}
client.send(exchange);
exchange.waitForDone();
return exchange;
}
示例5: getAllBooks
import org.eclipse.jetty.client.ContentExchange; //导入方法依赖的package包/类
@Override
public Book[] getAllBooks() {
try {
ContentExchange contentExchange = new ContentExchange(true);
contentExchange.setMethod("GET");
contentExchange.setURL("http://" + host + ":" + port + "/get_books");
httpClient.send(contentExchange);
if (contentExchange.waitForDone() == HttpExchange.STATUS_COMPLETED) {
return objectMapper.readValue(contentExchange.getResponseContent(), Book[].class);
} else {
throw new RuntimeException("Exception making request to retrieve all books");
}
} catch (Exception e) {
throw new RuntimeException("Exception making request to retrieve all books", e);
}
}
示例6: getBook
import org.eclipse.jetty.client.ContentExchange; //导入方法依赖的package包/类
@Override
public Book getBook(String id) {
try {
ContentExchange contentExchange = new ContentExchange(true);
contentExchange.setMethod("GET");
contentExchange.setURL("http://" + host + ":" + port + "/get_book" + "?id=" + id);
httpClient.send(contentExchange);
if (contentExchange.waitForDone() == HttpExchange.STATUS_COMPLETED) {
return objectMapper.readValue(contentExchange.getResponseContent(), Book.class);
} else {
throw new RuntimeException("Exception making request to retrieve all books");
}
} catch (Exception e) {
throw new RuntimeException("Exception making request to retrieve a book with id [" + id + "]", e);
}
}
示例7: notFoundXml
import org.eclipse.jetty.client.ContentExchange; //导入方法依赖的package包/类
@Test
public void notFoundXml() throws Exception {
ContentExchange exchange = sendRequest(FEED_URL + "('Z')");
exchange.waitForDone();
assertThat(exchange.getStatus(), is(HttpExchange.STATUS_COMPLETED));
assertThat(exchange.getResponseStatus(), is(HttpStatus.NOT_FOUND_404));
assertThat(exchange.getResponseFields().getStringField(HttpHeaders.CONTENT_TYPE), containsString(MediaType.APPLICATION_XML));
assertThat(exchange.getResponseContent().length(), greaterThan(0));
assertRegexMatches(exchange.getResponseContent(), ".*<code>NotFoundException</code>.*");
assertRegexNotMatches(exchange.getResponseContent(), ".*<innererror>.+</innererror>.*");
}
示例8: notFoundJson
import org.eclipse.jetty.client.ContentExchange; //导入方法依赖的package包/类
@Test
public void notFoundJson() throws Exception {
ContentExchange exchange = sendRequest(FEED_URL + "('Z')?$format=jsonverbose");
exchange.waitForDone();
assertThat(exchange.getStatus(), is(HttpExchange.STATUS_COMPLETED));
assertThat(exchange.getResponseStatus(), is(HttpStatus.NOT_FOUND_404));
assertThat(exchange.getResponseFields().getStringField(HttpHeaders.CONTENT_TYPE), containsString(MediaType.APPLICATION_JSON));
assertThat(exchange.getResponseContent().length(), greaterThan(0));
assertRegexMatches(exchange.getResponseContent(), ".*\"code\"\\s*:\\s*\"NotFoundException\".*");
assertRegexNotMatches(exchange.getResponseContent(), ".*\"innererror\"\\s*:\\s*\".+\".*");
}
示例9: badRequestXmlWithInnerError
import org.eclipse.jetty.client.ContentExchange; //导入方法依赖的package包/类
@Test
public void badRequestXmlWithInnerError() throws Exception {
simulateErrorResponseExtension();
ContentExchange exchange = sendRequest(FEED_URL + "(1.2)");
exchange.waitForDone();
assertThat(exchange.getStatus(), is(HttpExchange.STATUS_COMPLETED));
assertThat(exchange.getResponseStatus(), is(HttpStatus.NOT_FOUND_404));
assertThat(exchange.getResponseFields().getStringField(HttpHeaders.CONTENT_TYPE), containsString(MediaType.APPLICATION_XML));
assertThat(exchange.getResponseContent().length(), greaterThan(0));
assertRegexMatches(exchange.getResponseContent(), ".*<code>NotFoundException</code>.*<innererror>.+</innererror>.*");
}
示例10: badRequestJsonWithInnerError
import org.eclipse.jetty.client.ContentExchange; //导入方法依赖的package包/类
@Test
public void badRequestJsonWithInnerError() throws Exception {
simulateErrorResponseExtension();
ContentExchange exchange = sendRequest(FEED_URL + "(1.2)?$format=jsonverbose");
exchange.waitForDone();
assertThat(exchange.getStatus(), is(HttpExchange.STATUS_COMPLETED));
assertThat(exchange.getResponseStatus(), is(HttpStatus.NOT_FOUND_404));
assertThat(exchange.getResponseFields().getStringField(HttpHeaders.CONTENT_TYPE), containsString(MediaType.APPLICATION_JSON));
assertThat(exchange.getResponseContent().length(), greaterThan(0));
assertRegexMatches(exchange.getResponseContent(), ".*\"code\"\\s*:\\s*\"NotFoundException\".*\"innererror\"\\s*:\\s*\".+\".*");
}
示例11: sendRequest
import org.eclipse.jetty.client.ContentExchange; //导入方法依赖的package包/类
/**
* Helper method to send an HTTP request.
*/
protected ContentExchange sendRequest(String url) throws Exception {
ContentExchange exchange = new ContentExchange(true);
exchange.setURL(url);
client.send(exchange);
exchange.waitForDone();
return exchange;
}
示例12: readExchangeCallLog
import org.eclipse.jetty.client.ContentExchange; //导入方法依赖的package包/类
static CallLog[] readExchangeCallLog(ObjectMapper mapper, ContentExchange exchange) {
try {
exchange.waitForDone();
String responseJson = exchange.getResponseContent();
return mapper.readValue(responseJson, CallLog[].class);
} catch (Exception e) {
return new CallLog[0];
}
}
示例13: serviceUrlReturnsOkStatus
import org.eclipse.jetty.client.ContentExchange; //导入方法依赖的package包/类
@Test
public void serviceUrlReturnsOkStatus() throws Exception {
ContentExchange exchange = sendRequest(BASE_URI);
exchange.waitForDone();
verifyOkStatusIsReturned(exchange);
}
示例14: metaDataUrlReturnsOkStatus
import org.eclipse.jetty.client.ContentExchange; //导入方法依赖的package包/类
@Test
public void metaDataUrlReturnsOkStatus() throws Exception {
ContentExchange exchange = sendRequest(META_DATA_URL);
exchange.waitForDone();
verifyOkStatusIsReturned(exchange);
}
示例15: feedUrlReturnsOkStatus
import org.eclipse.jetty.client.ContentExchange; //导入方法依赖的package包/类
@Test
public void feedUrlReturnsOkStatus() throws Exception {
ContentExchange exchange = sendRequest(FEED_URL);
exchange.waitForDone();
verifyOkStatusIsReturned(exchange);
}