List of usage examples for org.apache.http.client.methods HttpHead HttpHead
public HttpHead(final String uri)
From source file:org.apache.solr.cloud.TestMiniSolrCloudClusterSSL.java
/** * Trivial helper method for doing a HEAD request of the specified URL using the specified client * and getting the HTTP statusCode from the response *///from www.ja v a 2 s. co m private static int doHeadRequest(final CloseableHttpClient client, final String url) throws Exception { return client.execute(new HttpHead(url)).getStatusLine().getStatusCode(); }
From source file:org.fcrepo.integration.http.api.FedoraLdpIT.java
License:asdf
@Test public void testHeadRepositoryGraph() { final HttpHead headObjMethod = new HttpHead(serverAddress); assertEquals(OK.getStatusCode(), getStatus(headObjMethod)); }
From source file:com.ibm.sbt.service.basic.ProxyService.java
protected HttpRequestBase createMethod(String smethod, URI uri, HttpServletRequest request) throws ServletException { Object timedObject = ProxyProfiler.getTimedObject(); if (getDebugHook() != null) { getDebugHook().getDumpRequest().setMethod(smethod); getDebugHook().getDumpRequest().setUrl(uri.toString()); }// w w w .j a v a 2 s . c o m if (smethod.equalsIgnoreCase("get")) { HttpGet method = new HttpGet(uri); ProxyProfiler.profileTimedRequest(timedObject, "create HttpGet"); return method; } else if (smethod.equalsIgnoreCase("put")) { HttpPut method = new HttpPut(uri); method = (HttpPut) prepareMethodWithUpdatedContent(method, request); ProxyProfiler.profileTimedRequest(timedObject, "create HttpPut"); return method; } else if (smethod.equalsIgnoreCase("post")) { HttpPost method = new HttpPost(uri); method = (HttpPost) prepareMethodWithUpdatedContent(method, request); ProxyProfiler.profileTimedRequest(timedObject, "create HttpPost"); return method; } else if (smethod.equalsIgnoreCase("delete")) { HttpDelete method = new HttpDelete(uri); ProxyProfiler.profileTimedRequest(timedObject, "create HttpDelete"); return method; } else if (smethod.equalsIgnoreCase("head")) { HttpHead method = new HttpHead(uri); ProxyProfiler.profileTimedRequest(timedObject, "create HttpHead"); return method; } else if (smethod.equalsIgnoreCase("options")) { HttpOptions method = new HttpOptions(uri); ProxyProfiler.profileTimedRequest(timedObject, "create HttpOptions"); return method; } else { ProxyProfiler.profileTimedRequest(timedObject, "failed creating method"); throw new ServletException("Illegal method, should be GET, PUT, POST, DELETE or HEAD"); } }
From source file:com.machinepublishers.jbrowserdriver.StreamConnection.java
/** * {@inheritDoc}//from ww w. j a va 2 s.c o m */ @Override public void connect() throws IOException { try { if (connected.compareAndSet(false, true)) { if (StatusMonitor.instance().isDiscarded(urlString)) { skip.set(true); LogsServer.instance().trace("Media skipped: " + urlString); } else if (isBlocked(url.getHost())) { skip.set(true); } else if (SettingsManager.settings() != null) { config.get().setCookieSpec("custom") .setSocketTimeout(SettingsManager.settings().socketTimeout()) .setConnectTimeout(SettingsManager.settings().connectTimeout()) .setConnectionRequestTimeout(SettingsManager.settings().connectionReqTimeout()); URI uri = null; try { uri = url.toURI(); } catch (URISyntaxException e) { //decode components of the url first, because often the problem is partially encoded urls uri = new URI(url.getProtocol(), url.getAuthority(), url.getPath() == null ? null : URLDecoder.decode(url.getPath(), "utf-8"), url.getQuery() == null ? null : URLDecoder.decode(url.getQuery(), "utf-8"), url.getRef() == null ? null : URLDecoder.decode(url.getRef(), "utf-8")); } if ("OPTIONS".equals(method.get())) { req.set(new HttpOptions(uri)); } else if ("GET".equals(method.get())) { req.set(new HttpGet(uri)); } else if ("HEAD".equals(method.get())) { req.set(new HttpHead(uri)); } else if ("POST".equals(method.get())) { req.set(new HttpPost(uri)); } else if ("PUT".equals(method.get())) { req.set(new HttpPut(uri)); } else if ("DELETE".equals(method.get())) { req.set(new HttpDelete(uri)); } else if ("TRACE".equals(method.get())) { req.set(new HttpTrace(uri)); } processHeaders(SettingsManager.settings(), req.get()); ProxyConfig proxy = SettingsManager.settings().proxy(); if (proxy != null && !proxy.directConnection() && !proxy.nonProxyHosts().contains(uri.getHost())) { config.get().setExpectContinueEnabled(proxy.expectContinue()); InetSocketAddress proxyAddress = new InetSocketAddress(proxy.host(), proxy.port()); if (proxy.type() == ProxyConfig.Type.SOCKS) { context.get().setAttribute("proxy.socks.address", proxyAddress); } else { config.get().setProxy(new HttpHost(proxy.host(), proxy.port())); } } context.get().setCookieStore(cookieStore); context.get().setRequestConfig(config.get().build()); StatusMonitor.instance().monitor(url, this); } } } catch (Throwable t) { throw new IOException(t.getMessage() + ": " + urlString, t); } }
From source file:org.soyatec.windowsazure.internal.util.HttpUtilities.java
/** * Create a httpRequest with the uri and method. * /*ww w . j a v a2 s .c om*/ * @param uri * @param method * @return HttpUriRequest */ public static HttpUriRequest createHttpRequest(URI uri, String method) { HttpUriRequest request; if (method.equals(HttpMethod.Get)) { request = new HttpGet(uri); } else if (method.equals(HttpMethod.Post)) { request = new HttpPost(uri); } else if (method.equals(HttpMethod.Delete)) { request = new HttpDelete(uri); } else if (method.equals(HttpMethod.Head)) { request = new HttpHead(uri); } else if (method.equals(HttpMethod.Options)) { request = new HttpOptions(uri); } else if (method.equals(HttpMethod.Put)) { request = new HttpPut(uri); } else if (method.equals(HttpMethod.Trace)) { request = new HttpTrace(uri); } else if (method.equals(HttpMerge.METHOD_NAME)) { request = new HttpMerge(uri); } else { throw new IllegalArgumentException(MessageFormat.format("{0} is not a valid HTTP method.", method)); } return request; }
From source file:org.brunocvcunha.taskerbox.core.http.TaskerboxHttpBox.java
/** * Gets the {@link HttpResponse} object for a given url using the given Http Client * * @param client/* w ww. j a v a2 s. c o m*/ * @param uri * @return * @throws ClientProtocolException * @throws IOException */ public long getResponseSizeForURL(DefaultHttpClient client, URI uri) throws ClientProtocolException, IOException { HttpHead httpHead = new HttpHead(uri); HttpResponse response1 = client.execute(httpHead); Header length = response1.getFirstHeader("Content-Length"); if (length == null) { return -1L; } return Long.valueOf(length.getValue()); }
From source file:org.apache.olingo.odata2.fit.basic.BasicHttpTest.java
protected HttpResponse executeHeadRequest(final String request) throws IOException { final HttpHead head = new HttpHead(URI.create(getEndpoint().toString() + request)); return getHttpClient().execute(head); }
From source file:fr.eolya.utils.http.HttpLoader.java
public int getHeadStatusCode(String url) { if (simulateHttps) url = url.replace("https://", "http://"); if (authBasicLogin != null) url = HttpUtils.urlAddBasicAuthentication(url, authBasicLogin.get("login"), authBasicLogin.get("password")); try {/*from w w w .j av a 2s . c o m*/ //this.url = url; URI uri = new URI(url); close(); // HttpClient client = getHttpClient(url); if (client == null) throw new IOException("HttpClient object creation failed"); // HttpGet HttpHead head = new HttpHead(uri); //if (head == null) throw new IOException("HttpHead object creation failed"); // execute response = client.execute(head); return response.getStatusLine().getStatusCode(); } catch (Exception e) { return -1; } }
From source file:com.microsoft.azure.management.resources.ResourceGroupOperationsImpl.java
/** * Checks whether resource group exists./*from www.ja va 2s . c o m*/ * * @param resourceGroupName Required. The name of the resource group to * check. The name is case insensitive. * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @return Resource group information. */ @Override public ResourceGroupExistsResult checkExistence(String resourceGroupName) throws IOException, ServiceException { // Validate if (resourceGroupName == null) { throw new NullPointerException("resourceGroupName"); } if (resourceGroupName != null && resourceGroupName.length() > 1000) { throw new IllegalArgumentException("resourceGroupName"); } if (Pattern.matches("^[-\\w\\._]+$", resourceGroupName) == false) { throw new IllegalArgumentException("resourceGroupName"); } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("resourceGroupName", resourceGroupName); CloudTracing.enter(invocationId, this, "checkExistenceAsync", tracingParameters); } // Construct URL String url = ""; url = url + "subscriptions/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/resourcegroups/"; url = url + URLEncoder.encode(resourceGroupName, "UTF-8"); ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("api-version=" + "2014-04-01-preview"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpHead httpRequest = new HttpHead(url); // Set Headers httpRequest.setHeader("Content-Type", "application/json; charset=utf-8"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_NO_CONTENT && statusCode != HttpStatus.SC_NOT_FOUND) { ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result ResourceGroupExistsResult result = null; // Deserialize Response result = new ResourceGroupExistsResult(); result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (statusCode == HttpStatus.SC_NO_CONTENT) { result.setExists(true); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }