Skip to content

Commit

Permalink
Add additional logs and make encode/decode toggleable via environment…
Browse files Browse the repository at this point in the history
… variables DEBUG_DISABLE_URL_DECODE and DEBUG_DISABLE_SPACE_ENCODE.
  • Loading branch information
kaladay committed Oct 11, 2024
1 parent 128e90c commit e3b2a98
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/main/java/edu/tamu/iiif/service/AbstractManifestService.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,20 @@ protected Model getRdfModel(String url) throws NotFoundException {

private String getRdf(String url) throws NotFoundException {
try {
url = URLDecoder.decode(url, StandardCharsets.UTF_8);
if (logger.isDebugEnabled()) {
logger.info("Requesting RDF for {}", url);
String doDecode = System.getenv("DEBUG_DISABLE_URL_DECODE");
System.out.print("\n\n\nDEBUG: getRdf(), url = " + url + ", url decoded = " + URLDecoder.decode(url, StandardCharsets.UTF_8) + ", (decoding is " + (doDecode == "true" ? "enabled" : "disabled") + ")\n\n\n");
if (doDecode == "true") {
url = URLDecoder.decode(url, StandardCharsets.UTF_8);
}
Optional<String> rdf = Optional.ofNullable(restTemplate.getForObject(url, String.class));
if (rdf.isPresent()) {
logger.debug("RDF for {}: \n{}\n", url, rdf.get());
return rdf.get();

logger.debug("Requesting RDF for {}", url);
String rdf = restTemplate.getForObject(url, String.class);
if (rdf != null) {
logger.debug("RDF for {}: \n{}\n", url, rdf);
return rdf;
}

logger.debug("RDF for {}: is not present\n", url);
} catch (RestClientException e) {
logger.error("Failed to get RDF for {}: {}", url, e.getMessage());
logger.debug("Error while requesting RDF for {}: {}", url, e.getMessage(), e);
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/edu/tamu/iiif/utility/StringUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ public static String decode(String value) {
}

public static String encodeSpaces(String value) {
String doEncode = System.getenv("DEBUG_DISABLE_SPACE_ENCODE");
if (doEncode == "true") {
System.out.print("\n\n\nDEBUG: replacing spaces, from '" + value + "' to '" + value.replace(" ", "%20") + "'\n\n\n");
return value.replace(" ", "%20");
}

System.out.print("\n\n\nDEBUG: not replacing spaces, from '" + value + "'\n\n\n");
return value;
}

Expand Down

0 comments on commit e3b2a98

Please sign in to comment.