CveReader2 implements ObjectFetcher<String, Cve> { public Cve fetch(String _key) throws CacheException { if (_key == null) return null; Cve cve = null; int sc = -1; String result = null; String uri = null; try { final String url = VulasConfiguration.getGlobal().getServiceUrl(Service.CVE, true); final CloseableHttpClient httpclient = HttpClients.createDefault(); uri = url.replaceAll("<ID>", _key); log.info("Query details of [" + _key + "] at [" + uri + "]"); final HttpGet method = new HttpGet(uri); if (ConnectionUtil.getProxyConfig() != null) method.setConfig(ConnectionUtil.getProxyConfig()); final CloseableHttpResponse response = httpclient.execute(method); try { sc = response.getStatusLine().getStatusCode(); final HttpEntity entity = response.getEntity(); if (sc == org.apache.http.HttpStatus.SC_OK && entity != null) { result = ConnectionUtil.readInputStream(entity.getContent()); cve = CveReader2.buildFromJson(_key, result); } else { log.error( "HTTP GET [url=" + uri + "] completed with [" + sc + "], and entity [" + entity + "]"); } } catch (ParseException e) { log.error("HTTP GET [url=" + uri + "] caused an exception: " + e.getMessage()); throw new CacheException(_key, e); } finally { response.close(); } log.info("Fetched " + cve + " for key [" + _key + "]"); } catch (ClientProtocolException e) { log.error("HTTP GET [url=" + uri + "] caused an exception: " + e.getMessage()); throw new CacheException(_key, e); } catch (IOException e) { log.error("HTTP GET [url=" + uri + "] caused an exception: " + e.getMessage()); log.error("Error: " + e.getMessage(), e); throw new CacheException(_key, e); } catch (ServiceConnectionException e) { log.error(e.getMessage()); throw new CacheException(_key, e); } return cve; }  static Cve read(String _key); static Cve read(String _key, boolean _force_fetch); Cve fetch(String _key);  }
@Test public void testFetch() throws CacheException { NvdRestServiceMockup.create(); final CveReader2 reader = new CveReader2(); reader.fetch("CVE-2019-17531"); }