List of usage examples for org.apache.http.client.methods HttpHead HttpHead
public HttpHead(final String uri)
From source file:com.woonoz.proxy.servlet.HttpHeadRequestHandler.java
@Override protected HttpRequestBase createHttpRequestBase(URI targetUri) { return new HttpHead(targetUri); }
From source file:org.dojotoolkit.zazl.internal.XMLHttpRequestUtils.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public static String xhrRequest(String shrDataString) { InputStream is = null;//from w ww .jav a 2 s.c o m String json = null; try { logger.logp(Level.FINER, XMLHttpRequestUtils.class.getName(), "xhrRequest", "shrDataString [" + shrDataString + "]"); Map<String, Object> xhrData = (Map<String, Object>) JSONParser.parse(new StringReader(shrDataString)); String url = (String) xhrData.get("url"); String method = (String) xhrData.get("method"); List headers = (List) xhrData.get("headers"); URL requestURL = createURL(url); URI uri = new URI(requestURL.toString()); HashMap httpMethods = new HashMap(7); httpMethods.put("DELETE", new HttpDelete(uri)); httpMethods.put("GET", new HttpGet(uri)); httpMethods.put("HEAD", new HttpHead(uri)); httpMethods.put("OPTIONS", new HttpOptions(uri)); httpMethods.put("POST", new HttpPost(uri)); httpMethods.put("PUT", new HttpPut(uri)); httpMethods.put("TRACE", new HttpTrace(uri)); HttpUriRequest request = (HttpUriRequest) httpMethods.get(method.toUpperCase()); if (request.equals(null)) { throw new Error("SYNTAX_ERR"); } for (Object header : headers) { StringTokenizer st = new StringTokenizer((String) header, ":"); String name = st.nextToken(); String value = st.nextToken(); request.addHeader(name, value); } HttpClient client = new DefaultHttpClient(); HttpResponse response = client.execute(request); Map headerMap = new HashMap(); HeaderIterator headerIter = response.headerIterator(); while (headerIter.hasNext()) { Header header = headerIter.nextHeader(); headerMap.put(header.getName(), header.getValue()); } int status = response.getStatusLine().getStatusCode(); String statusText = response.getStatusLine().toString(); is = response.getEntity().getContent(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line = null; StringBuffer sb = new StringBuffer(); while ((line = br.readLine()) != null) { sb.append(line); sb.append('\n'); } Map m = new HashMap(); m.put("status", new Integer(status)); m.put("statusText", statusText); m.put("responseText", sb.toString()); m.put("headers", headerMap.toString()); StringWriter w = new StringWriter(); JSONSerializer.serialize(w, m); json = w.toString(); logger.logp(Level.FINER, XMLHttpRequestUtils.class.getName(), "xhrRequest", "json [" + json + "]"); } catch (Throwable e) { logger.logp(Level.SEVERE, XMLHttpRequestUtils.class.getName(), "xhrRequest", "Failed request for [" + shrDataString + "]", e); } finally { if (is != null) { try { is.close(); } catch (IOException e) { } } } return json; }
From source file:com.brokenevent.nanotests.http.TestHeadRequest.java
/** * Initializes instance of the GET request for the given resource. * @param resource resource name//from w ww . j av a 2 s .com */ public TestHeadRequest(String resource) { super(resource); request = new HttpHead(resource); }
From source file:com.couchbase.capi.TestCAPI.java
public void testDatabaseHead() throws Exception { HttpClient client = getClient();// w w w.ja v a 2 s. c o m HttpUriRequest request = new HttpHead(String.format("http://localhost:%d/default", port)); HttpResponse response = client.execute(request); Assert.assertEquals(200, response.getStatusLine().getStatusCode()); }
From source file:com.moarub.util.UrlDeshortener.java
private DeshorteningResult doShortening(String... urls) { fAsync = true;//w w w .j a v a 2 s .c om Log.d("Deshortening", "URL " + urls[0] + "(" + fRedirects + ")"); fUrlTo = urls[0]; AndroidHttpClient httpClient = AndroidHttpClient.newInstance("Android ShareMore"); HttpHead headReq = new HttpHead(fUrlTo); try { HttpResponse resp = httpClient.execute(headReq); String resValue = resp.getLastHeader("Location") != null ? resp.getLastHeader("Location").getValue() : null; int statusCode = resp.getStatusLine().getStatusCode(); return new DeshorteningResult(resValue, statusCode); } catch (IOException e) { Log.d("Deshortening", e.getMessage()); return null; } finally { httpClient.close(); } }
From source file:org.deviceconnect.android.manager.test.FailHTTPServerTest.java
/** * HEAD?HTTP????./* w w w . j a va 2s . co m*/ * <pre> * ?HTTP * Method: HEAD * </pre> * <pre> * ?? * HTTP 501 Not Implemented??? * </pre> */ public void testHttpMethodHead() { URIBuilder builder = TestURIBuilder.createURIBuilder(); HttpUriRequest request = new HttpHead(builder.toString()); HttpResponse response = requestHttpResponse(request); assertEquals(HttpStatus.SC_NOT_IMPLEMENTED, response.getStatusLine().getStatusCode()); }
From source file:org.commonjava.maven.galley.transport.htcli.internal.HttpExistence.java
@Override public Boolean call() { String oldName = Thread.currentThread().getName(); request = new HttpHead(url); try {/*from w ww . ja v a 2s . co m*/ String newName = oldName + ": EXISTS " + url; Thread.currentThread().setName(newName); if (executeHttp()) { return true; } } catch (final TransferException e) { this.error = e; } finally { cleanup(); if (oldName != null) { Thread.currentThread().setName(oldName); } } return false; }
From source file:org.apache.droids.protocol.http.HttpClientContentLoader.java
public boolean exists(URI uri) throws IOException { HttpHead httphead = new HttpHead(uri); HttpResponse response = httpclient.execute(httphead); return response.getStatusLine().getStatusCode() == HttpStatus.SC_OK; }
From source file:org.elasticsearch.shell.command.HttpHeadCommand.java
@SuppressWarnings("unused") public HttpCommandResponse execute(String url) throws IOException { return new HttpCommandResponse(shellHttpClient.getHttpClient().execute(new HttpHead(url))); }