List of usage examples for org.apache.http.client.methods HttpHead HttpHead
public HttpHead(final String uri)
From source file:org.prx.playerhater.util.PlaylistParser.java
public static Uri[] parsePlaylist(Uri uri) { try {/*from w w w . j a v a 2 s . c o m*/ HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = httpclient.execute(new HttpHead(uri.toString())); Header contentType = response.getEntity().getContentType(); if (contentType != null) { String mimeType = contentType.getValue().split(";")[0].trim(); for (String plsMimeType : PLS_MIME_TYPES) { if (plsMimeType.equalsIgnoreCase(mimeType)) { return parsePls(uri); } } for (String m3uMimeType : M3U_MIME_TYPES) { if (m3uMimeType.equalsIgnoreCase(mimeType)) { return parseM3u(uri); } } } } catch (Exception e) { } return new Uri[] { uri }; }
From source file:HttpUtils.java
public static void testUrl(String url) throws ClientProtocolException, IOException { HttpHead head = new HttpHead(url); HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = httpclient.execute(head); StatusLine status = response.getStatusLine(); if (status.getStatusCode() == 404) { throw new FileNotFoundException(); }/* w w w . j a va 2s . c o m*/ if (status.getStatusCode() != 200) { throw new RuntimeException( "Could not get URL: " + status.getStatusCode() + ": " + status.getReasonPhrase()); } }
From source file:kontrol.HttpUtil.java
public static boolean exists(String url) { try {// www. j a va2 s .co m return getCookielessHttpClient(1000).execute(new HttpHead(new URI(url)), new BasicHttpContext()) .getStatusLine().getStatusCode() < 400; } catch (URISyntaxException e) { log.warn(e.getMessage()); return false; } catch (ClientProtocolException e) { log.warn(e.getMessage()); return false; } catch (IOException e) { log.warn(e.getMessage()); return false; } }
From source file:slash.navigation.rest.Head.java
public Head(String url) { super(new HttpHead(url)); }
From source file:com.cpyf.twelve.spies.qr.code.result.supplement.URIResultInfoRetriever.java
private static String unredirect(String uri) throws IOException { if (!isRedirector(uri)) { return uri; }/*from w w w . j av a2 s . c o m*/ HttpUriRequest head = new HttpHead(uri); AndroidHttpClient client = AndroidHttpClient.newInstance(null); HttpResponse response = client.execute(head); int status = response.getStatusLine().getStatusCode(); if (status == 301 || status == 302) { Header redirect = response.getFirstHeader("Location"); if (redirect != null) { String location = redirect.getValue(); if (location != null) { return location; } } } return uri; }
From source file:controller.HeadIT.java
@Test public void testHeadToGetSwitch() throws Exception { HttpHead head = new HttpHead(getHttpURl("/hello/html")); // When checking the content length, we must disable the compression: head.setHeader(HeaderNames.ACCEPT_ENCODING, "identity"); HttpResponse<String> response; try {/*from w w w . j a v a 2 s .c om*/ org.apache.http.HttpResponse resp = ClientFactory.getHttpClient().execute(head); response = new HttpResponse<>(resp, String.class); } finally { head.releaseConnection(); } assertThat(response.code()).isEqualTo(OK); assertThat(response.contentType()).isEqualTo(MimeTypes.HTML); System.out.println(response.headers()); assertThat(Integer.valueOf(response.header(CONTENT_LENGTH))).isEqualTo(20); }
From source file:com.liferay.mobile.android.util.PortalVersionUtil.java
protected static int getBuilderNumberHeader(String url) throws IOException { HttpClient client = new DefaultHttpClient(); HttpHead head = new HttpHead(url); HttpResponse response = client.execute(head); Header portalHeader = response.getFirstHeader("Liferay-Portal"); if (portalHeader == null) { return PortalVersion.UNKNOWN; }/*from w w w . j a va2 s . co m*/ String portalField = portalHeader.getValue(); int indexOfBuild = portalField.indexOf("Build"); if (indexOfBuild == -1) { return PortalVersion.UNKNOWN; } else { String buildNumber = portalField.substring(indexOfBuild + 6, indexOfBuild + 10); return Integer.valueOf(buildNumber); } }
From source file:org.dasein.cloud.aws.storage.S3Action.java
public HttpRequestBase getMethod(String url) { switch (this) { case OBJECT_EXISTS: return new HttpHead(url); case DELETE_BUCKET: case DELETE_OBJECT: return new HttpDelete(url); case LIST_BUCKETS: case LIST_CONTENTS: case LOCATE_BUCKET: case GET_OBJECT: case GET_ACL: return new HttpGet(url); case CREATE_BUCKET: case COPY_OBJECT: case PUT_OBJECT: case SET_ACL: return new HttpPut(url); }//from w w w.j a va 2s .com return null; }
From source file:com.servoy.extensions.plugins.http.HeadRequest.java
public HeadRequest(String url, DefaultHttpClient hc, IClientPluginAccess plugin) { super(url, hc, new HttpHead(url), plugin); }
From source file:org.talend.dataprep.api.service.command.preparation.CheckDatasetUsage.java
private HttpRequestBase onExecute(String dataSetId) { return new HttpHead(preparationServiceUrl + "/preparations/use/dataset/" + dataSetId); }