HttpJsonHomeClient implements JsonHomeClient { @Override public JsonHome get(final URI uri) { final HttpGet httpget = new HttpGet(uri); httpget.setHeader("Accept", "application/json"); final BasicHttpContext context = new BasicHttpContext(); final HttpResponse response; try { LOG.info("Getting json-home document {}", uri); response = httpClient.execute(httpget, context); final int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == 404) { LOG.warn("Json-home document {} not found. HTTP status is 404", uri); throw new NotFoundException("Resource " + uri + " not found"); } else if (statusCode >= 400) { final String status = response.getStatusLine().toString(); LOG.warn("Json-home document {} not found: {}", uri, status); throw new HttpStatusException(statusCode, "Failed to load json-home from " + uri + ": Received HTTP status code " + status); } } catch (final IOException e) { LOG.warn("Error getting json-home document {}: {}", uri, e.getMessage()); throw new JsonHomeClientException("Error getting json-home document " + uri, e); } finally { httpget.reset(); } final HttpEntity entity = response.getEntity(); if (entity != null) { InputStream stream = null; try { stream = entity.getContent(); return new JacksonJsonHomeParser().parse(stream); } catch (final IOException e) { throw new JsonHomeClientException("Exception caught while getting json-home from " + uri, e); } catch (final RuntimeException e) { httpget.abort(); throw new JsonHomeClientException("Exception caught while getting json-home from " + uri, e); } finally { if (stream != null) try { stream.close(); } catch (IOException e) { } } } throw new JsonHomeClientException("No content returned when getting json-home resource from " + uri); } HttpJsonHomeClient();  HttpJsonHomeClient(final HttpClient httpClient, final CacheConfig cacheConfig);  HttpJsonHomeClient(final HttpClient httpClient,
                              final HttpCacheStorage storage,
                              final CacheConfig cacheConfig); @Override JsonHome updateAndGet(final URI uri); @Override JsonHome get(final URI uri); @Override void shutdown();  }
@Test(enabled = false) public void shouldFindRegisteredResource() { final JsonHomeClient client = new HttpJsonHomeClient(); final JsonHome jsonHome = client.get(JSONHOME_URI); assertNotNull(jsonHome); assertTrue(jsonHome.hasResourceFor(RELATION_TYPE_URI)); }
@Test(enabled = false, expectedExceptions = NotFoundException.class) public void shouldThrowNotFoundExceptionForUnknownResource() { final JsonHomeClient client = new HttpJsonHomeClient(); final JsonHome jsonHome = client.get(URI.create("http: assertNull(jsonHome); }