List of usage examples for org.apache.http.impl.client DefaultHttpClient execute
public CloseableHttpResponse execute(final HttpUriRequest request) throws IOException, ClientProtocolException
From source file:org.elegosproject.romupdater.JSONParser.java
public static InputStream getJSONData(String url) throws Exception { HttpParams httpParameters = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParameters, 3000); DefaultHttpClient httpClient = new DefaultHttpClient(); URI uri;//from w ww. jav a2s .c o m InputStream data = null; try { uri = new URI(url); HttpGet method = new HttpGet(uri); HttpResponse response = httpClient.execute(method); data = response.getEntity().getContent(); } catch (Exception e) { Log.e(TAG, "Unable to download file: " + e); throw e; } return data; }
From source file:it.cdpaf.helper.DrawableManager.java
private static InputStream fetch(String urlString, Context ctx) throws MalformedURLException, IOException { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet request = new HttpGet(urlString); HttpResponse response = httpClient.execute(request); return response.getEntity().getContent(); }
From source file:org.jboss.as.test.manualmode.web.valve.authenticator.ValveUtil.java
/** * Access http://localhost///from www . j a va2 s . c o m * @return "valve" headers */ public static Header[] hitValve(URL url, int expectedResponseCode) throws Exception { HttpGet httpget = new HttpGet(url.toURI()); DefaultHttpClient httpclient = new DefaultHttpClient(); log.info("executing request" + httpget.getRequestLine()); HttpResponse response = httpclient.execute(httpget); int statusCode = response.getStatusLine().getStatusCode(); Header[] errorHeaders = response.getHeaders("X-Exception"); assertEquals("Wrong response code: " + statusCode + " On " + url, expectedResponseCode, statusCode); assertEquals("X-Exception(" + Arrays.toString(errorHeaders) + ") is null", 0, errorHeaders.length); return response.getHeaders("valve"); }
From source file:att.jaxrs.client.Webinar.java
public static String deleteWebinar(long content_id) { List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("content_id", Long.toString(content_id))); String resultStr = ""; try {/*from w w w . j a v a 2 s . co m*/ DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost post = new HttpPost(Constants.DELETE_WEBINAR_RESOURCE); post.setEntity(new UrlEncodedFormEntity(urlParameters)); HttpResponse result = httpClient.execute(post); System.out.println(Constants.RESPONSE_STATUS_CODE + result); resultStr = Util.getStringFromInputStream(result.getEntity().getContent()); System.out.println(Constants.RESPONSE_BODY + resultStr); } catch (Exception e) { System.out.println(e.getMessage()); } return resultStr; }
From source file:middleware.HTTPRequest.java
public static List<Vuelo> doGetVuelos() throws IOException { String result;/* w ww . ja v a2 s . c o m*/ String url = "http://localhost:8084/MVIv2/webapi/vuelos"; DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet getRequest = new HttpGet(url); getRequest.addHeader("Accept", "application/json"); HttpResponse response = httpClient.execute(getRequest); if (response.getStatusLine().getStatusCode() != 200) { throw new RuntimeException("ERROR AL CONSULTAR DEL TIPO: " + response.getStatusLine().getStatusCode()); } HttpEntity entity = response.getEntity(); result = EntityUtils.toString(entity); List<Vuelo> listaVuelos = getArrayVuelo(result); httpClient.getConnectionManager().shutdown(); return listaVuelos; }
From source file:middleware.HTTPRequest.java
public static List<Reserva> doGetReservas() throws IOException { String result;/* w ww.java 2 s. c o m*/ String url = "http://localhost:8084/MVIv2/webapi/reservas"; DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet getRequest = new HttpGet(url); getRequest.addHeader("Accept", "application/json"); HttpResponse response = httpClient.execute(getRequest); if (response.getStatusLine().getStatusCode() != 200) { throw new RuntimeException("ERROR AL CONSULTAR DEL TIPO: " + response.getStatusLine().getStatusCode()); } HttpEntity entity = response.getEntity(); result = EntityUtils.toString(entity); List<Reserva> listaReservas = getArrayReserva(result); httpClient.getConnectionManager().shutdown(); return listaReservas; }
From source file:att.jaxrs.client.Tag.java
public static String addTag(Tag tag) { final long tag_id = getExistingRecord(tag.getTag_name()); if (-1L != tag_id) { return "{response:{Tag: 'EXISTING_RECORD'},tag_id:" + tag_id + "}"; }// w ww .j ava 2 s .co m List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("tag_name", tag.getTag_name())); HttpResponse result; String resultStr = ""; try { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost post = new HttpPost(Constants.INSERT_TAG_RESOURCE); post.setEntity(new UrlEncodedFormEntity(urlParameters)); result = httpClient.execute(post); System.out.println(Constants.RESPONSE_STATUS_CODE + result); resultStr = Util.getStringFromInputStream(result.getEntity().getContent()); System.out.println(Constants.RESPONSE_BODY + resultStr); } catch (Exception e) { System.out.println(e.getMessage()); } return resultStr; }
From source file:att.jaxrs.client.Webinar.java
public static String addWebinar(Webinar webinar) { List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("content_id", webinar.getContent_id().toString())); urlParameters.add(new BasicNameValuePair("presenter", webinar.getPresenter())); String resultStr = ""; try {//from w w w. j ava 2 s . c om DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost post = new HttpPost(Constants.INSERT_WEBINAR_RESOURCE); post.setEntity(new UrlEncodedFormEntity(urlParameters)); HttpResponse result = httpClient.execute(post); System.out.println(Constants.RESPONSE_STATUS_CODE + result); resultStr = Util.getStringFromInputStream(result.getEntity().getContent()); System.out.println(Constants.RESPONSE_BODY + resultStr); } catch (Exception e) { System.out.println(e.getMessage()); } return resultStr; }
From source file:att.jaxrs.client.Webinar.java
public static String updateWebinar(Webinar webinar) { List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("content_id", webinar.getContent_id().toString())); urlParameters.add(new BasicNameValuePair("presenter", webinar.getPresenter())); String resultStr = ""; try {/* www . j a v a 2 s .c o m*/ DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost post = new HttpPost(Constants.UPDATE_WEBINAR_RESOURCE); post.setEntity(new UrlEncodedFormEntity(urlParameters)); HttpResponse result = httpClient.execute(post); System.out.println(Constants.RESPONSE_STATUS_CODE + result); resultStr = Util.getStringFromInputStream(result.getEntity().getContent()); System.out.println(Constants.RESPONSE_BODY + resultStr); } catch (Exception e) { System.out.println(e.getMessage()); } return resultStr; }
From source file:neembuu.uploader.external.CheckMajorUpdate.java
/** * @deprecated version.xml is located in update.zip which is used to get list * of latest plugins//from w w w. j a v a 2 s. co m */ @Deprecated private static String getVersionXmlOnline() throws IOException { 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"); DefaultHttpClient httpclient = new DefaultHttpClient(params); HttpGet httpget = new HttpGet("http://neembuuuploader.sourceforge.net/version.xml"); NULogger.getLogger().info("Checking for new version..."); HttpResponse response = httpclient.execute(httpget); return EntityUtils.toString(response.getEntity()); }