Source:
public static JsonObjectBuilder queryDoi(String persistentId, String baseUrl, String username, String password) { String doi = acceptOnlyDoi(persistentId); URL url; try { url = new URL(baseUrl + "/dois/" + doi); } catch (MalformedURLException ex) { return Json.createObjectBuilder().add("response", ex.getLocalizedMessage()); } HttpURLConnection connection = null; try { connection = (HttpURLConnection) url.openConnection(); } catch (IOException ex) { return Json.createObjectBuilder().add("response", ex.getLocalizedMessage()); } try { connection.setRequestMethod("GET"); } catch (ProtocolException ex) { return Json.createObjectBuilder().add("response", ex.getLocalizedMessage()); } String userpass = username + ":" + password; String basicAuth = "Basic " + new String(Base64.getEncoder().encode(userpass.getBytes())); connection.setRequestProperty("Authorization", basicAuth); int status = 0; try { status = connection.getResponseCode(); } catch (IOException ex) { throw new RuntimeException(BundleUtil.getStringFromBundle("pids.datacite.errors.noResponseCode", Arrays.asList(baseUrl))); } if (status != 200) { InputStream errorStream = connection.getErrorStream(); if (errorStream != null) { JsonObject out = Json.createReader(connection.getErrorStream()).readObject(); return Json.createObjectBuilder().add("response", out); } else { return Json.createObjectBuilder().add("response", BundleUtil.getStringFromBundle("pids.datacite.errors.noErrorStream")); } } JsonObject out; try { out = Json.createReader(connection.getInputStream()).readObject(); } catch (IOException ex) { return Json.createObjectBuilder().add("response", ex.getLocalizedMessage()); } JsonObject data = out.getJsonObject("data"); String id = data.getString("id"); JsonObject attributes = data.getJsonObject("attributes"); String state = attributes.getString("state"); JsonObjectBuilder ret = Json.createObjectBuilder() .add("id", id) .add("state", state); return ret; }

Target:
public static JsonObjectBuilder queryDoi(String persistentId, String baseUrl, String username, String password) { try { String doi = acceptOnlyDoi(persistentId); URL url; int status = 0; HttpURLConnection connection = null; try { url = new URL(baseUrl + "/dois/" + doi); connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); String userpass = username + ":" + password; String basicAuth = "Basic " + new String(Base64.getEncoder().encode(userpass.getBytes())); connection.setRequestProperty("Authorization", basicAuth); status = connection.getResponseCode(); } catch (IOException ex) { throw new InternalServerErrorException( BundleUtil.getStringFromBundle("pids.datacite.errors.noResponseCode", Arrays.asList(baseUrl))); } if (status == 404) { throw new NotFoundException(); } if (status != 200) { logger.severe("Received " + status + " error from DataCite for DOI: " + persistentId); InputStream errorStream = connection.getErrorStream(); if (errorStream != null) { JsonObject out = Json.createReader(connection.getErrorStream()).readObject(); logger.severe("DataCite error response: " + out.toString()); } else { logger.severe("No error stream from DataCite"); } throw new ServiceUnavailableException(); } JsonObject out; try { out = Json.createReader(connection.getInputStream()).readObject(); } catch (IOException ex) { return Json.createObjectBuilder().add("response", ex.getLocalizedMessage()); } JsonObject data = out.getJsonObject("data"); String id = data.getString("id"); JsonObject attributes = data.getJsonObject("attributes"); String state = attributes.getString("state"); JsonObjectBuilder ret = Json.createObjectBuilder().add("id", id).add("state", state); return ret; } catch (IllegalArgumentException ex) { throw new BadRequestException(ex.getLocalizedMessage()); } }