当前位置: 首页>>代码示例>>Java>>正文


Java HttpExchange.STATUS_COMPLETED属性代码示例

本文整理汇总了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);
    }
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:17,代码来源:BookServiceJettyHttpClient.java

示例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);
    }
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:18,代码来源:BookServiceJettyHttpClient.java

示例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;
            }
        }
    };
}
 
开发者ID:archos-sa,项目名称:aos-MediaLib,代码行数:32,代码来源:ArchosStreamClientImpl.java


注:本文中的org.eclipse.jetty.client.HttpExchange.STATUS_COMPLETED属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。