List of usage examples for org.apache.commons.httpclient Header Header
public Header(String paramString1, String paramString2)
From source file:ch.ksfx.web.services.spidering.http.HttpUserAgentHeaders.java
public static HttpUserAgentHeaders getDefaultHeaders() { HttpUserAgentHeaders headers = new HttpUserAgentHeaders(); headers.addHeader(new Header("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)")); headers.addHeader(new Header("Accept", "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*")); headers.addHeader(new Header("Accept-Language", "de-ch")); headers.addHeader(new Header("Accept-Encoding", "gzip, deflate")); headers.addHeader(new Header("Connection", "Keep-Alive")); return headers; }
From source file:ch.ksfx.web.services.spidering.http.HttpUserAgentHeaders.java
public void addHeader(String headerName, String headerValue) { this.headers.add(new Header(headerName, headerValue)); }
From source file:com.ibm.stocator.fs.swift.SwiftAPIDirect.java
/** * GET object//www. j av a2 s .c om * * @param path path to object * @param authToken authentication token * @param bytesFrom from from * @param bytesTo bytes to * @return SwiftGETResponse that includes input stream and length * @throws IOException if network errors */ public static SwiftGETResponse getObject(Path path, String authToken, long bytesFrom, long bytesTo) throws IOException { GetMethod method = new GetMethod(path.toString()); method.addRequestHeader(new Header("X-Auth-Token", authToken)); if (bytesTo > 0) { final String rangeValue = String.format("bytes=%d-%d", bytesFrom, bytesTo); method.addRequestHeader(new Header(Constants.RANGES_HTTP_HEADER, rangeValue)); } HttpMethodParams methodParams = method.getParams(); methodParams.setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); methodParams.setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, 15000); methodParams.setSoTimeout(60000); method.addRequestHeader(Constants.USER_AGENT_HTTP_HEADER, Constants.STOCATOR_USER_AGENT); final HttpClient client = new HttpClient(); int statusCode = client.executeMethod(method); SwiftInputStreamWrapper httpStream = new SwiftInputStreamWrapper(method); SwiftGETResponse getResponse = new SwiftGETResponse(httpStream, method.getResponseContentLength()); return getResponse; }
From source file:de.kapsi.net.daap.DaapHeaderConstructor.java
/** * Creates a new Chunk Header// ww w . j ava2 s . com * * @param request * @param contentLength * @return */ public static byte[] createChunkHeader(DaapRequest request, int contentLength) { try { DaapConnection connection = request.getConnection(); String serverName = connection.getServer().getConfig().getServerName(); ArrayList headers = new ArrayList(); headers.add(new Header("Date", DaapUtil.now())); headers.add(new Header("DAAP-Server", serverName)); headers.add(new Header("Content-Type", "application/x-dmap-tagged")); headers.add(new Header("Content-Length", Integer.toString(contentLength))); if (DaapUtil.COMPRESS) { headers.add(new Header("Content-Encoding", "gzip")); } return toByteArray(HTTP_OK, (Header[]) headers.toArray(new Header[0])); } catch (UnsupportedEncodingException err) { // Should never happen throw new RuntimeException(err); } catch (IOException err) { // Should never happen throw new RuntimeException(err); } }
From source file:com.appdynamics.extensions.apptweak.Stats.java
public Map<String, Object> getAppRating(MobileApplication app, String token) { Map<String, Object> appRatingMap = new HashMap<>(); HttpClient httpClient = new HttpClient(); Map<String, String> body = new HashMap<>(); JsonParser parser = new JsonParser(); String breadcrumb = "content."; body.put("country", app.getCountry()); body.put("language", app.getLanguage()); Header[] header = new Header[1]; header[0] = new Header("X-Apptweak-Key", token); HttpClient.Response<String> response = httpClient.get("https://api.apptweak.com/" + app.getReligion() + "/applications/" + app.getApplicationId() + "/ratings.json", body, header); if (response.statusCode != 200) { logger.error("Error: HTTP response code: " + response.statusCode + " | Message: " + response.getBody()); }/* w w w .j a v a2 s . c o m*/ if (app.getReligion().toLowerCase().equals("android")) { appRatingMap.put("average", parser.parseString(response.getBody(), "content.average").replace(".", "").substring(0, 4)); appRatingMap.put("count", parser.parseString(response.getBody(), "content.count")); appRatingMap.put("1", parser.parseString(response.getBody(), "content.star_count.1")); appRatingMap.put("2", parser.parseString(response.getBody(), "content.star_count.2")); appRatingMap.put("3", parser.parseString(response.getBody(), "content.star_count.3")); appRatingMap.put("4", parser.parseString(response.getBody(), "content.star_count.4")); appRatingMap.put("5", parser.parseString(response.getBody(), "content.star_count.5")); } else if (app.getReligion().toLowerCase().equals("ios")) { appRatingMap.put("average", parser.parseString(response.getBody(), "content.current_version.average") .replace(".", "").substring(0, 4)); appRatingMap.put("count", parser.parseString(response.getBody(), "content.current_version.count")); appRatingMap.put("1", parser.parseString(response.getBody(), "content.current_version.star_count.1")); appRatingMap.put("2", parser.parseString(response.getBody(), "content.current_version.star_count.2")); appRatingMap.put("3", parser.parseString(response.getBody(), "content.current_version.star_count.3")); appRatingMap.put("4", parser.parseString(response.getBody(), "content.current_version.star_count.4")); appRatingMap.put("5", parser.parseString(response.getBody(), "content.current_version.star_count.5")); } else { throw new RuntimeException(); } return appRatingMap; }
From source file:com.greenbird.mule.http.log.RequestPropertiesRetainerTest.java
@Test public void transformMessage_normal_relevantPropertiesRetained() throws Exception { HttpRequest request = new HttpRequest(new RequestLine("GET", REQUEST, HttpVersion.HTTP_1_1), new Header[] { new Header("testHeader", "testValue") }, ENCODING); MuleMessage message = new HttpMuleMessageFactory(context()).create(request, "UTF-8"); retainer.retainRequestProperties(message); Map<String, Object> retainedProperties = message .getInvocationProperty(RequestPropertiesRetainer.INITIAL_REQUEST_PROPERTY); assertThat(retainedProperties.size(), is(7)); @SuppressWarnings("unchecked") Map<String, String> headers = (Map<String, String>) retainedProperties.get(HttpConnector.HTTP_HEADERS); assertThat(headers.get("testHeader"), is("testValue")); assertThat(retainedProperties.get(HttpConnector.HTTP_METHOD_PROPERTY).toString(), is("GET")); assertThat(retainedProperties.get(HttpConnector.HTTP_VERSION_PROPERTY).toString(), is("HTTP/1.1")); assertThat(retainedProperties.get(HttpConnector.HTTP_REQUEST_PROPERTY).toString(), is(REQUEST)); assertThat(retainedProperties.get(HttpConnector.HTTP_QUERY_STRING).toString(), is("query=value")); }
From source file:lucee.commons.net.http.httpclient3.HttpMethodCloner.java
/** * Clones a HttpMethod. <br>/*w w w. jav a2s . c o m*/ * <b>Attention:</b> You have to clone a method before it has * been executed, because the URI can change if followRedirects * is set to true. * * @param m the HttpMethod to clone * * @return the cloned HttpMethod, null if the HttpMethod could * not be instantiated * * @throws java.io.IOException if the request body couldn't be read */ public static HttpMethod clone(HttpMethod m) { HttpMethod copy = null; try { copy = m.getClass().newInstance(); } catch (InstantiationException iEx) { } catch (IllegalAccessException iaEx) { } if (copy == null) { return null; } copy.setDoAuthentication(m.getDoAuthentication()); copy.setFollowRedirects(m.getFollowRedirects()); copy.setPath(m.getPath()); copy.setQueryString(m.getQueryString()); Header[] h = m.getRequestHeaders(); int size = (h == null) ? 0 : h.length; for (int i = 0; i < size; i++) { copy.setRequestHeader(new Header(h[i].getName(), h[i].getValue())); } copy.setStrictMode(m.isStrictMode()); if (m instanceof HttpMethodBase) { copyHttpMethodBase((HttpMethodBase) m, (HttpMethodBase) copy); } if (m instanceof EntityEnclosingMethod) { copyEntityEnclosingMethod((EntityEnclosingMethod) m, (EntityEnclosingMethod) copy); } return copy; }
From source file:DBpediaSpotlightClient.java
@Override public List<DBpediaResource> extract(Text text) throws AnnotationException { LOG.info("Querying API."); String spotlightResponse;/*from w w w . j a va 2s . c o m*/ try { GetMethod getMethod = new GetMethod(API_URL + "rest/annotate/?" + "confidence=" + CONFIDENCE + "&support=" + SUPPORT + "&text=" + URLEncoder.encode(text.text(), "utf-8")); getMethod.addRequestHeader(new Header("Accept", "application/json")); spotlightResponse = request(getMethod); } catch (UnsupportedEncodingException e) { throw new AnnotationException("Could not encode text.", e); } assert spotlightResponse != null; JSONObject resultJSON = null; JSONArray entities = null; try { resultJSON = new JSONObject(spotlightResponse); entities = resultJSON.getJSONArray("Resources"); } catch (JSONException e) { throw new AnnotationException("Received invalid response from DBpedia Spotlight API."); } LinkedList<DBpediaResource> resources = new LinkedList<DBpediaResource>(); for (int i = 0; i < entities.length(); i++) { try { JSONObject entity = entities.getJSONObject(i); resources.add(new DBpediaResource(entity.getString("@URI"), Integer.parseInt(entity.getString("@support")))); } catch (JSONException e) { LOG.error("JSON exception " + e); } } return resources; }
From source file:documentToVector.spotlight.evaluation.external.DBpediaSpotlightClient.java
@Override public List<DBpediaResource> extract(Text text) throws AnnotationException { LOG.info("Querying API."); String spotlightResponse;/*from w w w . jav a 2s .co m*/ try { GetMethod getMethod = new GetMethod(API_URL + "rest/annotate/?" + "confidence=" + CONFIDENCE + "&support=" + SUPPORT + "&text=" + URLEncoder.encode(text.text(), "utf-8")); getMethod.addRequestHeader(new Header("Accept", "application/json")); spotlightResponse = request(getMethod); } catch (UnsupportedEncodingException e) { throw new AnnotationException("Could not encode text.", e); } assert spotlightResponse != null; JSONObject resultJSON = null; JSONArray entities = null; try { resultJSON = new JSONObject(spotlightResponse); entities = resultJSON.getJSONArray("Resources"); } catch (JSONException e) { throw new AnnotationException("Received invalid response from DBpedia Spotlight API."); } LinkedList<DBpediaResource> resources = new LinkedList<DBpediaResource>(); for (int i = 0; i < entities.length(); i++) { try { JSONObject entity = entities.getJSONObject(i); resources.add(new DBpediaResource(entity.getString("@URI"), Integer.parseInt(entity.getString("@support"))) ); } catch (JSONException e) { LOG.error("JSON exception " + e); } } return resources; }
From source file:com.wandisco.s3hdfs.rewrite.redirect.Redirect.java
Redirect(HttpServletRequest request, HttpServletResponse response, S3HdfsPath path) { this.request = request; this.response = response; this.path = path; httpClient.getParams().setParameter("http.default-headers", Arrays.asList(new Header("Connection", "Keep-Alive"))); }