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


Java HttpClientRequest.putHeader方法代码示例

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


在下文中一共展示了HttpClientRequest.putHeader方法的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();
}
 
开发者ID:clidev,项目名称:spike.x,代码行数:27,代码来源:Ubidots.java

示例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();
}
 
开发者ID:santo74,项目名称:vertx-arangodb,代码行数:26,代码来源:AbstractRestAPI.java

示例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();        
}
 
开发者ID:santo74,项目名称:vertx-arangodb,代码行数:28,代码来源:AbstractRestAPI.java

示例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();        
}
 
开发者ID:santo74,项目名称:vertx-arangodb,代码行数:26,代码来源:AbstractRestAPI.java

示例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();
}
 
开发者ID:clidev,项目名称:spike.x,代码行数:35,代码来源:Flowdock.java

示例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();
}
 
开发者ID:clidev,项目名称:spike.x,代码行数:34,代码来源:NsqHttp.java

示例7: 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

示例8: 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

示例9: 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);
}
 
开发者ID:clidev,项目名称:spike.x,代码行数:33,代码来源:NsqInTest.java

示例10: 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

示例11: addRequestHeaders

import org.vertx.java.core.http.HttpClientRequest; //导入方法依赖的package包/类
protected HttpClientRequest addRequestHeaders(HttpClientRequest clientRequest, ArangoPersistor persistor, JsonObject headers) {
    // set headers
    if (persistor.getCredentials() != null) clientRequest.putHeader(HttpHeaders.AUTHORIZATION, "Basic " + persistor.getCredentials());
    if (headers != null) {
        for (String header : headers.getFieldNames()) {
            clientRequest.putHeader(header, headers.getString(header));
        }
    }
    
    return clientRequest;
}
 
开发者ID:santo74,项目名称:vertx-arangodb,代码行数:12,代码来源:AbstractRestAPI.java

示例12: 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

示例13: hardBounces

import org.vertx.java.core.http.HttpClientRequest; //导入方法依赖的package包/类
@Override
public void hardBounces(Date startDate, Date endDate, final Handler<Either<String, List<Bounce>>> handler) {
	if (startDate == null) {
		handler.handle(new Either.Left<String, List<Bounce>>("invalid.date"));
		return;
	}
	final DateFormat df = new SimpleDateFormat(DATE_FORMAT);
	final JsonObject payload = new JsonObject().putString("event", "hard_bounce");
	final String start = df.format(startDate);
	if (endDate != null) {
		payload.putString("start_date", start).putString("end_date", df.format(endDate));
	} else {
		payload.putString("date", start);
	}
	HttpClientRequest req = httpClient.post("/v2.0/report", new Handler<HttpClientResponse>() {
		@Override
		public void handle(final HttpClientResponse resp) {
			resp.bodyHandler(new Handler<Buffer>() {
				@Override
				public void handle(Buffer buffer) {
					try {
						JsonObject res = new JsonObject(buffer.toString());
						if ("success".equals(res.getString("code"))) {
							JsonArray l = res.getArray("data");
							if (l == null || l.size() == 0) {
								handler.handle(new Either.Right<String, List<Bounce>>(
										Collections.<Bounce>emptyList()));
								return;
							}
							List<Bounce> bounces = mapper.readValue(l.encode(),
									new TypeReference<List<Bounce>>(){});
							handler.handle(new Either.Right<String, List<Bounce>>(bounces));
						} else {
							handler.handle(new Either.Left<String, List<Bounce>>(
									res.getValue("message").toString()));
						}
					} catch (RuntimeException | IOException e) {
						handler.handle(new Either.Left<String, List<Bounce>>(e.getMessage()));
						log.error(e.getMessage(), e);
					}
				}
			});
		}
	});
	req.putHeader("api-key", apiKey);
	req.end(payload.encode());
}
 
开发者ID:web-education,项目名称:web-utils,代码行数:48,代码来源:SendInBlueSender.java

示例14: send

import org.vertx.java.core.http.HttpClientRequest; //导入方法依赖的package包/类
private void send(JsonObject json, final Handler<Message<JsonObject>> handler) {
	HttpClientRequest req = httpClient.post("/smtp/" + this.platform, new Handler<HttpClientResponse>() {
		@Override
		public void handle(HttpClientResponse resp) {
			if (resp.statusCode() == 200) {
				handler.handle(new ResultMessage());
			} else {
				handler.handle(new ResultMessage().error("GoMail HTTP status: " + resp.statusMessage()));					
			}
		}
	});
	req.putHeader("authorization", basicAuthHeader);
	JsonObject to = new JsonObject();
	JsonObject from = new JsonObject();
	JsonObject subject = new JsonObject();
	JsonObject headers = new JsonObject();

	to.putString("address", json.getArray("to").get(0).toString());

	from.putString("address", json.getString("from"));
	subject.putString("Subject", json.getString("subject"));

	JsonObject payload = new JsonObject().putObject("from", from)
			.putObject("to", to)
			.putString("subject", json.getString("subject"))
			.putString("body", json.getString("body"));

	/* TODO: Uncomment when GoMail supports multiple recipients
	if (json.getArray("cc") != null && json.getArray("cc").size() > 0) {
		JsonArray cc = new JsonArray();
		for (Object o : json.getArray("cc")) {
			JsonObject ccRecipient = new JsonObject();
			ccRecipient.putString("address", o.toString());
			cc.add(ccRecipient);
		}
		payload.putArray("cc", cc);
	}
	if (json.getArray("bcc") != null && json.getArray("bcc").size() > 0) {
		JsonArray bcc = new JsonArray();
		for (Object o : json.getArray("bcc")) {
			JsonObject bccRecipient = new JsonObject();
			bccRecipient.putString("address", o.toString());
			bcc.add(bccRecipient);
		}
		payload.putArray("bcc", bcc);
	}
	*/

	if (json.getArray("headers") != null) {
		for (Object o : json.getArray("headers")) {
			if (!(o instanceof JsonObject))
				continue;
			JsonObject h = (JsonObject) o;
			headers.putString(h.getString("name"), h.getString("value"));
		}
	}
	if (headers.size() > 0) {
		payload.putObject("headers", headers);
	}
	req.end(payload.encode());
}
 
开发者ID:web-education,项目名称:web-utils,代码行数:62,代码来源:GoMailSender.java

示例15: hardBounces

import org.vertx.java.core.http.HttpClientRequest; //导入方法依赖的package包/类
@Override
public void hardBounces(Date startDate, Date endDate, final Handler<Either<String, List<Bounce>>> handler) {
	if (startDate == null) {
		handler.handle(new Either.Left<String, List<Bounce>>("invalid.date"));
		return;
	}
	final DateFormat df = new SimpleDateFormat(DATE_FORMAT);
	final String start = df.format(startDate);
	HttpClientRequest req = httpClient.get("/bounce/hard/since/" + start, new Handler<HttpClientResponse>() {
		@Override
		public void handle(final HttpClientResponse resp) {
			if (resp.statusCode() == 200) {
				resp.bodyHandler(new Handler<Buffer>() {
					@Override
					public void handle(Buffer buffer) {
						try {
							JsonObject res = new JsonObject(buffer.toString());

							JsonArray l = res.getArray("hard_bounces");
							if (l == null || l.size() == 0) {
								handler.handle(
										new Either.Right<String, List<Bounce>>(Collections.<Bounce>emptyList()));
								return;
							}
							List<Bounce> bounces = mapper.readValue(l.encode(), new TypeReference<List<Bounce>>() {
							});
							handler.handle(new Either.Right<String, List<Bounce>>(bounces));

						} catch (RuntimeException | IOException e) {
							handler.handle(new Either.Left<String, List<Bounce>>(e.getMessage()));
							log.error(e.getMessage(), e);
						}
					}
				});
			} else {
				handler.handle(new Either.Left<String, List<Bounce>>("GoMail HTTP status: " + resp.statusMessage()));
			}
		}
	});
	req.putHeader("authorization", basicAuthHeader);
	req.end();
}
 
开发者ID:web-education,项目名称:web-utils,代码行数:43,代码来源:GoMailSender.java


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