List of usage examples for org.apache.http.conn HttpHostConnectException getMessage
public String getMessage()
From source file:org.mifosplatform.common.Utils.java
public static String loginIntoServerAndGetBase64EncodedAuthenticationKey() { try {//from w w w . j ava 2s . c o m System.out.println("-----------------------------------LOGIN-----------------------------------------"); final String json = RestAssured.post(LOGIN_URL).asString(); assertThat("Failed to login into mifosx platform", StringUtils.isBlank(json), is(false)); return JsonPath.with(json).get("base64EncodedAuthenticationKey"); } catch (final Exception e) { if (e instanceof HttpHostConnectException) { final HttpHostConnectException hh = (HttpHostConnectException) e; fail("Failed to connect to mifosx platform:" + hh.getMessage()); } throw new RuntimeException(e); } }
From source file:com.gst.common.Utils.java
public static String loginIntoServerAndGetBase64EncodedAuthenticationKey() { try {/* w w w . j a v a 2s . c om*/ System.out.println("-----------------------------------LOGIN-----------------------------------------"); final String json = RestAssured.post(LOGIN_URL).asString(); assertThat("Failed to login into fineract platform", StringUtils.isBlank(json), is(false)); return JsonPath.with(json).get("base64EncodedAuthenticationKey"); } catch (final Exception e) { if (e instanceof HttpHostConnectException) { final HttpHostConnectException hh = (HttpHostConnectException) e; fail("Failed to connect to fineract platform:" + hh.getMessage()); } throw new RuntimeException(e); } }
From source file:io.cloudslang.content.httpclient.execute.HttpClientExecutor.java
public CloseableHttpResponse execute() { CloseableHttpResponse response;//from w w w .j a va 2s . c o m try { response = closeableHttpClient.execute(httpRequestBase, context); } catch (SocketTimeoutException ste) { throw new RuntimeException("Socket timeout: " + ste.getMessage(), ste); } catch (HttpHostConnectException connectEx) { throw new RuntimeException("Connection error: " + connectEx.getMessage(), connectEx); } catch (IOException e) { throw new RuntimeException("Error while executing http request: " + e.getMessage(), e); } return response; }
From source file:org.apache.stratos.nginx.extension.NginxStatisticsReader.java
/** * Make a http request to http://127.0.0.1:<proxy-port>/nginx_status and find writing count. * @param proxyPort/*from w w w . ja v a 2 s . c o m*/ * @return */ private int findWritingCount(int proxyPort) { try { URL url = new URL("http", "127.0.0.1", proxyPort, "/nginx_status"); DefaultHttpClient httpClient = new DefaultHttpClient(); HttpUriRequest request = new HttpGet(url.toURI()); HttpResponse response = httpClient.execute(request); if (response.getStatusLine().getStatusCode() != 200) { throw new RuntimeException("http://127.0.0.1:" + proxyPort + "/nginx_status was not found"); } BufferedReader reader = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); String output, result = ""; while ((output = reader.readLine()) != null) { result += output; } Pattern pattern = Pattern.compile("(Writing: )([0-1]*)"); Matcher matcher = pattern.matcher(result); if (matcher.find()) { // Deduct one to remove the above request int writingCount = Integer.parseInt(matcher.group(2)) - 1; if (log.isDebugEnabled()) { log.debug(String.format("Writing count: [proxy] %d [value] %d", proxyPort, writingCount)); } return writingCount; } throw new RuntimeException("Writing block was not found in nginx_status response"); } catch (HttpHostConnectException ignore) { if (ignore.getMessage().contains("Connection refused")) { log.warn("Could not find in-flight request count, connection refused: " + "http://127.0.0.1:" + proxyPort + "/nginx_status"); } } catch (Exception e) { log.error("Could not find in-flight request count: http://127.0.0.1:" + proxyPort + "/nginx_status", e); } return 0; }
From source file:com.yaon.NewServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* www . ja va 2 s. com*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text"); PrintWriter out = response.getWriter(); String ip = request.getParameter("ip"); String port = request.getParameter("port"); String uname = request.getParameter("uname"); String pass = request.getParameter("pass"); StringWriter sw = new StringWriter(); if ("null".equals(ip) && "null".equals(port) && "null".equals(uname) && "null".equals(pass)) { out.println("Null Argument Passed !!"); } else { try { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost postRequest = new HttpPost("http://" + ip + ":" + port + "/Yaon/GetInfo"); postRequest.addHeader( BasicScheme.authenticate(new UsernamePasswordCredentials(uname, pass), "UTF-8", false)); HttpResponse res = httpClient.execute(postRequest); if (res.getStatusLine().getStatusCode() == 401) { throw new Exception("Http Authentication Failed !"); } BufferedReader br = new BufferedReader(new InputStreamReader((res.getEntity().getContent()))); String output; System.out.println("Output from Server.... \n"); while ((output = br.readLine()) != null) { System.out.println(output); sw.append(output); sw.append("\n"); } httpClient.getConnectionManager().shutdown(); } catch (HttpHostConnectException e) { out.println(e.getMessage()); } catch (Exception e) { out.println(e.getMessage()); } out.println(sw.toString()); } }
From source file:org.kie.smoke.wb.util.unit.GetIgnoreRule.java
@Override public Statement apply(Statement base, FrameworkMethod method, Object target) { Statement result = base;//from ww w . jav a2 s . c o m if (hasConditionalIgnoreAnnotation(method)) { String urlString = getGetUrl(target, method); String message = "Ignored because [GET] " + urlString + " failed."; boolean liveServer = false; try { new URL(urlString); // check that url is a valid url string liveServer = true; } catch (MalformedURLException e) { liveServer = false; message = "Ignored because [" + urlString + "] is not a valid URL."; } if (liveServer) { try { Response response = Request.Get(urlString).execute(); int code = response.returnResponse().getStatusLine().getStatusCode(); if (code > 401) { liveServer = false; message = "Ignored because [GET] " + urlString + " returned " + code; } } catch (HttpHostConnectException hhce) { liveServer = false; message = "Ignored because server is not available: " + hhce.getMessage(); } catch (Exception e) { liveServer = false; message = "Ignored because [GET] " + urlString + " threw: " + e.getMessage(); } } if (!liveServer) { result = new IgnoreStatement(message); } } return result; }
From source file:org.kie.remote.tests.base.unit.GetIgnoreRule.java
@Override public Statement apply(Statement base, FrameworkMethod method, Object target) { Statement result = base;//from www .j av a2 s . c o m if (hasConditionalIgnoreAnnotation(method)) { IgnoreIfGETFails anno = method.getAnnotation(IgnoreIfGETFails.class); String urlString = anno.getUrl(); String message = "Ignored because [GET] " + urlString + " failed."; boolean liveServer = false; try { new URL(urlString); liveServer = true; } catch (MalformedURLException e) { liveServer = false; message = "Ignored because [" + urlString + "] is not a valid URL."; } if (anno.getUserName() == null || anno.getUserName().isEmpty()) { liveServer = false; message = "Ignored because user name was empty or null."; } if (anno.getPassword() == null || anno.getPassword().isEmpty()) { liveServer = false; message = "Ignored because password was empty or null."; } if (liveServer) { try { Response response = Request.Get(urlString).addHeader(HttpHeaders.AUTHORIZATION, basicAuthenticationHeader(anno.getUserName(), anno.getPassword())).execute(); int code = response.returnResponse().getStatusLine().getStatusCode(); if (code > 401) { liveServer = false; message = "Ignored because [GET] " + urlString + " returned " + code; } } catch (HttpHostConnectException hhce) { liveServer = false; message = "Ignored because server is not available: " + hhce.getMessage(); } catch (Exception e) { liveServer = false; message = "Ignored because [GET] " + urlString + " threw: " + e.getMessage(); } } if (!liveServer) { result = new IgnoreStatement(message); } } return result; }
From source file:org.everit.osgi.authentication.cas.tests.CasAuthenticationTestComponent.java
@Test public void test_04_SingleApp_Restart() throws Exception { sampleApp1.assertHello(johndoe, HelloWorldServlet.GUEST); sampleApp1.casLogin(johndoe);//from w w w .j a v a2 s . c o m Assert.assertTrue(johndoe.isLoggedIn()); sampleApp1.assertHello(johndoe, CasResourceIdResolver.JOHNDOE); sampleApp1.stop(); try { sampleApp1.assertHello(johndoe, CasResourceIdResolver.JOHNDOE); Assert.fail(); } catch (HttpHostConnectException e) { Assert.assertTrue(e.getMessage().contains("Connection refused")); } sampleApp1.setPort(); // required to set the port of the server to the selected random port otherwise Jetty will // chose an other random port sampleApp1.start(); sampleApp1.assertHello(johndoe, CasResourceIdResolver.JOHNDOE); }
From source file:com.elastic.support.util.RestExec.java
protected HttpResponse exec(String url) { try {/*from ww w . j a v a 2 s.com*/ HttpGet httpget = new HttpGet(url); if (isSecured) { return client.execute(httpHost, httpget, getLocalContext(httpHost)); } else { return client.execute(httpHost, httpget); } } catch (HttpHostConnectException e) { logger.log(SystemProperties.DIAG, "Host connection error.", e); throw new RuntimeException("Host connection error: " + e.getMessage()); } catch (Exception e) { logger.log(SystemProperties.DIAG, "Query Execution Error", e); throw new RuntimeException("Query Execution Error: " + e.getMessage()); } }
From source file:org.everit.authentication.cas.ecm.tests.CasAuthenticationTestComponent.java
@Test public void test04SingleAppRestart() throws Exception { sampleApp1.assertHello(johndoe, HelloWorldServlet.GUEST); sampleApp1.casLogin(johndoe);// www . ja v a 2s. c om Assert.assertTrue(johndoe.isLoggedIn()); sampleApp1.assertHello(johndoe, CasResourceIdResolver.JOHNDOE); sampleApp1.stop(); try { sampleApp1.assertHello(johndoe, CasResourceIdResolver.JOHNDOE); Assert.fail(); } catch (HttpHostConnectException e) { Assert.assertTrue(e.getMessage().contains("Connection refused")); } sampleApp1.setPort(); // required to set the port of the server to the selected random port // otherwise Jetty will // chose an other random port sampleApp1.start(); sampleApp1.assertHello(johndoe, CasResourceIdResolver.JOHNDOE); }