|
24 | 24 | */
|
25 | 25 | package org.goobi.api.rest.process.thumbnail;
|
26 | 26 |
|
| 27 | +import java.io.UnsupportedEncodingException; |
27 | 28 | import java.net.URI;
|
28 | 29 | import java.net.URISyntaxException;
|
29 | 30 | import java.net.URLEncoder;
|
|
42 | 43 | import jakarta.ws.rs.PathParam;
|
43 | 44 | import jakarta.ws.rs.container.ContainerRequestContext;
|
44 | 45 | import jakarta.ws.rs.core.Context;
|
| 46 | +import jakarta.ws.rs.core.UriBuilder; |
45 | 47 | import lombok.extern.log4j.Log4j2;
|
46 | 48 |
|
47 | 49 | @jakarta.ws.rs.Path("process/thumbs/{processId}/{foldername}/{filename}")
|
@@ -91,4 +93,20 @@ public void createResourceURI(HttpServletRequest request, String processId, Stri
|
91 | 93 | public String getGoobiURIPrefix() {
|
92 | 94 | return GoobiThumbnailResource.class.getAnnotation(jakarta.ws.rs.Path.class).value();
|
93 | 95 | }
|
| 96 | + |
| 97 | + /** |
| 98 | + * This needs to override the createResourceURI method of the ImageResource class which otherwise throws an error due to different number of path |
| 99 | + * variables The actual value of the URI is created in {@link #createResourceURI(HttpServletRequest, String, String, String) |
| 100 | + */ |
| 101 | + @Override |
| 102 | + protected URI createResourceURI(URI baseURI, String directory, String filename) throws IllegalRequestException { |
| 103 | + try { |
| 104 | + return UriBuilder.fromUri(baseURI) |
| 105 | + .path(getURIPrefix()) |
| 106 | + .build("", URLEncoder.encode(directory, "utf-8"), URLEncoder.encode(filename, "utf-8")); |
| 107 | + } catch (UnsupportedEncodingException e) { |
| 108 | + log.error("Failed to create image request uri"); |
| 109 | + throw new IllegalRequestException("Unable to evaluate request to '" + directory + "', '" + filename + "'"); |
| 110 | + } |
| 111 | + } |
94 | 112 | }
|
0 commit comments