Skip to content

Commit

Permalink
Add the code to handle if the response is not a xml.
Browse files Browse the repository at this point in the history
  • Loading branch information
taojing2002 committed Feb 15, 2022
1 parent 5db371f commit f5fd654
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/main/java/edu/ucsb/nceas/osti_elink/OSTIElinkService.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,19 @@ private String getMetadata(String identifier, String type) throws OSTIElinkExcep
public void setMetadata(String doi, String doiPrefix, String metadataXML) throws OSTIElinkException {
String ostiId = getOstiId(doi, doiPrefix);// if the doi can't be found, an exception will be thrown.
String newMetadataXML = addOrReplaceOstiIdToXMLMetadata(ostiId, metadataXML);
log.debug("OSTIElinkService.setMetadata - the new xml metadata with the osti id " + ostiId +
log.info("OSTIElinkService.setMetadata - the new xml metadata with the osti id " + ostiId +
" for the doi identifier " + doi + " is:\n" + newMetadataXML);
byte[] reponse = sendRequest(POST, baseURL, newMetadataXML);
log.debug("OSTIElinkService.setMetadata - the response from the OSTI service is:\n " + new String(reponse));
Document doc = generateDOM(reponse);
String status = getElementValue(doc, STATUS);
Document doc = null;
String status = null;
try {
doc = generateDOM(reponse);
status = getElementValue(doc, STATUS);
} catch (Exception e) {
log.error("OSTIElinkService.setMetadata - can't get the status of the repsonse:\n" +
new String(reponse) + "since:\n" + e.getLocalizedMessage());
}
if (status == null || !status.equalsIgnoreCase(SUCCESS)) {
throw new OSTIElinkException("OSTIElinkService.setMetadata - Error: " + new String(reponse));
}
Expand Down

0 comments on commit f5fd654

Please sign in to comment.