List of usage examples for org.apache.http.protocol HTTP USER_AGENT
String USER_AGENT
To view the source code for org.apache.http.protocol HTTP USER_AGENT.
Click Source Link
From source file:org.apache.synapse.transport.passthru.util.PassThroughTransportUtils.java
/** * Remove unwanted headers from the given header map. * * @param headers http header map * @param targetConfiguration configurations for the passThrough transporter */// w w w . j av a2 s.c o m private static void removeUnwantedHeadersFromHeaderMap(Map headers, TargetConfiguration targetConfiguration) { Iterator iter = headers.keySet().iterator(); while (iter.hasNext()) { String headerName = (String) iter.next(); if (HTTP.CONN_DIRECTIVE.equalsIgnoreCase(headerName) || HTTP.TRANSFER_ENCODING.equalsIgnoreCase(headerName)) { iter.remove(); } if (HTTP.CONN_KEEP_ALIVE.equalsIgnoreCase(headerName) && !targetConfiguration.isPreserveHttpHeader(HTTP.CONN_KEEP_ALIVE)) { iter.remove(); } if (HTTP.CONTENT_LEN.equalsIgnoreCase(headerName) && !targetConfiguration.isPreserveHttpHeader(HTTP.CONTENT_LEN)) { iter.remove(); } if (HTTP.CONTENT_TYPE.equalsIgnoreCase(headerName) && !targetConfiguration.isPreserveHttpHeader(HTTP.CONTENT_TYPE)) { iter.remove(); } if (HTTP.DATE_HEADER.equalsIgnoreCase(headerName) && !targetConfiguration.isPreserveHttpHeader(HTTP.DATE_HEADER)) { iter.remove(); } if (HTTP.SERVER_HEADER.equalsIgnoreCase(headerName) && !targetConfiguration.isPreserveHttpHeader(HTTP.SERVER_HEADER)) { iter.remove(); } if (HTTP.USER_AGENT.equalsIgnoreCase(headerName) && !targetConfiguration.isPreserveHttpHeader(HTTP.USER_AGENT)) { iter.remove(); } } }
From source file:org.opennms.core.web.HttpClientWrapper.java
/** * Execute the given HTTP method, returning an HTTP response. * /* ww w.j av a 2 s .co 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); }
From source file:org.opennms.netmgt.ncs.northbounder.NCSNorthbounder.java
private void postAlarms(HttpEntity entity) { //Need a configuration bean for these int connectionTimeout = 3000; int socketTimeout = 3000; Integer retryCount = 3;//from w w w . j a va2 s. c o m HttpVersion httpVersion = determineHttpVersion(m_config.getHttpVersion()); URI uri = m_config.getURI(); System.err.println("uri = " + uri); final HttpClientWrapper clientWrapper = HttpClientWrapper.create().setSocketTimeout(socketTimeout) .setConnectionTimeout(connectionTimeout).setRetries(retryCount).useBrowserCompatibleCookies() .dontReuseConnections(); if ("https".equals(uri.getScheme())) { try { clientWrapper.useRelaxedSSL("https"); } catch (final GeneralSecurityException e) { throw new NorthbounderException("Failed to configure Relaxed SSL handling.", e); } } final HttpEntityEnclosingRequestBase method = m_config.getMethod().getRequestMethod(uri); if (m_config.getVirtualHost() != null && !m_config.getVirtualHost().trim().isEmpty()) { method.setHeader(HTTP.TARGET_HOST, m_config.getVirtualHost()); } if (m_config.getUserAgent() != null && !m_config.getUserAgent().trim().isEmpty()) { method.setHeader(HTTP.USER_AGENT, m_config.getUserAgent()); } method.setProtocolVersion(httpVersion); method.setEntity(entity); CloseableHttpResponse response = null; try { System.err.println("execute: " + method); response = clientWrapper.execute(method); } catch (ClientProtocolException e) { throw new NorthbounderException(e); } catch (IOException e) { throw new NorthbounderException(e); } finally { IOUtils.closeQuietly(clientWrapper); } if (response != null) { try { int code = response.getStatusLine().getStatusCode(); final HttpResponseRange range = new HttpResponseRange("200-399"); if (!range.contains(code)) { LOG.warn("response code out of range for uri: {}. Expected {} but received {}", uri, range, code); throw new NorthbounderException("response code out of range for uri:" + uri + ". Expected " + range + " but received " + code); } } finally { IOUtils.closeQuietly(clientWrapper); } } LOG.debug(response != null ? response.getStatusLine().getReasonPhrase() : "Response was null"); }
From source file:org.yamj.core.service.metadata.online.SearchEngineTools.java
private DigestedResponse requestContent(CharSequence cs) throws IOException { HttpGet httpGet = new HttpGet(cs.toString()); httpGet.setHeader(HTTP.USER_AGENT, "Mozilla/6.0 (Windows NT 6.2; WOW64; rv:16.0.1) Gecko/20121011 Firefox/16.0.1"); return httpClient.requestContent(httpGet, charset); }