本文整理汇总了Java中org.eclipse.jetty.client.HttpExchange.STATUS_COMPLETED属性的典型用法代码示例。如果您正苦于以下问题:Java HttpExchange.STATUS_COMPLETED属性的具体用法?Java HttpExchange.STATUS_COMPLETED怎么用?Java HttpExchange.STATUS_COMPLETED使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.eclipse.jetty.client.HttpExchange
的用法示例。
在下文中一共展示了HttpExchange.STATUS_COMPLETED属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAllBooks
@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);
}
}
示例2: getBook
@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);
}
}
示例3: createCallable
@Override
protected Callable<StreamResponseMessage> createCallable(final StreamRequestMessage requestMessage,
final HttpContentExchange exchange) {
return new Callable<StreamResponseMessage>() {
public StreamResponseMessage call() throws Exception {
if (log.isLoggable(Level.FINE))
log.fine("Sending HTTP request: " + requestMessage);
client.send(exchange);
int exchangeState = exchange.waitForDone();
if (exchangeState == HttpExchange.STATUS_COMPLETED) {
try {
return exchange.createResponse();
} catch (Throwable t) {
log.log(Level.WARNING, "Error reading response: " + requestMessage, Exceptions.unwrap(t));
return null;
}
} else if (exchangeState == HttpExchange.STATUS_CANCELLED) {
// That's ok, happens when we abort the exchange after timeout
return null;
} else if (exchangeState == HttpExchange.STATUS_EXCEPTED) {
// The warnings of the "excepted" condition are logged in HttpContentExchange
return null;
} else {
log.warning("Unhandled HTTP exchange status: " + exchangeState);
return null;
}
}
};
}