List of usage examples for org.apache.http.client HttpClient execute
HttpResponse execute(HttpUriRequest request) throws IOException, ClientProtocolException;
From source file:neembuu.uploader.versioning.CheckUser.java
public static void getCanCustomizeNormalizing(UserSetPriv usp) { boolean canCustomizeNormalizing = true; String normalization = ".neembuu"; HttpParams params = new BasicHttpParams(); params.setParameter("http.useragent", "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2) Gecko/20100115 Firefox/3.6"); HttpClient httpclient = NUHttpClient.getHttpClient(); HttpGet httpget = new HttpGet("http://neembuu.com/uploader/api/user.xml?userid=" + UserImpl.I().uid()); NULogger.getLogger().info("Checking for user priviledges ..."); try {//from w ww . j av a2 s. c om HttpResponse response = httpclient.execute(httpget); String respxml = EntityUtils.toString(response.getEntity()); canCustomizeNormalizing = getCanCustomizeNormalizingFromXml(respxml); normalization = getNormalization(respxml); NULogger.getLogger().log(Level.INFO, "CanCustomizeNormalizing: {0}", canCustomizeNormalizing); } catch (Exception ex) { NULogger.getLogger().log(Level.INFO, "Exception while checking update\n{0}", ex); } usp.setCanCustomizeNormalizing(canCustomizeNormalizing); usp.setNormalization(normalization); }
From source file:org.artags.android.app.widget.HttpUtils.java
/** * Gets an url content// w w w.j av a 2s . c o m * @param url The url * @return The content */ public static String getUrl(String url) { String result = ""; HttpClient httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet(url); HttpResponse response; try { response = httpclient.execute(httpget); HttpEntity entity = response.getEntity(); if (entity != null) { InputStream instream = entity.getContent(); result = convertStreamToString(instream); } } catch (IOException ex) { Log.e(HttpUtils.class.getName(), ex.getMessage()); } return result; }
From source file:org.jboss.as.test.clustering.cluster.ejb.xpc.StatefulWithXPCFailoverTestCase.java
private static void assertExecuteUrl(HttpClient client, URI url) throws IOException { HttpResponse response = client.execute(new HttpGet(url)); try {// w w w . j av a2s.co m assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); } finally { org.apache.http.client.utils.HttpClientUtils.closeQuietly(response); } }
From source file:com.tweetlanes.android.urlservice.ApiService.java
public static HttpResponse getRequest(String url, String debugName) { HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(); HttpResponse response = null;//from w ww. j av a 2 s. c o m try { request.setURI(new URI(url)); //Log.d("tweetlanes url fetch", url); response = client.execute(request); //Log.d(TAG, debugName + " complete"); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return response; }
From source file:edu.isi.karma.util.HTTPUtil.java
public static String executeHTTPDeleteRequest(String uri) throws ClientProtocolException, IOException { HttpClient httpClient = new DefaultHttpClient(); HttpDelete request = new HttpDelete(uri); HttpResponse response = httpClient.execute(request); // Parse the response and store it in a String HttpEntity entity = response.getEntity(); StringBuilder responseString = new StringBuilder(); if (entity != null) { BufferedReader buf = new BufferedReader(new InputStreamReader(entity.getContent())); String line = buf.readLine(); while (line != null) { responseString.append(line); responseString.append('\n'); line = buf.readLine();/*w w w . j a va 2 s .c om*/ } } return responseString.toString(); }
From source file:org.sonar.plugins.buildstability.ci.jenkins.JenkinsUtils.java
public static void doLogin(HttpClient client, String hostName, String username, String password) throws IOException { String hudsonLoginEntryUrl = hostName + "/login"; HttpGet loginLink = new HttpGet(hudsonLoginEntryUrl); HttpResponse response = client.execute(loginLink); checkResult(response.getStatusLine().getStatusCode(), hudsonLoginEntryUrl); EntityUtils.consume(response.getEntity()); String location = hostName + "/j_acegi_security_check"; boolean loggedIn = false; while (!loggedIn) { HttpPost loginMethod = new HttpPost(location); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("j_username", username)); nvps.add(new BasicNameValuePair("j_password", password)); nvps.add(new BasicNameValuePair("action", "login")); loginMethod.setEntity(new UrlEncodedFormEntity(nvps)); try {//from ww w . ja v a2s.c o m HttpResponse response2 = client.execute(loginMethod); if (response2.getStatusLine().getStatusCode() / 100 == 3) { // Commons HTTP client refuses to handle redirects for POST // so we have to do it manually. location = response2.getFirstHeader("Location").getValue(); } else { checkResult(response2.getStatusLine().getStatusCode(), location); loggedIn = true; } EntityUtils.consume(response2.getEntity()); } finally { loginMethod.releaseConnection(); } } }
From source file:com.tweetlanes.android.urlservice.ApiService.java
public static HttpResponse postRequest(String url, String debugName) { HttpClient client = new DefaultHttpClient(); HttpPost request = new HttpPost(); HttpResponse response = null;//from www . j ava 2 s .c o m try { request.setURI(new URI(url)); //Log.d("tweetlanes url fetch", url); response = client.execute(request); //Log.d(TAG, debugName + " complete"); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return response; }
From source file:jfabrix101.lib.helper.NetworkHelper.java
/** * Download content from a URL in binary format with a max size. * /*w ww .j a v a 2 s. c o m*/ * @param url - URL from which to download * @return - The array of byte of content * @throws Exception - Exception if something went wrong or the content-lngth is too long */ public static byte[] getBinaryData(String url, long maxSizeLength) throws Exception { HttpClient client = new DefaultHttpClient(); HttpGet getHttp = new HttpGet(url); HttpResponse response = client.execute(getHttp); int returnCode = response.getStatusLine().getStatusCode(); long length = response.getEntity().getContentLength(); if (length > maxSizeLength) throw new RuntimeException("contentLength too big !!"); byte[] result = EntityUtils.toByteArray(response.getEntity()); if (returnCode != HttpStatus.SC_OK) { mLogger.error("UpdateServiceHelper() - Network error reading URL %s", url); mLogger.error("UpdateServiceHelper() - Network error: HttpStatusCode : %s", response.getStatusLine().getStatusCode()); return null; } return result; }
From source file:org.jboss.additional.testsuite.jdkall.present.clustering.cluster.ejb.xpc.StatefulWithXPCFailoverTestCase.java
private static void assertExecuteUrl(HttpClient client, URI url) throws IOException { HttpResponse response = client.execute(new HttpGet(url)); try {//from w w w . j av a 2 s . c o m assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); } finally { HttpClientUtils.closeQuietly(response); } }
From source file:com.ettrema.httpclient.Utils.java
public static HttpResult executeHttpWithResult(HttpClient client, HttpUriRequest m, OutputStream out) throws IOException { HttpResponse resp = client.execute(m); HttpEntity entity = resp.getEntity(); if (entity != null) { InputStream in = null;//from w w w . j a v a 2s . co m try { in = entity.getContent(); if (out != null) { IOUtils.copy(in, out); } } finally { IOUtils.closeQuietly(in); } } Map<String, String> mapOfHeaders = new HashMap<String, String>(); for (Header h : resp.getAllHeaders()) { mapOfHeaders.put(h.getName(), h.getValue()); // TODO: should concatenate multi-valued headers } HttpResult result = new HttpResult(resp.getStatusLine().getStatusCode(), mapOfHeaders); return result; }