List of usage examples for org.apache.http.client.methods HttpHead HttpHead
public HttpHead()
From source file:org.xwiki.android.test.utils.xmlrpc.RestClient.java
public int headRequest(String Uri) throws IOException { HttpHead request = new HttpHead(); URI requestUri;/*from w w w .ja va2 s .c o m*/ try { requestUri = new URI(Uri); request.setURI(requestUri); } catch (URISyntaxException e) { e.printStackTrace(); } log.debug("Request URL :" + Uri); try { HttpResponse response = client.execute(request); log.debug("Response status", response.getStatusLine().toString()); return response.getStatusLine().getStatusCode(); } catch (ClientProtocolException e) { e.printStackTrace(); return -1; } }
From source file:pt.sapo.pai.vip.VipServlet.java
@Override protected void doHead(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response, () -> new HttpHead()); }
From source file:org.apache.maven.wagon.providers.http.AbstractHttpClientWagonTest.java
public void testTurnOffDefaultHeaders() { HttpConfiguration config = new HttpConfiguration(); config.setAll(new HttpMethodConfiguration().setUseDefaultHeaders(false)); TestWagon wagon = new TestWagon(); wagon.setHttpConfiguration(config);//from w w w .java2 s.co m HttpHead method = new HttpHead(); wagon.setHeaders(method); // these are the default headers. // method.addRequestHeader( "Cache-control", "no-cache" ); // method.addRequestHeader( "Cache-store", "no-store" ); // method.addRequestHeader( "Pragma", "no-cache" ); // method.addRequestHeader( "Expires", "0" ); // method.addRequestHeader( "Accept-Encoding", "gzip" ); Header header = method.getFirstHeader("Cache-control"); assertNull(header); header = method.getFirstHeader("Cache-store"); assertNull(header); header = method.getFirstHeader("Pragma"); assertNull(header); header = method.getFirstHeader("Expires"); assertNull(header); header = method.getFirstHeader("Accept-Encoding"); assertNull(header); }
From source file:com.tealeaf.util.HTTP.java
public Response makeRequest(Methods method, URI uri, HashMap<String, String> requestHeaders, String data) { HttpRequestBase request = null;/*from w w w.j av a 2 s .c om*/ try { if (method == Methods.GET) { request = new HttpGet(); } else if (method == Methods.POST) { request = new HttpPost(); if (data != null) { ((HttpPost) request).setEntity(new StringEntity(data, "UTF-8")); } } else if (method == Methods.PUT) { request = new HttpPut(); if (data != null) { ((HttpPut) request).setEntity(new StringEntity(data, "UTF-8")); } } else if (method == Methods.DELETE) { request = new HttpDelete(); } else if (method == Methods.HEAD) { request = new HttpHead(); } } catch (UnsupportedEncodingException e) { logger.log(e); } request.setURI(uri); AndroidHttpClient client = AndroidHttpClient.newInstance(userAgent); if (requestHeaders != null) { for (Map.Entry<String, String> entry : requestHeaders.entrySet()) { request.addHeader(new BasicHeader(entry.getKey(), entry.getValue())); } } HttpResponse response = null; Response retVal = new Response(); retVal.headers = new HashMap<String, String>(); try { response = client.execute(request, localContext); } catch (SocketTimeoutException e) { // forget it--we don't care that the user couldn't connect // TODO hand this back as an error to JS } catch (IOException e) { if (!caughtIOException) { caughtIOException = true; logger.log(e); } } catch (Exception e) { logger.log(e); } if (response != null) { retVal.status = response.getStatusLine().getStatusCode(); retVal.body = readContent(response); for (Header header : response.getAllHeaders()) { retVal.headers.put(header.getName(), header.getValue()); } } client.close(); return retVal; }
From source file:com.lonepulse.zombielink.request.RequestUtils.java
/** * <p>Retrieves the proper extension of {@link HttpRequestBase} for the given {@link InvocationContext}. * This implementation is solely dependent upon the {@link RequestMethod} property in the annotated * metdata of the endpoint method definition.</p> * * @param context//from w w w. j av a2s .c o m * the {@link InvocationContext} for which a {@link HttpRequestBase} is to be generated * <br><br> * @return the {@link HttpRequestBase} translated from the {@link InvocationContext}'s {@link RequestMethod} * <br><br> * @throws NullPointerException * if the supplied {@link InvocationContext} was {@code null} * <br><br> * @since 1.3.0 */ static HttpRequestBase translateRequestMethod(InvocationContext context) { RequestMethod requestMethod = Metadata.findMethod(assertNotNull(context).getRequest()); switch (requestMethod) { case POST: return new HttpPost(); case PUT: return new HttpPut(); case PATCH: return new HttpPatch(); case DELETE: return new HttpDelete(); case HEAD: return new HttpHead(); case TRACE: return new HttpTrace(); case OPTIONS: return new HttpOptions(); case GET: default: return new HttpGet(); } }
From source file:groovyx.net.http.RESTClient.java
/** * <p>Perform a HEAD request, often used to check preconditions before * sending a large PUT or POST request.</p> * * @param args named parameters - see//from ww w.j a v a2 s. com * {@link HTTPBuilder.RequestConfigDelegate#setPropertiesFromMap(Map)} * @return a {@link HttpResponseDecorator}, unless the default success * handler is overridden. * @throws ClientProtocolException * @throws IOException * @throws URISyntaxException */ public Object head(Map<String, ?> args) throws URISyntaxException, ClientProtocolException, IOException { return this.doRequest(new RequestConfigDelegate(args, new HttpHead(), null)); }
From source file:org.easyj.http.EasyRESTHttpClient.java
/** * Executes a HEAD HTTP request and returns the body response as {@code String} * * @param uri URI of the resource to be requested * @return The body response of the request as {@code String} *//*from www . ja va2s . c o m*/ public EasyRESTHttpClient head(String uri) { method = new HttpHead(); return execute(uri); }
From source file:org.easyj.http.EasyHttpClient.java
/** * Executes a HEAD HTTP request and returns the body response as {@code String} * * @param uri URI of the resource to be requested * @return The body response of the request as {@code String} *///from www . j av a 2 s. c o m public EasyHttpClient head(String uri) { method = new HttpHead(); return execute(uri); }
From source file:com.naryx.tagfusion.cfm.http.cfHttpConnection.java
private HttpUriRequest resolveMethod(String _method, boolean _multipart) throws cfmRunTimeException { String method = _method.toUpperCase(); if (method.equals("GET")) { return new HttpGet(); } else if (method.equals("POST")) { return new HttpPost(); } else if (method.equals("HEAD")) { return new HttpHead(); } else if (method.equals("TRACE")) { return new HttpTrace(); } else if (method.equals("DELETE")) { return new HttpDelete(); } else if (method.equals("OPTIONS")) { return new HttpOptions(); } else if (method.equals("PUT")) { return new HttpPut(); }/*from w w w . j a va2 s . co m*/ throw newRunTimeException("Unsupported METHOD value [" + method + "]. Valid METHOD values are GET, POST, HEAD, TRACE, DELETE, OPTIONS and PUT."); }
From source file:com.archivas.clienttools.arcutils.impl.adapter.HCAPAdapter.java
/** * Get the archive Capacity. This includes both total capacity and remaning capacity. * //from w ww. j a v a2 s.c o m * @param url * A url pointing to any valid (ie existing) object in the archive. Typically, * clients would use the root, but it is not required. * @return * @throws StorageAdapterException */ public ArcCapacity getArchiveCapacity(URL url) throws StorageAdapterException { ArcCapacity result = null; HttpHost httpHost = new HttpHost(url.getHost(), url.getPort(), url.getProtocol()); HttpUriRequest request = new HttpHead(); try { // Eventually we will just return this cookie which will be passed back to the caller. HcapAdapterCookie cookie = new HcapAdapterCookie(request, httpHost); synchronized (savingCookieLock) { if (savedCookie != null) { throw new RuntimeException( "This adapter already has a current connection to host -- cannot create two at once."); } savedCookie = cookie; } executeMethod(cookie); this.handleHttpResponse(cookie.getResponse(), "checking capacity of", url.getHost()); if (cookie.getResponse() != null) { result = new ArcCapacity(); result.setTotal(Long.parseLong(cookie.getResponse() .getFirstHeader(HttpGatewayConstants.HEADER_AVAILABLE_CAPACITY).toString())); result.setAvailable( Long.parseLong(cookie.getResponse().getFirstHeader("X-ArcAvailableCapacity").toString())); } } catch (IOException e) { this.handleIOExceptionFromRequest(e, "checking capacity of", url.getHost()); } finally { close(); } return result; }