mirror of
https://github.com/simon987/music-graph-api.git
synced 2025-04-20 02:16:41 +00:00
Upgrade to java 11, Basic JAX-RS setup
This commit is contained in:
parent
1bbc342b7f
commit
4aab07f4cd
61
pom.xml
61
pom.xml
@ -8,29 +8,36 @@
|
|||||||
<artifactId>music-graph</artifactId>
|
<artifactId>music-graph</artifactId>
|
||||||
<version>0.1</version>
|
<version>0.1</version>
|
||||||
|
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<version>3.6.2</version>
|
<version>3.8.0</version>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>1.8</source>
|
<release>11</release>
|
||||||
<target>1.8</target>
|
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<executions>
|
||||||
<version>3.0.2</version>
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>single</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
<configuration>
|
<configuration>
|
||||||
<archive>
|
<archive>
|
||||||
<manifest>
|
<manifest>
|
||||||
<mainClass>net.simon987.Main</mainClass>
|
<mainClass>net.simon987.Main</mainClass>
|
||||||
</manifest>
|
</manifest>
|
||||||
</archive>
|
</archive>
|
||||||
|
<descriptorRefs>
|
||||||
|
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||||
|
</descriptorRefs>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
@ -51,5 +58,45 @@
|
|||||||
<version>3.1.8</version>
|
<version>3.1.8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.containers/jersey-container-grizzly2-http -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.glassfish.jersey.containers</groupId>
|
||||||
|
<artifactId>jersey-container-grizzly2-http</artifactId>
|
||||||
|
<version>2.28</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.inject/jersey-hk2 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.glassfish.jersey.inject</groupId>
|
||||||
|
<artifactId>jersey-hk2</artifactId>
|
||||||
|
<version>2.28</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.media/jersey-media-json-jackson -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.glassfish.jersey.media</groupId>
|
||||||
|
<artifactId>jersey-media-json-jackson</artifactId>
|
||||||
|
<version>2.28</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.xml.bind</groupId>
|
||||||
|
<artifactId>jaxb-api</artifactId>
|
||||||
|
<version>2.4.0-b180830.0359</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-osgi -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.sun.xml.bind</groupId>
|
||||||
|
<artifactId>jaxb-osgi</artifactId>
|
||||||
|
<version>2.4.0-b180830.0438</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-core -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.sun.xml.bind</groupId>
|
||||||
|
<artifactId>jaxb-core</artifactId>
|
||||||
|
<version>2.3.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
@ -1,9 +1,40 @@
|
|||||||
package net.simon987;
|
package net.simon987;
|
||||||
|
|
||||||
|
import net.simon987.logging.LogManager;
|
||||||
|
import net.simon987.webapi.Index;
|
||||||
|
import org.glassfish.grizzly.http.server.HttpServer;
|
||||||
|
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
|
||||||
|
import org.glassfish.jersey.jackson.JacksonFeature;
|
||||||
|
import org.glassfish.jersey.server.ResourceConfig;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
|
private final static Logger LOGGER = LogManager.getLogger();
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
System.out.println("Hello, world");
|
LOGGER.info("test");
|
||||||
|
startHttpServer();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void startHttpServer() {
|
||||||
|
|
||||||
|
ResourceConfig rc = new ResourceConfig();
|
||||||
|
|
||||||
|
rc.registerClasses(Index.class);
|
||||||
|
rc.registerClasses(JacksonFeature.class);
|
||||||
|
|
||||||
|
try {
|
||||||
|
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(
|
||||||
|
new URI("http://localhost:8080/"),
|
||||||
|
rc);
|
||||||
|
|
||||||
|
server.start();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
21
src/main/java/net/simon987/logging/LogManager.java
Normal file
21
src/main/java/net/simon987/logging/LogManager.java
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package net.simon987.logging;
|
||||||
|
|
||||||
|
import java.util.logging.*;
|
||||||
|
|
||||||
|
public class LogManager {
|
||||||
|
|
||||||
|
private static Logger logger;
|
||||||
|
|
||||||
|
static {
|
||||||
|
logger = Logger.getLogger("music-graph");
|
||||||
|
|
||||||
|
Handler handler = new StdOutHandler();
|
||||||
|
|
||||||
|
logger.setUseParentHandlers(false);
|
||||||
|
logger.addHandler(handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Logger getLogger() {
|
||||||
|
return logger;
|
||||||
|
}
|
||||||
|
}
|
24
src/main/java/net/simon987/logging/MusicGraphFormatter.java
Normal file
24
src/main/java/net/simon987/logging/MusicGraphFormatter.java
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package net.simon987.logging;
|
||||||
|
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.logging.Formatter;
|
||||||
|
import java.util.logging.LogRecord;
|
||||||
|
|
||||||
|
|
||||||
|
public class MusicGraphFormatter extends Formatter {
|
||||||
|
|
||||||
|
private static final DateFormat dateFormat = new SimpleDateFormat("MM-dd HH:mm:ss");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String format(LogRecord record) {
|
||||||
|
|
||||||
|
Date date = new Date();
|
||||||
|
|
||||||
|
return String.format(
|
||||||
|
"[%s] (MG) %s: %s\n",
|
||||||
|
dateFormat.format(date), record.getLevel(), record.getMessage()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
20
src/main/java/net/simon987/logging/StdOutHandler.java
Normal file
20
src/main/java/net/simon987/logging/StdOutHandler.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package net.simon987.logging;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.LogRecord;
|
||||||
|
import java.util.logging.StreamHandler;
|
||||||
|
|
||||||
|
public class StdOutHandler extends StreamHandler {
|
||||||
|
|
||||||
|
StdOutHandler() {
|
||||||
|
super(System.out, new MusicGraphFormatter());
|
||||||
|
|
||||||
|
this.setLevel(Level.ALL);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized void publish(LogRecord record) {
|
||||||
|
super.publish(record);
|
||||||
|
flush();
|
||||||
|
}
|
||||||
|
}
|
20
src/main/java/net/simon987/models/ApiInfo.java
Normal file
20
src/main/java/net/simon987/models/ApiInfo.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package net.simon987.models;
|
||||||
|
|
||||||
|
public class ApiInfo {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private String version;
|
||||||
|
|
||||||
|
public ApiInfo(String name, String version) {
|
||||||
|
this.name = name;
|
||||||
|
this.version = version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVersion() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
}
|
23
src/main/java/net/simon987/webapi/Index.java
Normal file
23
src/main/java/net/simon987/webapi/Index.java
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package net.simon987.webapi;
|
||||||
|
|
||||||
|
import net.simon987.models.ApiInfo;
|
||||||
|
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
@Path("/")
|
||||||
|
public class Index {
|
||||||
|
|
||||||
|
private static final ApiInfo INFO = new ApiInfo(
|
||||||
|
"music-graph",
|
||||||
|
"0.1"
|
||||||
|
);
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public ApiInfo get() {
|
||||||
|
return INFO;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user