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


Java HttpClientResponse.dataHandler方法代码示例

本文整理汇总了Java中org.vertx.java.core.http.HttpClientResponse.dataHandler方法的典型用法代码示例。如果您正苦于以下问题:Java HttpClientResponse.dataHandler方法的具体用法?Java HttpClientResponse.dataHandler怎么用?Java HttpClientResponse.dataHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.vertx.java.core.http.HttpClientResponse的用法示例。


在下文中一共展示了HttpClientResponse.dataHandler方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseData

import org.vertx.java.core.http.HttpClientResponse; //导入方法依赖的package包/类
private void parseData(HttpClientResponse response, final Handler<JsonObject> handler) {
    if (response.statusCode() == 200) {
        final Buffer buff = new Buffer();
        response.dataHandler(new Handler<Buffer>() {
            @Override
            public void handle(Buffer event) {
                buff.appendBuffer(event);
            }
        });
        response.endHandler(new Handler<Void>() {
            @Override
            public void handle(Void end) {
                handleResponse(buff.toString(), handler);
            }
        });
    } else {
        handler.handle(new JsonObject().putString("status", "error").putString("message", response.statusMessage()));
    }
}
 
开发者ID:OPEN-ENT-NG,项目名称:collaborative-editor,代码行数:20,代码来源:EPLiteConnection.java

示例2: handleSuccess

import org.vertx.java.core.http.HttpClientResponse; //导入方法依赖的package包/类
@Override
protected void handleSuccess(final HttpClientResponse response) {

    final Buffer body = new Buffer(0);

    response.dataHandler(new Handler<Buffer>() {
        @Override
        public void handle(final Buffer data) {
            body.appendBuffer(data);
        }
    });

    response.endHandler(new VoidHandler() {
        @Override
        public void handle() {
            //
            // Parse query response
            //
            String responseData = new String(body.getBytes(), StandardCharsets.UTF_8);
            logger().trace("Response: {}", responseData);
            JsonObject jsonData = new JsonObject(responseData);
            JsonArray items = jsonData.getArray(API_KEY_RESULTS, new JsonArray());
            boolean found = false;
            for (int i = 0; i < items.size(); i++) {
                JsonObject item = items.get(i);
                //
                // Handle existing item (datasource, variable, etc..)
                //
                m_resultHandler.handleResponse(item);
                found = true;
            }
            m_resultHandler.responseDone();
            //
            // Create new item (datasource, variable, etc..)
            //
            if (!found && m_data != null) {
                try {
                    logger().debug("Creating: {}", m_data.encode());
                    IConnection<HttpClient> connection = connections().next();
                    UbidotsPost postHandler = new UbidotsPost(
                            connection,
                            m_resultHandler,
                            query(),
                            token(),
                            m_data);
                    connection.doRequest(postHandler);

                } catch (ConnectionException e) {
                    logger().error("Failed to create datasource or variable", e);
                }
            }
        }
    });
}
 
开发者ID:clidev,项目名称:spike.x,代码行数:55,代码来源:Ubidots.java

示例3: httpHealthCheck

import org.vertx.java.core.http.HttpClientResponse; //导入方法依赖的package包/类
private void httpHealthCheck(
        final HttpConnection connection,
        final HttpClientResponse response,
        final Handler<Boolean> handler) {

    m_logger.trace("Got response: {}/{}",
            response.statusCode(),
            response.statusMessage());

    if (response.statusCode() < HTTP_ERR_CODE) {

        final Buffer body = new Buffer(0);
        response.dataHandler(new Handler<Buffer>() {
            @Override
            public void handle(final Buffer data) {
                if (response.statusCode() >= HTTP_SUCCESS_CODE
                        && response.statusCode() < HTTP_REDIRECTION_CODE) {

                    body.appendBuffer(data);
                }
            }
        });
        response.endHandler(new VoidHandler() {
            @Override
            public void handle() {
                if (response.statusCode() >= HTTP_SUCCESS_CODE
                        && response.statusCode() < HTTP_REDIRECTION_CODE) {

                    String status = new String(body.getBytes(), StandardCharsets.UTF_8);
                    connection.setConnected(true);
                    if (handler != null) {
                        handler.handle(TRUE);
                    }
                    m_logger.trace("Connected to healthy host: {} ({})",
                            connection.getAddress(), status);
                } else {
                    handleFailure(connection, response, handler);
                }
            }
        });
    } else {
        handleFailure(connection, response, handler);
    }
}
 
开发者ID:clidev,项目名称:spike.x,代码行数:45,代码来源:DefaultHttpConnectionHealthChecker.java


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