List of usage examples for org.apache.http.impl.client DefaultHttpClient DefaultHttpClient
public DefaultHttpClient()
From source file:net.modelbased.proasense.storage.registry.RegisterSensorSSN.java
public static String postSensor(Sensor sensor) throws RequestErrorException { String content = JsonPrinter.sensorToJson(sensor); URI target;/* w w w . ja v a 2 s . c om*/ try { target = new URI(sensor.getUri().toString() + SENSOR_PATH); } catch (URISyntaxException e1) { e1.printStackTrace(); throw new RequestErrorException(e1.getMessage()); } HttpClient client = new DefaultHttpClient(); HttpPost request = new HttpPost(target); request.setHeader("Content-type", "application/json"); String response = null; try { StringEntity seContent = new StringEntity(content); seContent.setContentType("text/json"); request.setEntity(seContent); response = resolveResponse(client.execute(request)); } catch (Exception e) { throw new RequestErrorException(e.getMessage()); } return response; }
From source file:com.huguesjohnson.retroleague.util.HttpFetch.java
public static InputStream fetch(String address, int timeout) throws MalformedURLException, IOException { HttpGet httpRequest = new HttpGet(URI.create(address)); HttpClient httpclient = new DefaultHttpClient(); final HttpParams httpParameters = httpclient.getParams(); HttpConnectionParams.setConnectionTimeout(httpParameters, timeout); HttpConnectionParams.setSoTimeout(httpParameters, timeout); HttpResponse response = (HttpResponse) httpclient.execute(httpRequest); HttpEntity entity = response.getEntity(); BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity); InputStream instream = bufHttpEntity.getContent(); return (instream); }
From source file:com.teleca.jamendo.util.Caller.java
/** * Performs HTTP GET using Apache HTTP Client v 4 * /* ww w . j av a 2s . c om*/ * @param url * @return * @throws ErrorMsg */ public static String doGet(String url) throws ErrorMsg { String data = null; if (requestCache != null) { data = requestCache.get(url); if (data != null) { Log.d(MyApplication.TAG, "Caller.doGet [cached] " + url); return data; } } // initialize HTTP GET request objects HttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); HttpResponse httpResponse; try { // execute request try { httpResponse = httpClient.execute(httpGet); } catch (UnknownHostException e) { ErrorMsg wsError = new ErrorMsg(); wsError.setMessage(e.getLocalizedMessage()); throw wsError; } catch (SocketException e) { ErrorMsg wsError = new ErrorMsg(); wsError.setMessage(e.getLocalizedMessage()); throw wsError; } // request data HttpEntity httpEntity = httpResponse.getEntity(); if (httpEntity != null) { InputStream inputStream = httpEntity.getContent(); data = convertStreamToString(inputStream); // cache the result if (requestCache != null) { requestCache.put(url, data); } } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Log.d(MyApplication.TAG, "Caller.doGet " + url); return data; }
From source file:de.incoherent.suseconferenceclient.app.HTTPWrapper.java
public static Bitmap getImage(String url) throws ClientProtocolException, IOException { HttpClient client = new DefaultHttpClient(); HttpGet get = new HttpGet(url); Log.d("SUSEConferences", "Get: " + url); HttpResponse response = client.execute(get); StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (statusCode >= 200 && statusCode <= 299) { final HttpEntity entity = response.getEntity(); if (entity != null) { InputStream inputStream = null; try { inputStream = entity.getContent(); final Bitmap bitmap = BitmapFactory.decodeStream(inputStream); return bitmap; } finally { if (inputStream != null) { inputStream.close(); }/*from ww w.jav a 2 s.c o m*/ entity.consumeContent(); } } else { throw new HttpResponseException(statusCode, statusLine.getReasonPhrase()); } } else { throw new HttpResponseException(statusCode, statusLine.getReasonPhrase()); } }
From source file:com.alta189.cyborg.factoids.util.HTTPUtil.java
public static String readRandomLine(String url) { HttpGet request = new HttpGet(url); HttpClient httpClient = new DefaultHttpClient(); try {//from w w w. ja v a2 s . c o m HttpResponse response = httpClient.execute(request); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); List<String> lines = new ArrayList<String>(); String line = ""; while ((line = rd.readLine()) != null) { lines.add(line); } if (lines.size() > 1) { int i = randomNumber(0, lines.size() + 1); return lines.get(i); } else if (lines.size() == 1) { return lines.get(0); } } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:com.bricolsoftconsulting.geocoderplus.util.http.HttpRetriever.java
public HttpRetriever() { httpclient = new DefaultHttpClient(); }
From source file:edu.mit.media.funf.IOUtils.java
public static String httpGet(String uri, HttpParams params) { String responseBody = null;//w ww . j a v a 2 s .c om HttpClient httpclient = new DefaultHttpClient(); StringBuilder uriBuilder = new StringBuilder(uri); HttpGet httpget = new HttpGet(uriBuilder.toString()); if (params != null) { httpget.setParams(params); } ResponseHandler<String> responseHandler = new BasicResponseHandler(); try { responseBody = httpclient.execute(httpget, responseHandler); } catch (ClientProtocolException e) { Log.e(TAG, "HttpGet Error: ", e); responseBody = null; } catch (IOException e) { Log.e(TAG, "HttpGet Error: ", e); responseBody = null; } finally { httpclient.getConnectionManager().shutdown(); } return responseBody; }
From source file:ru.phsystems.irisx.voice.httpPOST.java
/** * Constructor will setup httpclient, post request method and useragent information as required *///from w ww .j a v a 2s. c om public httpPOST() { httpclient = new DefaultHttpClient(); System.setProperty("http.agent", ""); httppost = new HttpPost(speechAPIURL); HttpProtocolParams.setUserAgent(httpclient.getParams(), User_Agent); httppost.setHeader(HeaderType, HeaderContent); }
From source file:WSpatern.RootFolderWS.java
public void getRoot(String token) { try {/* w ww.j ava2s . c o m*/ DefaultHttpClient client = new DefaultHttpClient(); HttpGet get = new HttpGet("http://documenta-dms.com/DMSWS/api/v1/dir/" + token + "/get_root"); 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.github.egonw.ops4j.Concepts.java
public static Concepts getInstance(String server, String apiID, String appKey) throws MalformedURLException { return new Concepts(server, apiID, appKey, new DefaultHttpClient()); }