@Test public void shouldReturnTrueWhenUnableToConnect() { given(restTemplate.getForEntity( anyString(), eq(String.class), Matchers.<Map<String, String>>any())) .willThrow(RestClientException.class); boolean isSafe = verifier.isSafe(LONG_URL); assertThat(isSafe).isTrue(); }
public final boolean isSafe(String url) { final Map<String, String> formParameters = this.config.getParameters(); formParameters.put(PARAMETER_URL, url); boolean safe = true; try { final ResponseEntity<String> response = client.getForEntity( config.getApiUrl(), String.class, formParameters); LOGGER.debug("Google Safe Browsing API returned HTTP Status: {} and message: {}", response.getStatusCode(), response.getBody()); if (response.getStatusCode() == HttpStatus.OK) { LOGGER.debug("Possible unsafe link: {} - {}", url, response.getBody()); safe = false; } } catch (RestClientException restException) { LOGGER.warn("Exception occurred during HTTP call to Google Safe Browsing API: {}", restException); } return safe; }
GoogleSafeBrowsingUrlVerifier implements UrlVerifier { public final boolean isSafe(String url) { final Map<String, String> formParameters = this.config.getParameters(); formParameters.put(PARAMETER_URL, url); boolean safe = true; try { final ResponseEntity<String> response = client.getForEntity( config.getApiUrl(), String.class, formParameters); LOGGER.debug("Google Safe Browsing API returned HTTP Status: {} and message: {}", response.getStatusCode(), response.getBody()); if (response.getStatusCode() == HttpStatus.OK) { LOGGER.debug("Possible unsafe link: {} - {}", url, response.getBody()); safe = false; } } catch (RestClientException restException) { LOGGER.warn("Exception occurred during HTTP call to Google Safe Browsing API: {}", restException); } return safe; } }
GoogleSafeBrowsingUrlVerifier implements UrlVerifier { public final boolean isSafe(String url) { final Map<String, String> formParameters = this.config.getParameters(); formParameters.put(PARAMETER_URL, url); boolean safe = true; try { final ResponseEntity<String> response = client.getForEntity( config.getApiUrl(), String.class, formParameters); LOGGER.debug("Google Safe Browsing API returned HTTP Status: {} and message: {}", response.getStatusCode(), response.getBody()); if (response.getStatusCode() == HttpStatus.OK) { LOGGER.debug("Possible unsafe link: {} - {}", url, response.getBody()); safe = false; } } catch (RestClientException restException) { LOGGER.warn("Exception occurred during HTTP call to Google Safe Browsing API: {}", restException); } return safe; } @Autowired  GoogleSafeBrowsingUrlVerifier(RestTemplate clnt, GoogleSafeBrowsingConfig cnfg); }
GoogleSafeBrowsingUrlVerifier implements UrlVerifier { public final boolean isSafe(String url) { final Map<String, String> formParameters = this.config.getParameters(); formParameters.put(PARAMETER_URL, url); boolean safe = true; try { final ResponseEntity<String> response = client.getForEntity( config.getApiUrl(), String.class, formParameters); LOGGER.debug("Google Safe Browsing API returned HTTP Status: {} and message: {}", response.getStatusCode(), response.getBody()); if (response.getStatusCode() == HttpStatus.OK) { LOGGER.debug("Possible unsafe link: {} - {}", url, response.getBody()); safe = false; } } catch (RestClientException restException) { LOGGER.warn("Exception occurred during HTTP call to Google Safe Browsing API: {}", restException); } return safe; } @Autowired  GoogleSafeBrowsingUrlVerifier(RestTemplate clnt, GoogleSafeBrowsingConfig cnfg); final boolean isSafe(String url); }
GoogleSafeBrowsingUrlVerifier implements UrlVerifier { public final boolean isSafe(String url) { final Map<String, String> formParameters = this.config.getParameters(); formParameters.put(PARAMETER_URL, url); boolean safe = true; try { final ResponseEntity<String> response = client.getForEntity( config.getApiUrl(), String.class, formParameters); LOGGER.debug("Google Safe Browsing API returned HTTP Status: {} and message: {}", response.getStatusCode(), response.getBody()); if (response.getStatusCode() == HttpStatus.OK) { LOGGER.debug("Possible unsafe link: {} - {}", url, response.getBody()); safe = false; } } catch (RestClientException restException) { LOGGER.warn("Exception occurred during HTTP call to Google Safe Browsing API: {}", restException); } return safe; } @Autowired  GoogleSafeBrowsingUrlVerifier(RestTemplate clnt, GoogleSafeBrowsingConfig cnfg); final boolean isSafe(String url);  }