List of usage examples for org.apache.http.client.methods HttpHead HttpHead
public HttpHead(final String uri)
From source file:com.googlecode.webutilities.servlets.WebProxyServlet.java
private HttpUriRequest getRequest(String method, String url) { if (HttpPost.METHOD_NAME.equals(method)) { return new HttpPost(url); } else if (HttpPut.METHOD_NAME.equals(method)) { return new HttpPut(url); } else if (HttpDelete.METHOD_NAME.equals(method)) { return new HttpDelete(url); } else if (HttpOptions.METHOD_NAME.equals(method)) { return new HttpOptions(url); } else if (HttpHead.METHOD_NAME.equals(method)) { return new HttpHead(url); }/*from ww w . j a va 2 s . com*/ return new HttpGet(url); }
From source file:com.ksc.http.apache.request.impl.ApacheHttpRequestFactory.java
private HttpRequestBase createApacheRequest(Request<?> request, String uri, String encodedParams) throws FakeIOException { switch (request.getHttpMethod()) { case HEAD://from ww w. j a va 2s .co m return new HttpHead(uri); case GET: return new HttpGet(uri); case DELETE: return new HttpDelete(uri); case PATCH: return wrapEntity(request, new HttpPatch(uri), encodedParams); case POST: return wrapEntity(request, new HttpPost(uri), encodedParams); case PUT: return wrapEntity(request, new HttpPut(uri), encodedParams); default: throw new KscClientException("Unknown HTTP method name: " + request.getHttpMethod()); } }
From source file:com.iflytek.android.framework.volley.toolbox.HttpClientStack.java
/** * Creates the appropriate subclass of HttpUriRequest for passed in request. *//*from ww w . j a v a2s . c o m*/ @SuppressWarnings("deprecation") /* protected */ static HttpUriRequest createHttpRequest(Request<?> request, Map<String, String> additionalHeaders) throws AuthFailureError { switch (request.getMethod()) { case Method.DEPRECATED_GET_OR_POST: { // This is the deprecated way that needs to be handled for backwards compatibility. // If the request's post body is null, then the assumption is that the request is // GET. Otherwise, it is assumed that the request is a POST. byte[] postBody = request.getPostBody(); if (postBody != null) { HttpPost postRequest = new HttpPost(request.getUrl()); postRequest.addHeader(HEADER_CONTENT_TYPE, request.getPostBodyContentType()); HttpEntity entity; entity = new ByteArrayEntity(postBody); postRequest.setEntity(entity); return postRequest; } else { return new HttpGet(request.getUrl()); } } case Method.GET: return new HttpGet(request.getUrl()); case Method.DELETE: return new HttpDelete(request.getUrl()); case Method.POST: { HttpPost postRequest = new HttpPost(request.getUrl()); VolleyLog.d("1:" + request.getBodyContentType()); postRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(postRequest, request); return postRequest; } case Method.PUT: { HttpPut putRequest = new HttpPut(request.getUrl()); putRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(putRequest, request); return putRequest; } case Method.HEAD: return new HttpHead(request.getUrl()); case Method.OPTIONS: return new HttpOptions(request.getUrl()); case Method.TRACE: return new HttpTrace(request.getUrl()); case Method.PATCH: { HttpPatch patchRequest = new HttpPatch(request.getUrl()); patchRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(patchRequest, request); return patchRequest; } default: throw new IllegalStateException("Unknown request method."); } }
From source file:com.semagia.cassa.client.AbstractClient.java
/** * Returns if the provided graph URI returns a HTTP 200 - Ok status. * /*w w w.j a va 2 s . com*/ * @param graphURI The graph URI. * @return {@code true} if the graph URI exists, otherwise {@code false}. * @throws IOException In case of an error. */ protected boolean existsGraph(final URI graphURI) throws IOException { final HttpHead head = new HttpHead(graphURI); return getStatusCode(head) == 200; }
From source file:com.google.dataconnector.client.fetchrequest.HttpFetchStrategy.java
/** * Based on the inbound request type header, determine the correct http * method to use. If a method cannot be determined (or not specified), * HTTP GET is attempted./*from w w w .ja v a 2 s .c om*/ */ HttpRequestBase getMethod(FetchRequest request) { String method = null; for (MessageHeader h : request.getHeadersList()) { if ("x-sdc-http-method".equalsIgnoreCase(h.getKey())) { method = h.getValue().toUpperCase(); } } LOG.info(request.getId() + ": method=" + method + ", resource=" + request.getResource() + ((request.hasContents()) ? ", payload_size=" + request.getContents().size() : "")); if (method == null) { LOG.info(request.getId() + ": No http method specified. Default to GET."); method = "GET"; } if ("GET".equals(method)) { return new HttpGet(request.getResource()); } if ("POST".equals(method)) { HttpPost httpPost = new HttpPost(request.getResource()); if (request.hasContents()) { LOG.debug(request.getId() + ": Content = " + new String(request.getContents().toByteArray())); httpPost.setEntity(new ByteArrayEntity(request.getContents().toByteArray())); } return httpPost; } if ("PUT".equals(method)) { HttpPut httpPut = new HttpPut(request.getResource()); if (request.hasContents()) { LOG.debug(request.getId() + ": Content = " + new String(request.getContents().toByteArray())); httpPut.setEntity(new ByteArrayEntity(request.getContents().toByteArray())); } return httpPut; } if ("DELETE".equals(method)) { return new HttpDelete(request.getResource()); } if ("HEAD".equals(method)) { return new HttpHead(request.getResource()); } LOG.info(request.getId() + ": Unknown method " + method); return null; }
From source file:com.github.snowdream.android.widget.NotFoundWebView.java
/** * Check the status code//from w w w . ja v a2s. c o m * * @param url * @return status code */ private int getRespStatus(String url) { int status = -1; try { HttpHead head = new HttpHead(url); HttpClient client = new DefaultHttpClient(); HttpResponse resp = client.execute(head); status = resp.getStatusLine().getStatusCode(); } catch (IOException e) { e.printStackTrace(); } return status; }
From source file:com.volley.toolbox.HttpClientStack.java
/** * httprequest?httprequest?httpurlrequest * Creates the appropriate subclass of HttpUriRequest for passed in request. *//* w w w.ja va 2 s . c om*/ @SuppressWarnings("deprecation") /* protected */ static HttpUriRequest createHttpRequest(Request<?> request, Map<String, String> additionalHeaders) throws AuthFailureError { switch (request.getMethod()) { case Method.DEPRECATED_GET_OR_POST: { // This is the deprecated way that needs to be handled for backwards compatibility. // If the request's post body is null, then the assumption is that the request is // GET. Otherwise, it is assumed that the request is a POST. byte[] postBody = request.getPostBody(); if (postBody != null) { HttpPost postRequest = new HttpPost(request.getUrl()); postRequest.addHeader(HEADER_CONTENT_TYPE, request.getPostBodyContentType()); HttpEntity entity; entity = new ByteArrayEntity(postBody); postRequest.setEntity(entity); return postRequest; } else { return new HttpGet(request.getUrl()); } } case Method.GET: return new HttpGet(request.getUrl()); case Method.DELETE: return new HttpDelete(request.getUrl()); case Method.POST: { HttpPost postRequest = new HttpPost(request.getUrl()); postRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); // body? -? setEntityIfNonEmptyBody(postRequest, request); return postRequest; } case Method.PUT: { HttpPut putRequest = new HttpPut(request.getUrl()); putRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(putRequest, request); return putRequest; } case Method.HEAD: return new HttpHead(request.getUrl()); case Method.OPTIONS: return new HttpOptions(request.getUrl()); case Method.TRACE: return new HttpTrace(request.getUrl()); case Method.PATCH: { HttpPatch patchRequest = new HttpPatch(request.getUrl()); patchRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(patchRequest, request); return patchRequest; } default: throw new IllegalStateException("Unknown request method."); } }
From source file:com.androidex.volley.toolbox.HttpClientStack.java
/** * Creates the appropriate subclass of HttpUriRequest for passed in request. *//* www . j a va 2s.co m*/ @SuppressWarnings("deprecation") /* protected */static HttpUriRequest createHttpRequest(Request<?> request, Map<String, String> additionalHeaders) throws AuthFailureError, IOException { switch (request.getMethod()) { case Method.DEPRECATED_GET_OR_POST: { // This is the deprecated way that needs to be handled for backwards // compatibility. // If the request's post body is null, then the assumption is that // the request is // GET. Otherwise, it is assumed that the request is a POST. byte[] postBody = request.getPostBody(); if (postBody != null) { HttpPost postRequest = new HttpPost(request.getUrl()); postRequest.addHeader(HEADER_CONTENT_TYPE, request.getPostBodyContentType()); HttpEntity entity; entity = new ByteArrayEntity(postBody); postRequest.setEntity(entity); return postRequest; } else { return new HttpGet(request.getUrl()); } } case Method.GET: return new HttpGet(request.getUrl()); case Method.DELETE: return new HttpDelete(request.getUrl()); case Method.POST: { HttpPost postRequest = new HttpPost(request.getUrl()); setEntityIfNonEmptyBody(postRequest, request); return postRequest; } case Method.PUT: { HttpPut putRequest = new HttpPut(request.getUrl()); putRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(putRequest, request); return putRequest; } case Method.HEAD: return new HttpHead(request.getUrl()); case Method.OPTIONS: return new HttpOptions(request.getUrl()); case Method.TRACE: return new HttpTrace(request.getUrl()); case Method.PATCH: { HttpPatch patchRequest = new HttpPatch(request.getUrl()); setEntityIfNonEmptyBody(patchRequest, request); return patchRequest; } default: throw new IllegalStateException("Unknown request method."); } }
From source file:com.mobillium.paparasdk.sdk.sampleapp.webservice.PaparaHttpClientStack.java
/** * Creates the appropriate subclass of HttpUriRequest for passed in request. *///from www. j ava 2s. c om @SuppressWarnings("deprecation") /* protected */ static HttpUriRequest createHttpRequest(Request<?> request, Map<String, String> additionalHeaders) throws AuthFailureError { switch (request.getMethod()) { case Method.DEPRECATED_GET_OR_POST: { // This is the deprecated way that needs to be handled for backwards compatibility. // If the request's post body is null, then the assumption is that the request is // GET. Otherwise, it is assumed that the request is a POST. byte[] postBody = request.getPostBody(); if (postBody != null) { HttpPost postRequest = new HttpPost(request.getUrl()); postRequest.addHeader(HEADER_CONTENT_TYPE, request.getPostBodyContentType()); HttpEntity entity; entity = new ByteArrayEntity(postBody); postRequest.setEntity(entity); return postRequest; } else { return new HttpGet(request.getUrl()); } } case Method.GET: return new HttpGet(request.getUrl()); case Method.DELETE: OwnHttpDelete deleteRequest = new OwnHttpDelete(request.getUrl()); deleteRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(deleteRequest, request); return deleteRequest; case Method.POST: { HttpPost postRequest = new HttpPost(request.getUrl()); postRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(postRequest, request); return postRequest; } case Method.PUT: { OwnHttpPut deletepOwnHttpPut = new OwnHttpPut(request.getUrl()); deletepOwnHttpPut.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(deletepOwnHttpPut, request); // HttpPut putRequest = new HttpPut(request.getUrl()); // putRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); // setEntityIfNonEmptyBody(putRequest, request); return deletepOwnHttpPut; } case Method.HEAD: return new HttpHead(request.getUrl()); case Method.OPTIONS: return new HttpOptions(request.getUrl()); case Method.TRACE: return new HttpTrace(request.getUrl()); case Method.PATCH: { HttpPatch patchRequest = new HttpPatch(request.getUrl()); patchRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(patchRequest, request); return patchRequest; } default: throw new IllegalStateException("Unknown request method."); } }
From source file:org.opensaml.util.http.HttpResource.java
/** {@inheritDoc} */ public boolean exists() throws ResourceException { HttpUriRequest httpRequest = new HttpHead(resourceUrl); try {//from ww w .java2 s. c o m HttpResponse httpResponse = httpClient.execute(httpRequest); int statusCode = httpResponse.getStatusLine().getStatusCode(); httpRequest.abort(); if (statusCode == HttpStatus.SC_METHOD_NOT_ALLOWED) { log.debug(resourceUrl + " does not support HEAD requests, falling back to GET request"); httpRequest = buildGetRequest(); httpResponse = httpClient.execute(httpRequest); statusCode = httpResponse.getStatusLine().getStatusCode(); httpRequest.abort(); } if (statusCode != HttpStatus.SC_OK) { return false; } final String etag = getETag(httpResponse); final String lastModified = getLastModified(httpResponse); if ((etag != null && !ObjectSupport.equals(etag, cachedResourceETag)) || (lastModified != null && !ObjectSupport.equals(lastModified, cachedResourceLastModified))) { expireCache(); } return true; } catch (IOException e) { throw new ResourceException("Error contacting resource " + resourceUrl, e); } finally { httpRequest.abort(); } }