List of usage examples for org.apache.http.impl.client BasicResponseHandler BasicResponseHandler
BasicResponseHandler
From source file:com.commonsware.android.internet.WeatherDemo.java
private void updateForecast(Location loc) { String url = String.format(format, loc.getLatitude(), loc.getLongitude()); HttpGet getMethod = new HttpGet(url); try {//from ww w. ja va 2 s. com ResponseHandler<String> responseHandler = new BasicResponseHandler(); String responseBody = client.execute(getMethod, responseHandler); buildForecasts(responseBody); String page = generatePage(); browser.loadDataWithBaseURL(null, page, "text/html", "UTF-8", null); } catch (Throwable t) { Toast.makeText(this, "Request failed: " + t.toString(), 4000).show(); } }
From source file:com.noelportugal.amazonecho.AmazonEchoApi.java
public String httpGet(String url) { String output = ""; try {//from w w w . j ava 2 s .c o m HttpGet httpGet = new HttpGet(BASE_URL + url); httpGet.setHeader(HttpHeaders.USER_AGENT, "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13"); HttpResponse httpResponse = httpclient.execute(httpGet); StatusLine responseStatus = httpResponse.getStatusLine(); // System.out.println(responseStatus); int statusCode = responseStatus.getStatusCode(); if (statusCode == 200) { httpResponse.getEntity(); output = new BasicResponseHandler().handleResponse(httpResponse); } } catch (Exception e) { System.err.println("httpGet Error: " + e.getMessage()); } return output; }
From source file:com.openkm.applet.Util.java
/** * Upload scanned document to OpenKM/*w ww. j a va 2s. co m*/ * */ public static String createDocument(String token, String path, String fileName, String fileType, String url, List<BufferedImage> images) throws MalformedURLException, IOException { log.info("createDocument(" + token + ", " + path + ", " + fileName + ", " + fileType + ", " + url + ", " + images + ")"); File tmpDir = createTempDir(); File tmpFile = new File(tmpDir, fileName + "." + fileType); ImageOutputStream ios = ImageIO.createImageOutputStream(tmpFile); String response = ""; try { if ("pdf".equals(fileType)) { ImageUtils.writePdf(images, ios); } else if ("tif".equals(fileType)) { ImageUtils.writeTiff(images, ios); } else { if (!ImageIO.write(images.get(0), fileType, ios)) { throw new IOException("Not appropiated writer found!"); } } ios.flush(); ios.close(); if (token != null) { // Send image HttpClient client = new DefaultHttpClient(); MultipartEntity form = new MultipartEntity(); form.addPart("file", new FileBody(tmpFile)); form.addPart("path", new StringBody(path, Charset.forName("UTF-8"))); form.addPart("action", new StringBody("0")); // FancyFileUpload.ACTION_INSERT HttpPost post = new HttpPost(url + "/frontend/FileUpload;jsessionid=" + token); post.setHeader("Cookie", "jsessionid=" + token); post.setEntity(form); ResponseHandler<String> responseHandler = new BasicResponseHandler(); response = client.execute(post, responseHandler); } else { // Store in disk String home = System.getProperty("user.home"); File dst = new File(home, tmpFile.getName()); copyFile(tmpFile, dst); response = "Image copied to " + dst.getPath(); } } finally { FileUtils.deleteQuietly(tmpDir); } log.info("createDocument: " + response); return response; }
From source file:dk.i2m.drupal.resource.UserResource.java
public void logout() throws HttpResponseException, IOException { URLBuilder builder = new URLBuilder(getDc().getHostname()); builder.add(getDc().getEndpoint());//from w ww . j a v a 2 s . co m builder.add(getAlias()); builder.add("logout"); HttpPost method = new HttpPost(builder.toURI()); ResponseHandler<String> handler = new BasicResponseHandler(); getDc().getHttpClient().execute(method, handler); }
From source file:com.diversityarrays.dalclient.httpimpl.DalHttpFactoryImpl.java
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override/* w w w . j av a 2 s . c om*/ public DalResponseHandler<String> createBasicResponseHandler() { return new DalResponseHandlerImpl(new BasicResponseHandler()); }
From source file:com.kasabi.data.movies.dbpedia.DBPediaBaseLinker.java
protected String getURI(HttpClient httpclient, String type, String string) { String uri = null;/* ww w. ja va2 s .co m*/ try { String queryClass = type != null ? "&QueryClass=" + URLEncoder.encode(type, "UTF-8") : ""; String queryString = "?QueryString=" + URLEncoder.encode(string, "UTF-8"); HttpGet httpget = new HttpGet( "http://lookup.dbpedia.org/api/search.asmx/KeywordSearch" + queryString + queryClass); ResponseHandler<String> responseHandler = new BasicResponseHandler(); String responseBody = httpclient.execute(httpget, responseHandler); Document document = Jsoup.parse(responseBody); Elements elements = document.select("result > uri"); if (!elements.isEmpty()) { uri = elements.first().text(); } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return uri; }
From source file:com.github.kristofa.test.http.MockHttpServerTestNG.java
@Test public void testShouldHandlePostRequests() throws IOException { // Given a mock server configured to respond to a POST / with data // "Hello World" with an ID responseProvider.expect(Method.POST, "/", "text/plain; charset=UTF-8", "Hello World").respondWith(200, "text/plain", "ABCD1234"); // When a request for POST / arrives final HttpPost req = new HttpPost(baseUrl + "/"); req.setEntity(new StringEntity("Hello World", UTF_8)); final ResponseHandler<String> handler = new BasicResponseHandler(); final String responseBody = client.execute(req, handler); // Then the response is "ABCD1234" Assert.assertEquals("ABCD1234", responseBody); }
From source file:hotandcold.HNCAPI.java
public coord getinfo(int id) { String request = servIP + "verb=g&id=" + id; HttpClient client = new DefaultHttpClient(); HttpGet get = new HttpGet(request); ResponseHandler<String> responseHandler = new BasicResponseHandler(); try {//from w ww . j a v a 2 s.com String responseBody = client.execute(get, responseHandler); JSONObject obj = new JSONObject(responseBody); obj = obj.getJSONObject("coord"); coord c = new coord(obj.getDouble("long"), obj.getDouble("lat")); return c; } catch (IOException | JSONException ex) { Logger.getLogger(HNCAPI.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:org.labkey.freezerpro.export.ExportSamplesCommand.java
public FreezerProCommandResonse execute(HttpClient client, PipelineJob job) { HttpPost post = new HttpPost(_url); try {/*from w w w . jav a 2 s. c om*/ List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("method", "search_samples")); params.add(new BasicNameValuePair("username", _username)); params.add(new BasicNameValuePair("password", _password)); if (_searchFilterString != null) params.add(new BasicNameValuePair("query", _searchFilterString)); else params.add(new BasicNameValuePair("query", "")); params.add(new BasicNameValuePair("start", String.valueOf(_startRecord))); params.add(new BasicNameValuePair("limit", String.valueOf(_limit))); post.setEntity(new UrlEncodedFormEntity(params)); ResponseHandler<String> handler = new BasicResponseHandler(); HttpResponse response = client.execute(post); StatusLine status = response.getStatusLine(); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) return new ExportSamplesResponse(_export, handler.handleResponse(response), status.getStatusCode(), job); else return new ExportSamplesResponse(_export, status.getReasonPhrase(), status.getStatusCode(), job); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.jimkont.contactFix.provider.ProviderHTTPPost.java
/** * Connects to the server//from w w w. ja v a 2s . c o m */ public static String executePost(String url, ArrayList<NameValuePair> params) { final ResponseHandler<String> responseHandler; HttpEntity entity = null; try { entity = new UrlEncodedFormEntity(params); } catch (final UnsupportedEncodingException e) { // this should never happen. throw new AssertionError(e); } final HttpPost post = new HttpPost(url); post.addHeader(entity.getContentType()); post.setEntity(entity); maybeCreateHttpClient(); try { responseHandler = new BasicResponseHandler(); String responseBody = mHttpClient.execute(post, responseHandler); return responseBody; } catch (final IOException e) { return null; } finally { } }