@Test public void testgetSurveillerStatus_InvalidParams() throws SerialException, SQLException { HealthCheckEntity hcv = daoService.createHealthCheckEntity(0, cte, region_id, TestDataProvider.getMesosPlatform()); HealthCheckVO hcvo = new HealthCheckVO(); Map<String,String> paramList = new HashMap<String,String>(); paramList.put("URL","http: paramList.put("BASIC_AUTH_USERNAME", "sa"); paramList.put("BASIC_AUTH_PASSWORD", "sa"); hcvo.setParamDetails(paramList); paramDetails=paramList; init(hcvo); try { StatusVO result = getSurveillerStatus(); } catch(Exception e) { } }
@Override public StatusVO getSurveillerStatus() { HttpURLConnection conn = null; try { if(paramDetails.get(PARAM_KEY_URL)==null ){ logger.error("Configuration Error : The URL is null in DB"); throw new IllegalArgumentException("Configuration Error : The URL is null in DB"); } URL url = new URL(paramDetails.get(PARAM_KEY_URL)); conn = (HttpURLConnection) url.openConnection(); if(paramDetails.get(BASIC_AUTH_USERNAME) != null && paramDetails.get(BASIC_AUTH_PASSWORD) != null){ String authString = paramDetails.get(BASIC_AUTH_USERNAME) + ":" + paramDetails.get(BASIC_AUTH_PASSWORD); byte[] authEncBytes = Base64.getEncoder().encode(authString.getBytes()); conn.setRequestProperty("Authorization", "Basic " + (new String(authEncBytes))); } conn.setConnectTimeout(TIME_OUT); conn.setReadTimeout(TIME_OUT); conn.setRequestMethod("GET"); conn.connect(); logger.debug("Connecting URL : " + paramDetails.get(PARAM_KEY_URL) + "; HTTP Status : " + conn.getResponseCode()); if(conn.getResponseCode() == HttpsURLConnection.HTTP_OK || conn.getResponseCode() == HttpsURLConnection.HTTP_CREATED || conn.getResponseCode() == HttpsURLConnection.HTTP_ACCEPTED || conn.getResponseCode() == HttpsURLConnection.HTTP_NOT_AUTHORITATIVE || conn.getResponseCode() == HttpsURLConnection.HTTP_NO_CONTENT || conn.getResponseCode() == HttpsURLConnection.HTTP_RESET || conn.getResponseCode() == HttpsURLConnection.HTTP_PARTIAL){ return new StatusVO(Status.UP); }else{ return new StatusVO(Status.DOWN,"Got an HTTP error while connection. Http Error Code = " + conn.getResponseCode() + ". URL=" + paramDetails.get(PARAM_KEY_URL)); } } catch(UnknownHostException ue){ logger.error("Got UnknownHostException", ue); return new StatusVO(Status.DOWN,"Unable to resolve DNS - " + ue.getMessage() + ". URL=" + paramDetails.get(PARAM_KEY_URL)); } catch (Exception e) { logger.error("Got Exception while connecting", e); return new StatusVO(Status.DOWN,e.getMessage() + ". URL=" + paramDetails.get(PARAM_KEY_URL)); }finally{ try { if(conn != null){ conn.disconnect(); } }catch (Exception e) { logger.error("Got Exception while disconnecting", e); } } }
URLOpenableHandler extends SurveillerHandler { @Override public StatusVO getSurveillerStatus() { HttpURLConnection conn = null; try { if(paramDetails.get(PARAM_KEY_URL)==null ){ logger.error("Configuration Error : The URL is null in DB"); throw new IllegalArgumentException("Configuration Error : The URL is null in DB"); } URL url = new URL(paramDetails.get(PARAM_KEY_URL)); conn = (HttpURLConnection) url.openConnection(); if(paramDetails.get(BASIC_AUTH_USERNAME) != null && paramDetails.get(BASIC_AUTH_PASSWORD) != null){ String authString = paramDetails.get(BASIC_AUTH_USERNAME) + ":" + paramDetails.get(BASIC_AUTH_PASSWORD); byte[] authEncBytes = Base64.getEncoder().encode(authString.getBytes()); conn.setRequestProperty("Authorization", "Basic " + (new String(authEncBytes))); } conn.setConnectTimeout(TIME_OUT); conn.setReadTimeout(TIME_OUT); conn.setRequestMethod("GET"); conn.connect(); logger.debug("Connecting URL : " + paramDetails.get(PARAM_KEY_URL) + "; HTTP Status : " + conn.getResponseCode()); if(conn.getResponseCode() == HttpsURLConnection.HTTP_OK || conn.getResponseCode() == HttpsURLConnection.HTTP_CREATED || conn.getResponseCode() == HttpsURLConnection.HTTP_ACCEPTED || conn.getResponseCode() == HttpsURLConnection.HTTP_NOT_AUTHORITATIVE || conn.getResponseCode() == HttpsURLConnection.HTTP_NO_CONTENT || conn.getResponseCode() == HttpsURLConnection.HTTP_RESET || conn.getResponseCode() == HttpsURLConnection.HTTP_PARTIAL){ return new StatusVO(Status.UP); }else{ return new StatusVO(Status.DOWN,"Got an HTTP error while connection. Http Error Code = " + conn.getResponseCode() + ". URL=" + paramDetails.get(PARAM_KEY_URL)); } } catch(UnknownHostException ue){ logger.error("Got UnknownHostException", ue); return new StatusVO(Status.DOWN,"Unable to resolve DNS - " + ue.getMessage() + ". URL=" + paramDetails.get(PARAM_KEY_URL)); } catch (Exception e) { logger.error("Got Exception while connecting", e); return new StatusVO(Status.DOWN,e.getMessage() + ". URL=" + paramDetails.get(PARAM_KEY_URL)); }finally{ try { if(conn != null){ conn.disconnect(); } }catch (Exception e) { logger.error("Got Exception while disconnecting", e); } } } }
URLOpenableHandler extends SurveillerHandler { @Override public StatusVO getSurveillerStatus() { HttpURLConnection conn = null; try { if(paramDetails.get(PARAM_KEY_URL)==null ){ logger.error("Configuration Error : The URL is null in DB"); throw new IllegalArgumentException("Configuration Error : The URL is null in DB"); } URL url = new URL(paramDetails.get(PARAM_KEY_URL)); conn = (HttpURLConnection) url.openConnection(); if(paramDetails.get(BASIC_AUTH_USERNAME) != null && paramDetails.get(BASIC_AUTH_PASSWORD) != null){ String authString = paramDetails.get(BASIC_AUTH_USERNAME) + ":" + paramDetails.get(BASIC_AUTH_PASSWORD); byte[] authEncBytes = Base64.getEncoder().encode(authString.getBytes()); conn.setRequestProperty("Authorization", "Basic " + (new String(authEncBytes))); } conn.setConnectTimeout(TIME_OUT); conn.setReadTimeout(TIME_OUT); conn.setRequestMethod("GET"); conn.connect(); logger.debug("Connecting URL : " + paramDetails.get(PARAM_KEY_URL) + "; HTTP Status : " + conn.getResponseCode()); if(conn.getResponseCode() == HttpsURLConnection.HTTP_OK || conn.getResponseCode() == HttpsURLConnection.HTTP_CREATED || conn.getResponseCode() == HttpsURLConnection.HTTP_ACCEPTED || conn.getResponseCode() == HttpsURLConnection.HTTP_NOT_AUTHORITATIVE || conn.getResponseCode() == HttpsURLConnection.HTTP_NO_CONTENT || conn.getResponseCode() == HttpsURLConnection.HTTP_RESET || conn.getResponseCode() == HttpsURLConnection.HTTP_PARTIAL){ return new StatusVO(Status.UP); }else{ return new StatusVO(Status.DOWN,"Got an HTTP error while connection. Http Error Code = " + conn.getResponseCode() + ". URL=" + paramDetails.get(PARAM_KEY_URL)); } } catch(UnknownHostException ue){ logger.error("Got UnknownHostException", ue); return new StatusVO(Status.DOWN,"Unable to resolve DNS - " + ue.getMessage() + ". URL=" + paramDetails.get(PARAM_KEY_URL)); } catch (Exception e) { logger.error("Got Exception while connecting", e); return new StatusVO(Status.DOWN,e.getMessage() + ". URL=" + paramDetails.get(PARAM_KEY_URL)); }finally{ try { if(conn != null){ conn.disconnect(); } }catch (Exception e) { logger.error("Got Exception while disconnecting", e); } } }  }
URLOpenableHandler extends SurveillerHandler { @Override public StatusVO getSurveillerStatus() { HttpURLConnection conn = null; try { if(paramDetails.get(PARAM_KEY_URL)==null ){ logger.error("Configuration Error : The URL is null in DB"); throw new IllegalArgumentException("Configuration Error : The URL is null in DB"); } URL url = new URL(paramDetails.get(PARAM_KEY_URL)); conn = (HttpURLConnection) url.openConnection(); if(paramDetails.get(BASIC_AUTH_USERNAME) != null && paramDetails.get(BASIC_AUTH_PASSWORD) != null){ String authString = paramDetails.get(BASIC_AUTH_USERNAME) + ":" + paramDetails.get(BASIC_AUTH_PASSWORD); byte[] authEncBytes = Base64.getEncoder().encode(authString.getBytes()); conn.setRequestProperty("Authorization", "Basic " + (new String(authEncBytes))); } conn.setConnectTimeout(TIME_OUT); conn.setReadTimeout(TIME_OUT); conn.setRequestMethod("GET"); conn.connect(); logger.debug("Connecting URL : " + paramDetails.get(PARAM_KEY_URL) + "; HTTP Status : " + conn.getResponseCode()); if(conn.getResponseCode() == HttpsURLConnection.HTTP_OK || conn.getResponseCode() == HttpsURLConnection.HTTP_CREATED || conn.getResponseCode() == HttpsURLConnection.HTTP_ACCEPTED || conn.getResponseCode() == HttpsURLConnection.HTTP_NOT_AUTHORITATIVE || conn.getResponseCode() == HttpsURLConnection.HTTP_NO_CONTENT || conn.getResponseCode() == HttpsURLConnection.HTTP_RESET || conn.getResponseCode() == HttpsURLConnection.HTTP_PARTIAL){ return new StatusVO(Status.UP); }else{ return new StatusVO(Status.DOWN,"Got an HTTP error while connection. Http Error Code = " + conn.getResponseCode() + ". URL=" + paramDetails.get(PARAM_KEY_URL)); } } catch(UnknownHostException ue){ logger.error("Got UnknownHostException", ue); return new StatusVO(Status.DOWN,"Unable to resolve DNS - " + ue.getMessage() + ". URL=" + paramDetails.get(PARAM_KEY_URL)); } catch (Exception e) { logger.error("Got Exception while connecting", e); return new StatusVO(Status.DOWN,e.getMessage() + ". URL=" + paramDetails.get(PARAM_KEY_URL)); }finally{ try { if(conn != null){ conn.disconnect(); } }catch (Exception e) { logger.error("Got Exception while disconnecting", e); } } }  @Override StatusVO getSurveillerStatus(); }
URLOpenableHandler extends SurveillerHandler { @Override public StatusVO getSurveillerStatus() { HttpURLConnection conn = null; try { if(paramDetails.get(PARAM_KEY_URL)==null ){ logger.error("Configuration Error : The URL is null in DB"); throw new IllegalArgumentException("Configuration Error : The URL is null in DB"); } URL url = new URL(paramDetails.get(PARAM_KEY_URL)); conn = (HttpURLConnection) url.openConnection(); if(paramDetails.get(BASIC_AUTH_USERNAME) != null && paramDetails.get(BASIC_AUTH_PASSWORD) != null){ String authString = paramDetails.get(BASIC_AUTH_USERNAME) + ":" + paramDetails.get(BASIC_AUTH_PASSWORD); byte[] authEncBytes = Base64.getEncoder().encode(authString.getBytes()); conn.setRequestProperty("Authorization", "Basic " + (new String(authEncBytes))); } conn.setConnectTimeout(TIME_OUT); conn.setReadTimeout(TIME_OUT); conn.setRequestMethod("GET"); conn.connect(); logger.debug("Connecting URL : " + paramDetails.get(PARAM_KEY_URL) + "; HTTP Status : " + conn.getResponseCode()); if(conn.getResponseCode() == HttpsURLConnection.HTTP_OK || conn.getResponseCode() == HttpsURLConnection.HTTP_CREATED || conn.getResponseCode() == HttpsURLConnection.HTTP_ACCEPTED || conn.getResponseCode() == HttpsURLConnection.HTTP_NOT_AUTHORITATIVE || conn.getResponseCode() == HttpsURLConnection.HTTP_NO_CONTENT || conn.getResponseCode() == HttpsURLConnection.HTTP_RESET || conn.getResponseCode() == HttpsURLConnection.HTTP_PARTIAL){ return new StatusVO(Status.UP); }else{ return new StatusVO(Status.DOWN,"Got an HTTP error while connection. Http Error Code = " + conn.getResponseCode() + ". URL=" + paramDetails.get(PARAM_KEY_URL)); } } catch(UnknownHostException ue){ logger.error("Got UnknownHostException", ue); return new StatusVO(Status.DOWN,"Unable to resolve DNS - " + ue.getMessage() + ". URL=" + paramDetails.get(PARAM_KEY_URL)); } catch (Exception e) { logger.error("Got Exception while connecting", e); return new StatusVO(Status.DOWN,e.getMessage() + ". URL=" + paramDetails.get(PARAM_KEY_URL)); }finally{ try { if(conn != null){ conn.disconnect(); } }catch (Exception e) { logger.error("Got Exception while disconnecting", e); } } }  @Override StatusVO getSurveillerStatus();  }