List of usage examples for org.apache.http.conn HttpHostConnectException printStackTrace
public void printStackTrace()
From source file:fr.enseirb.odroidx.videomanager.Uploader.java
private final int SendName(String fileName) { int port = PORT; try {// w w w .j a va 2 s .co m client = new DefaultHttpClient(); String getURL = "http://".concat(server_ip).concat(SERVLET_UPLOAD).concat(fileName); HttpGet get = new HttpGet(getURL); HttpResponse responseGet = client.execute(get); HttpEntity resEntityGet = responseGet.getEntity(); /* * if (resEntityGet != null) { // do something with the response * String response = EntityUtils.toString(resEntityGet); * Log.i("GET RESPONSE", response); port = * Integer.parseInt(response); } */ } catch (HttpHostConnectException e) { STATUS = HTTP_SERVER; e.printStackTrace(); } catch (Exception e) { STATUS = HTTP_SERVER; e.printStackTrace(); } try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } return port; }
From source file:org.oss.bonita.utils.bonita.RestClient.java
private int executePostRequest(String apiURI, UrlEncodedFormEntity entity) { try {/*from w w w.ja v a2s.co m*/ HttpPost postRequest = new HttpPost(bonitaURI + apiURI); postRequest.setEntity(entity); HttpResponse response = httpClient.execute(postRequest, httpContext); return consumeResponse(response, true); } catch (HttpHostConnectException e) { throw new RuntimeException( "Bonita bundle may not have been started, or the URL is invalid. Please verify hostname and port number. URL used is: " + bonitaURI, e); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } }
From source file:org.camunda.bpm.ext.sdk.impl.ClientCommandContext.java
public HttpResponse execute(HttpRequestBase req) { HttpResponse response = null;//from w w w . jav a 2 s .co m try { response = httpClient.execute(req); } catch (HttpHostConnectException e) { throw new CamundaClientException( "Unable to connect to host " + req.getURI().getHost() + ". Full uri=" + req.getURI(), e); } catch (Exception e) { throw new CamundaClientException("Exception while executing request", e); } int statusCode = response.getStatusLine().getStatusCode(); if (statusCode < 200 || statusCode >= 300) { HttpEntity entity = response.getEntity(); String responseStr = ""; try { InputStream content = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(content)); while (reader.ready()) { responseStr += reader.readLine(); } } catch (Exception e) { e.printStackTrace(); } throw new CamundaClientException( "Request " + req + " returned error: " + response.getStatusLine() + ": " + responseStr); } return response; }
From source file:org.wildfly.swarm.proc.Monitor.java
/** * Main test execution. Spawns an external process * @param iteration/*from w w w . j ava2 s .c o m*/ * @param file * @param httpCheck * @param collector */ private void runTest(int iteration, File file, String httpCheck, final Collector collector) { System.out.println("Testing " + file.getAbsolutePath() + ", iteration " + iteration); String id = file.getAbsolutePath(); String uid = UUID.randomUUID().toString(); Process process = null; int attempts = 0; try { Path workDir = Files.createDirectories( this.workDir.toPath().resolve(Paths.get(file.getName(), "iteration-" + iteration))); Path tmp = Files.createDirectory(workDir.resolve("tmp")); ProcessBuilder pb = new ProcessBuilder("java", "-Duid=" + uid, "-Djava.io.tmpdir=" + tmp.toAbsolutePath().toString(), "-jar", file.getAbsolutePath()) .redirectOutput(workDir.resolve("stdout.txt").toFile()) .redirectError(workDir.resolve("stderr.txt").toFile()); final long s0 = System.currentTimeMillis(); process = pb.start(); final CloseableHttpClient httpClient = HttpClients.createDefault(); while (true) { if (attempts >= NUM_CONNECTION_ATTEMPTS) { System.out.println("Max attempts reached, escaping sequence"); break; } CloseableHttpResponse response = null; try { HttpGet request = new HttpGet(httpCheck); response = httpClient.execute(request); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == 200) { collector.onMeasurement(id, Measure.STARTUP_TIME, (double) (System.currentTimeMillis() - s0)); warmup(httpClient, httpCheck); measureMemory(id, uid, collector); measureJarSize(id, file, collector); measureTmpDirSize(id, tmp, collector); break; } else if (statusCode == 404) { // this can happen during server boot, when the HTTP endpoint is already exposed // but the application is not yet deployed } else { System.err.println("Failed to execute HTTP check: " + statusCode); break; } } catch (HttpHostConnectException e) { // server not running yet } finally { if (response != null) { response.close(); } } attempts++; Thread.sleep(MS_BETWEEN_ATTEMPTS); } httpClient.close(); final long s1 = System.currentTimeMillis(); process.destroy(); boolean finished = process.waitFor(2, TimeUnit.SECONDS); if (finished) { collector.onMeasurement(id, Measure.SHUTDOWN_TIME, (double) (System.currentTimeMillis() - s1)); } } catch (Throwable t) { t.printStackTrace(); } finally { if (process != null && process.isAlive()) { process.destroyForcibly(); try { process.waitFor(2, TimeUnit.SECONDS); } catch (InterruptedException e) { e.printStackTrace(); } } } }
From source file:rinor.Rest_com.java
@SuppressWarnings("null") public static JSONObject connect(String url, String login, String password) { tracerengine Tracer = null;/* w ww . ja v a 2 s. co m*/ JSONObject json = null; try { DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.getCredentialsProvider().setCredentials(new AuthScope(null, -1), new UsernamePasswordCredentials(login + ":" + password)); // TODO Set timeout // this doesn't work //httpclient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 10000); HttpGet httpget = new HttpGet(url); HttpResponse response; String result = null; response = httpclient.execute(httpget); if (response.getStatusLine().getStatusCode() == 200) { HttpEntity entity = response.getEntity(); if (entity != null) { InputStream instream = entity.getContent(); result = convertStreamToString(instream); json = new JSONObject(result); instream.close(); } } else { Tracer.d(mytag, "Resource not available>"); } } catch (HttpHostConnectException e) { //e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } return json; }