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


Java RequestBuilder.addHeader方法代码示例

本文整理汇总了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");
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:DefaultAhcBinding.java

示例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;
}
 
开发者ID:broamski,项目名称:cantilever,代码行数:18,代码来源:HTTPUtils.java

示例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;
}
 
开发者ID:broamski,项目名称:cantilever,代码行数:18,代码来源:HTTPUtils.java

示例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;
}
 
开发者ID:broamski,项目名称:cantilever,代码行数:15,代码来源:HTTPUtils.java

示例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());
		}
	}
 
开发者ID:broamski,项目名称:cantilever,代码行数:59,代码来源:HTTPAsyncPost.java

示例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());
		}
	}
 
开发者ID:broamski,项目名称:cantilever,代码行数:55,代码来源:HTTPAsyncGet.java

示例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));
	}
}
 
开发者ID:mjeanroy,项目名称:junit-servers,代码行数:12,代码来源:NingAsyncHttpRequest.java

示例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());
	}
}
 
开发者ID:mjeanroy,项目名称:junit-servers,代码行数:12,代码来源:NingAsyncHttpRequest.java


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