Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Spring 6, Jakarta and Java 21 #354

Merged
merged 3 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/maven_build_verification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
- name: Set up JDK 21
uses: actions/setup-java@v2
with:
java-version: '11'
java-version: '21'
distribution: 'adopt'
- name: Restore Maven cache
uses: skjolber/maven-cache-github-action@v1
Expand Down
11 changes: 7 additions & 4 deletions development/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
# Base Image
FROM tomcat:9.0-jdk11
FROM tomcat:11-jdk21

ENV LAREX_VERSION="0.7.4"

# Enable Networking on port 8080 (Tomcat)
EXPOSE 8080

# Installing dependencies and deleting cache
# Install dependencies
RUN apt-get update && apt-get install -y \
wget

# Download maven project
# Deploy Larex
COPY Larex.war /usr/local/tomcat/webapps/Larex.war

# Create books and savedir path
# Create directories for books and savedir
RUN mkdir /home/books /home/savedir

# Copy larex.properties
COPY dev.properties /larex.properties
ENV LAREX_CONFIG=/larex.properties

# Default working directory
WORKDIR /usr/local/tomcat
81 changes: 36 additions & 45 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,67 +13,65 @@
<url>https://github.com/OCR4all/LAREX</url>

<properties>
<jstl.version>1.2</jstl.version>
<java.version>1.8</java.version>
<spring.version>5.2.24.RELEASE</spring.version>
<jstl.version>3.0.0</jstl.version>
<java.version>21</java.version>
<spring.version>6.1.14</spring.version>
<cglib.version>3.2.8</cglib.version>
<logback.version>1.5.6</logback.version>
<log.sl4j.version>2.1.0-alpha1</log.sl4j.version>
<junit.jupiter.version>5.6.2</junit.jupiter.version>
</properties>

<dependencies>
<!-- jstl -->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<groupId>jakarta.servlet.jsp.jstl</groupId>
<artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
<version>${jstl.version}</version>
</dependency>

<!-- Spring core & mvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
<groupId>org.glassfish.web</groupId>
<artifactId>jakarta.servlet.jsp.jstl</artifactId>
<version>3.0.1</version>
</dependency>

<!-- Spring core & mvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<type>jar</type>
<scope>compile</scope>
<scope>test</scope>
</dependency>

<!-- Logging -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${log.sl4j.version}</version>
</dependency>


<!-- Java Advanced Imaging (JAI) Image I/O Tools -->
<dependency>
Expand All @@ -87,14 +85,6 @@
<version>1.4.0</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<type>jar</type>
<scope>test</scope>
</dependency>

<!-- CGLib for @Configuration -->
<dependency>
<groupId>cglib</groupId>
Expand All @@ -103,35 +93,36 @@
<scope>runtime</scope>
</dependency>

<!-- Servlet Spec -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>6.1.0</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.3</version>
<scope>provided</scope>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<version>3.0.0</version>
</dependency>


<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.13.0</version>
<version>2.18.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.4.2</version>
<version>2.18.2</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.openpnp/opencv -->
<dependency>
<groupId>org.openpnp</groupId>
<artifactId>opencv</artifactId>
<version>4.6.0-0</version>
<version>4.9.0-0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.json/json -->
Expand Down Expand Up @@ -169,11 +160,6 @@
<artifactId>Maths</artifactId>
<version>1.5b</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.locationtech.jts/jts-core -->
<dependency>
<groupId>org.locationtech.jts</groupId>
Expand All @@ -200,6 +186,11 @@
<id>Internal project repository</id>
<url>file://${basedir}/src/lib/repository</url>
</repository>
<repository>
<id>maven_central</id>
<name>Maven Central</name>
<url>https://repo.maven.apache.org/maven2/</url>
</repository>
</repositories>

<distributionManagement>
Expand Down Expand Up @@ -235,4 +226,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
19 changes: 8 additions & 11 deletions src/main/java/de/uniwue/web/config/MvcConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.CacheControl;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.multipart.support.StandardServletMultipartResolver;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
Expand All @@ -15,21 +15,20 @@

/**
* Basic MVC Configuration for the folder configuration and system library.
*
*
*/
@Configuration
@ComponentScan(basePackages = "com.web")
@EnableWebMvc
public class MvcConfiguration implements WebMvcConfigurer {

/*
* System library for openCV
* System library for openCV
*/
static {
nu.pattern.OpenCV.loadShared();
System.loadLibrary(org.opencv.core.Core.NATIVE_LIBRARY_NAME);
nu.pattern.OpenCV.loadLocally();
}

@Bean
public ViewResolver getViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
Expand All @@ -39,12 +38,10 @@ public ViewResolver getViewResolver() {
}

@Bean(name = "multipartResolver")
public CommonsMultipartResolver createMultipartResolver() {
CommonsMultipartResolver resolver=new CommonsMultipartResolver();
resolver.setDefaultEncoding("utf-8");
return resolver;
public StandardServletMultipartResolver createMultipartResolver() {
return new StandardServletMultipartResolver();
}

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/")
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/de/uniwue/web/controller/DataController.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import java.util.Collection;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.servlet.ServletContext;
import jakarta.servlet.ServletContext;

import de.uniwue.web.communication.BatchLoadRequest;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
Expand Down
18 changes: 8 additions & 10 deletions src/main/java/de/uniwue/web/controller/FileController.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

import javax.annotation.PostConstruct;
import jakarta.annotation.PostConstruct;
import javax.imageio.ImageIO;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import jakarta.servlet.ServletContext;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
Expand Down Expand Up @@ -42,7 +42,6 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import org.w3c.dom.Document;

import de.uniwue.algorithm.data.MemoryCleaner;
Expand Down Expand Up @@ -109,11 +108,10 @@ private void init() {
public ResponseEntity<byte[]> getImage(@PathVariable("imageEnc") final String imageEnc,
@RequestParam(value = "resize", defaultValue = "false") boolean doResize) throws IOException {
try {

File imageFile;
byte[] imageBytes = null;
String image = java.net.URLDecoder.decode(imageEnc, StandardCharsets.UTF_8.name()).replaceAll("‡","/");
if(image.startsWith("\"")) { image = image.substring(1); }
image = image.replaceFirst("^\"", "").replaceFirst("\"$", "");
if(fileManager.checkFlat()) {
// Find file with image name
final File directory = new File(fileManager.getLocalBooksPath() + File.separator);
Expand Down Expand Up @@ -202,11 +200,11 @@ public ResponseEntity<byte[]> getImage(@PathVariable("imageEnc") final String im
*
*/
@RequestMapping(value = "file/upload/annotations", method = RequestMethod.POST, headers = "Accept=*/*")
public @ResponseBody PageAnnotations uploadSegmentation(@RequestParam("file") CommonsMultipartFile multipart,
public @ResponseBody PageAnnotations uploadSegmentation(@RequestParam("file") MultipartFile multipart,
@RequestParam("pageNr") int pageNr,
@RequestParam("bookID") int bookID,
@RequestParam("xmlName") String xmlName) throws IOException {
multipart.getFileItem().getName();
multipart.getName();
File file = new File(xmlName);
FileUtils.writeByteArrayToFile(file, multipart.getBytes());
FileUtils.writeByteArrayToFile(file, multipart.getBytes());
Expand Down Expand Up @@ -411,7 +409,7 @@ private File getXMLFilePath(String xmlName, Integer bookid){
if(!savedir.endsWith(File.separator)) { savedir += File.separator; }
return new File(savedir + xmlName);
} else {
logger.error("Warning: Save dir {} not set. File {} could not been saved.",
logger.error("Warning: Save dir {} not set. File {} could not been saved.",
savedir, xmlName);
}
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/de/uniwue/web/controller/LibraryController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import java.nio.charset.StandardCharsets;
import java.util.*;

import javax.annotation.PostConstruct;
import javax.servlet.ServletContext;
import jakarta.servlet.ServletContext;

import de.uniwue.web.communication.DirectRequest;
import de.uniwue.web.config.Constants;
import de.uniwue.web.io.MetsReader;

import jakarta.annotation.PostConstruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -177,7 +177,7 @@ public String home(Model model) throws IOException {
}
return directRequest;
}

/**
* returns each imagePath in given directory
* respecting the SubExtensionFilter set in properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import jakarta.annotation.PostConstruct;
import jakarta.servlet.ServletContext;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
Expand Down
Loading
Loading