From 5f4e426c87f30f5cb433fa23c7d6016dd3323640 Mon Sep 17 00:00:00 2001 From: Ralf Eichinger Date: Fri, 15 May 2020 15:16:15 +0200 Subject: [PATCH] Migrate from dc-commons-file 4 to 5 (#144) --- README.md | 30 ++++++++--------- nbactions.xml | 6 ++-- pom.xml | 15 +++++---- .../config/SpringConfigBackendImage.java | 5 +-- .../SpringConfigBackendPresentation.java | 5 +-- .../image/business/ImageServiceImpl.java | 8 ++--- .../backend/PresentationRepositoryImpl.java | 33 +++++++------------ 7 files changed, 49 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index f3642cd4..d8ca01e8 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ Hymir is a Java based IIIF Server. It is based on our [IIIF API Java Libraries]( ## Prerequisites - Server with minimum 4GB RAM. -- Java 8 +- Java 11 ## Installation @@ -107,7 +107,7 @@ Application configuration: see [here](src/main/resources/application.yml) (`loca - in production ```sh -$ java -jar hymir-4.0.0-exec.jar --spring.profiles.active=PROD +$ java -jar hymir--exec.jar --spring.profiles.active=PROD ``` Logging: to file `./hymir.log` in [Logstash](https://www.elastic.co/de/products/logstash)-JSON format @@ -119,7 +119,7 @@ Application configuration: see [here](src/main/resources/application.yml) (`PROD - in production with custom logging configuration file: ```sh -$ java -jar hymir-4.0.0-exec.jar --logging.config=file:/etc/hymir/logback-spring.xml --spring.profiles.active=PROD +$ java -jar hymir--exec.jar --logging.config=file:/etc/hymir/logback-spring.xml --spring.profiles.active=PROD ``` Read and . @@ -129,19 +129,19 @@ Read -exec.jar --spring.profiles.active=PROD ``` - in production with a custom server port (e.g. port 8080): ```sh -$ java -jar hymir-4.0.0-exec.jar --server.port=8080 --spring.profiles.active=PROD +$ java -jar hymir--exec.jar --server.port=8080 --spring.profiles.active=PROD ``` Complete parametrized example: ```sh -$ java -jar hymir-4.0.0-exec.jar --logging.config=file:/etc/hymir/logback-spring.xml --server.port=8080 --spring.profiles.active=PROD +$ java -jar hymir--exec.jar --logging.config=file:/etc/hymir/logback-spring.xml --server.port=8080 --spring.profiles.active=PROD ``` (and `application.yml` beside jar file). @@ -171,7 +171,7 @@ You can pass the path to your custom resolving rules with the `--spring.config.a Example: ```sh -$ java -jar hymir-4.0.0-exec.jar --spring.config.additional-location=file:/etc/hymir/rules.yml +$ java -jar hymir--exec.jar --spring.config.additional-location=file:/etc/hymir/rules.yml ``` Example file `/etc/hymir/rules.yml`: @@ -245,7 +245,7 @@ You can configure another url prefix on server startup using system property `cu Example: ```sh -$ java -jar target/hymir-4.0.0-exec.jar --custom.iiif.image.urlPrefix='/iiifImage/' --spring.config.additional-location=file:/etc/hymir/rules.yml --spring.profiles.active=local +$ java -jar target/hymir--exec.jar --custom.iiif.image.urlPrefix='/iiifImage/' --spring.config.additional-location=file:/etc/hymir/rules.yml --spring.profiles.active=local ``` Resulting URL: `http://localhost:9000/iiifImage/00113391_00001/full/300,/0/default.jpg` @@ -281,7 +281,7 @@ You can configure another url prefix on server startup using system property `cu Example: ```sh -$ java -jar hymir-4.0.0-exec.jar --custom.iiif.presentation.urlPrefix='/iiifPresentation/' --spring.config.additional-location=file:/etc/hymir/rules.yml --spring.profiles.active=local +$ java -jar hymir--exec.jar --custom.iiif.presentation.urlPrefix='/iiifPresentation/' --spring.config.additional-location=file:/etc/hymir/rules.yml --spring.profiles.active=local ``` Resulting URL: `http://localhost:9000/iiifPresentation/00113391/manifest` @@ -319,7 +319,7 @@ If you want human readable logging to console use `--spring.profiles.active=loca Example: Custom config file with human readable logging ```sh -$ java -jar hymir-4.0.0-exec.jar --logging.config=file:/etc/hymir/logback-spring.xml +$ java -jar hymir--exec.jar --logging.config=file:/etc/hymir/logback-spring.xml ``` Example file `/etc/hymir/logback-spring.xml`: @@ -380,7 +380,7 @@ Your custom `application.yml` does not have to replace all default properties. I To get the default configuration file, you should download the `hymir-.jar` file (NOT containing `-exec` in filename) from and unpack the contained `application.yml` with: ```sh -$ jar xfv hymir-4.0.0.jar application.yml +$ jar xfv hymir-.jar application.yml ``` Now put the file beside the executable Hymir jar and edit it according to your requirements. @@ -445,7 +445,7 @@ Monitoring endpoints under http://localhost:9001/monitoring (HAL-Browser-GUI), a To change monitoring port, e.g. to `8081` use `management.server.port` option: ```sh -$ java -jar hymir-4.0.0-exec.jar --management.server.port=8081 +$ java -jar hymir--exec.jar --management.server.port=8081 ``` ### Out Of Memory handling @@ -453,7 +453,7 @@ $ java -jar hymir-4.0.0-exec.jar --management.server.port=8081 In case the IIIF server runs out of memory it should quit - use java options for this. (To be restarted automatically install it as systemd service, see below.) ```sh -$ java -jar hymir-4.0.0-exec.jar -XX:+ExitOnOutOfMemoryError -XX:+CrashOnOutOfMemoryError +$ java -jar hymir--exec.jar -XX:+ExitOnOutOfMemoryError -XX:+CrashOnOutOfMemoryError ``` ### Configure IIIF service as systemd service @@ -470,7 +470,7 @@ After=syslog.target [Service] User=iiif -ExecStart=/usr/bin/java -jar /opt/hymir-4.0.0-exec.jar \ +ExecStart=/usr/bin/java -jar /opt/hymir--exec.jar \ -XX:+ExitOnOutOfMemoryError -XX:+CrashOnOutOfMemoryError \ --spring.config.additional-location=file:/etc/hymir/rules.yml \ --spring.profiles.active=PROD \ @@ -497,7 +497,7 @@ $ sudo systemctl start iiif-hymir.service ## Development * Install git client -* Install Java JDK 1.8 or above +* Install Java JDK 11 or above * Install Apache Maven buildttool ```sh diff --git a/nbactions.xml b/nbactions.xml index a5e2d0b6..f78f9509 100644 --- a/nbactions.xml +++ b/nbactions.xml @@ -45,7 +45,7 @@ org.codehaus.mojo:exec-maven-plugin:1.2.1:exec - -classpath %classpath de.digitalcollections.iiif.hymir.Application --rules=file:/etc/hymir/rules.yml --spring.profiles.active=local + -classpath %classpath de.digitalcollections.iiif.hymir.Application --spring.config.additional-location=file:/etc/hymir/rules.yml --spring.profiles.active=local java @@ -59,7 +59,7 @@ org.codehaus.mojo:exec-maven-plugin:1.2.1:exec - -Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath de.digitalcollections.iiif.hymir.Application --rules=file:/etc/hymir/rules.yml --spring.profiles.active=local + -agentlib:jdwp=transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath de.digitalcollections.iiif.hymir.Application --spring.config.additional-location=file:/etc/hymir/rules.yml --spring.profiles.active=local java true @@ -74,7 +74,7 @@ org.codehaus.mojo:exec-maven-plugin:1.2.1:exec - -classpath %classpath de.digitalcollections.iiif.hymir.Application --rules=file:/etc/hymir/rules.yml --spring.profiles.active=local + -classpath %classpath de.digitalcollections.iiif.hymir.Application --spring.config.additional-location=file:/etc/hymir/rules.yml --spring.profiles.active=local java diff --git a/pom.xml b/pom.xml index 3329388d..4780c91a 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ de.digitalcollections iiif-server-hymir - 4.1.4-SNAPSHOT + 4.2.0-SNAPSHOT jar https://github.com/dbmdz/iiif-server-hymir @@ -78,7 +78,10 @@ 1.2.0 1.4 - 4.0.3 + 5.0.1 + 4.1.1 + 4.1.1 + 4.1.2 29.0-jre 0.3.8 0.4.4 @@ -183,22 +186,22 @@ de.digitalcollections.commons dc-commons-file - ${version.dc-commons} + ${version.dc-commons-file} de.digitalcollections.commons dc-commons-server - ${version.dc-commons} + ${version.dc-commons-server} de.digitalcollections.commons dc-commons-springboot - ${version.dc-commons} + ${version.dc-commons-springboot} de.digitalcollections.commons dc-commons-springmvc - ${version.dc-commons} + ${version.dc-commons-springmvc} de.digitalcollections.imageio diff --git a/src/main/java/de/digitalcollections/iiif/hymir/config/SpringConfigBackendImage.java b/src/main/java/de/digitalcollections/iiif/hymir/config/SpringConfigBackendImage.java index ca2e279f..89c1fd39 100644 --- a/src/main/java/de/digitalcollections/iiif/hymir/config/SpringConfigBackendImage.java +++ b/src/main/java/de/digitalcollections/iiif/hymir/config/SpringConfigBackendImage.java @@ -1,5 +1,6 @@ package de.digitalcollections.iiif.hymir.config; +import de.digitalcollections.commons.file.config.SpringConfigCommonsFile; import java.util.Arrays; import java.util.HashSet; import java.util.Iterator; @@ -10,12 +11,12 @@ import javax.imageio.spi.IIORegistry; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; /** Backend configuration. */ @Configuration -@ComponentScan(basePackages = {"de.digitalcollections.commons.file.config"}) +@Import(SpringConfigCommonsFile.class) public class SpringConfigBackendImage { private static final Logger LOGGER = LoggerFactory.getLogger(SpringConfigBackendImage.class); diff --git a/src/main/java/de/digitalcollections/iiif/hymir/config/SpringConfigBackendPresentation.java b/src/main/java/de/digitalcollections/iiif/hymir/config/SpringConfigBackendPresentation.java index 50d6fa7f..f2390b44 100644 --- a/src/main/java/de/digitalcollections/iiif/hymir/config/SpringConfigBackendPresentation.java +++ b/src/main/java/de/digitalcollections/iiif/hymir/config/SpringConfigBackendPresentation.java @@ -1,9 +1,10 @@ package de.digitalcollections.iiif.hymir.config; -import org.springframework.context.annotation.ComponentScan; +import de.digitalcollections.commons.file.config.SpringConfigCommonsFile; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; /** Backend configuration. */ @Configuration -@ComponentScan(basePackages = {"de.digitalcollections.commons.file.config"}) +@Import(SpringConfigCommonsFile.class) public class SpringConfigBackendPresentation {} diff --git a/src/main/java/de/digitalcollections/iiif/hymir/image/business/ImageServiceImpl.java b/src/main/java/de/digitalcollections/iiif/hymir/image/business/ImageServiceImpl.java index 1c0d21c3..dc562490 100644 --- a/src/main/java/de/digitalcollections/iiif/hymir/image/business/ImageServiceImpl.java +++ b/src/main/java/de/digitalcollections/iiif/hymir/image/business/ImageServiceImpl.java @@ -1,7 +1,7 @@ package de.digitalcollections.iiif.hymir.image.business; import com.google.common.collect.Streams; -import de.digitalcollections.commons.file.business.impl.resolved.ResolvedFileResourceServiceImpl; +import de.digitalcollections.commons.file.business.api.FileResourceService; import de.digitalcollections.iiif.hymir.image.business.api.ImageSecurityService; import de.digitalcollections.iiif.hymir.image.business.api.ImageService; import de.digitalcollections.iiif.hymir.model.exception.InvalidParametersException; @@ -57,7 +57,7 @@ public static boolean containsAlphaChannel(BufferedImage image) { } private final ImageSecurityService imageSecurityService; - private final ResolvedFileResourceServiceImpl fileResourceService; + private final FileResourceService fileResourceService; @Value("${custom.iiif.logo:}") private String logoUrl; @@ -76,7 +76,7 @@ public static boolean containsAlphaChannel(BufferedImage image) { public ImageServiceImpl( @Autowired(required = false) ImageSecurityService imageSecurityService, - @Autowired ResolvedFileResourceServiceImpl fileResourceService) { + @Autowired FileResourceService fileResourceService) { this.imageSecurityService = imageSecurityService; this.fileResourceService = fileResourceService; } @@ -479,6 +479,6 @@ protected DecodedImage(BufferedImage img, Dimension targetSize, int rotation) { this.img = img; this.targetSize = targetSize; this.rotation = rotation; - } +} } } diff --git a/src/main/java/de/digitalcollections/iiif/hymir/presentation/backend/PresentationRepositoryImpl.java b/src/main/java/de/digitalcollections/iiif/hymir/presentation/backend/PresentationRepositoryImpl.java index 4fde7079..cec8c23b 100644 --- a/src/main/java/de/digitalcollections/iiif/hymir/presentation/backend/PresentationRepositoryImpl.java +++ b/src/main/java/de/digitalcollections/iiif/hymir/presentation/backend/PresentationRepositoryImpl.java @@ -1,6 +1,6 @@ package de.digitalcollections.iiif.hymir.presentation.backend; -import de.digitalcollections.commons.file.business.impl.resolved.ResolvedFileResourceServiceImpl; +import de.digitalcollections.commons.file.business.api.FileResourceService; import de.digitalcollections.iiif.hymir.model.exception.InvalidDataException; import de.digitalcollections.iiif.hymir.model.exception.ResolvingException; import de.digitalcollections.iiif.hymir.presentation.backend.api.PresentationRepository; @@ -13,12 +13,9 @@ import de.digitalcollections.model.api.identifiable.resource.exceptions.ResourceIOException; import de.digitalcollections.model.api.identifiable.resource.exceptions.ResourceNotFoundException; import java.io.IOException; -import java.io.InputStream; -import java.net.URI; import java.nio.charset.StandardCharsets; import java.time.Instant; import java.time.ZoneOffset; -import org.apache.commons.io.IOUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -36,7 +33,7 @@ public class PresentationRepositoryImpl implements PresentationRepository { @Autowired private IiifObjectMapper objectMapper; - @Autowired private ResolvedFileResourceServiceImpl resourceService; + @Autowired private FileResourceService fileResourceService; @Override public AnnotationList getAnnotationList(String identifier, String name, String canvasId) @@ -44,13 +41,14 @@ public AnnotationList getAnnotationList(String identifier, String name, String c String annotationListName = name + "-" + identifier + "_" + canvasId; FileResource resource; try { - resource = resourceService.find(annotationListName, MimeType.MIME_APPLICATION_JSON); + resource = fileResourceService.find(annotationListName, MimeType.MIME_APPLICATION_JSON); } catch (ResourceIOException ex) { LOGGER.error("Error getting annotation list for name {}", annotationListName, ex); throw new ResolvingException("No annotation list for name " + annotationListName); } try { - return objectMapper.readValue(getResourceJson(resource.getUri()), AnnotationList.class); + return objectMapper.readValue( + fileResourceService.getAsString(resource, StandardCharsets.UTF_8), AnnotationList.class); } catch (IOException ex) { LOGGER.error("Could not retrieve annotation list {}", annotationListName, ex); throw new InvalidDataException( @@ -65,13 +63,14 @@ public Collection getCollection(String name) String collectionName = COLLECTION_PREFIX + name; FileResource resource; try { - resource = resourceService.find(collectionName, MimeType.MIME_APPLICATION_JSON); + resource = fileResourceService.find(collectionName, MimeType.MIME_APPLICATION_JSON); } catch (ResourceIOException ex) { LOGGER.error("Error getting manifest for collection {}", name, ex); throw new ResolvingException("No collection for name " + name); } try { - return objectMapper.readValue(getResourceJson(resource.getUri()), Collection.class); + return objectMapper.readValue( + fileResourceService.getAsString(resource, StandardCharsets.UTF_8), Collection.class); } catch (IOException ex) { LOGGER.info("Could not retrieve collection {}", collectionName, ex); throw new InvalidDataException( @@ -84,13 +83,14 @@ public Manifest getManifest(String identifier) throws ResolvingException, ResourceNotFoundException, InvalidDataException { FileResource resource; try { - resource = resourceService.find(identifier, MimeType.MIME_APPLICATION_JSON); + resource = fileResourceService.find(identifier, MimeType.MIME_APPLICATION_JSON); } catch (ResourceIOException ex) { LOGGER.error("Error getting manifest for identifier {}", identifier, ex); throw new ResolvingException("No manifest for identifier " + identifier); } try { - return objectMapper.readValue(getResourceJson(resource.getUri()), Manifest.class); + return objectMapper.readValue( + fileResourceService.getAsString(resource, StandardCharsets.UTF_8), Manifest.class); } catch (IOException ex) { LOGGER.error("Manifest {} can not be parsed", identifier, ex); throw new InvalidDataException("Manifest " + identifier + " can not be parsed", ex); @@ -112,7 +112,7 @@ public Instant getCollectionModificationDate(String identifier) private Instant getResourceModificationDate(String identifier) throws ResolvingException, ResourceNotFoundException { try { - FileResource resource = resourceService.find(identifier, MimeType.MIME_APPLICATION_JSON); + FileResource resource = fileResourceService.find(identifier, MimeType.MIME_APPLICATION_JSON); return resource.getLastModified().toInstant(ZoneOffset.UTC); } catch (ResourceIOException ex) { LOGGER.error( @@ -120,13 +120,4 @@ private Instant getResourceModificationDate(String identifier) throw new ResolvingException("No manifest for identifier " + identifier); } } - - protected String getResourceJson(URI resourceUri) - throws ResolvingException, ResourceNotFoundException { - try (InputStream is = resourceService.getInputStream(resourceUri)) { - return IOUtils.toString(is, StandardCharsets.UTF_8); - } catch (IOException e) { - throw new ResolvingException(e); - } - } }