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

Migrate uni-resolver-web to Spring Boot #271

Merged
merged 12 commits into from
Jan 5, 2022
Merged
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@

<did-common-java.version>0.4.0</did-common-java.version>

<eclipse.jetty.version>9.4.18.v20190429</eclipse.jetty.version>
<eclipse.jetty.version>9.4.44.v20210927</eclipse.jetty.version>
<slf4j.version>1.7.25</slf4j.version>
<apache.log4j.version>2.17.0</apache.log4j.version>
<fasterxml.jackson.version>2.11.2</fasterxml.jackson.version>
<gson.version>2.8.6</gson.version>
<commons-codec.version>1.14</commons-codec.version>
<httpclient.version>4.5.13</httpclient.version>
<javax.servlet.version>2.5</javax.servlet.version>
<springframework.version>5.2.9.RELEASE</springframework.version>
<springframework.version>5.3.14</springframework.version>
<junit.version>4.13.1</junit.version>

<!-- Plugin Versions -->
Expand Down
12 changes: 8 additions & 4 deletions uni-resolver-web/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ RUN cd /opt/universal-resolver/uni-resolver-web && mvn clean install package -N

# build image

FROM jetty:9.4-jre11
FROM openjdk:11-jre-slim
MAINTAINER Markus Sabadello <markus@danubetech.com>

COPY --from=build /opt/universal-resolver/uni-resolver-web/target/*.war /var/lib/jetty/webapps/ROOT.war
COPY --from=build /opt/universal-resolver/uni-resolver-web/config.json /var/lib/jetty/
WORKDIR /opt/universal-resolver/uni-resolver-web/

COPY --from=build /opt/universal-resolver/uni-resolver-web/target/*-exec.jar ./
COPY --from=build /opt/universal-resolver/uni-resolver-web/config.json ./

ENV uniresolver_web_spring_profiles_active=default

# done

EXPOSE 8080
CMD java -Djetty.http.port=8080 -jar /usr/local/jetty/start.jar
CMD java -jar *.jar
145 changes: 78 additions & 67 deletions uni-resolver-web/pom.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<artifactId>uni-resolver-web</artifactId>
<packaging>war</packaging>
<packaging>jar</packaging>
<name>uni-resolver-web</name>

<parent>
Expand All @@ -11,73 +12,83 @@
<version>0.5-SNAPSHOT</version>
</parent>

<properties>
<java.version>11</java.version>
<spring.boot.version>2.6.2</spring.boot.version>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<configuration>
<jettyConfig>
${basedir}/src/test/resources/jetty.xml
</jettyConfig>
<useTestClasspath>true</useTestClasspath>
<systemProperties>
<systemProperty>
<name>jetty.port</name>
<value>8080</value>
</systemProperty>
<systemProperty>
<name>slf4j</name>
<value>true</value>
</systemProperty>
<systemProperty>
<name>log4j2.configurationFile</name>
<value>file:${basedir}/src/test/resources/log4j2-test.properties</value>
</systemProperty>
</systemProperties>
<webApp>
<contextPath>/</contextPath>
<jettyEnvXml>
${basedir}/src/test/resources/jetty-env.xml
</jettyEnvXml>
<webInfIncludeJarPattern>^$</webInfIncludeJarPattern>
<containerIncludeJarPattern>^$</containerIncludeJarPattern>
</webApp>
</configuration>
</plugin>
</plugins>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<configuration>
<mainClass>uniresolver.web.WebUniResolverApplication</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>exec</classifier>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
</dependency>
<dependency>
<groupId>decentralized-identity</groupId>
<artifactId>uni-resolver-local</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring.boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>


<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<dependency>
<groupId>decentralized-identity</groupId>
<artifactId>uni-resolver-local</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
package uniresolver.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.HttpRequestHandler;
import uniresolver.ResolutionException;
import uniresolver.UniResolver;
import uniresolver.result.ResolveDataModelResult;
import uniresolver.result.ResolveRepresentationResult;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;

@WebServlet
public abstract class WebUniResolver extends HttpServlet implements HttpRequestHandler, UniResolver {

@Autowired
@Qualifier("UniResolver")
private UniResolver uniResolver;

protected WebUniResolver() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package uniresolver.web;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

@SpringBootApplication
public class WebUniResolverApplication extends SpringBootServletInitializer {

public static void main(String[] args) {
SpringApplication.run(WebUniResolverApplication.class, args);
}

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(WebUniResolverApplication.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package uniresolver.web.config;

import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import uniresolver.local.LocalUniResolver;
import uniresolver.web.servlet.MethodsServlet;
import uniresolver.web.servlet.PropertiesServlet;
import uniresolver.web.servlet.ResolveServlet;
import uniresolver.web.servlet.TestIdentifiersServlet;

import java.io.IOException;

@Configuration
public class WebAppConfig {

@Bean(name = "UniResolver")
public LocalUniResolver localUniResolver() throws IOException {
return LocalUniResolver.fromConfigFile("./config.json");
}

@Bean(name = "ResolveServlet")
public ResolveServlet resolveServlet() {
return new ResolveServlet();
}

@Bean
public ServletRegistrationBean<PropertiesServlet> propertiesServletRegistrationBean() {
return new ServletRegistrationBean<>(propertiesServlet(), "/1.0/properties/*");
}

@Bean(name = "PropertiesServlet")
public PropertiesServlet propertiesServlet() {
return new PropertiesServlet();
}

@Bean
public ServletRegistrationBean<ResolveServlet> resolveServletRegistrationBean() {
return new ServletRegistrationBean<>(resolveServlet(), "/1.0/identifiers/*");
}

@Bean(name = "MethodServlet")
public MethodsServlet methodsServlet() {
return new MethodsServlet();
}

@Bean
public ServletRegistrationBean<MethodsServlet> methodServletRegistrationBean() {
return new ServletRegistrationBean<>(methodsServlet(), "/1.0/methods/*");
}

@Bean(name = "TestIdentifiersServlet")
public TestIdentifiersServlet testIdentifiersServlet() {
return new TestIdentifiersServlet();
}

@Bean
public ServletRegistrationBean<TestIdentifiersServlet> testIdentifiersServletRegistrationBean() {
return new ServletRegistrationBean<>(testIdentifiersServlet(), "/1.0/testIdentifiers/*");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
management.endpoint.health.probes.enabled=true
management.health.livenessState.enabled=true
management.health.readinessState.enabled=true
management.endpoint.health.show-details=always
management.endpoint.health.status.http-mapping.down=500
management.endpoint.health.status.http-mapping.out_of_service=503
management.endpoint.health.status.http-mapping.warning=500

management.endpoints.web.exposure.include=*
4 changes: 4 additions & 0 deletions uni-resolver-web/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
server.port=8080
server.servlet.contextPath=/

spring.profiles.active=${uniresolver_web_spring_profiles_active}
24 changes: 0 additions & 24 deletions uni-resolver-web/src/main/resources/log4j2.properties

This file was deleted.

20 changes: 20 additions & 0 deletions uni-resolver-web/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">

<PatternLayout
pattern="%style{%d{ISO8601}}{red} %highlight{%-5level }[%style{%t}{bright,blue}] %style{%C{1.}}{bright,yellow}: %msg%n%throwable"/>
</Console>
</Appenders>

<Loggers>
<Root level="info">
<AppenderRef ref="Console"/>
</Root>
<Logger name="uniresolver" level="debug" additivity="false">
<AppenderRef ref="Console"/>
</Logger>
</Loggers>

</Configuration>
Loading