List of usage examples for org.apache.http.client HttpClient execute
HttpResponse execute(HttpUriRequest request) throws IOException, ClientProtocolException;
From source file:net.a2bsoft.buss.http.SendQuery.java
public static String sendQuery(String query) { try {//from w w w .ja v a 2 s . com query = URLEncoder.encode(query, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return e.getMessage(); } URL url = null; try { url = new URL( "http://www.atb.no/xmlhttprequest.php?service=routeplannerOracle.getOracleAnswer&question=" + query); } catch (MalformedURLException e) { e.printStackTrace(); } String result = null; HttpParams my_httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(my_httpParams, 30000); HttpConnectionParams.setSoTimeout(my_httpParams, 30000); HttpClient client = new DefaultHttpClient(my_httpParams); HttpGet get = new HttpGet(url.toString()); HttpResponse resp; try { resp = client.execute(get); InputStream data = resp.getEntity().getContent(); result = new BufferedReader(new InputStreamReader(data)).readLine(); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); return sendQueryBusstuc(query); // return e.getMessage(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return sendQueryBusstuc(query); // return e.getMessage(); } return result; }
From source file:org.wso2.security.tools.dependencycheck.scanner.NotificationManager.java
public static void notifyScanStatus(String status) throws NotificationManagerException { int i = 0;//from www . j a v a 2 s. co m while (i < 10) { try { URI uri = (new URIBuilder()).setHost(automationManagerHost).setPort(automationManagerPort) .setScheme("http").setPath(ScannerProperties.getNotifyScanStatus()) .addParameter("containerId", myContainerId).addParameter("status", status).build(); HttpClient httpClient = HttpClientBuilder.create().build(); HttpGet get = new HttpGet(uri); HttpResponse response = httpClient.execute(get); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { LOGGER.info("Notified successfully"); return; } else { i++; } Thread.sleep(2000); } catch (URISyntaxException | InterruptedException | IOException e) { LOGGER.error("Error occurred while notifying the scan status to automation manager", e); i++; } } throw new NotificationManagerException("Error occurred while notifying status to Automation Manager"); }
From source file:v2.service.generic.library.utils.HttpClientUtil.java
public static HttpResponse sendRequest(HttpClient httpclient, HttpUriRequest httpost) throws IOException { HttpResponse response = httpclient.execute(httpost); return response; }
From source file:de.incoherent.suseconferenceclient.app.HTTPWrapper.java
public static String getRawText(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) { StringBuilder builder = new StringBuilder(); HttpEntity responseEntity = response.getEntity(); InputStream content = responseEntity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(content)); String line;/*from w w w . jav a 2 s . co m*/ while ((line = reader.readLine()) != null) { builder.append(line); } return builder.toString(); } else { throw new HttpResponseException(statusCode, statusLine.getReasonPhrase()); } }
From source file:Extras.JSON.java
public static HttpResponse request(String URL, List parametros) { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(URL); HttpResponse response = null;// w ww . j a v a2 s. c om try { httppost.setEntity(new UrlEncodedFormEntity(parametros)); response = httpclient.execute(httppost); } catch (Exception e) { System.out.println(e.getMessage()); } return response; }
From source file:org.wso2.security.tools.dependencycheck.scanner.NotificationManager.java
private static void notifyStatus(String path, boolean status) throws NotificationManagerException { int i = 0;/* w ww . j av a 2s .c o m*/ while (i < 10) { try { URI uri = (new URIBuilder()).setHost(automationManagerHost).setPort(automationManagerPort) .setScheme("http").setPath(path).addParameter("containerId", myContainerId) .addParameter("status", String.valueOf(status)).build(); HttpClient httpClient = HttpClientBuilder.create().build(); HttpGet get = new HttpGet(uri); HttpResponse response = httpClient.execute(get); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { LOGGER.info("Notified successfully"); return; } else { i++; } Thread.sleep(2000); } catch (URISyntaxException | InterruptedException | IOException e) { LOGGER.error("Error occurred while notifying the status to automation manager", e); i++; } } throw new NotificationManagerException("Error occurred while notifying status to Automation Manager"); }
From source file:com.twitter.heron.integration_test.core.HttpUtils.java
static int httpJsonPost(String newHttpPostUrl, String jsonData) throws IOException, ParseException { HttpClient client = HttpClientBuilder.create().build(); HttpPost post = new HttpPost(newHttpPostUrl); StringEntity requestEntity = new StringEntity(jsonData, ContentType.APPLICATION_JSON); post.setEntity(requestEntity);/*from ww w .j a v a 2s. c o m*/ HttpResponse response = client.execute(post); return response.getStatusLine().getStatusCode(); }
From source file:org.yamj.api.common.http.DigestedResponseReader.java
/** * Process the response and return the content * * @param httpClient//from w w w . j a v a2 s . co m * @param httpRequest * @param charset * @return * @throws IOException */ private static DigestedResponse processRequest(HttpClient httpClient, HttpRequestBase httpRequest, Charset charset) throws IOException { try { final HttpResponse response = httpClient.execute(httpRequest); final DigestedResponse digestedResponse = new DigestedResponse(); digestedResponse.setStatusCode(response.getStatusLine().getStatusCode()); if (response.getEntity() != null) { digestedResponse.setContent(getContent(response, charset)); } return digestedResponse; } catch (ConnectTimeoutException | SocketTimeoutException ex) { LOG.trace("Timeout exception", ex); httpRequest.releaseConnection(); // a timeout should result in a 503 error // to signal that the service is temporarily not available return new DigestedResponse(HTTP_STATUS_503, ""); } catch (IOException ex) { httpRequest.releaseConnection(); throw ex; } }
From source file:org.wso2.security.tools.product.manager.handler.HttpRequestHandler.java
/** * Send HTTP GET request//from w w w. j a v a2s .c om * * @param request Requested URI * @return HTTPResponse after executing the command */ public static HttpResponse sendGetRequest(URI request) { try { HttpClientBuilder clientBuilder = HttpClients.custom(); HttpClient httpClient = clientBuilder.setRetryHandler(new DefaultHttpRequestRetryHandler(3, false)) .build(); HttpGet httpGetRequest = new HttpGet(request); return httpClient.execute(httpGetRequest); } catch (IOException e) { LOGGER.error("Error occurred while sending GET request to " + request.getPath(), e); } return null; }
From source file:org.wso2.security.tools.findsecbugs.scanner.NotificationManager.java
public static void notifyScanStatus(String status) throws NotificationManagerException { int i = 0;/* w ww . j ava 2 s .co m*/ while (i < 10) { try { URI uri = (new URIBuilder()).setHost(automationManagerHost).setPort(automationManagerPort) .setScheme("http").setPath(SCAN_STATUS).addParameter("containerId", myContainerId) .addParameter("status", status).build(); HttpClient httpClient = HttpClientBuilder.create().build(); HttpGet get = new HttpGet(uri); HttpResponse response = httpClient.execute(get); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { LOGGER.info("Notified successfully"); return; } else { i++; } Thread.sleep(2000); } catch (URISyntaxException | InterruptedException | IOException e) { LOGGER.error("Error occurred while notifying the scan status to automation manager", e); i++; } } throw new NotificationManagerException("Error occurred while notifying status to Automation Manager"); }