@Test public void the_reservation_url_is_returned_if_available() throws IOException { prepareExpectations(SC_OK); assertThat(new ServiceRegistration().getAddNewReservationUrl()).isNotEmpty(); }
@Produces @AddReservationUrl public String getAddNewReservationUrl() { if (lastCheck.isBefore(now().minusMinutes(MINUTES_PER_CHECK))) { available = false; LOGGER.info(() -> "Checking availability of " + ADD_NEW_RESERVATION_URL); SocketConfig socketConfig = copy(DEFAULT).setSoTimeout(2000).build(); try (CloseableHttpClient client = HttpClientBuilder.create().setDefaultSocketConfig(socketConfig).build(); CloseableHttpResponse response = client.execute(HttpHost.create(HOST_URL), new HttpGet(ADD_NEW_RESERVATION_URL))) { available = SC_OK == response.getStatusLine().getStatusCode(); if (SC_OK != response.getStatusLine().getStatusCode()) { LOGGER.log(WARNING, () -> "Cannot access url for new reservations!"); } } catch (IOException e) { LOGGER.log(SEVERE, e, () -> "Cannot access url for new reservations!"); } } return available ? ADD_NEW_RESERVATION_URL : null; }
ServiceRegistration { @Produces @AddReservationUrl public String getAddNewReservationUrl() { if (lastCheck.isBefore(now().minusMinutes(MINUTES_PER_CHECK))) { available = false; LOGGER.info(() -> "Checking availability of " + ADD_NEW_RESERVATION_URL); SocketConfig socketConfig = copy(DEFAULT).setSoTimeout(2000).build(); try (CloseableHttpClient client = HttpClientBuilder.create().setDefaultSocketConfig(socketConfig).build(); CloseableHttpResponse response = client.execute(HttpHost.create(HOST_URL), new HttpGet(ADD_NEW_RESERVATION_URL))) { available = SC_OK == response.getStatusLine().getStatusCode(); if (SC_OK != response.getStatusLine().getStatusCode()) { LOGGER.log(WARNING, () -> "Cannot access url for new reservations!"); } } catch (IOException e) { LOGGER.log(SEVERE, e, () -> "Cannot access url for new reservations!"); } } return available ? ADD_NEW_RESERVATION_URL : null; } }
ServiceRegistration { @Produces @AddReservationUrl public String getAddNewReservationUrl() { if (lastCheck.isBefore(now().minusMinutes(MINUTES_PER_CHECK))) { available = false; LOGGER.info(() -> "Checking availability of " + ADD_NEW_RESERVATION_URL); SocketConfig socketConfig = copy(DEFAULT).setSoTimeout(2000).build(); try (CloseableHttpClient client = HttpClientBuilder.create().setDefaultSocketConfig(socketConfig).build(); CloseableHttpResponse response = client.execute(HttpHost.create(HOST_URL), new HttpGet(ADD_NEW_RESERVATION_URL))) { available = SC_OK == response.getStatusLine().getStatusCode(); if (SC_OK != response.getStatusLine().getStatusCode()) { LOGGER.log(WARNING, () -> "Cannot access url for new reservations!"); } } catch (IOException e) { LOGGER.log(SEVERE, e, () -> "Cannot access url for new reservations!"); } } return available ? ADD_NEW_RESERVATION_URL : null; }  }
ServiceRegistration { @Produces @AddReservationUrl public String getAddNewReservationUrl() { if (lastCheck.isBefore(now().minusMinutes(MINUTES_PER_CHECK))) { available = false; LOGGER.info(() -> "Checking availability of " + ADD_NEW_RESERVATION_URL); SocketConfig socketConfig = copy(DEFAULT).setSoTimeout(2000).build(); try (CloseableHttpClient client = HttpClientBuilder.create().setDefaultSocketConfig(socketConfig).build(); CloseableHttpResponse response = client.execute(HttpHost.create(HOST_URL), new HttpGet(ADD_NEW_RESERVATION_URL))) { available = SC_OK == response.getStatusLine().getStatusCode(); if (SC_OK != response.getStatusLine().getStatusCode()) { LOGGER.log(WARNING, () -> "Cannot access url for new reservations!"); } } catch (IOException e) { LOGGER.log(SEVERE, e, () -> "Cannot access url for new reservations!"); } } return available ? ADD_NEW_RESERVATION_URL : null; }  @Produces @AddReservationUrl String getAddNewReservationUrl(); }
ServiceRegistration { @Produces @AddReservationUrl public String getAddNewReservationUrl() { if (lastCheck.isBefore(now().minusMinutes(MINUTES_PER_CHECK))) { available = false; LOGGER.info(() -> "Checking availability of " + ADD_NEW_RESERVATION_URL); SocketConfig socketConfig = copy(DEFAULT).setSoTimeout(2000).build(); try (CloseableHttpClient client = HttpClientBuilder.create().setDefaultSocketConfig(socketConfig).build(); CloseableHttpResponse response = client.execute(HttpHost.create(HOST_URL), new HttpGet(ADD_NEW_RESERVATION_URL))) { available = SC_OK == response.getStatusLine().getStatusCode(); if (SC_OK != response.getStatusLine().getStatusCode()) { LOGGER.log(WARNING, () -> "Cannot access url for new reservations!"); } } catch (IOException e) { LOGGER.log(SEVERE, e, () -> "Cannot access url for new reservations!"); } } return available ? ADD_NEW_RESERVATION_URL : null; }  @Produces @AddReservationUrl String getAddNewReservationUrl();  }