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


Java HttpClientRequest.exceptionHandler方法代码示例

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


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

示例1: doRequest

import org.vertx.java.core.http.HttpClientRequest; //导入方法依赖的package包/类
@Override
protected void doRequest(final HttpClient client) {

    // Build query URI
    StringBuilder queryUri = new StringBuilder(m_query);
    queryUri.append(API_KEY_TOKEN);
    queryUri.append(m_token);

    m_logger.trace("Executing query: {} (host: {})",
            queryUri, getConnection().getAddress());

    HttpClientRequest request = doGet(queryUri.toString(), m_handler);
    request.exceptionHandler(new DefaultConnectionExceptionHandler(
            getConnection()));
    request.end();
}
 
开发者ID:clidev,项目名称:spike.x,代码行数:17,代码来源:Ubidots.java

示例2: doRequest

import org.vertx.java.core.http.HttpClientRequest; //导入方法依赖的package包/类
@Override
protected void doRequest(final HttpClient client) {

    URI apiUri = getConnection().getAddress();
    HttpClientRequest request = doPost(apiUri.getPath(), new HttpClientResponseAdapter() {

        @Override
        protected void handleFailure(final HttpClientResponse response) {
            if (response.statusCode() != 201) {
                m_logger.trace("{}", m_body);
                m_logger.error("Failed to publish event to Flowdock: {} (host: {})",
                        m_subject,
                        getConnection().getAddress(),
                        new IllegalStateException("HTTP post failure: "
                                + response.statusCode()
                                + "/"
                                + response.statusMessage()));
            }
        }
    });

    request.putHeader(CONTENT_TYPE, "application/json");
    request.putHeader(CONTENT_LENGTH, String.valueOf(m_body.length()));

    // HTTP basic authentication
    request.putHeader(HttpHeaders.AUTHORIZATION, "Basic "
            + base64Token(m_apiToken));

    request.exceptionHandler(new DefaultConnectionExceptionHandler(
            getConnection()));

    request.write(m_body);
    request.end();
}
 
开发者ID:clidev,项目名称:spike.x,代码行数:35,代码来源:Flowdock.java

示例3: doRequest

import org.vertx.java.core.http.HttpClientRequest; //导入方法依赖的package包/类
@Override
protected void doRequest(final HttpClient client) {

    String uri = NSQ_PUBLISH_URI + "?topic=" + m_topic;
    HttpClientRequest request = doPost(uri, new HttpClientResponseAdapter() {

        @Override
        protected void handleFailure(final HttpClientResponse response) {
            if (response.statusCode() != 200) {
                m_logger.error("Failed to publish events to topic: {} (host: {})",
                        m_topic,
                        getConnection().getAddress(),
                        new IllegalStateException("HTTP post failure: "
                                + response.statusCode()
                                + "/"
                                + response.statusMessage()));
            }
        }
    });

    StringBuilder bulk = new StringBuilder();
    for (JsonObject event : m_events) {
        bulk.append(event.toString());
        bulk.append("\n"); // http://nsq.io/components/nsqd.html#mpub
    }

    byte[] body = bulk.toString().getBytes();
    request.putHeader(CONTENT_LENGTH, String.valueOf(body.length));
    request.exceptionHandler(new DefaultConnectionExceptionHandler(
            getConnection()));
    request.write(new Buffer(body));
    request.end();
}
 
开发者ID:clidev,项目名称:spike.x,代码行数:34,代码来源:NsqHttp.java

示例4: doRequest

import org.vertx.java.core.http.HttpClientRequest; //导入方法依赖的package包/类
@Override
protected void doRequest(final HttpClient client) {

    // Build query URI
    Escaper escaper = UrlEscapers.urlFormParameterEscaper();
    StringBuilder queryUri = new StringBuilder(INFLUXDB_QUERY_URI);
    queryUri.append(escaper.escape(m_query));

    m_logger.debug("Executing query: {} (host: {})",
            queryUri, getConnection().getAddress());

    HttpClientRequest request = doGet(queryUri.toString(), new HttpClientResponseAdapter() {

        @Override
        protected void handleFailure(final HttpClientResponse response) {
            if (response.statusCode() != 200) {
                m_logger.error("Failed to execute query: {} (host: {})",
                        m_query,
                        getConnection().getAddress(),
                        new IllegalStateException("HTTP get failure: "
                                + response.statusCode()
                                + "/"
                                + response.statusMessage()));
            }
        }
    });

    // HTTP basic authentication
    if (!Strings.isNullOrEmpty(m_adminUser)) {
        request.putHeader(HttpHeaders.Names.AUTHORIZATION, "Basic "
                + base64UserAndPassword(m_adminUser, m_adminPassword));
    }

    request.exceptionHandler(new DefaultConnectionExceptionHandler(
            getConnection()));
    request.end();
}
 
开发者ID:clidev,项目名称:spike.x,代码行数:38,代码来源:InfluxDb.java

示例5: doRequest

import org.vertx.java.core.http.HttpClientRequest; //导入方法依赖的package包/类
@Override
protected void doRequest(final HttpClient client) {
    
    final String uri = m_dweetPath + m_thingName;
    HttpClientRequest request = doPost(uri, new HttpClientResponseAdapter() {
        
        @Override
        protected void handleFailure(final HttpClientResponse response) {
            if (response.statusCode() != 204) {
                m_logger.error("Failed to publish event to: {} (host: {})",
                        uri,
                        getConnection().getAddress(),
                        new IllegalStateException("HTTP post failure: "
                                + response.statusCode()
                                + "/"
                                + response.statusMessage()));
            }
        }
    });
    
    m_logger.trace("Publishing event: {}", m_event);
    byte[] body = m_event.encode().getBytes();
    request.putHeader(CONTENT_TYPE, "application/json");
    request.putHeader(CONTENT_LENGTH, String.valueOf(body.length));
    request.exceptionHandler(new DefaultConnectionExceptionHandler(
            getConnection()));
    request.write(new Buffer(body));
    request.end();
}
 
开发者ID:clidev,项目名称:spike.x,代码行数:30,代码来源:Dweet.java

示例6: doRequest

import org.vertx.java.core.http.HttpClientRequest; //导入方法依赖的package包/类
@Override
protected void doRequest(final HttpClient client) {

    // Build form params
    final StringBuilder dataUri = new StringBuilder("XMLDATA=");
    dataUri.append(loadFileContents());

    HttpClientRequest request = doPost("/", new HttpClientResponseAdapter() {

        @Override
        protected void handleFailure(final HttpClientResponse response) {
            if (response.statusCode() != 200) {
                m_logger.error("Failed to send data to NRDP server: {} (host: {})",
                        dataUri.toString(),
                        getConnection().getAddress(),
                        new IllegalStateException("HTTP post failure: "
                                + response.statusCode()
                                + "/"
                                + response.statusMessage()));
            }
        }
    });

    byte[] body = dataUri.toString().getBytes();
    request.putHeader(CONTENT_LENGTH, String.valueOf(body.length));
    request.exceptionHandler(new DefaultConnectionExceptionHandler(
            getConnection()));
    request.write(new Buffer(body));
    request.end();
}
 
开发者ID:clidev,项目名称:spike.x,代码行数:31,代码来源:NagiosNrdpTest.java

示例7: doGet

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

    HttpClientAdapter adapter = new HttpClientAdapter(connection) {

        @Override
        protected void doRequest(final HttpClient client) {

            HttpClientRequest request = connection.getClient().get(getUri,
                    new Handler<HttpClientResponse>() {

                        @Override
                        public void handle(final HttpClientResponse response) {
                            httpHealthCheck(connection, response, handler);
                        }
                    });

            Handler<Throwable> exceptionHandler = exceptionHandler();
            if (exceptionHandler == null) {
                exceptionHandler = new DefaultConnectionExceptionHandler(connection);
            }

            request.exceptionHandler(exceptionHandler);
            request.end();
        }
    };
    connection.doRequest(adapter);
}
 
开发者ID:clidev,项目名称:spike.x,代码行数:31,代码来源:DefaultHttpConnectionHealthChecker.java

示例8: doRequest

import org.vertx.java.core.http.HttpClientRequest; //导入方法依赖的package包/类
@Override
protected void doRequest(final HttpClient client) {

    String uri = ES_PUBLISH_URI;
    HttpClientRequest request = doPost(uri, new HttpClientResponseAdapter() {

        @Override
        protected void handleFailure(final HttpClientResponse response) {
            if (response.statusCode() != 200) {
                m_logger.error("Failed to index events: {} (host: {} index: {})",
                        m_batchEvent.getString(EVENT_FIELD_ID),
                        getConnection().getAddress(),
                        m_indexSelector,
                        new IllegalStateException("HTTP post failure: "
                                + response.statusCode()
                                + "/"
                                + response.statusMessage()));
            }
        }
    });

    //
    // Operate on arrays only (batches)
    //
    JsonArray batch = m_batchEvent.getArray(EVENT_FIELD_BATCH_EVENTS, new JsonArray());
    if (!m_batchEvent.containsField(EVENT_FIELD_BATCH_EVENTS)) {
        batch.addObject(m_batchEvent);
    }

    //
    // Build bulk of json data to post
    // https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html
    //
    StringBuilder bulk = new StringBuilder();
    for (int i = 0; i < batch.size(); i++) {
        //
        // Translate index name and type from event contents (if needed)
        //
        JsonObject event = batch.get(i);
        String index = String.valueOf(m_variables.translate(event, m_indexSelector));
        String type = String.valueOf(m_variables.translate(event, m_indexType));

        // Action and meta data
        bulk.append("{\"index\":{\"_index\":\"");
        bulk.append(index);
        bulk.append("\",\"_type\":\"");
        bulk.append(type);
        bulk.append("\",\"_id\":\"");
        bulk.append(event.getString(EVENT_FIELD_ID));
        bulk.append("\"}}\n");
        // Index data
        bulk.append(event.toString());
        bulk.append("\n");
    }

    byte[] body = bulk.toString().getBytes();
    request.putHeader(CONTENT_LENGTH, String.valueOf(body.length));
    request.exceptionHandler(new DefaultConnectionExceptionHandler(
            getConnection()));
    request.write(new Buffer(body));
    request.end();
}
 
开发者ID:clidev,项目名称:spike.x,代码行数:63,代码来源:Elasticsearch.java


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