commit
a1a07e473b
@ -0,0 +1,4 @@
|
||||
.idea
|
||||
pom.xml.versionsBackup
|
||||
*.iml
|
||||
target
|
@ -0,0 +1,191 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>se.metasolutions.recruit</groupId>
|
||||
<artifactId>rest-parent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>REST</name>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<prerequisites>
|
||||
<maven>3.0</maven>
|
||||
</prerequisites>
|
||||
|
||||
<properties>
|
||||
<slf4j.version>1.7.30</slf4j.version>
|
||||
<log4j.version>2.17.1</log4j.version>
|
||||
<restlet.version>2.4.3</restlet.version>
|
||||
<jetty.version>9.4.44.v20210927</jetty.version>
|
||||
<servlet.version>3.1.0</servlet.version>
|
||||
<jsonorg.version>20201115</jsonorg.version>
|
||||
<guava.version>30.1-jre</guava.version>
|
||||
<maven.compiler.release>11</maven.compiler.release>
|
||||
</properties>
|
||||
|
||||
<modules>
|
||||
<module>standalone</module>
|
||||
<module>webapp</module>
|
||||
</modules>
|
||||
|
||||
<organization>
|
||||
<name>MetaSolutions AB</name>
|
||||
<url>https://www.metasolutions.se</url>
|
||||
</organization>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<version>2.8.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>appassembler-maven-plugin</artifactId>
|
||||
<version>2.0.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
<configuration>
|
||||
<release>${maven.compiler.release}</release>
|
||||
<encoding>UTF-8</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>EntryStore</id>
|
||||
<url>https://maven.entrystore.org</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>Restlet</id>
|
||||
<url>https://maven.restlet.talend.com</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
</dependencies>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-alpn-client</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-alpn-java-client</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-alpn-java-server</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-client</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-continuation</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-deploy</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-http</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-io</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-jmx</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-rewrite</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-security</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-server</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-servlet</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-servlets</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-util</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-webapp</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-xml</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.http2</groupId>
|
||||
<artifactId>http2-client</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.http2</groupId>
|
||||
<artifactId>http2-common</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.http2</groupId>
|
||||
<artifactId>http2-hpack</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.http2</groupId>
|
||||
<artifactId>http2-http-client-transport</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.http2</groupId>
|
||||
<artifactId>http2-server</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
</project>
|
@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>rest-standalone-common</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>REST Standalone Common</name>
|
||||
|
||||
<parent>
|
||||
<groupId>se.metasolutions.recruit</groupId>
|
||||
<artifactId>rest-standalone</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>se.metasolutions.recruit</groupId>
|
||||
<artifactId>rest-webapp</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>${servlet.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-cli</groupId>
|
||||
<artifactId>commons-cli</artifactId>
|
||||
<version>1.4</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,135 @@
|
||||
package se.metasolutions.recruit;
|
||||
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.CommandLineParser;
|
||||
import org.apache.commons.cli.DefaultParser;
|
||||
import org.apache.commons.cli.HelpFormatter;
|
||||
import org.apache.commons.cli.Option;
|
||||
import org.apache.commons.cli.Options;
|
||||
import org.apache.commons.cli.ParseException;
|
||||
import org.apache.commons.cli.PatternOptionBuilder;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.core.config.Configurator;
|
||||
import org.restlet.Application;
|
||||
import org.restlet.Component;
|
||||
import org.restlet.Context;
|
||||
import org.restlet.Server;
|
||||
import org.restlet.data.Protocol;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
public abstract class RestApplicationStandalone extends Application {
|
||||
|
||||
private final static org.slf4j.Logger log = LoggerFactory.getLogger(RestApplicationStandalone.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.setProperty("org.restlet.engine.loggerFacadeClass", "org.restlet.ext.slf4j.Slf4jLoggerFacade");
|
||||
|
||||
CommandLineParser parser = new DefaultParser();
|
||||
Options options = new Options();
|
||||
options.addOption(Option.builder("p").
|
||||
longOpt("port").
|
||||
desc("port to listen on; default: 8282").
|
||||
hasArg().
|
||||
argName("PORT").
|
||||
optionalArg(false).
|
||||
type(PatternOptionBuilder.NUMBER_VALUE).
|
||||
build());
|
||||
options.addOption(Option.builder("l").
|
||||
longOpt("log-level").
|
||||
desc("log level, one of: ALL, TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF; default: INFO").
|
||||
hasArg().
|
||||
argName("LEVEL").
|
||||
optionalArg(false).
|
||||
build());
|
||||
options.addOption(Option.builder().
|
||||
longOpt("connector-params").
|
||||
desc("comma separated list of parameters to be used for the server connector." +
|
||||
"Example for Jetty: \"threadPool.minThreads=50,threadPool.maxThreads=250\"; " +
|
||||
"see the JavaDoc of JettyServerHelper for available parameters").
|
||||
hasArg().
|
||||
argName("SETTINGS").
|
||||
optionalArg(false).
|
||||
build());
|
||||
options.addOption(Option.builder("h").longOpt("help").desc("display this help").build());
|
||||
|
||||
CommandLine cl = null;
|
||||
try {
|
||||
cl = parser.parse(options, args);
|
||||
} catch (ParseException e) {
|
||||
System.err.println(e.getMessage() + "\n");
|
||||
printHelp(options);
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
if (cl.hasOption("help")) {
|
||||
printHelp(options);
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
String strPort = cl.getOptionValue("p", "8282");
|
||||
int port = 8282;
|
||||
try {
|
||||
port = Integer.parseInt(strPort);
|
||||
} catch (NumberFormatException nfe) {
|
||||
System.err.println("Invalid port number, must be integer: " + strPort + "\n");
|
||||
printHelp(options);
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
configureLogging(cl.getOptionValue("log-level", "INFO"));
|
||||
|
||||
Component component = new Component();
|
||||
Server server = component.getServers().add(Protocol.HTTP, port);
|
||||
|
||||
String conParams;
|
||||
if (cl.hasOption("connector-params")) {
|
||||
conParams = cl.getOptionValue("connector-params");
|
||||
for (String param : conParams.split(",")) {
|
||||
if (param.length() > 0) {
|
||||
String[] kv = param.split("=");
|
||||
if (kv.length == 2) {
|
||||
log.debug("Adding connector parameter: {}={}", kv[0], kv[1]);
|
||||
server.getContext().getParameters().add(kv[0].trim(), kv[1].trim());
|
||||
} else {
|
||||
System.err.println("Invalid connector parameter: " + param);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
component.getLogService().setResponseLogFormat("{ciua} \"{m} {rp} {rq}\" {S} {ES} {es} {hh} {cig} {fi}");
|
||||
server.getContext().getParameters().add("useForwardedForHeader", "true");
|
||||
component.getClients().add(Protocol.HTTP);
|
||||
component.getClients().add(Protocol.HTTPS);
|
||||
Context c = component.getContext().createChildContext();
|
||||
|
||||
try {
|
||||
component.getDefaultHost().attach(new RestApplication(c));
|
||||
component.start();
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void printHelp(Options options) {
|
||||
HelpFormatter formatter = new HelpFormatter();
|
||||
formatter.setWidth(100);
|
||||
formatter.setLeftPadding(2);
|
||||
formatter.printHelp("rowstore", options,true);
|
||||
}
|
||||
|
||||
private static void configureLogging(String logLevel) {
|
||||
Level l = Level.toLevel(logLevel, Level.INFO);
|
||||
Configurator.setRootLevel(l);
|
||||
log.info("Log level set to " + l);
|
||||
}
|
||||
|
||||
private static void out(String s) {
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<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/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>se.metasolutions.recruit</groupId>
|
||||
<artifactId>rest-standalone</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>rest-standalone-jetty</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>REST Standalone Jetty</name>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
<testResources>
|
||||
<testResource>
|
||||
<directory>src/test/resources</directory>
|
||||
<includes>
|
||||
<include>**/*.xml</include>
|
||||
<include>**/*.properties</include>
|
||||
</includes>
|
||||
</testResource>
|
||||
</testResources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<release>${maven.compiler.release}</release>
|
||||
<compilerArgument></compilerArgument>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>appassembler-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<programs>
|
||||
<program>
|
||||
<mainClass>se.metasolutions.recruit.RestApplicationStandaloneJetty</mainClass>
|
||||
<name>rest</name>
|
||||
</program>
|
||||
</programs>
|
||||
<repositoryLayout>flat</repositoryLayout>
|
||||
<useWildcardClassPath>true</useWildcardClassPath>
|
||||
<assembleDirectory>${project.build.directory}/dist</assembleDirectory>
|
||||
<extraJvmArguments></extraJvmArguments>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>assemble</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>se.metasolutions.recruit</groupId>
|
||||
<artifactId>rest-standalone-common</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.restlet.jse</groupId>
|
||||
<artifactId>org.restlet.ext.jetty</artifactId>
|
||||
<version>${restlet.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,10 @@
|
||||
package se.metasolutions.recruit;
|
||||
|
||||
/**
|
||||
* Main class to start using Jetty.
|
||||
*
|
||||
* @author Hannes Ebner
|
||||
*/
|
||||
public class RestApplicationStandaloneJetty extends RestApplicationStandalone {
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<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/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>se.metasolutions.recruit</groupId>
|
||||
<artifactId>rest-parent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>rest-standalone</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>REST Standalone</name>
|
||||
|
||||
<modules>
|
||||
<module>common</module>
|
||||
<module>jetty</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
@ -0,0 +1,134 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>rest-webapp</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>REST WebApp</name>
|
||||
|
||||
<parent>
|
||||
<groupId>se.metasolutions.recruit</groupId>
|
||||
<artifactId>rest-parent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>make-a-jar</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-install-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>install</phase>
|
||||
<goals>
|
||||
<goal>install-file</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<packaging>jar</packaging>
|
||||
<artifactId>${project.artifactId}</artifactId>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<version>${project.version}</version>
|
||||
<file>${project.build.directory}/${project.artifactId}-${project.version}.jar</file>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.restlet.jse</groupId>
|
||||
<artifactId>org.restlet</artifactId>
|
||||
<version>${restlet.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.restlet.jse</groupId>
|
||||
<artifactId>org.restlet.ext.json</artifactId>
|
||||
<version>${restlet.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.restlet.jee</groupId>
|
||||
<artifactId>org.restlet.ext.servlet</artifactId>
|
||||
<version>${restlet.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.restlet.jse</groupId>
|
||||
<artifactId>org.restlet.ext.slf4j</artifactId>
|
||||
<version>${restlet.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>${servlet.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.json</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
<version>${jsonorg.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<version>99.0-does-not-exist</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging-api</artifactId>
|
||||
<version>99.0-does-not-exist</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
<version>${slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j-impl</artifactId>
|
||||
<version>${log4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-api</artifactId>
|
||||
<version>${log4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>${log4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,135 @@
|
||||
package se.metasolutions.recruit;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.core.config.Configurator;
|
||||
import se.metasolutions.recruit.resources.DefaultResource;
|
||||
import se.metasolutions.recruit.resources.StatusResource;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.restlet.Application;
|
||||
import org.restlet.Context;
|
||||
import org.restlet.Restlet;
|
||||
import org.restlet.engine.io.IoUtils;
|
||||
import org.restlet.routing.Router;
|
||||
import org.restlet.routing.Template;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Boilerplate for a REST API.
|
||||
*/
|
||||
public class RestApplication extends Application {
|
||||
|
||||
static Logger log = LoggerFactory.getLogger(RestApplication.class);
|
||||
|
||||
public static String KEY = RestApplication.class.getCanonicalName();
|
||||
|
||||
public static String NAME = "REST";
|
||||
|
||||
private static String VERSION = null;
|
||||
|
||||
public RestApplication(Context parentContext) throws IOException, JSONException {
|
||||
this(parentContext, null);
|
||||
}
|
||||
|
||||
public RestApplication(Context parentContext, URI configURI) throws IOException, JSONException {
|
||||
super(parentContext);
|
||||
getContext().getAttributes().put(KEY, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Restlet createInboundRoot() {
|
||||
getContext().getParameters().add("useForwardedForHeader", "true");
|
||||
|
||||
Router router = new Router(getContext());
|
||||
router.setDefaultMatchingMode(Template.MODE_EQUALS);
|
||||
|
||||
// global scope
|
||||
router.attach("/status", StatusResource.class);
|
||||
router.attach("/", DefaultResource.class);
|
||||
|
||||
return router;
|
||||
}
|
||||
|
||||
public static String getVersion() {
|
||||
if (VERSION == null) {
|
||||
URI versionFile = getConfigurationURI("VERSION.txt");
|
||||
try {
|
||||
log.debug("Reading version number from " + versionFile);
|
||||
VERSION = readFirstLine(versionFile.toURL());
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
if (VERSION == null) {
|
||||
VERSION = new SimpleDateFormat("yyyyMMdd").format(new Date());
|
||||
}
|
||||
}
|
||||
return VERSION;
|
||||
}
|
||||
|
||||
public static URI getConfigurationURI(String fileName) {
|
||||
URL resURL = Thread.currentThread().getContextClassLoader().getResource(fileName);
|
||||
try {
|
||||
if (resURL != null) {
|
||||
return resURL.toURI();
|
||||
}
|
||||
} catch (URISyntaxException e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
|
||||
String classPath = System.getProperty("java.class.path");
|
||||
String[] pathElements = classPath.split(System.getProperty("path.separator"));
|
||||
for (String element : pathElements) {
|
||||
File newFile = new File(element, fileName);
|
||||
if (newFile.exists()) {
|
||||
return newFile.toURI();
|
||||
}
|
||||
}
|
||||
log.error("Unable to find " + fileName + " in classpath");
|
||||
return null;
|
||||
}
|
||||
|
||||
private void setLogLevel(String logLevel) {
|
||||
Level l = Level.toLevel(logLevel, Level.INFO);
|
||||
Configurator.setRootLevel(l);
|
||||
log.info("Log level set to " + l);
|
||||
}
|
||||
|
||||
private static String readFirstLine(URL url) {
|
||||
BufferedReader in = null;
|
||||
try {
|
||||
in = new BufferedReader(new InputStreamReader(url.openStream()));
|
||||
return in.readLine();
|
||||
} catch (IOException ioe) {
|
||||
log.error(ioe.getMessage());
|
||||
} finally {
|
||||
if (in != null) {
|
||||
try {
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void stop() throws Exception {
|
||||
log.info("Shutting down");
|
||||
super.stop();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,104 @@
|
||||
package se.metasolutions.recruit.resources;
|
||||
|
||||
import se.metasolutions.recruit.RestApplication;
|
||||
import org.restlet.Context;
|
||||
import org.restlet.Request;
|
||||
import org.restlet.Response;
|
||||
import org.restlet.data.MediaType;
|
||||
import org.restlet.data.ServerInfo;
|
||||
import org.restlet.resource.ServerResource;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Base resource from which all other REST resources are subclassed. Handles basic functionality such as parsing of parameters.
|
||||
*/
|
||||
public class BaseResource extends ServerResource {
|
||||
|
||||
private static ServerInfo serverInfo;
|
||||
|
||||
protected MediaType format;
|
||||
|
||||
protected HashMap<String,String> parameters;
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(BaseResource.class);
|
||||
|
||||
@Override
|
||||
public void init(Context c, Request request, Response response) {
|
||||
parameters = parseRequest(request.getResourceRef().getRemainingPart());
|
||||
super.init(c, request, response);
|
||||
|
||||
if (parameters.containsKey("format")) {
|
||||
String format = parameters.get("format");
|
||||
if (format != null) {
|
||||
// workaround for URL-decoded pluses (space) in MIME-type names, e.g. ld+json
|
||||
format = format.replaceAll(" ", "+");
|
||||
this.format = new MediaType(format);
|
||||
}
|
||||
}
|
||||
|
||||
// we set a custom Server header in the HTTP response
|
||||
setServerInfo(this.getServerInfo());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doRelease() {
|
||||
|
||||
}
|
||||
|
||||
static public HashMap<String, String> parseRequest(String request) {
|
||||
HashMap<String, String> argsAndVal = new HashMap<String, String>();
|
||||
|
||||
int r = request.lastIndexOf("?");
|
||||
String req = request.substring(r + 1);
|
||||
String[] arguments = req.split("&");
|
||||
|
||||
try {
|
||||
for (int i = 0; i < arguments.length; i++) {
|
||||
if (arguments[i].contains("=")) {
|
||||
String[] elements = arguments[i].split("=");
|
||||
String key = urlDecode(elements[0]).trim();
|
||||
String value = urlDecode(elements[1]).trim();
|
||||
if (key.length() > 0) {
|
||||
argsAndVal.put(key, value);
|
||||
}
|
||||
} else {
|
||||
String key = urlDecode(arguments[i]).trim();
|
||||
if (key.length() > 0) {
|
||||
argsAndVal.put(key, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
// special case!
|
||||
argsAndVal.put(req, "");
|
||||
}
|
||||
return argsAndVal;
|
||||
}
|
||||
|
||||
private static String urlDecode(String input) {
|
||||
if (input != null) {
|
||||
try {
|
||||
return URLDecoder.decode(input, "UTF-8");
|
||||
} catch (UnsupportedEncodingException uee) {
|
||||
log.error(uee.getMessage());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerInfo getServerInfo() {
|
||||
if (serverInfo == null) {
|
||||
ServerInfo si = super.getServerInfo();
|
||||
si.setAgent(RestApplication.NAME + "/" + RestApplication.getVersion());
|
||||
serverInfo = si;
|
||||
}
|
||||
return serverInfo;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package se.metasolutions.recruit.resources;
|
||||
|
||||
import org.restlet.data.Status;
|
||||
import org.restlet.representation.Representation;
|
||||
import org.restlet.representation.StringRepresentation;
|
||||
import org.restlet.resource.Get;
|
||||
import org.restlet.resource.ResourceException;
|
||||
|
||||
|
||||
/**
|
||||
* Fallback if no other REST resource matches. Returns 404.
|
||||
*/
|
||||
public class DefaultResource extends BaseResource {
|
||||
|
||||
@Get
|
||||
public Representation represent() throws ResourceException {
|
||||
getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
|
||||
String msg = "You made a request against the REST API. There is no resource at this URL.";
|
||||
return new StringRepresentation(msg);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package se.metasolutions.recruit.resources;
|
||||
|
||||
import se.metasolutions.recruit.RestApplication;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.restlet.ext.json.JsonRepresentation;
|
||||
import org.restlet.representation.Representation;
|
||||
import org.restlet.resource.Get;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
|
||||
public class StatusResource extends BaseResource {
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(StatusResource.class);
|
||||
|
||||
@Get("json")
|
||||
public Representation getJvmStatus() throws JSONException {
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("version", RestApplication.getVersion());
|
||||
result.put("totalMemory", Runtime.getRuntime().totalMemory());
|
||||
result.put("freeMemory", Runtime.getRuntime().freeMemory());
|
||||
result.put("maxMemory", Runtime.getRuntime().maxMemory());
|
||||
result.put("availableProcessors", Runtime.getRuntime().availableProcessors());
|
||||
result.put("totalCommittedMemory", getTotalCommittedMemory());
|
||||
result.put("committedHeap", ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getCommitted());
|
||||
result.put("totalUsedMemory", getTotalUsedMemory());
|
||||
result.put("usedHeap", ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed());
|
||||
return new JsonRepresentation(result);
|
||||
}
|
||||
|
||||
long getTotalCommittedMemory() {
|
||||
return ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getCommitted() +
|
||||
ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage().getCommitted();
|
||||
}
|
||||
|
||||
long getTotalUsedMemory() {
|
||||
return ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed() +
|
||||
ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage().getUsed();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1 @@
|
||||
1.0-SNAPSHOT
|
@ -0,0 +1,14 @@
|
||||
name = PropertiesConfig
|
||||
appenders = console
|
||||
|
||||
appender.console.type = Console
|
||||
appender.console.name = STDOUT
|
||||
appender.console.layout.type = PatternLayout
|
||||
appender.console.layout.pattern = [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %replace{%msg}{\r?\n}{\u21B5}%n
|
||||
|
||||
rootLogger.level = INFO
|
||||
rootLogger.appenderRefs = stdout
|
||||
rootLogger.appenderRef.stdout.ref = STDOUT
|
||||
|
||||
logger.jetty.name = org.eclipse.jetty
|
||||
logger.jetty.level = INFO
|
Loading…
Reference in new issue