本文整理汇总了Java中org.vertx.java.core.http.HttpClientRequest.write方法的典型用法代码示例。如果您正苦于以下问题:Java HttpClientRequest.write方法的具体用法?Java HttpClientRequest.write怎么用?Java HttpClientRequest.write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.vertx.java.core.http.HttpClientRequest
的用法示例。
在下文中一共展示了HttpClientRequest.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doRequest
import org.vertx.java.core.http.HttpClientRequest; //导入方法依赖的package包/类
@Override
protected void doRequest(final HttpClient client) {
// Build post URI
StringBuilder postUri = new StringBuilder(m_query);
postUri.append(API_KEY_TOKEN);
postUri.append(m_token);
m_logger.trace("Executing post: {} (host: {})",
postUri, getConnection().getAddress());
HttpClientRequest request = doPost(postUri.toString(), m_responseHandler);
m_logger.trace("Posting data: {}", m_data);
byte[] body;
if (m_data.isObject()) {
body = ((JsonObject) m_data).encode().getBytes();
} else {
body = ((JsonArray) m_data).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();
}
示例2: httpPost
import org.vertx.java.core.http.HttpClientRequest; //导入方法依赖的package包/类
/**
* Performs a HTTP POST request on the specified address, using the body parameter for the request body
*
* @param persistor instance of the RestPersistor
* @param apiPath URL path to use for the request
* @param headers optional headers to set in the request
* @param body the JSON document to send in the body of the request
* @param timeout timeout for the HTTP connection
* @param msg the Vertx Message object to which the error message can be send
*/
protected void httpPost(ArangoPersistor persistor, String apiPath, JsonObject headers, JsonObject body, int timeout, Message<JsonObject> msg) {
// launch the request
HttpClientRequest clientRequest = persistor.getClient().post(apiPath, new RestResponseHandler(msg, logger, helper));
// set headers
clientRequest = addRequestHeaders(clientRequest, persistor, headers);
// set content-length before we write the body !
clientRequest.putHeader(HttpHeaders.CONTENT_LENGTH, Integer.toString(body.toString().length()));
// write the body
clientRequest.write(body.toString());
// end the request
clientRequest.setTimeout(timeout).end();
}
示例3: httpPut
import org.vertx.java.core.http.HttpClientRequest; //导入方法依赖的package包/类
/**
* Performs a HTTP PUT request on the specified address, using the body parameter for the request body
*
* @param persistor instance of the RestPersistor
* @param apiPath URL path to use for the request
* @param headers optional headers to set in the request
* @param body the JSON document to send in the body of the request
* @param timeout timeout for the HTTP connection
* @param msg the Vertx Message object to which the error message can be send
*/
protected void httpPut(ArangoPersistor persistor, String apiPath, JsonObject headers, JsonObject body, int timeout, Message<JsonObject> msg) {
// launch the request
HttpClientRequest clientRequest = persistor.getClient().put(apiPath, new RestResponseHandler(msg, logger, helper));
// set Headers and end the request
addRequestHeaders(clientRequest, persistor, headers);
if (body != null) {
// set content-length before we write the body !
clientRequest.putHeader(HttpHeaders.CONTENT_LENGTH, Integer.toString(body.toString().length()));
// write the body
clientRequest.write(body.toString());
}
// end the request
clientRequest.setTimeout(timeout).end();
}
示例4: httpPatch
import org.vertx.java.core.http.HttpClientRequest; //导入方法依赖的package包/类
/**
* Performs a HTTP PATCH request on the specified address, using the body parameter for the request body
*
* @param persistor instance of the RestPersistor
* @param apiPath URL path to use for the request
* @param headers optional headers to set in the request
* @param body the JSON document to send in the body of the request
* @param timeout timeout for the HTTP connection
* @param msg the Vertx Message object to which the error message can be send
*/
protected void httpPatch(ArangoPersistor persistor, String apiPath, JsonObject headers, JsonObject body, int timeout, Message<JsonObject> msg) {
// launch the request
HttpClientRequest clientRequest = persistor.getClient().patch(apiPath, new RestResponseHandler(msg, logger, helper));
// set headers
clientRequest = addRequestHeaders(clientRequest, persistor, headers);
// set content-length before we write the body !
clientRequest.putHeader(HttpHeaders.CONTENT_LENGTH, Integer.toString(body.toString().length()));
// write the body
clientRequest.write(body.toString());
// end the request
clientRequest.setTimeout(timeout).end();
}
示例5: 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();
}
示例6: 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();
}
示例7: 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();
}
示例8: doPost
import org.vertx.java.core.http.HttpClientRequest; //导入方法依赖的package包/类
private void doPost(
final HttpConnection connection,
final String message,
final int index) {
HttpClientAdapter adapter = new HttpClientAdapter(connection) {
private int m_counter;
@Override
protected void doRequest(final HttpClient client) {
HttpClientRequest request = client.post(NSQ_PUBLISH_URI, new HttpClientResponseAdapter() {
@Override
protected void handleFailure(final HttpClientResponse response) {
m_logger.error("Failed to post message {}: {}/{}",
index, response.statusCode(), response.statusMessage());
Assert.fail();
VertxAssert.testComplete();
}
});
byte[] body = message.getBytes();
request.putHeader(CONTENT_LENGTH, String.valueOf(body.length));
request.write(new Buffer(body));
request.end();
}
};
connection.doRequest(adapter);
}
示例9: 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();
}
示例10: postResponse
import org.vertx.java.core.http.HttpClientRequest; //导入方法依赖的package包/类
private void postResponse(final EventBusBridgeResponse response) {
httpClient.setHost(url.getHost());
httpClient.setPort(url.getPort());
HttpClientRequest request = httpClient.post(url.toExternalForm(), responseHandler);
request.setChunked(true);
request.headers().add("Content-Type", mediaType);
try {
String responseBody = SerializationHelper.serialize(response, mediaType);
request.write(responseBody);
request.end();
} catch (JsonProcessingException | JAXBException e) {
LOGGER.error("Unable to serialize response\n" + response + "\n to: " + mediaType);
}
}
示例11: sendAuthzError
import org.vertx.java.core.http.HttpClientRequest; //导入方法依赖的package包/类
@Override
public void sendAuthzError(ResourceState errorState, Resource resource, int status) throws Exception {
URI uri = this.destination.resolve(resource.id());
HttpClientRequest request = this.httpClient.put(uri.getPath(), (response) -> {
});
request.setChunked(true);
RequestContext requestContext = new RequestContext.Builder().build();
ByteBuf encoded = codec.encode(requestContext, errorState);
request.write(new Buffer(encoded));
request.end();
}
示例12: resourceUpdated
import org.vertx.java.core.http.HttpClientRequest; //导入方法依赖的package包/类
@Override
public void resourceUpdated(ResourceResponse resourceResponse) throws Exception {
URI uri = destinationUri(resourceResponse.resource());
HttpClientRequest request = this.httpClient.put(uri.getPath(), (response) -> {
});
request.setChunked(true);
RequestContext requestContext = new RequestContext.Builder().build();
ByteBuf encoded = codec.encode(requestContext, resourceResponse.state());
request.write(new Buffer(encoded));
request.end();
}
示例13: resourceDeleted
import org.vertx.java.core.http.HttpClientRequest; //导入方法依赖的package包/类
@Override
public void resourceDeleted(ResourceResponse resourceResponse) throws Exception {
URI uri = destinationUri(resourceResponse.resource());
HttpClientRequest request = this.httpClient.delete(uri.getPath(), (response) -> {
});
request.setChunked(true);
RequestContext requestContext = new RequestContext.Builder().build();
ByteBuf encoded = codec.encode(requestContext, resourceResponse.state());
request.write(new Buffer(encoded));
request.end();
}
示例14: 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();
}
示例15: doRequest
import org.vertx.java.core.http.HttpClientRequest; //导入方法依赖的package包/类
@Override
protected void doRequest(final HttpClient client) {
// Build write URI
StringBuilder queryUri = new StringBuilder(INFLUXDB_PUBLISH_URI);
queryUri.append(m_databaseName);
queryUri.append("&precision=");
queryUri.append(m_precision);
queryUri.append("&consistency=");
queryUri.append(m_consistency);
HttpClientRequest request = doPost(queryUri.toString(), new HttpClientResponseAdapter() {
@Override
protected void handleFailure(final HttpClientResponse response) {
if (response.statusCode() != 200) {
m_logger.error("Failed to write data points to InfluxDB: {} (host: {})",
m_points,
getConnection().getAddress(),
new IllegalStateException("HTTP post failure: "
+ response.statusCode()
+ "/"
+ response.statusMessage()));
}
}
});
StringBuilder bulk = new StringBuilder();
for (String point : m_points) {
bulk.append(point);
bulk.append("\n"); // https://influxdb.com/docs/v0.9/write_protocols/write_syntax.html
}
byte[] body = bulk.toString().getBytes();
request.putHeader(CONTENT_LENGTH, String.valueOf(body.length));
// HTTP basic authentication
if (!Strings.isNullOrEmpty(m_base64UserAndPassword)) {
request.putHeader(HttpHeaders.Names.AUTHORIZATION, "Basic "
+ m_base64UserAndPassword);
}
request.exceptionHandler(new DefaultConnectionExceptionHandler(
getConnection()));
request.write(new Buffer(body));
request.end();
}