List of usage examples for org.apache.http.client.methods HttpRequestWrapper setHeader
public void setHeader(String str, String str2)
From source file:org.opennms.core.web.HttpClientWrapper.java
/** * Execute the given HTTP method, returning an HTTP response. * // ww w. ja va2s. c o m * Note that when you are done with the response, you must call {@link #closeResponse()} so that it gets cleaned up properly. */ public CloseableHttpResponse execute(final HttpUriRequest method) throws ClientProtocolException, IOException { LOG.debug("execute: " + this.toString() + "; method: " + method.toString()); // override some headers with our versions final HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(method); if (!isEmpty(m_userAgent)) { requestWrapper.setHeader(HTTP.USER_AGENT, m_userAgent); } if (!isEmpty(m_virtualHost)) { requestWrapper.setHeader(HTTP.TARGET_HOST, m_virtualHost); } if (m_version != null) { if (HttpVersion.HTTP_1_1.equals(m_version) && isEmpty(m_virtualHost)) { // NMS-7506, set HTTP version to 1.0 if virtual host is not set (since 1.1 requires a virtual host) requestWrapper.setProtocolVersion(HttpVersion.HTTP_1_0); } else { requestWrapper.setProtocolVersion(m_version); } } return getClient().execute(requestWrapper); }