本文整理汇总了Java中com.ning.http.client.RequestBuilder.addHeader方法的典型用法代码示例。如果您正苦于以下问题:Java RequestBuilder.addHeader方法的具体用法?Java RequestBuilder.addHeader怎么用?Java RequestBuilder.addHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.ning.http.client.RequestBuilder
的用法示例。
在下文中一共展示了RequestBuilder.addHeader方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: populateHeaders
import com.ning.http.client.RequestBuilder; //导入方法依赖的package包/类
protected void populateHeaders(RequestBuilder builder, AhcEndpoint endpoint, Exchange exchange) {
HeaderFilterStrategy strategy = endpoint.getHeaderFilterStrategy();
// propagate headers as HTTP headers
for (Map.Entry<String, Object> entry : exchange.getIn().getHeaders().entrySet()) {
String headerValue = exchange.getIn().getHeader(entry.getKey(), String.class);
if (strategy != null && !strategy.applyFilterToCamelHeaders(entry.getKey(), headerValue, exchange)) {
if (log.isTraceEnabled()) {
log.trace("Adding header {} = {}", entry.getKey(), headerValue);
}
builder.addHeader(entry.getKey(), headerValue);
}
}
if (endpoint.isConnectionClose()) {
builder.addHeader("Connection", "close");
}
}
示例2: buildCustomGETHeaders
import com.ning.http.client.RequestBuilder; //导入方法依赖的package包/类
public RequestBuilder buildCustomGETHeaders(RequestBuilder request, HTTPLogObject http_log) {
String one_time_GET_header = GETHeaderCache.instance.fetchPayload(http_log.getRequest());
String header_delimiter = ConfigurationSingleton.instance
.getConfigItem("replay.request.headers.delimiter");
String[] headers = one_time_GET_header.split(header_delimiter);
for (int i = 0; i < headers.length; i++) {
try {
String header_key = headers[i].split(":")[0].trim();
String header_value = headers[i].split(":")[1].trim();
request.addHeader(header_key, header_value);
}
catch (Exception e) {
logger.trace("No or invalid header detected for " + http_log.getRequest() + ".");
}
}
return request;
}
示例3: buildCustomPOSTHeaders
import com.ning.http.client.RequestBuilder; //导入方法依赖的package包/类
public RequestBuilder buildCustomPOSTHeaders(RequestBuilder request, HTTPLogObject http_log) {
String one_time_POST_header = POSTHeaderCache.instance.fetchPayload(http_log.getRequest());
String header_delimiter = ConfigurationSingleton.instance
.getConfigItem("replay.request.headers.delimiter");
String[] headers = one_time_POST_header.split(header_delimiter);
for (int i = 0; i < headers.length; i++) {
try {
String header_key = headers[i].split(":")[0].trim();
String header_value = headers[i].split(":")[1].trim();
request.addHeader(header_key, header_value);
}
catch (Exception e) {
logger.trace("No or invalid header detected for " + http_log.getRequest() + ".");
}
}
return request;
}
示例4: buildDefaultHeaders
import com.ning.http.client.RequestBuilder; //导入方法依赖的package包/类
public RequestBuilder buildDefaultHeaders(RequestBuilder request, HTTPLogObject http_log) {
String headers[] = http_log.getHeaders();
for (int i = 0; i < headers.length; i++) {
try {
String header_key = headers[i].split(":")[0].trim();
String header_value = headers[i].split(":")[1].trim();
request.addHeader(header_key, header_value);
}
catch (Exception e) {
logger.trace("No or invalid header detected for " + http_log.getRequest() + ".");
}
}
return request;
}
示例5: HTTPAsyncPost
import com.ning.http.client.RequestBuilder; //导入方法依赖的package包/类
public HTTPAsyncPost(AsyncHttpClient client, HTTPLogObject http_log) {
RequestBuilder builder = new RequestBuilder("POST");
url_request = http_log.getURLRequest();
HTTPUtils util = new HTTPUtils();
builder = util.buildDefaultHeaders(builder, http_log);
// Add additional POST headers, if specified
builder = util.buildCustomPOSTHeaders(builder, http_log);
builder.addHeader("User-Agent", http_log.getUseragent());
String one_time_payload = POSTPayloadCache.instance.fetchPayload(http_log.getRequest());
logger.debug("Here is the randomized payload: " + one_time_payload);
builder.setBody(one_time_payload);
Request request = builder.setUrl(http_log.getURLRequest()).build();
AsyncHandler<Response> asyncHandler = new AsyncHandler<Response>() {
private final Response.ResponseBuilder builder = new Response.ResponseBuilder();
public STATE onBodyPartReceived(final HttpResponseBodyPart content)
throws Exception {
builder.accumulate(content);
return STATE.CONTINUE;
}
public STATE onStatusReceived(final HttpResponseStatus status)
throws Exception {
builder.accumulate(status);
return STATE.CONTINUE;
}
public STATE onHeadersReceived(final HttpResponseHeaders headers)
throws Exception {
builder.accumulate(headers);
return STATE.CONTINUE;
}
public Response onCompleted() throws Exception {
logger.debug("POST - " + url_request + " - "
+ builder.build().getStatusCode());
return builder.build();
}
@Override
public void onThrowable(Throwable t) {
logger.error(t.getMessage());
}
};
try {
client.executeRequest(request, asyncHandler);
} catch (IOException e) {
logger.error(e.getMessage());
}
}
示例6: HTTPAsyncGet
import com.ning.http.client.RequestBuilder; //导入方法依赖的package包/类
public HTTPAsyncGet(AsyncHttpClient client, HTTPLogObject http_log) {
RequestBuilder builder = new RequestBuilder("GET");
url_request = http_log.getURLRequest();
HTTPUtils util = new HTTPUtils();
builder = util.buildDefaultHeaders(builder, http_log);
// Add additional GET headers, if specified
builder = util.buildCustomGETHeaders(builder, http_log);
builder.addHeader("User-Agent", http_log.getUseragent());
Request request = builder.setUrl(url_request).build();
AsyncHandler<Response> asyncHandler = new AsyncHandler<Response>() {
private final Response.ResponseBuilder builder = new Response.ResponseBuilder();
public STATE onBodyPartReceived(final HttpResponseBodyPart content)
throws Exception {
builder.accumulate(content);
return STATE.CONTINUE;
}
public STATE onStatusReceived(final HttpResponseStatus status)
throws Exception {
builder.accumulate(status);
return STATE.CONTINUE;
}
public STATE onHeadersReceived(final HttpResponseHeaders headers)
throws Exception {
builder.accumulate(headers);
return STATE.CONTINUE;
}
public Response onCompleted() throws Exception {
logger.debug("GET - " + url_request + " - "
+ builder.build().getStatusCode());
return builder.build();
}
@Override
public void onThrowable(Throwable t) {
logger.error(t.getMessage());
}
};
try {
client.executeRequest(request, asyncHandler);
} catch (IOException e) {
logger.error(e.getMessage());
}
}
示例7: handleCookies
import com.ning.http.client.RequestBuilder; //导入方法依赖的package包/类
/**
* Add cookies to the final HTTP request.
*
* @param builder The pending HTTP request.
* @see RequestBuilder#addCookie(com.ning.http.client.cookie.Cookie)
*/
private void handleCookies(RequestBuilder builder) {
if (!cookies.isEmpty()) {
builder.addHeader(HttpHeaders.COOKIE, Cookies.serialize(cookies));
}
}
示例8: handleHeaders
import com.ning.http.client.RequestBuilder; //导入方法依赖的package包/类
/**
* Add request headers.
*
* @param builder The pending HTTP request.
* @see RequestBuilder#addHeader(String, String)
*/
private void handleHeaders(RequestBuilder builder) {
for (HttpHeader header : headers.values()) {
builder.addHeader(header.getName(), header.serializeValues());
}
}