List of usage examples for org.apache.http.client.methods HttpUriRequest abort
void abort() throws UnsupportedOperationException;
From source file:com.music.tools.SongDBDownloader.java
public static void main(String[] args) throws Exception { HttpClient client = new DefaultHttpClient(); // HttpHost proxy = new HttpHost("localhost", 8888); // client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); HttpContext ctx = new BasicHttpContext(); HttpUriRequest req = new HttpGet( "http://www.hooktheory.com/analysis/view/the-beatles/i-want-to-hold-your-hand"); client.execute(req, ctx);/*ww w . ja va2 s .c o m*/ req.abort(); List<String> urls = getSongUrls( "http://www.hooktheory.com/analysis/browseSearch?sQuery=&sOrderBy=views&nResultsPerPage=525&nPage=1", client, ctx); List<List<? extends NameValuePair>> paramsList = new ArrayList<>(urls.size()); for (String songUrl : urls) { paramsList.addAll(getSongParams(songUrl, client, ctx)); } int i = 0; for (List<? extends NameValuePair> params : paramsList) { HttpPost request = new HttpPost("http://www.hooktheory.com/songs/getXML"); request.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0.1"); request.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); request.setHeader("Accept-Encoding", "gzip, deflate"); request.setHeader("Accept-Language", "en,en-us;q=0.7,bg;q=0.3"); request.setHeader("Content-Type", "application/x-www-form-urlencoded"); request.setHeader("Origin", "http://www.hooktheory.com"); request.setHeader("Referer", URLEncoder.encode("http://www.hooktheory.com/swf/DNALive Version 1.0.131.swf", "utf-8")); HttpEntity entity = new UrlEncodedFormEntity(params); request.setEntity(entity); try { HttpResponse response = client.execute(request, ctx); if (response.getStatusLine().getStatusCode() == 200) { InputStream is = response.getEntity().getContent(); String xml = CharStreams.toString(new InputStreamReader(is)); is.close(); Files.write(xml, new File("c:/tmp/musicdb/" + i + ".xml"), Charset.forName("utf-8")); } else { System.out.println(response.getStatusLine()); System.out.println(params); } i++; request.abort(); } catch (Exception ex) { System.out.println(params); ex.printStackTrace(); } } }
From source file:nya.miku.wishmaster.http.streamer.HttpResponseModel.java
/** ?? ? ?? ?? HTTP-? HTTP- */ static void release(HttpUriRequest request, HttpResponse response) { try {//from w ww . ja v a 2 s .c o m if (request != null) request.abort(); } catch (Exception e) { Logger.e(TAG, e); } try { if (response != null) { HttpEntity entity = response.getEntity(); EntityUtilsHC4.consume(entity); } } catch (Exception e) { Logger.e(TAG, e); } try { if (response != null && response instanceof Closeable) ((Closeable) response).close(); } catch (Exception e) { Logger.e(TAG, e); } }
From source file:com.music.tools.SongDBDownloader.java
private static String getResponseAsString(String urlString, HttpClient client, HttpContext ctx) throws IOException { HttpUriRequest req = new HttpGet(urlString); InputStream is = client.execute(req, ctx).getEntity().getContent(); String result = CharStreams.toString(new InputStreamReader(is)); is.close();//from ww w. ja v a 2 s .c om req.abort(); return result; }
From source file:org.pixmob.appengine.client.AppEngineClient.java
private static void closeResources(HttpUriRequest req, HttpResponse resp) { try {/*from w ww . ja v a 2s .co m*/ req.abort(); } catch (UnsupportedOperationException ignore) { } final HttpEntity entity = resp != null ? resp.getEntity() : null; if (entity != null) { try { entity.consumeContent(); } catch (IOException ignore) { } } }
From source file:com.piusvelte.sonet.core.SonetHttpClient.java
protected static byte[] httpBlobResponse(HttpClient httpClient, HttpUriRequest httpRequest) { if (httpClient != null) { HttpResponse httpResponse;// ww w .j a va 2 s .com HttpEntity entity = null; try { httpResponse = httpClient.execute(httpRequest); StatusLine statusLine = httpResponse.getStatusLine(); entity = httpResponse.getEntity(); switch (statusLine.getStatusCode()) { case 200: case 201: case 204: if (entity != null) { return getBlob(new FlushedInputStream(entity.getContent())); } break; } } catch (ClientProtocolException e) { Log.e(TAG, e.toString()); try { httpRequest.abort(); } catch (UnsupportedOperationException ignore) { Log.e(TAG, ignore.toString()); } } catch (IOException e) { Log.e(TAG, e.toString()); try { httpRequest.abort(); } catch (UnsupportedOperationException ignore) { Log.e(TAG, ignore.toString()); } } finally { if (entity != null) { try { entity.consumeContent(); } catch (IOException e) { Log.e(TAG, e.toString()); } } } } return null; }
From source file:com.arcbees.vcs.util.HttpClientWrapperImpl.java
public HttpResponse execute(HttpUriRequest request) throws IOException { try {/*from w w w . ja v a 2 s.c om*/ return httpClient.execute(request); } catch (IOException e) { request.abort(); throw e; } }
From source file:org.fourthline.cling.transport.impl.apache.StreamClientImpl.java
@Override protected void abort(HttpUriRequest request) { request.abort(); }
From source file:com.arcbees.vcs.AbstractVcsApi.java
protected HttpResponse executeRequest(HttpClientWrapper httpClient, HttpUriRequest request, Credentials credentials) throws IOException { try {//from w ww . j ava 2 s. c om return doExecuteRequest(httpClient, request, credentials); } finally { request.abort(); } }
From source file:com.github.horrorho.liquiddonkey.cloud.engine.Donkey.java
void kill() { HttpUriRequest local = request.getAndSet(null); if (local != null) { logger.debug("-- kill() > killing"); try {//from w w w . j ava 2 s. com local.abort(); } catch (UnsupportedOperationException ex) { logger.warn("-- kill() > exception: {}", ex); } } else { logger.debug("-- kill() > already killed"); } }
From source file:com.semagia.cassa.client.AbstractClient.java
/** * Executes the request and returns the status code. * // ww w . jav a 2s . c om * @param request The request to execute. * @return The status code. * @throws IOException In case of an error. */ protected int getStatusCode(final HttpUriRequest request) throws IOException { final HttpResponse response = execute(request); final int status = response.getStatusLine().getStatusCode(); request.abort(); return status; }