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.apache.tika.parser.recognition.tf.TensorflowRESTVideoRecogniser.java
@Override public void initialize(Map<String, Param> params) throws TikaConfigException { try {/*from w ww .j a v a 2 s .co m*/ healthUri = URI.create(apiBaseUri + "/ping"); apiUri = URI.create(apiBaseUri + String.format(Locale.getDefault(), "/classify/video?topn=%1$d&min_confidence=%2$f&mode=%3$s", topN, minConfidence, mode)); DefaultHttpClient client = new DefaultHttpClient(); HttpResponse response = client.execute(new HttpGet(healthUri)); available = response.getStatusLine().getStatusCode() == 200; LOG.info("Available = {}, API Status = {}", available, response.getStatusLine()); LOG.info("topN = {}, minConfidence = {}", topN, minConfidence); } catch (Exception e) { available = false; throw new TikaConfigException(e.getMessage(), e); } }
From source file:org.neo4j.qa.features.StartAndStopFeatureTest.java
private int statusCode(String uri, DefaultHttpClient httpClient) throws IOException { HttpResponse response = httpClient.execute(new HttpGet(uri)); EntityUtils.toString(response.getEntity()); return response.getStatusLine().getStatusCode(); }
From source file:com.example.android.navigationdrawerexample.LocationFileReader.java
public List<String[]> getFile() throws ClientProtocolException, IOException { DefaultHttpClient httpclient = new DefaultHttpClient(); HttpGet httppost = new HttpGet(url); HttpResponse response = httpclient.execute(httppost); HttpEntity ht = response.getEntity(); BufferedHttpEntity buf = new BufferedHttpEntity(ht); InputStream is = buf.getContent(); BufferedReader r = new BufferedReader(new InputStreamReader(is)); StringBuilder total = new StringBuilder(); String line;//from ww w . ja v a2 s. c o m String[] location; while ((line = r.readLine()) != null) { total.append(line + "\n"); location = total.toString().split(" "); locationList.add(location); total.setLength(0); } return locationList; }
From source file:de.ifgi.mosia.wpswfs.handler.ProxyRequestHandler.java
protected HttpResponse executeHttpPost(HttpPost post) throws IOException { DefaultHttpClient client = new DefaultHttpClient(); return client.execute(post); }
From source file:com.amazonaws.util.HttpUtils.java
/** * Fetches a file from the URI given and returns an input stream to it. * * @param uri the uri of the file to fetch * @param config optional configuration overrides * @return an InputStream containing the retrieved data * @throws IOException on error/*w ww . j a v a 2s . c o m*/ */ public static InputStream fetchFile(final URI uri, final ClientConfiguration config) throws IOException { HttpParams httpClientParams = new BasicHttpParams(); HttpProtocolParams.setUserAgent(httpClientParams, getUserAgent(config)); HttpConnectionParams.setConnectionTimeout(httpClientParams, getConnectionTimeout(config)); HttpConnectionParams.setSoTimeout(httpClientParams, getSocketTimeout(config)); DefaultHttpClient httpclient = new DefaultHttpClient(httpClientParams); if (config != null) { String proxyHost = config.getProxyHost(); int proxyPort = config.getProxyPort(); if (proxyHost != null && proxyPort > 0) { HttpHost proxy = new HttpHost(proxyHost, proxyPort); httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); if (config.getProxyUsername() != null && config.getProxyPassword() != null) { httpclient.getCredentialsProvider().setCredentials(new AuthScope(proxyHost, proxyPort), new NTCredentials(config.getProxyUsername(), config.getProxyPassword(), config.getProxyWorkstation(), config.getProxyDomain())); } } } HttpResponse response = httpclient.execute(new HttpGet(uri)); if (response.getStatusLine().getStatusCode() != 200) { throw new IOException("Error fetching file from " + uri + ": " + response); } return new HttpClientWrappingInputStream(httpclient, response.getEntity().getContent()); }
From source file:com.pti.mates.ServerUtilities.java
private static void post2(String endpoint, final String msg, final String id, final Context ctx) { DefaultHttpClient client = new MyHttpClient(ctx); HttpPost post = new HttpPost("https://54.194.14.115:443/send"); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); nameValuePairs.add(new BasicNameValuePair("receiver", id)); nameValuePairs.add(new BasicNameValuePair("sender", Common.getFBID())); nameValuePairs.add(new BasicNameValuePair("data", msg)); try {/*from w w w. java 2 s .c om*/ post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } // Execute the Post call and obtain the response HttpResponse postResponse; s = "s No inicialitzada"; try { postResponse = client.execute(post); HttpEntity responseEntity = postResponse.getEntity(); InputStream is = responseEntity.getContent(); s = convertStreamToString(is); } catch (ClientProtocolException e) { Log.e("ERROR", e.toString()); e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); Log.e("ERROR", e.toString()); s = "ERROR: " + e.toString() + " :("; } Log.d("CHIVATO", "FIN THREAD"); //return s; }
From source file:com.thoughtmetric.tl.TLLib.java
public static void postMessage(String message, String backurl, String topicId, Context context) throws IOException { DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.setCookieStore(cookieStore); HttpPost httpost = new HttpPost(POST_URL); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("bericht", message)); nvps.add(new BasicNameValuePair("stage", "1")); nvps.add(new BasicNameValuePair("backurl", backurl)); nvps.add(new BasicNameValuePair("topic_id", topicId)); nvps.add(new BasicNameValuePair("submit_button", "Post")); try {//from w ww .j a v a2 s . c o m httpost.setEntity(new UrlEncodedFormEntity(nvps)); HttpResponse response = httpclient.execute(httpost); HttpEntity entity = response.getEntity(); if (entity != null) { entity.consumeContent(); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } }
From source file:org.wso2.carbon.esb.passthru.transport.test.ESBJAVA3022SendingSoapRequestAfterRestRequestTestCase.java
@Test(groups = "wso2.esb", description = "test to verify that the soap builder/formatter is invoked properly" + "when the soap request is made after rest request.") public void testSendingSoapCallAfterRestCall() throws Exception { String restURL = getApiInvocationURL("api_poc_messagetype");//esbServer.getServiceUrl() + "/testmessagetype"; DefaultHttpClient httpclient = new DefaultHttpClient(); HttpGet request = new HttpGet(restURL); HttpResponse response = httpclient.execute(request); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String responseText = ""; String line = ""; while ((line = rd.readLine()) != null) { responseText = responseText.concat(line); }/*from w ww. j a v a 2 s .c o m*/ assertFalse(responseText.contains("soapenv:Envelope"), "Another <soapenv:Envelope> tag found inside soap body."); assertFalse(responseText.contains("soapenv:Body"), "Another <soapenv:Body> tag found inside soap body."); }
From source file:ru.naumen.servacc.test.HTTPProxyConnectionTest.java
private HttpResponse httpGet(String uri) throws IOException { DefaultHttpClient httpClient = new DefaultHttpClient(); return httpClient.execute(new HttpGet(uri)); }
From source file:de.ifgi.mosia.wpswfs.handler.ProxyRequestHandler.java
protected HttpResponse executeHttpGet(String subUrl) throws IOException { HttpGet get = new HttpGet(String.format("%s?%s", config.getWFSURL(), subUrl)); DefaultHttpClient client = new DefaultHttpClient(); return client.execute(get); }