List of usage examples for org.apache.http.impl.client DefaultHttpClient execute
public CloseableHttpResponse execute(final HttpUriRequest request) throws IOException, ClientProtocolException
From source file:com.login.android.cardapio.garcom.util.DrawableManager.java
private InputStream fetch(String urlString) throws MalformedURLException, IOException { HttpParams httpParameters = new BasicHttpParams(); int timeoutConnection = 10000; HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters); HttpGet request = new HttpGet(urlString); HttpResponse response = httpClient.execute(request); return response.getEntity().getContent(); }
From source file:es.rocapal.utils.Download.HTTPActions.java
public String doGetPetition(String url) { try {//from w ww . j av a 2 s . c o m DefaultHttpClient httpclient = new DefaultHttpClient(); HttpGet httpGet = null; httpGet = new HttpGet(url); HttpResponse response = httpclient.execute(httpGet); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { HttpEntity entity = response.getEntity(); String str = EntityUtils.toString(entity); Log.d("doGetPetition", str); return str; } return String.valueOf(response.getStatusLine().getStatusCode()); } catch (IOException e) { Log.e("doGetPetition", e.getMessage()); return null; } }
From source file:WSpatern.DownloadLink.java
public void getLink(String token, String id) { try {//from w w w . ja v a2 s . com DefaultHttpClient client = new DefaultHttpClient(); HttpGet get = new HttpGet("http://documenta-dms.com/DMSWS/api/v1/file/" + token + "/link_by_id/" + id); HttpResponse response = client.execute(get); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line = ""; while ((line = rd.readLine()) != null) { System.out.println(line); parseXML(line); } } catch (IOException ex) { Logger.getLogger(ValidTokenWS.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.aremaitch.codestock2010.datadownloader.ConferenceAgendaDownloader.java
@Override public JSONObject getSessionData() { JSONObject result = null;/* w w w . j a v a2 s .c o m*/ try { ACLogger.info(CSConstants.AGENDADWNLDSVC_LOG_TAG, "downloading session data"); DefaultHttpClient hc = new DefaultHttpClient(); HttpGet hg = new HttpGet(getSessionUrl()); HttpResponse response = hc.execute(hg); result = new JSONObject(EntityUtils.toString(response.getEntity())); } catch (JSONException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return result; }
From source file:org.openml.knime.OpenMLWebservice.java
/** * Upload a run./*from www .j a va 2s . c o m*/ * * @param description Description to the run * @param files Run files * @param user Name of the user * @param password Password of the user * @return Response from the server * @throws Exception */ public static String sendRuns(final File description, final File[] files, final String user, final String password) throws Exception { String result = ""; DefaultHttpClient httpclient = new DefaultHttpClient(); Credentials credentials = new UsernamePasswordCredentials(user, password); AuthScope scope = new AuthScope(new URI(WEBSERVICEURL).getHost(), 80); httpclient.getCredentialsProvider().setCredentials(scope, credentials); try { String url = WEBSERVICEURL + "?f=openml.run.upload"; HttpPost httppost = new HttpPost(url); MultipartEntity reqEntity = new MultipartEntity(); FileBody descriptionBin = new FileBody(description); reqEntity.addPart("description", descriptionBin); for (int i = 0; i < files.length; i++) { FileBody bin = new FileBody(files[i]); reqEntity.addPart("predictions", bin); } httppost.setEntity(reqEntity); HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity(); if (response.getStatusLine().getStatusCode() < 200) { throw new Exception(response.getStatusLine().getReasonPhrase()); } if (resEntity != null) { result = convertStreamToString(resEntity.getContent()); } ErrorDocument errorDoc = null; try { errorDoc = ErrorDocument.Factory.parse(result); } catch (Exception e) { // no error XML should mean no error } if (errorDoc != null && errorDoc.validate()) { ErrorDocument.Error error = errorDoc.getError(); String errorMessage = error.getCode() + " : " + error.getMessage(); if (error.isSetAdditionalInformation()) { errorMessage += " : " + error.getAdditionalInformation(); } throw new Exception(errorMessage); } EntityUtils.consume(resEntity); } finally { try { httpclient.getConnectionManager().shutdown(); } catch (Exception ignore) { // ignore } } return result; }
From source file:com.aremaitch.codestock2010.datadownloader.ConferenceAgendaDownloader.java
@Override public JSONObject getSpeakerData() { JSONObject result = null;/* w ww . j ava 2 s.com*/ try { ACLogger.info(CSConstants.AGENDADWNLDSVC_LOG_TAG, "downloading speaker data"); DefaultHttpClient hc = new DefaultHttpClient(); HttpGet hg = new HttpGet(getSpeakersUrl()); HttpResponse response = hc.execute(hg); result = new JSONObject(EntityUtils.toString(response.getEntity())); } catch (JSONException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return result; }
From source file:org.kaaproject.kaa.demo.powerplant.data.RestDataEndpoint.java
private JSONArray fetchJson(HttpGet getRequest) throws IOException, ClientProtocolException, JSONException { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpResponse response = httpClient.execute(getRequest); if (response.getStatusLine().getStatusCode() != 200) { throw new RuntimeException("Failed : HTTP error code : " + response.getStatusLine().getStatusCode()); }/*from w w w . j a v a 2s.c om*/ BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); StringBuilder sb = new StringBuilder(); System.out.println("Output from Server .... \n"); String output; while ((output = br.readLine()) != null) { sb.append(output); sb.append(System.getProperty("line.separator")); } httpClient.getConnectionManager().shutdown(); JSONArray jsonArray = new JSONArray(sb.toString()); return jsonArray; }
From source file:WSpatern.ListOfFile.java
public void getFile(String token, String id) { try {/* w w w . j ava 2 s .c om*/ DefaultHttpClient client = new DefaultHttpClient(); HttpGet get = new HttpGet("http://documenta-dms.com/DMSWS/api/v1/dir/" + token + "/link_by_id/" + id); HttpResponse response = client.execute(get); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line = ""; while ((line = rd.readLine()) != null) { System.out.println(line); parseXML(line); } } catch (IOException ex) { Logger.getLogger(ValidTokenWS.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.ibm.xsp.xflow.activiti.util.HttpClientUtil.java
public static String get(String url, Cookie[] cookies) { String body = null;/*www .j a va 2 s .c o m*/ try { StringBuffer buffer = new StringBuffer(); DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet getRequest = new HttpGet(url); httpClient.setCookieStore(new BasicCookieStore()); for (int i = 0; i < cookies.length; i++) { logger.finest("Cookie:" + cookies[i].getName() + ":" + cookies[i].getValue() + ":" + cookies[i].getDomain() + ":" + cookies[i].getPath()); BasicClientCookie cookie = new BasicClientCookie(cookies[i].getName(), cookies[i].getValue()); cookie.setVersion(0); URL urlParse = new URL(url); String host = urlParse.getHost(); String domain = null; if (host != null && host.indexOf('.') > 0) { domain = host.substring(host.indexOf('.') + 1); } logger.finest("Domain:" + domain); cookie.setDomain(domain); cookie.setPath("/"); httpClient.getCookieStore().addCookie(cookie); } HttpResponse response = httpClient.execute(getRequest); BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); String output; logger.finest("Output from Server .... \n"); while ((output = br.readLine()) != null) { logger.finest(output); buffer.append(output); } httpClient.getConnectionManager().shutdown(); body = buffer.toString(); } catch (Exception e) { e.printStackTrace(); } return body; }
From source file:de.mendelson.comm.as2.client.HTMLPanel.java
/**Sets a new page to the viewer and handles the Stack update *@param url URL to move to/*from w w w . j a v a 2 s . co m*/ */ public Header[] setURL(String urlStr, String userAgent, File fallbackOnError) { Header[] header = new Header[0]; try { //post for header data HttpPost filePost = new HttpPost(new URL(urlStr).toExternalForm()); HttpParams params = filePost.getParams(); HttpProtocolParams.setUserAgent(params, userAgent); DefaultHttpClient httpClient = new DefaultHttpClient(); HttpResponse httpResponse = httpClient.execute(filePost); header = httpResponse.getAllHeaders(); int status = httpResponse.getStatusLine().getStatusCode(); if (status != HttpServletResponse.SC_OK) { throw new Exception("HTTP " + status); } httpClient.getConnectionManager().shutdown(); //now get for body data this.jEditorPane.setPage(new URL(urlStr)); } catch (Exception e) { e.printStackTrace(); try { this.setPage(fallbackOnError); } catch (Exception ex) { //nop } } return (header); }