本文整理汇总了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()));
}
}
示例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);
}
}
}
});
}
示例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);
}
}