List of usage examples for org.apache.http.client.methods HttpHead HttpHead
public HttpHead(final String uri)
From source file:org.apache.marmotta.platform.core.services.content.HTTPContentReader.java
/** * Check whether the specified resource has content of the specified mimetype for this reader. Returns true * in this case, false otherwise./*ww w .ja v a 2s .c o m*/ * * @param resource the resource to check * @param mimetype the mimetype to look for * @return true if content of this mimetype is associated with the resource, false otherwise */ @Override public boolean hasContent(Resource resource, String mimetype) { try { RepositoryConnection conn = sesameService.getConnection(); try { MediaContentItem mci = FacadingFactory.createFacading(conn).createFacade(resource, MediaContentItem.class); String location = mci.getContentLocation(); // if no location is explicitly specified, use the resource URI itself if (location == null && resource instanceof URI && resource.stringValue().startsWith("http://")) { location = resource.stringValue(); } try { if (location != null) { log.info("reading remote resource {}", location); HttpHead head = new HttpHead(location); head.setHeader("Accept", mimetype); return httpClientService.execute(head, new ResponseHandler<Boolean>() { @Override public Boolean handleResponse(HttpResponse response) throws ClientProtocolException, IOException { return response.getStatusLine().getStatusCode() == 200; } }); } else return false; } catch (IOException ex) { return false; } } finally { conn.commit(); conn.close(); } } catch (RepositoryException ex) { handleRepositoryException(ex, FileSystemContentReader.class); return false; } }
From source file:org.fcrepo.client.utils.HttpHelper.java
/** * Create HEAD method//from w ww . jav a2 s. c o m * @param path Resource path, relative to repository baseURL * @return HEAD method **/ public HttpHead createHeadMethod(final String path) { return new HttpHead(repositoryURL + path); }
From source file:leap.lang.http.client.apache.ApacheHttpRequest.java
protected HttpRequestBase newRequest(String url) { initRequest();//w w w .j ava2 s. c om if (method.equals(HTTP.Method.GET)) { request = new HttpGet(url); } if (method.equals(HTTP.Method.POST)) { request = new HttpPost(url); } if (method.equals(HTTP.Method.PUT)) { request = new HttpPut(url); } if (method.equals(HTTP.Method.DELETE)) { request = new HttpDelete(url); } if (method.equals(HTTP.Method.PATCH)) { request = new HttpPatch(url); } if (method.equals(HTTP.Method.HEAD)) { request = new HttpHead(url); } if (method.equals(HTTP.Method.OPTIONS)) { request = new HttpOptions(url); } if (null == request) { throw new IllegalStateException("Http method '" + method.name() + "' not supported now"); } //set headers Header[] headerArray = headers.getAllHeaders(); if (null != headerArray && headerArray.length > 0) { request.setHeaders(headerArray); } if (null != entity) { entityEnclosingRequest().setEntity(entity); } return request; }
From source file:com.reachcall.pretty.http.ProxyServlet.java
@Override public void doHead(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { Match match = (Match) req.getAttribute("match"); HttpHead method = new HttpHead(match.toURL()); copyHeaders(req, method);/*w ww .jav a 2s. c om*/ this.execute(match, method, req, resp); }
From source file:com.liferay.sync.engine.lan.session.LanSession.java
protected Callable<SyncLanClientQueryResult> createSyncLanClientQueryResultCallable( final SyncLanClient syncLanClient, SyncFile syncFile) { String url = _getUrl(syncLanClient, syncFile); final HttpHead httpHead = new HttpHead(url); return new Callable<SyncLanClientQueryResult>() { @Override/* w ww . jav a2 s. c om*/ public SyncLanClientQueryResult call() throws Exception { SyncLanClientQueryResult syncLanClientQueryResult = new SyncLanClientQueryResult(); syncLanClientQueryResult.setSyncLanClient(syncLanClient); HttpResponse httpResponse = _queryHttpClient.execute(httpHead, HttpClientContext.create()); Header connectionsCountHeader = httpResponse.getFirstHeader("connectionsCount"); if (connectionsCountHeader == null) { return null; } syncLanClientQueryResult .setConnectionsCount(GetterUtil.getInteger(connectionsCountHeader.getValue())); Header downloadRateHeader = httpResponse.getFirstHeader("downloadRate"); if (downloadRateHeader == null) { return null; } syncLanClientQueryResult.setDownloadRate(GetterUtil.getInteger(downloadRateHeader.getValue())); Header encryptedTokenHeader = httpResponse.getFirstHeader("encryptedToken"); if (encryptedTokenHeader == null) { return null; } syncLanClientQueryResult.setEncryptedToken(encryptedTokenHeader.getValue()); Header maxConnectionsHeader = httpResponse.getFirstHeader("maxConnections"); if (maxConnectionsHeader == null) { return null; } syncLanClientQueryResult.setMaxConnections(GetterUtil.getInteger(maxConnectionsHeader.getValue())); return syncLanClientQueryResult; } }; }
From source file:org.greencheek.spring.rest.SSLCachingHttpComponentsClientHttpRequestFactory.java
/** * Create a Commons HttpMethodBase object for the given HTTP method and URI specification. * @param httpMethod the HTTP method//from ww w. ja va 2 s. c om * @param uri the URI * @return the Commons HttpMethodBase object */ protected HttpUriRequest createHttpUriRequest(HttpMethod httpMethod, URI uri) { switch (httpMethod) { case GET: return new HttpGet(uri); case DELETE: return new HttpDelete(uri); case HEAD: return new HttpHead(uri); case OPTIONS: return new HttpOptions(uri); case POST: return new HttpPost(uri); case PUT: return new HttpPut(uri); case TRACE: return new HttpTrace(uri); // Not supported in 3.0.6 // case PATCH: // return new HttpPatch(uri); default: throw new IllegalArgumentException("Invalid HTTP method: " + httpMethod); } }
From source file:org.gbif.pubindex.service.impl.ArticleIndexerImpl.java
private String headContentType(String url) { // execute head request HttpHead req = new HttpHead(url); try {/* www .java 2s .c o m*/ HttpResponse response = client.execute(req); Header ct = response.getFirstHeader("Content-Type"); return ct == null ? null : StringUtils.trimToNull(ct.getValue()); } catch (Exception e) { LOG.warn("Head request for article {} failed: {}", url, e.getMessage()); } return null; }
From source file:org.ocpsoft.redoculous.tests.WebTest.java
/** * Request a resource from the deployed test-application. The {@link HttpServletRequest#getContextPath()} will be * automatically prepended to the given path. * <p>//from w w w . j ava 2 s . c o m * E.g: A path of '/example' will be sent as '/rewrite-test/example' */ public HttpAction<HttpHead> head(final String path) { DefaultHttpClient client = new DefaultHttpClient(); try { HttpHead request = new HttpHead(getBaseURL() + getContextPath() + path); HttpContext context = new BasicHttpContext(); HttpResponse response = client.execute(request, context); return new HttpAction<HttpHead>(client, context, request, response, getBaseURL(), getContextPath()); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.wso2.carbon.automation.extensions.servers.httpserver.SimpleHttpClient.java
/** * Send a HTTP Head request to the specified URL * * @param url Target endpoint URL * @param headers Any HTTP headers that should be added to the request * @return Returned HTTP response/*from w ww . j a v a 2 s . c om*/ * @throws IOException If an error occurs while making the invocation */ public HttpResponse doHead(String url, final Map<String, String> headers) throws IOException { HttpUriRequest request = new HttpHead(url); setHeaders(headers, request); return client.execute(request); }