Skip to content

Commit

Permalink
Merge branch 'release/1.35.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
jannistsiroyannis committed Apr 23, 2024
2 parents 7c69341 + b86f47f commit 952cfbd
Show file tree
Hide file tree
Showing 129 changed files with 316,067 additions and 1,362 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '17'
java-version: '21'
distribution: 'microsoft'
- name: Build with Gradle
uses: gradle/[email protected]
with:
arguments: build
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
- name: Execute Gradle build
run: ./gradlew build
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ for e.g. Fedora/CentOS/RHEL with minor adjustments.
Windows:
Download and install https://www.postgresql.org/download/windows/
4. [Java](https://openjdk.java.net/) (version 17)
4. [Java](https://openjdk.java.net/) (version 21)
```
sudo apt install openjdk-17-jdk # or openjdk-17-headless
sudo apt install openjdk-21-jdk # or openjdk-21-headless
```
5. [nginx](https://nginx.org/)
Expand Down
59 changes: 43 additions & 16 deletions apix_server/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
apply plugin: 'war'
apply from: '../gretty.plugin'
apply plugin: 'java-library'

def mainClassName = "whelk.ApixServer"

repositories {
mavenCentral()
Expand All @@ -16,12 +17,13 @@ configurations.all {
dependencies {
// XL dependencies
implementation(project(':whelk-core'))
implementation(project(':server-common'))

// Jetty
implementation "org.eclipse.jetty:jetty-webapp:${jettyVersion}"
// HTTP
api "jakarta.servlet:jakarta.servlet-api:${servletApiVersion}"
implementation "org.eclipse.jetty:jetty-server:${jettyVersion}"
implementation "org.eclipse.jetty:jetty-http:${jettyVersion}"
implementation "org.eclipse.jetty:jetty-io:${jettyVersion}"
implementation "org.eclipse.jetty.ee8:jetty-ee8-servlet:${jettyVersion}"
implementation "org.eclipse.jetty.ee8:jetty-ee8-security:${jettyVersion}"

// Logging
implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: "${log4jVersion}"
Expand All @@ -35,18 +37,43 @@ dependencies {
testImplementation 'junit:junit:4.12'
}

gretty {
httpPort = 8280
contextPath = '/apix'
jar {
dependsOn ':server-common:jar'

manifest {
attributes "Main-Class": mainClassName,
// log4j uses multi-release to ship different stack walking implementations for different java
// versions. Since we repackage everything as a fat jar, that jar must also be multi-release.
"Multi-Release": true
}

afterEvaluate {
appRunDebug {
debugPort = 5007
debugSuspend = false
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from {
configurations.runtimeClasspath.collect {
it.isDirectory() ? it : project.zipTree(it).matching {
exclude 'META-INF/*.RSA', 'META-INF/*.SF', 'META-INF/*.DSA','build','.gradle/**','build.gradle','gradle','gradlew','gradlew.bat','test'
}
}
}
}

war {
archiveFileName = 'apix.war'
}
task(appRun, dependsOn: "classes", type: JavaExec) {
classpath = sourceSets.test.runtimeClasspath
mainClass = mainClassName
minHeapSize = "1g"
maxHeapSize = "4g"
systemProperties(
'xl.secret.properties': System.getProperty("xl.secret.properties"),
'xl.logRoot': System.getProperty("xl.logRoot", "./logs"),
'xl.apix-users.properties': System.getProperty("xl.apix-users.properties"),
'xl.http.port': System.getProperty("xl.http.port", "8184")
)
args(System.getProperty("args", "").split() as String[])

debugOptions {
enabled = true
port = 5008
server = true
suspend = false
}
}
72 changes: 72 additions & 0 deletions apix_server/src/main/java/whelk/ApixServer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package whelk;

import io.prometheus.client.exporter.MetricsServlet;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.eclipse.jetty.ee8.nested.ServletConstraint;
import org.eclipse.jetty.ee8.security.ConstraintAware;
import org.eclipse.jetty.ee8.security.ConstraintMapping;
import org.eclipse.jetty.ee8.servlet.ServletContextHandler;
import org.eclipse.jetty.security.HashLoginService;
import org.eclipse.jetty.security.LoginService;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.resource.PathResourceFactory;
import org.eclipse.jetty.util.resource.Resource;
import whelk.apixserver.ApixCatServlet;
import whelk.apixserver.ApixSearchServlet;

public class ApixServer extends XlServer {
private static final Logger log = LogManager.getLogger(ApixServer.class);

private static final String USER_PROPERTIES_PATH_PARAMETER = "xl.apix-users.properties";

@Override
protected void configureHandlers(Server server) {
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SECURITY);
context.setContextPath("/");

if (context.getSecurityHandler() instanceof ConstraintAware security)
{
ServletConstraint constraint = new ServletConstraint();
constraint.setAuthenticate(true);
constraint.setRoles(new String[]{ "apix" });

ConstraintMapping mapping = new ConstraintMapping();
mapping.setPathSpec("/apix/*");
mapping.setConstraint(constraint);
security.addConstraintMapping(mapping);

// One row per user:
// <username>: <password> [, <role>...}
// for example:
// foo: bar, apix
String fileName = System.getProperty(USER_PROPERTIES_PATH_PARAMETER, "");
if ("".equals(fileName)) {
throw new IllegalStateException(USER_PROPERTIES_PATH_PARAMETER + " not configured");
}

Resource config = new PathResourceFactory().newResource(fileName);
LoginService loginService = new HashLoginService("ApixRealm", config);
server.addBean(loginService);
context.getSecurityHandler().setAuthMethod("BASIC");
context.getSecurityHandler().setLoginService(loginService);
log.info("Getting APIX users from {}", fileName);
}
else
{
throw new RuntimeException("Not a ConstraintAware SecurityHandler");
}

context.addServlet(MetricsServlet.class, "/metrics");
context.addServlet(ApixCatServlet.class, "/apix/0.1/cat/*");
context.addServlet(ApixSearchServlet.class, "/apix/0.1/cat/libris/search");

serveStaticContent(context);

server.setHandler(context);
}

public static void main(String[] args) throws Exception {
new ApixServer().run();
}
}
2 changes: 1 addition & 1 deletion apix_server/src/main/java/whelk/apixserver/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static String convertToMarcXml(Document document)
{
try
{
return (String) s_toMarcConverter.convert(document.data, document.getShortId()).get(JsonLd.getNON_JSON_CONTENT_KEY());
return (String) s_toMarcConverter.convert(document.data, document.getShortId()).get(JsonLd.NON_JSON_CONTENT_KEY);
}
catch (Exception | Error e)
{
Expand Down
4 changes: 2 additions & 2 deletions apix_server/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Properties>
<Property name="catalina.base">.</Property>
<Property name="xl.logRoot">./logs</Property>
</Properties>

<Appenders>
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout pattern="%d{ISO8601} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
<File name="File" fileName="${sys:catalina.base}/logs/whelk-apix.log">
<File name="File" fileName="${sys:xl.logRoot}/whelk-apix.log">
<PatternLayout pattern="%d{ISO8601} [%t] %-5level %logger{36} - %msg%n"/>
</File>
</Appenders>
Expand Down
88 changes: 0 additions & 88 deletions apix_server/src/main/webapp/WEB-INF/web.xml

This file was deleted.

6 changes: 4 additions & 2 deletions batchimport/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,16 @@ test.testLogging {
exceptionFormat = "full"
}

mainClassName = 'whelk.importer.Main'
application {
mainClass = 'whelk.importer.Main'
}

jar {
dependsOn ':whelk-core:jar'
manifest {
attributes 'Implementation-Title':'Libris XL metadata importer',
'Implementation-Version': '1.0',
'Main-class': mainClassName,
'Main-class': application.mainClass,
// log4j uses multi-release to ship different stack walking implementations for different java
// versions. Since we repackage everything as a fat jar, that jar must also be multi-release.
"Multi-Release": true
Expand Down
2 changes: 1 addition & 1 deletion batchimport/src/main/java/whelk/importer/XL.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class XL
verbose = m_parameters.getVerbose();
m_properties = PropertyLoader.loadProperties("secret");
m_whelk = Whelk.createLoadedSearchWhelk(m_properties);
m_repeatableTerms = m_whelk.getJsonld().getRepeatableTerms();
m_repeatableTerms = m_whelk.getJsonld().repeatableTerms;
m_marcFrameConverter = m_whelk.getMarcFrameConverter();
m_linkfinder = new LinkFinder(m_whelk.getStorage());
if (parameters.getMergeRuleFile() != null) {
Expand Down
5 changes: 4 additions & 1 deletion batchimport/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Properties>
<Property name="catalina.base">.</Property>
<Property name="xl.logRoot">./logs</Property>
</Properties>

<Appenders>
<Console name="STDERR" target="SYSTEM_ERR">
<PatternLayout pattern="%msg%n"/>
</Console>
<File name="File" fileName="${sys:xl.logRoot}/whelk-batchimport.log">
<PatternLayout pattern="%d{ISO8601} [%t] %-5level %logger{36} - %msg%n"/>
</File>
</Appenders>

<Loggers>
Expand Down
8 changes: 5 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ plugins {

allprojects {
apply plugin: 'java'
sourceCompatibility = 17
targetCompatibility = 17
java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}
// Run manually with "./gradlew autoLintGradle"
// Unused dependency warning cannot always be trusted, always verify ("this dependency is unused and can be removed")
gradleLint.rules = ['all-dependency']
Expand All @@ -27,7 +29,7 @@ allprojects {
ignoreFailures = true
dependencies {
codenarc('org.codenarc:CodeNarc:3.3.0')
codenarc('org.codehaus.groovy:groovy-all:3.0.7')
codenarc('org.codehaus.groovy:groovy-all:3.0.20')
}
}
}
7 changes: 4 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
org.gradle.daemon=true
groovyVersion=3.0.9
jettyVersion = 9.4.44.v20210927
groovyVersion=3.0.20
servletApiVersion = 4.0.3
jettyVersion = 12.0.6
prometheusVersion = 0.15.0
log4jVersion = 2.17.0
resilience4jVersion = 1.7.1
Expand All @@ -9,4 +10,4 @@ httpComponentsClientVersion = 4.5.13
systemProp.https.protocols=TLSv1.1,TLSv1.2
spockVersion=2.1-groovy-3.0
guavaVersion=31.1-jre
jacocoVersion=0.8.8
jacocoVersion=0.8.11
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 952cfbd

Please sign in to comment.