diff --git a/CHANGELOG.md b/CHANGELOG.md
index cc781cd..4c5965d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,11 @@ Proteus Changelog.
## Unreleased
### No issue
+**Migrate to Jakarta.**
+
+
+[ffb84eaddbbc01e](https://github.com/noboomu/proteus/commit/ffb84eaddbbc01e) Joshua Bauer *2023-09-27 18:41:05*
+
**Switch to SourceBuddy from OpenHFT for dynamic complilation. Breaks < JDK 17 compatability however.**
diff --git a/README.md b/README.md
index 7fb3bd5..695e1c3 100644
--- a/README.md
+++ b/README.md
@@ -479,7 +479,7 @@ Inspired by [Play](http://playframework.com), [Jooby](http://jooby.org), and [li
Dependencies
----------
-* [JDK 8](http://www.oracle.com/technetwork/java/javase/downloads/index.html)
+* [JDK 17](http://www.oracle.com/technetwork/java/javase/downloads/index.html)
* [Maven 3](http://maven.apache.org/)
diff --git a/pom.xml b/pom.xml
index 241cd05..e5aeda2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -47,7 +47,7 @@
3.12.0
1.9
32.1.2-jre
- 5.1.0
+ 6.0.0
2.15.2
3.1.0
1.18
@@ -114,11 +114,11 @@
${micrometer-core.version}
-
-
-
-
-
+
+
+
+
+
com.sun.xml.ws
@@ -153,11 +153,6 @@
${project.version}
-
- io.sinistral
- proteus-swagger
- ${project.version}
-
@@ -253,6 +248,7 @@
+ org.apache.maven.plugins
maven-surefire-plugin
${maven-surefire-plugin.version}
diff --git a/proteus-core/pom.xml b/proteus-core/pom.xml
index a4674dc..5dfcb72 100644
--- a/proteus-core/pom.xml
+++ b/proteus-core/pom.xml
@@ -7,6 +7,9 @@
io.sinistral
0.7.0-SNAPSHOT
+
+ 2.1.2
+
4.0.0
proteus-core
@@ -192,6 +195,19 @@ Proteus Changelog.
${jakarta-ws-rs.version}
+
+ jakarta.validation
+ jakarta.validation-api
+ ${jakarta-validation-api.version}
+
+
+
+
+ jakarta.activation
+ jakarta.activation-api
+ ${jakarta.activation-api.version}
+
+
@@ -244,12 +260,6 @@ Proteus Changelog.
${typesafe-config.version}
-
- jakarta.validation
- jakarta.validation-api
- ${jakarta-validation-api.version}
-
-
org.yaml
diff --git a/proteus-core/src/main/java/io/sinistral/proteus/ProteusApplication.java b/proteus-core/src/main/java/io/sinistral/proteus/ProteusApplication.java
index 9ff77a0..b00217b 100644
--- a/proteus-core/src/main/java/io/sinistral/proteus/ProteusApplication.java
+++ b/proteus-core/src/main/java/io/sinistral/proteus/ProteusApplication.java
@@ -285,19 +285,15 @@ public void buildServer() {
final Instant compilationStartTime = Instant.now();
- ExecutorService handlerCompilationExecutor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
-
- CountDownLatch countDownLatch = new CountDownLatch(registeredControllers.size());
-
- CopyOnWriteArrayList>> routerClasses = new CopyOnWriteArrayList<>();
-
- ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
+ List>> routerClasses = new ArrayList<>();
+//
+// ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
log.info("Compiling route handlers...");
for (Class> controllerClass : registeredControllers) {
- handlerCompilationExecutor.submit(() -> {
+
try {
@@ -311,15 +307,10 @@ public void buildServer() {
log.debug("Compiling {}...", controllerClass);
- log.debug("Generating {}...", controllerClass);
-
final String source = generator.generateClassSource();
log.debug("Generated {}...", controllerClass);
-
- lock.writeLock().lock();
-
try {
final var compiled = Compiler.java().from(source).compile();
@@ -340,22 +331,14 @@ public void buildServer() {
}
- lock.writeLock().unlock();
} catch (Exception e) {
log.error("Failed to compile", e);
}
- countDownLatch.countDown();
- });
}
- try {
- countDownLatch.await();
- } catch (Exception e) {
- log.error("Failed waiting for handlers to generate", e);
- }
log.debug("Compilation completed in {}", DurationFormatUtils.formatDurationHMS(Duration.between(compilationStartTime, Instant.now()).toMillis()));
diff --git a/proteus-core/src/main/java/io/sinistral/proteus/server/ServerResponse.java b/proteus-core/src/main/java/io/sinistral/proteus/server/ServerResponse.java
index 99cc299..7c895e8 100644
--- a/proteus-core/src/main/java/io/sinistral/proteus/server/ServerResponse.java
+++ b/proteus-core/src/main/java/io/sinistral/proteus/server/ServerResponse.java
@@ -14,7 +14,6 @@
import io.undertow.server.handlers.Cookie;
import io.undertow.server.handlers.ExceptionHandler;
import io.undertow.util.*;
-import jakarta.ws.rs.core.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -33,7 +32,6 @@
/**
* @author jbauer
* Base server response. Friendlier interface to underlying exchange.
- * @TODO extend jakarta.ws.rs.core.Response
*/
public class ServerResponse
@@ -57,7 +55,7 @@ public class ServerResponse
protected int status = StatusCodes.OK;
protected final HeaderMap headers = new HeaderMap();
protected final Map cookies = new HashMap<>();
- protected String contentType = jakarta.ws.rs.core.MediaType.APPLICATION_JSON;
+ protected String contentType = MediaType.APPLICATION_JSON.contentType();
protected T entity;
protected Throwable throwable;
// protected Class extends JsonContext> jsonContext;
@@ -175,14 +173,7 @@ public void setStatus(int status)
this.status = status;
}
- /**
- * @param status
- * the status to set
- */
- public void setStatus(Response.Status status)
- {
- this.status = status.getStatusCode();
- }
+
public ServerResponse body(ByteBuffer body)
{
@@ -266,11 +257,7 @@ public ServerResponse throwable(Throwable throwable)
return this;
}
- public ServerResponse status(Response.Status status)
- {
- this.status = status.getStatusCode();
- return this;
- }
+
public ServerResponse status(int status)
{
@@ -301,11 +288,11 @@ protected void setContentType(String contentType)
{
this.contentType = contentType;
- if (this.contentType.contains(jakarta.ws.rs.core.MediaType.APPLICATION_JSON)) {
+ if (this.contentType.contains(MediaType.APPLICATION_JSON.contentType())) {
if (!this.preprocessed) {
this.processJson = true;
}
- } else if (this.contentType.contains(jakarta.ws.rs.core.MediaType.APPLICATION_XML)) {
+ } else if (this.contentType.contains(MediaType.APPLICATION_XML.contentType())) {
if (!this.preprocessed) {
this.processXml = true;
}
@@ -319,12 +306,6 @@ public ServerResponse contentType(String contentType)
}
- public ServerResponse contentType(jakarta.ws.rs.core.MediaType mediaType)
- {
- this.setContentType(mediaType.toString());
- return this;
- }
-
public ServerResponse contentType(MediaType mediaType)
{
this.setContentType(mediaType.contentType());
@@ -336,19 +317,19 @@ public ServerResponse applicationJson()
if (!this.preprocessed) {
this.processJson = true;
}
- this.contentType = jakarta.ws.rs.core.MediaType.APPLICATION_JSON;
+ this.contentType = MediaType.APPLICATION_JSON.contentType();
return this;
}
public ServerResponse textHtml()
{
- this.contentType = jakarta.ws.rs.core.MediaType.TEXT_HTML;
+ this.contentType = MediaType.TEXT_HTML_UTF8.contentType();
return this;
}
public ServerResponse applicationOctetStream()
{
- this.contentType = jakarta.ws.rs.core.MediaType.APPLICATION_OCTET_STREAM;
+ this.contentType = MediaType.APPLICATION_OCTET_STREAM.contentType();
return this;
}
@@ -357,13 +338,13 @@ public ServerResponse applicationXml()
if (!this.preprocessed) {
this.processXml = true;
}
- this.contentType = jakarta.ws.rs.core.MediaType.APPLICATION_XML;
+ this.contentType = MediaType.APPLICATION_XML.contentType();
return this;
}
public ServerResponse textPlain()
{
- this.contentType = jakarta.ws.rs.core.MediaType.TEXT_PLAIN;
+ this.contentType = MediaType.TEXT_PLAIN_UTF8.contentType();
return this;
}
diff --git a/proteus-core/src/main/java/io/sinistral/proteus/server/exceptions/ServerException.java b/proteus-core/src/main/java/io/sinistral/proteus/server/exceptions/ServerException.java
index 2a9feb1..30604ba 100644
--- a/proteus-core/src/main/java/io/sinistral/proteus/server/exceptions/ServerException.java
+++ b/proteus-core/src/main/java/io/sinistral/proteus/server/exceptions/ServerException.java
@@ -3,7 +3,7 @@
*/
package io.sinistral.proteus.server.exceptions;
-import jakarta.ws.rs.core.Response.Status;
+import io.undertow.util.StatusCodes;
/**
* @author jbauer
@@ -16,7 +16,7 @@ public class ServerException extends RuntimeException
*/
private static final long serialVersionUID = 8360356916374374408L;
- private Integer status = Status.BAD_REQUEST.getStatusCode();
+ private Integer status = StatusCodes.BAD_REQUEST;
public ServerException(int status)
{
@@ -25,13 +25,6 @@ public ServerException(int status)
this.status = status;
}
- public ServerException(Status status)
- {
- super();
-
- this.status = status.getStatusCode();
- }
-
/**
* @param message
*/
@@ -42,15 +35,6 @@ public ServerException(String message, int status)
this.status = status;
}
- /**
- * @param message
- */
- public ServerException(String message, Status status)
- {
- super(message);
-
- this.status = status.getStatusCode();
- }
/**
* @param cause
@@ -62,15 +46,6 @@ public ServerException(Throwable cause, int status)
this.status = status;
}
- /**
- * @param cause
- */
- public ServerException(Throwable cause, Status status)
- {
- super(cause);
-
- this.status = status.getStatusCode();
- }
public ServerException(String message, Throwable cause, int status)
{
@@ -79,13 +54,6 @@ public ServerException(String message, Throwable cause, int status)
this.status = status;
}
- public ServerException(String message, Throwable cause, Status status)
- {
- super(message, cause);
-
- this.status = status.getStatusCode();
- }
-
/**
* @return the status
*/
diff --git a/proteus-core/src/main/java/io/sinistral/proteus/server/handlers/HandlerGenerator.java b/proteus-core/src/main/java/io/sinistral/proteus/server/handlers/HandlerGenerator.java
index 793958c..c32c0e7 100644
--- a/proteus-core/src/main/java/io/sinistral/proteus/server/handlers/HandlerGenerator.java
+++ b/proteus-core/src/main/java/io/sinistral/proteus/server/handlers/HandlerGenerator.java
@@ -53,8 +53,6 @@
import java.lang.reflect.Type;
import java.net.URI;
import java.net.URL;
-import java.nio.file.Files;
-import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
diff --git a/proteus-core/src/main/java/io/sinistral/proteus/server/handlers/ServerFallbackHandler.java b/proteus-core/src/main/java/io/sinistral/proteus/server/handlers/ServerFallbackHandler.java
index 3e3ca64..af396e8 100644
--- a/proteus-core/src/main/java/io/sinistral/proteus/server/handlers/ServerFallbackHandler.java
+++ b/proteus-core/src/main/java/io/sinistral/proteus/server/handlers/ServerFallbackHandler.java
@@ -6,6 +6,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.google.inject.Inject;
+import io.sinistral.proteus.protocol.MediaType;
import io.sinistral.proteus.server.predicates.ServerPredicates;
import io.undertow.server.HttpHandler;
import io.undertow.server.HttpServerExchange;
@@ -35,19 +36,19 @@ public void handleRequest(HttpServerExchange exchange) throws Exception
if (ServerPredicates.ACCEPT_JSON_PREDICATE.resolve(exchange)) {
responseBody = objectMapper.writeValueAsString(new Message(statusCode, reason));
- exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, jakarta.ws.rs.core.MediaType.APPLICATION_JSON);
+ exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, MediaType.APPLICATION_JSON.contentType());
} else if (ServerPredicates.ACCEPT_XML_PREDICATE.resolve(exchange)) {
responseBody = xmlMapper.writeValueAsString(new Message(statusCode, reason));
- exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, jakarta.ws.rs.core.MediaType.APPLICATION_XML);
+ exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, MediaType.APPLICATION_XML.contentType());
} else if (ServerPredicates.ACCEPT_HTML_PREDICATE.resolve(exchange)) {
responseBody = "Error" + statusCode + " - " + reason + "";
- exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, jakarta.ws.rs.core.MediaType.TEXT_HTML);
+ exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, MediaType.HTML_UTF_8.contentType());
} else {
responseBody = statusCode + " - " + reason;
- exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, jakarta.ws.rs.core.MediaType.TEXT_PLAIN);
+ exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, MediaType.PLAIN_TEXT_UTF_8.contentType());
}
exchange.getResponseHeaders().put(Headers.CONTENT_LENGTH, "" + responseBody.length());
diff --git a/proteus-core/src/main/java/io/sinistral/proteus/server/handlers/TypeHandler.java b/proteus-core/src/main/java/io/sinistral/proteus/server/handlers/TypeHandler.java
index e254b8d..9b31c55 100644
--- a/proteus-core/src/main/java/io/sinistral/proteus/server/handlers/TypeHandler.java
+++ b/proteus-core/src/main/java/io/sinistral/proteus/server/handlers/TypeHandler.java
@@ -276,11 +276,11 @@ else if (handler.parameterTypes[i] instanceof Class)
long minValue = min.value();
builder.beginControlFlow("if( $L < $L )", pName, minValue);
- builder.addStatement("throw new io.sinistral.proteus.server.exceptions.ServerException($S,jakarta.ws.rs.core.Response.Status.BAD_REQUEST)", min.message()
+ builder.addStatement("throw new io.sinistral.proteus.server.exceptions.ServerException($S,io.undertow.util.StatusCodes.BAD_REQUEST)", min.message()
.equals("{jakarta.validation.constraints.Min.message}") ? "must be greater than or equal to " + minValue : min.message());
builder.endControlFlow();
builder.beginControlFlow("else if( $L > $L )", pName, maxValue);
- builder.addStatement("throw new io.sinistral.proteus.server.exceptions.ServerException($S,jakarta.ws.rs.core.Response.Status.BAD_REQUEST)", max.message()
+ builder.addStatement("throw new io.sinistral.proteus.server.exceptions.ServerException($S,io.undertow.util.StatusCodes.BAD_REQUEST)", max.message()
.equals("{jakarta.validation.constraints.Max.message}") ? "must be less than or equal to " + maxValue : max.message());
builder.endControlFlow();
@@ -290,7 +290,7 @@ else if (max != null)
long maxValue = max.value();
builder.beginControlFlow("if( $L > $L )", pName, maxValue);
- builder.addStatement("throw new io.sinistral.proteus.server.exceptions.ServerException($S,jakarta.ws.rs.core.Response.Status.BAD_REQUEST)", max.message()
+ builder.addStatement("throw new io.sinistral.proteus.server.exceptions.ServerException($S,io.undertow.util.StatusCodes.BAD_REQUEST)", max.message()
.equals("{jakarta.validation.constraints.Max.message}") ? "must be less than or equal to " + maxValue : max.message());
builder.endControlFlow();
}
@@ -299,7 +299,7 @@ else if (max != null)
long minValue = min.value();
builder.beginControlFlow("if( $L < $L )", pName, minValue);
- builder.addStatement("throw new io.sinistral.proteus.server.exceptions.ServerException($S,jakarta.ws.rs.core.Response.Status.BAD_REQUEST)", min.message()
+ builder.addStatement("throw new io.sinistral.proteus.server.exceptions.ServerException($S,io.undertow.util.StatusCodes.BAD_REQUEST)", min.message()
.equals("{jakarta.validation.constraints.Min.message}") ? "must be greater than or equal to " + minValue : min.message());
builder.endControlFlow();
}
diff --git a/proteus-core/src/test/java/io/sinistral/proteus/test/controllers/Tests.java b/proteus-core/src/test/java/io/sinistral/proteus/test/controllers/Tests.java
index 5cb61d8..ba65631 100644
--- a/proteus-core/src/test/java/io/sinistral/proteus/test/controllers/Tests.java
+++ b/proteus-core/src/test/java/io/sinistral/proteus/test/controllers/Tests.java
@@ -3,47 +3,12 @@
*/
package io.sinistral.proteus.test.controllers;
-import static io.sinistral.proteus.server.ServerResponse.response;
-import static io.sinistral.proteus.test.wrappers.TestWrapper.DEBUG_TEST_KEY;
-
-import java.io.File;
-import java.math.BigDecimal;
-import java.nio.ByteBuffer;
-import java.nio.file.Paths;
-import java.sql.Timestamp;
-import java.time.Instant;
-import java.time.OffsetDateTime;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
-import java.util.UUID;
-import java.util.concurrent.CompletableFuture;
-
-import jakarta.validation.constraints.Max;
-import jakarta.validation.constraints.Min;
-
-import com.google.common.io.Files;
-import jakarta.ws.rs.BeanParam;
-import jakarta.ws.rs.Consumes;
-import jakarta.ws.rs.FormParam;
-import jakarta.ws.rs.GET;
-import jakarta.ws.rs.HeaderParam;
-import jakarta.ws.rs.POST;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.PathParam;
-import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.QueryParam;
-import jakarta.ws.rs.core.MediaType;
-import jakarta.ws.rs.core.Response;
-
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableMap;
+import com.google.common.io.Files;
import com.google.inject.Inject;
import com.google.inject.Singleton;
-
import io.sinistral.proteus.annotations.Blocking;
import io.sinistral.proteus.annotations.Chain;
import io.sinistral.proteus.annotations.Debug;
@@ -51,14 +16,30 @@
import io.sinistral.proteus.server.ServerResponse;
import io.sinistral.proteus.server.exceptions.ServerException;
import io.sinistral.proteus.test.models.User;
-
import io.sinistral.proteus.test.wrappers.TestClassWrapper;
import io.sinistral.proteus.test.wrappers.TestWrapper;
import io.undertow.server.HttpServerExchange;
import io.undertow.server.handlers.form.FormData;
+import io.undertow.util.StatusCodes;
+import jakarta.validation.constraints.Max;
+import jakarta.validation.constraints.Min;
+import jakarta.ws.rs.*;
+import jakarta.ws.rs.core.MediaType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.File;
+import java.math.BigDecimal;
+import java.nio.ByteBuffer;
+import java.sql.Timestamp;
+import java.time.Instant;
+import java.time.OffsetDateTime;
+import java.util.*;
+import java.util.concurrent.CompletableFuture;
+
+import static io.sinistral.proteus.server.ServerResponse.response;
+import static io.sinistral.proteus.test.wrappers.TestWrapper.DEBUG_TEST_KEY;
+
/**
* @author jbauer
*
@@ -67,8 +48,8 @@
@SuppressWarnings("ALL")
@Path("/tests")
-@Produces((MediaType.APPLICATION_JSON))
-@Consumes((MediaType.MEDIA_TYPE_WILDCARD))
+@Produces((MediaType.APPLICATION_JSON))
+@Consumes((MediaType.MEDIA_TYPE_WILDCARD))
@Singleton
@Chain({TestClassWrapper.class})
public class Tests
@@ -555,7 +536,7 @@ public ServerResponse