From 37b46cd541bfb59eebff868125a7631fd9f2ae69 Mon Sep 17 00:00:00 2001 From: Joshua Bauer Date: Thu, 20 Jul 2023 18:15:43 -0700 Subject: [PATCH] Added additional MediaType to support Wavefront and Pixar. --- CHANGELOG.md | 5 + pom.xml | 1110 +++++++++-------- proteus-core/CHANGELOG.md | 75 ++ proteus-core/pom.xml | 686 +++++----- .../sinistral/proteus/ProteusApplication.java | 306 ++--- .../sinistral/proteus/protocol/MediaType.java | 118 +- .../test/server/StandardEndpointsTest.java | 4 +- proteus-openapi/pom.xml | 20 +- 8 files changed, 1187 insertions(+), 1137 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8c2699..58c8816 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ Proteus Changelog. ## Unreleased ### No issue +**Update unauthorized access error message.** + + +[cf2017a27c0c148](https://github.com/noboomu/proteus/commit/cf2017a27c0c148) Joshua Bauer *2023-03-03 22:34:40* + **Silence cached compiler logs and upgrade to blackbird** diff --git a/pom.xml b/pom.xml index 02f80bc..5e801ca 100644 --- a/pom.xml +++ b/pom.xml @@ -1,536 +1,580 @@ - - 4.0.0 - - io.sinistral - proteus-project - pom - 0.5.2-SNAPSHOT - Proteus Project - - Proteus is an extremely light, fast, and flexible Java REST API framework built atop Undertow. - http://github.com/noboomu/proteus - - - proteus-core - proteus-openapi - - - - - MIT License - http://www.opensource.org/licenses/mit-license.php - - - - - - Joshua Lee Bauer - bauer@sinistral.io - - - - - scm:git:git://github.com/noboomu/proteus.git - scm:git:ssh://github.com/noboomu/proteus.git - http://github.com/noboomu/proteus/tree/master - HEAD - - - - - 1.60 - 2.11.0 - 3.12.0 - 1.9 - 31.1-jre - 5.1.0 - 4.4.15 - 2.13.3 - 2.1.6 - 1.18 - 12 - 1.13.0 - 1.2.11 - 3.8.1 - 3.0.0-M1 - 1.6 - 3.2.0 - 3.2.0 - 2.5.3 - 3.2.1 - 3.2.1 - 3.0.0-M3 - 3.0.0-M4 - 1.6.8 - 2.2.1 - 2.23ea0 - UTF-8 - ${project.version} - 0.10.2 - 1.7.36 - 1.30 - 1.5.21 - 1.4.2 - 2.2.18.Final - 6.3.0 - 1.9.1 - - - - - - org.junit.jupiter - junit-jupiter-api - 5.8.2 - test - - - - org.junit.vintage - junit-vintage-engine - 5.8.2 - test - - - - io.rest-assured - rest-assured - 3.2.0 - test - - - - io.micrometer - micrometer-core - ${micrometer-core.version} - - - - - - - - - com.fasterxml.jackson - jackson-bom - ${jackson.version} - import - pom - - - - io.sinistral - proteus-core - ${project.version} - - - - io.sinistral - proteus-openapi - ${project.version} - - - - io.sinistral - proteus-swagger - ${project.version} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - sonatype-snapshots - https://oss.sonatype.org/content/repositories/snapshots - - true - - - false - - - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - ${java.version} - -parameters - UTF-8 - - - - - maven-jar-plugin - ${maven-jar-plugin.version} - - - - true - true - - - - - - - org.apache.maven.plugins - maven-enforcer-plugin - ${maven-enforcer-plugin.version} - - - enforce-versions - - enforce - - - - - ${java.version} - - - - - - - - - maven-surefire-plugin - ${maven-surefire-plugin.version} - - - org.apache.maven.surefire - surefire-junit47 - ${maven-surefire-plugin.version} - - - - -Dconfig.file=src/test/resources/application.conf - -Dlogback.configuration=src/test/resources/logback-test.xml - - - - - org.apache.maven.plugins - maven-javadoc-plugin - - 8 - false - - ${maven-javadoc-plugin.version} - - - attach-javadocs - - jar - - - none - - - - - - - - org.apache.maven.plugins - maven-gpg-plugin - ${maven-gpg-plugin.version} - - - sign-artifacts - verify - - sign - - - - - gpg - - - - org.sonatype.plugins - nexus-staging-maven-plugin - ${nexus-staging-maven-plugin.version} - true - - ossrh - https://oss.sonatype.org/ - false - - - - - org.apache.maven.plugins - maven-release-plugin - ${maven-release-plugin.version} - - true - v@{project.version} - central - deploy - - - - - - - - - - - org.apache.maven.plugins - maven-source-plugin - ${maven-source-plugin.version} - - - attach-sources - - jar-no-fork - - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - - 8 - - ${maven-javadoc-plugin.version} - - - attach-javadocs - - jar - - - none - - - - - - - - org.apache.maven.plugins - maven-gpg-plugin - ${maven-gpg-plugin.version} - - - sign-artifacts - verify - - sign - - - - - gpg - - - - org.sonatype.plugins - nexus-staging-maven-plugin - ${nexus-staging-plugin.version} - true - - ossrh - https://oss.sonatype.org/ - false - - - - org.apache.maven.plugins - maven-release-plugin - ${maven-release-plugin.version} - - false - v@{project.version} - ossrh - deploy - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - ${java.version} - ${java.version} - -parameters - - - - - org.apache.maven.plugins - maven-enforcer-plugin - - - enforce-versions - - enforce - - - - - ${java.version} - - - - - - - - maven-surefire-plugin - ${maven-surefire-plugin.version} - - - org.apache.maven.surefire - surefire-junit47 - ${maven-surefire-plugin.version} - - - - -Dconfig.file=src/test/resources/application.conf - -Dlogback.configuration=src/test/resources/logback-test.xml - - - - - - - - - - - - - - - pom.xml - - - central - - - - - org.apache.maven.plugins - maven-source-plugin - ${maven-source-plugin.version} - - - attach-sources - - jar-no-fork - - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - ${maven-javadoc-plugin.version} - - 8 - - - - attach-javadocs - - jar - - - none - - - - - - - org.apache.maven.plugins - maven-gpg-plugin - ${maven-gpg-plugin.version} - - - sign-artifacts - verify - - sign - - - gpg - - - - - - - org.sonatype.plugins - nexus-staging-maven-plugin - ${nexus-staging-maven-plugin.version} - true - - ossrh - https://oss.sonatype.org/ - false - - - - - - - - - - - ossrh - Sonatype Nexus Snapshots - https://oss.sonatype.org/content/repositories/snapshots - - - ossrh - Nexus Release Repository - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - - https://oss.sonatype.org/content/groups/public/io/sinistral/proteus-project - - + + 4.0.0 + + io.sinistral + proteus-project + pom + 0.6.0-SNAPSHOT + Proteus Project + + Proteus is an extremely light, fast, and flexible Java REST API framework built atop Undertow. + + http://github.com/noboomu/proteus + + + proteus-core + proteus-openapi + + + + + MIT License + http://www.opensource.org/licenses/mit-license.php + + + + + + Joshua Lee Bauer + bauer@sinistral.io + + + + + scm:git:git://github.com/noboomu/proteus.git + scm:git:ssh://github.com/noboomu/proteus.git + http://github.com/noboomu/proteus/tree/master + HEAD + + + + + 1.60 + 2.11.0 + 3.12.0 + 1.9 + 31.1-jre + 5.1.0 + 4.4.15 + 2.13.3 + 2.1.6 + 1.18 + 12 + 1.13.0 + 1.2.11 + 3.8.1 + 3.0.0-M1 + 1.6 + 3.2.0 + 3.2.0 + 2.5.3 + 3.2.1 + 3.2.1 + 3.0.0-M3 + 3.0.0-M4 + 1.6.8 + 2.2.1 + 2.23ea0 + UTF-8 + ${project.version} + 0.10.2 + 1.7.36 + 1.30 + 1.5.21 + 1.4.2 + 2.2.18.Final + 6.3.0 + 1.9.1 + + + + + + org.jetbrains + annotations + 24.0.1 + + + + org.junit.jupiter + junit-jupiter-api + 5.8.2 + test + + + + org.junit.vintage + junit-vintage-engine + 5.8.2 + test + + + + io.rest-assured + rest-assured + 5.3.0 + test + + + + io.micrometer + micrometer-core + ${micrometer-core.version} + + + + + + + + + + com.sun.xml.ws + jaxws-ri + 4.0.1 + pom + + + + + + + + com.fasterxml.jackson + jackson-bom + ${jackson.version} + import + pom + + + + io.sinistral + proteus-core + ${project.version} + + + + io.sinistral + proteus-openapi + ${project.version} + + + + io.sinistral + proteus-swagger + ${project.version} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + sonatype-snapshots + https://oss.sonatype.org/content/repositories/snapshots + + true + + + false + + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + ${java.version} + 17 + -parameters + + --add-opens=java.base/java.lang=ALL-UNNAMED --illegal-access=deny + + UTF-8 + + + + + maven-jar-plugin + ${maven-jar-plugin.version} + + + + true + true + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${maven-enforcer-plugin.version} + + + enforce-versions + + enforce + + + + + ${java.version} + + + + + + + + + maven-surefire-plugin + ${maven-surefire-plugin.version} + + + org.apache.maven.surefire + surefire-junit47 + ${maven-surefire-plugin.version} + + + + -Dconfig.file=src/test/resources/application.conf + -Dlogback.configuration=src/test/resources/logback-test.xml + --add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED + --add-exports=java.base/jdk.internal.ref=ALL-UNNAMED + --add-exports=java.base/sun.nio.ch=ALL-UNNAMED + --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED + --add-opens=jdk.compiler/com.sun.tools.javac=ALL-UNNAMED + --add-opens=java.base/java.lang=ALL-UNNAMED + --add-opens=java.base/java.lang.reflect=ALL-UNNAMED + --add-opens=java.base/java.io=ALL-UNNAMED + --add-opens=java.base/java.util=ALL-UNNAMED + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + 8 + false + + ${maven-javadoc-plugin.version} + + + attach-javadocs + + jar + + + none + + + + + + + + org.apache.maven.plugins + maven-gpg-plugin + ${maven-gpg-plugin.version} + + + sign-artifacts + verify + + sign + + + + + gpg + + + + org.sonatype.plugins + nexus-staging-maven-plugin + ${nexus-staging-maven-plugin.version} + true + + ossrh + https://oss.sonatype.org/ + false + + + + + org.apache.maven.plugins + maven-release-plugin + ${maven-release-plugin.version} + + true + v@{project.version} + central + deploy + + + + + + + + + + + org.apache.maven.plugins + maven-source-plugin + ${maven-source-plugin.version} + + + attach-sources + + jar-no-fork + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + 8 + + ${maven-javadoc-plugin.version} + + + attach-javadocs + + jar + + + none + + + + + + + + org.apache.maven.plugins + maven-gpg-plugin + ${maven-gpg-plugin.version} + + + sign-artifacts + verify + + sign + + + + + gpg + + + + org.sonatype.plugins + nexus-staging-maven-plugin + ${nexus-staging-plugin.version} + true + + ossrh + https://oss.sonatype.org/ + false + + + + org.apache.maven.plugins + maven-release-plugin + ${maven-release-plugin.version} + + false + v@{project.version} + ossrh + deploy + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + ${java.version} + ${java.version} + -parameters + + + + + org.apache.maven.plugins + maven-enforcer-plugin + + + enforce-versions + + enforce + + + + + ${java.version} + + + + + + + + maven-surefire-plugin + ${maven-surefire-plugin.version} + + + org.apache.maven.surefire + surefire-junit47 + ${maven-surefire-plugin.version} + + + + -Dconfig.file=src/test/resources/application.conf + -Dlogback.configuration=src/test/resources/logback-test.xml + --add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED + --add-exports=java.base/jdk.internal.ref=ALL-UNNAMED + --add-exports=java.base/sun.nio.ch=ALL-UNNAMED + --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED + --add-opens=jdk.compiler/com.sun.tools.javac=ALL-UNNAMED + --add-opens=java.base/java.lang=ALL-UNNAMED + --add-opens=java.base/java.lang.reflect=ALL-UNNAMED + --add-opens=java.base/java.io=ALL-UNNAMED + --add-opens=java.base/java.util=ALL-UNNAMED + + + + + + + + + + + + + + + pom.xml + + + central + + + + + org.apache.maven.plugins + maven-source-plugin + ${maven-source-plugin.version} + + + attach-sources + + jar-no-fork + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${maven-javadoc-plugin.version} + + 8 + + + + attach-javadocs + + jar + + + none + + + + + + + org.apache.maven.plugins + maven-gpg-plugin + ${maven-gpg-plugin.version} + + + sign-artifacts + verify + + sign + + + gpg + + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + ${nexus-staging-maven-plugin.version} + true + + ossrh + https://oss.sonatype.org/ + false + + + + + + + + + + + ossrh + Sonatype Nexus Snapshots + https://oss.sonatype.org/content/repositories/snapshots + + + ossrh + Nexus Release Repository + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + https://oss.sonatype.org/content/groups/public/io/sinistral/proteus-project + + \ No newline at end of file diff --git a/proteus-core/CHANGELOG.md b/proteus-core/CHANGELOG.md index 98c0ae6..58c8816 100644 --- a/proteus-core/CHANGELOG.md +++ b/proteus-core/CHANGELOG.md @@ -4,6 +4,81 @@ Proteus Changelog. ## Unreleased ### No issue +**Update unauthorized access error message.** + + +[cf2017a27c0c148](https://github.com/noboomu/proteus/commit/cf2017a27c0c148) Joshua Bauer *2023-03-03 22:34:40* + +**Silence cached compiler logs and upgrade to blackbird** + + +[e9bb94e12f4589d](https://github.com/noboomu/proteus/commit/e9bb94e12f4589d) Joshua Bauer *2023-02-08 19:42:32* + +**Improve compatability** + + +[cb61cb367557f63](https://github.com/noboomu/proteus/commit/cb61cb367557f63) Joshua Bauer *2022-08-13 01:59:47* + +**Safer threaded compilation and caching of generated classes** + + +[d5eb3e745471280](https://github.com/noboomu/proteus/commit/d5eb3e745471280) Joshua Bauer *2022-08-13 01:58:36* + +**Reduce logging.** + + +[f6a8f1986b6d0da](https://github.com/noboomu/proteus/commit/f6a8f1986b6d0da) Joshua Bauer *2022-07-19 20:15:26* + +**Tweak parameters.** + + +[ee303d97a9b0d7b](https://github.com/noboomu/proteus/commit/ee303d97a9b0d7b) Joshua Bauer *2022-07-19 02:03:30* + +**Add graceful shutdown option.** + + +[cc429604e4feaa6](https://github.com/noboomu/proteus/commit/cc429604e4feaa6) Joshua Bauer *2022-07-18 20:30:03* + +**Bump version** + + +[2a75891265dacc6](https://github.com/noboomu/proteus/commit/2a75891265dacc6) noboomu *2022-07-07 01:07:12* + +**Fix for typo** + + +[4403a37f03eb1b1](https://github.com/noboomu/proteus/commit/4403a37f03eb1b1) noboomu *2022-07-07 01:05:50* + +**Parsers passing all tests.** + + +[254a69e83e1d8ea](https://github.com/noboomu/proteus/commit/254a69e83e1d8ea) noboomu *2022-07-07 01:03:24* + +**Functioning parser.** + + +[a250d32af788caf](https://github.com/noboomu/proteus/commit/a250d32af788caf) noboomu *2022-07-06 22:51:58* + +**Updated dependencies and new tests.** + + +[054892c369e65d0](https://github.com/noboomu/proteus/commit/054892c369e65d0) Joshua Bauer *2022-07-06 02:19:08* + +**Updated dependencies and new tests.** + + +[70af2b6c38728c1](https://github.com/noboomu/proteus/commit/70af2b6c38728c1) Joshua Bauer *2022-07-06 02:16:29* + +**Fix tmp file handling.** + + +[8ff44d154739bf3](https://github.com/noboomu/proteus/commit/8ff44d154739bf3) Joshua Bauer *2022-05-23 17:53:30* + +**Better generic support.** + + +[f4f363ccb6e99eb](https://github.com/noboomu/proteus/commit/f4f363ccb6e99eb) Joshua Bauer *2022-04-22 00:00:28* + **Added support for last-modified using java.time.Instant.** diff --git a/proteus-core/pom.xml b/proteus-core/pom.xml index 64e6fcf..a83495c 100644 --- a/proteus-core/pom.xml +++ b/proteus-core/pom.xml @@ -1,53 +1,54 @@ - - - proteus-project - io.sinistral - 0.5.2-SNAPSHOT - - - 4.0.0 - proteus-core - Proteus Core - - - jar - - - - - src/main/resources - false - - - - - src/test/resources - - - src/test/java - - **/*.java - - - - - - - - se.bjurr.gitchangelog - git-changelog-maven-plugin - ${changelog.version} - - - GenerateGitChangelog - generate-sources - - git-changelog - - - - + + proteus-project + io.sinistral + 0.6.0-SNAPSHOT + + + 4.0.0 + proteus-core + Proteus Core + + jar + + + + + src/main/resources + false + + + + + src/test/resources + + + src/test/java + + **/*.java + + + + + + + + se.bjurr.gitchangelog + git-changelog-maven-plugin + ${changelog.version} + + + GenerateGitChangelog + generate-sources + + git-changelog + + + + - - - - - - - - org.apache.maven.plugins - maven-jar-plugin - 3.1.0 - - - - test-jar - - - - **/*.class - - - - - - - org.apache.maven.plugins - maven-source-plugin - - - org.apache.maven.plugins - maven-javadoc-plugin - - - maven-surefire-plugin - org.apache.maven.plugins - - - - org.apache.maven.plugins - maven-gpg-plugin - - - org.sonatype.plugins - nexus-staging-maven-plugin - - - org.apache.maven.plugins - maven-release-plugin - - - - org.apache.maven.plugins - maven-compiler-plugin - - - - - - - io.undertow - undertow-core - ${undertow.version} - - - - ch.qos.logback - logback-classic - ${logback-classic.version} - - - org.slf4j - slf4j-api - - - - - - org.apache.commons - commons-text - ${commons-text.version} - - - - - org.slf4j - slf4j-api - ${slf4j.version} - - - org.slf4j - slf4j-ext - ${slf4j.version} - - - - jakarta.ws.rs - jakarta.ws.rs-api - ${jakarta-ws-rs.version} - - - - net.openhft - compiler - ${openhft-compiler.version} - - - org.slf4j - slf4j-api - - - com.sun.java - tools - - - - - - com.squareup - javapoet - ${javapoet.version} - - - - - com.google.guava - guava - ${guava.version} - - - - - com.google.inject - guice - ${guice.version} - - - com.google.guava - guava - - - - - - com.typesafe - config - ${typesafe-config.version} - - - - javax.validation - validation-api - 2.0.1.Final - - - - org.yaml - snakeyaml - ${snakeyaml.version} - - - - commons-io - commons-io - ${commons-io.version} - - - - org.apache.httpcomponents - httpcore - ${httpcore.version} - - - - org.fusesource.jansi - jansi - ${jansi.version} - - - - com.fasterxml.woodstox - woodstox-core - ${woodstox.version} - - - - com.fasterxml.jackson.core - jackson-annotations - - - - com.fasterxml.jackson.core - jackson-core - - - - com.fasterxml.jackson.dataformat - jackson-dataformat-xml - - - - com.fasterxml.jackson.dataformat - jackson-dataformat-yaml - - - - com.fasterxml.jackson.module - jackson-module-parameter-names - - - - com.fasterxml.jackson.module - jackson-module-blackbird - - - - com.fasterxml.jackson.datatype - jackson-datatype-jdk8 - - - - com.fasterxml.jackson.datatype - jackson-datatype-jsr310 - - - - com.fasterxml.jackson.core - jackson-databind - - - - - org.apache.commons - commons-lang3 - ${commons-lang3.version} - - - org.reflections - reflections - ${reflections.version} - compile - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - https://oss.sonatype.org/content/groups/public/io/sinistral/proteus-core - + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.1.0 + + + + test-jar + + + + **/*.class + + + + + + + org.apache.maven.plugins + maven-source-plugin + + + org.apache.maven.plugins + maven-javadoc-plugin + + + maven-surefire-plugin + org.apache.maven.plugins + + + + org.apache.maven.plugins + maven-gpg-plugin + + + org.sonatype.plugins + nexus-staging-maven-plugin + + + org.apache.maven.plugins + maven-release-plugin + + + + org.apache.maven.plugins + maven-compiler-plugin + + ${java.version} + ${java.version} + -parameters + + -parameters + --add-opens=java.base/java.lang=ALL-UNNAMED --illegal-access=deny + + UTF-8 + + + + + + + + io.undertow + undertow-core + ${undertow.version} + + + + ch.qos.logback + logback-classic + ${logback-classic.version} + + + org.slf4j + slf4j-api + + + + + + org.apache.commons + commons-text + ${commons-text.version} + + + + org.slf4j + slf4j-api + ${slf4j.version} + + + org.slf4j + slf4j-ext + ${slf4j.version} + + + + jakarta.ws.rs + jakarta.ws.rs-api + ${jakarta-ws-rs.version} + + + + net.openhft + compiler + ${openhft-compiler.version} + + + org.slf4j + slf4j-api + + + com.sun.java + tools + + + + + + com.squareup + javapoet + ${javapoet.version} + + + + com.google.guava + guava + ${guava.version} + + + + com.google.inject + guice + ${guice.version} + + + com.google.guava + guava + + + + + + com.typesafe + config + ${typesafe-config.version} + + + + javax.validation + validation-api + 2.0.1.Final + + + + org.yaml + snakeyaml + ${snakeyaml.version} + + + + commons-io + commons-io + ${commons-io.version} + + + + org.apache.httpcomponents + httpcore + ${httpcore.version} + + + + org.fusesource.jansi + jansi + ${jansi.version} + + + + com.fasterxml.woodstox + woodstox-core + ${woodstox.version} + + + + com.fasterxml.jackson.core + jackson-annotations + + + + com.fasterxml.jackson.core + jackson-core + + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + + + + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + + + + com.fasterxml.jackson.module + jackson-module-parameter-names + + + + com.fasterxml.jackson.module + jackson-module-blackbird + + + + com.fasterxml.jackson.datatype + jackson-datatype-jdk8 + + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + + + + com.fasterxml.jackson.core + jackson-databind + + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + org.reflections + reflections + ${reflections.version} + compile + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + https://oss.sonatype.org/content/groups/public/io/sinistral/proteus-core + \ No newline at end of file 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 88b7336..3349d7a 100644 --- a/proteus-core/src/main/java/io/sinistral/proteus/ProteusApplication.java +++ b/proteus-core/src/main/java/io/sinistral/proteus/ProteusApplication.java @@ -12,6 +12,7 @@ import com.google.inject.Injector; import com.google.inject.Module; import com.google.inject.name.Named; +//import com.javax0.sourcebuddy.Compiler; import com.typesafe.config.Config; import io.sinistral.proteus.modules.ConfigModule; import io.sinistral.proteus.server.endpoints.EndpointInfo; @@ -119,42 +120,36 @@ public class ProteusApplication { final Instant startTime = Instant.now(); - public ProteusApplication() - { + public ProteusApplication() { injector = Guice.createInjector(new ConfigModule()); injector.injectMembers(this); } - public ProteusApplication(String configFile) - { + public ProteusApplication(String configFile) { injector = Guice.createInjector(new ConfigModule(configFile)); injector.injectMembers(this); } - public ProteusApplication(URL configURL) - { + public ProteusApplication(URL configURL) { injector = Guice.createInjector(new ConfigModule(configURL)); injector.injectMembers(this); } - public ProteusApplication(Module... modules) - { + public ProteusApplication(Module... modules) { injector = Guice.createInjector(modules); injector.injectMembers(this); } - public void start() - { + public void start() { - if (this.isRunning()) - { + if (this.isRunning()) { log.warn("Server has already started..."); return; } @@ -167,8 +162,7 @@ public void start() injector = injector.createChildInjector(modules); - if (rootHandlerClass == null && rootHandler == null) - { + if (rootHandlerClass == null && rootHandler == null) { log.debug("No root handler class or root HttpHandler was specified, using default ServerDefaultHttpHandler."); rootHandlerClass = ServerDefaultHttpHandler.class; } @@ -182,27 +176,23 @@ public void start() serviceManager = new ServiceManager(services); serviceManager.addListener(new Listener() { - public void stopped() - { + public void stopped() { log.info("Services are stopped"); } - public void healthy() - { + public void healthy() { log.info("Services are healthy"); startupDuration = Duration.between(startTime, Instant.now()); - for (ListenerInfo info : undertow.getListenerInfo()) - { + for (ListenerInfo info : undertow.getListenerInfo()) { log.debug("listener info: " + info); SocketAddress address = info.getAddress(); - if (address != null) - { + if (address != null) { ports.add(((java.net.InetSocketAddress) address).getPort()); } } @@ -211,20 +201,17 @@ public void healthy() } - public void failure(Service service) - { + public void failure(Service service) { log.error("Service failure: " + service); startupDuration = Duration.between(startTime, Instant.now()); - for (ListenerInfo info : undertow.getListenerInfo()) - { + for (ListenerInfo info : undertow.getListenerInfo()) { log.debug("listener info: " + info); SocketAddress address = info.getAddress(); - if (address != null) - { + if (address != null) { ports.add(((java.net.InetSocketAddress) address).getPort()); } } @@ -238,21 +225,17 @@ public void failure(Service service) Runtime.getRuntime().addShutdownHook(new Thread(() -> { - if (!this.isRunning()) - { + if (!this.isRunning()) { log.warn("Server is not running..."); return; } - try - { + try { shutdown(); mainThread.join(); - } catch (InterruptedException ex) - { + } catch (InterruptedException ex) { log.error("Shutdown was interrupted", ex); - } catch (TimeoutException timeout) - { + } catch (TimeoutException timeout) { log.error("Shutdown timed out", timeout); } })); @@ -263,14 +246,11 @@ public void failure(Service service) Duration timeout = config.getDuration("application.services.timeout"); - try - { + try { serviceManager.startAsync().awaitHealthy(timeout); - } catch (TimeoutException e) - { + } catch (TimeoutException e) { log.error("Failed start to services within {} minutes", timeout, e); - } catch (Exception e) - { + } catch (Exception e) { log.error("Failed to start services", e); } @@ -280,11 +260,9 @@ public void failure(Service service) } - public void shutdown() throws TimeoutException - { + public void shutdown() throws TimeoutException { - if (!this.isRunning()) - { + if (!this.isRunning()) { log.warn("Server is not running..."); return; } @@ -300,14 +278,12 @@ public void shutdown() throws TimeoutException log.info("Shutdown complete"); } - public boolean isRunning() - { + public boolean isRunning() { return this.running.get(); } - public void buildServer() - { + public void buildServer() { final Instant compilationStartTime = Instant.now(); @@ -321,42 +297,50 @@ public void buildServer() log.info("Compiling route handlers..."); - for (Class controllerClass : registeredControllers) - { + for (Class controllerClass : registeredControllers) { handlerCompilationExecutor.submit(() -> { - try - { - - // log.debug("Generating {}...", controllerClass); + try { - final File tempFile = getTemporaryDirectoryPath().toFile(); + log.debug("Generating {}...", controllerClass); HandlerGenerator generator = new HandlerGenerator("io.sinistral.proteus.controllers.handlers", controllerClass); + log.debug("injecting {}...", controllerClass); + injector.injectMembers(generator); - // log.debug("Compiling {}...", controllerClass); + log.debug("Compiling {}...", controllerClass); - try (CachedCompiler cachedCompiler = new CachedCompiler(null, tempFile)) - { - final String source = generator.generateClassSource(); + log.debug("Generating {}...", controllerClass); + + final String source = generator.generateClassSource(); + + log.debug("Generated {}...", controllerClass); + + + lock.writeLock().lock(); + + try (CachedCompiler cachedCompiler = new CachedCompiler(null, getTemporaryDirectoryPath().toFile())) { - Class> routerClass = cachedCompiler.loadFromJava(generator.getCanonicalName(), source); + Class> routerClass = (Class>) cachedCompiler.loadFromJava(generator.getCanonicalName(), source); - lock.writeLock().lock(); + log.debug("Loaded from java {}...", controllerClass); routerClasses.add(routerClass); - lock.writeLock().unlock(); + + } catch (Exception e) + { + log.error("Failed to compile {}", controllerClass, e); } + lock.writeLock().unlock(); - } catch (Exception e) - { - log.error("Exception creating handlers for {}", controllerClass.getName(), e); + } catch (Exception e) { + log.error("Failed to compile", e); } countDownLatch.countDown(); @@ -364,18 +348,15 @@ public void buildServer() } - try - { + try { countDownLatch.await(); - } catch (Exception e) - { + } 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())); - for (Class> clazz : routerClasses) - { + for (Class> clazz : routerClasses) { Supplier generatedRouteSupplier = injector.getInstance(clazz); router.addAll(generatedRouteSupplier.get()); } @@ -386,42 +367,34 @@ public void buildServer() HttpHandler handler; - if (rootHandlerClass != null) - { + if (rootHandlerClass != null) { handler = injector.getInstance(rootHandlerClass); - } - else - { + } else { handler = rootHandler; } SessionAttachmentHandler sessionAttachmentHandler = null; - try - { + try { sessionAttachmentHandler = injector.getInstance(SessionAttachmentHandler.class); - } catch (Exception e) - { + } catch (Exception e) { log.debug("No session attachment handler found."); } - if (sessionAttachmentHandler != null) - { + if (sessionAttachmentHandler != null) { log.info("Using session attachment handler."); sessionAttachmentHandler.setNext(handler); handler = sessionAttachmentHandler; } - if (config.hasPath("undertow.gracefulShutdown") && config.getBoolean("undertow.gracefulShutdown")) - { + if (config.hasPath("undertow.gracefulShutdown") && config.getBoolean("undertow.gracefulShutdown")) { handler = new GracefulShutdownHandler(handler); } int httpPort = config.getInt("application.ports.http"); - if (System.getProperty("http.port") != null) - { + if (System.getProperty("http.port") != null) { httpPort = Integer.parseInt(System.getProperty("http.port")); } @@ -429,30 +402,27 @@ public void buildServer() Undertow.Builder undertowBuilder = Undertow.builder().addHttpListener(httpPort, config.getString("application.host")) - .setBufferSize(Long.valueOf(config.getMemorySize("undertow.bufferSize").toBytes()).intValue()) - .setIoThreads(processorCount * config.getInt("undertow.ioThreadsMultiplier")) - .setWorkerThreads(processorCount * config.getInt("undertow.workerThreadsMultiplier")) - .setDirectBuffers(config.getBoolean("undertow.directBuffers")) - .setSocketOption(org.xnio.Options.BACKLOG, config.getInt("undertow.socket.backlog")) - .setSocketOption(org.xnio.Options.REUSE_ADDRESSES, config.getBoolean("undertow.socket.reuseAddresses")) - .setSocketOption(org.xnio.Options.READ_TIMEOUT, config.getInt("undertow.socket.readTimeout")) - .setSocketOption(org.xnio.Options.WRITE_TIMEOUT, config.getInt("undertow.socket.writeTimeout")) - .setServerOption(UndertowOptions.ENABLE_HTTP2, config.getBoolean("undertow.server.enableHttp2")) - .setServerOption(UndertowOptions.ALWAYS_SET_DATE, config.getBoolean("undertow.server.alwaysSetDate")) - .setServerOption(UndertowOptions.ALWAYS_SET_KEEP_ALIVE, config.getBoolean("undertow.server.alwaysSetKeepAlive")) - .setServerOption(UndertowOptions.RECORD_REQUEST_START_TIME, config.getBoolean("undertow.server.recordRequestStartTime")) - .setServerOption(UndertowOptions.MAX_ENTITY_SIZE, config.getBytes("undertow.server.maxEntitySize")) - .setServerOption(UndertowOptions.MAX_BUFFERED_REQUEST_SIZE, config.getInt("undertow.server.maxBufferedRequestSize")) - .setHandler(handler); - - if (config.getBoolean("undertow.ssl.enabled")) - { - try - { + .setBufferSize(Long.valueOf(config.getMemorySize("undertow.bufferSize").toBytes()).intValue()) + .setIoThreads(processorCount * config.getInt("undertow.ioThreadsMultiplier")) + .setWorkerThreads(processorCount * config.getInt("undertow.workerThreadsMultiplier")) + .setDirectBuffers(config.getBoolean("undertow.directBuffers")) + .setSocketOption(org.xnio.Options.BACKLOG, config.getInt("undertow.socket.backlog")) + .setSocketOption(org.xnio.Options.REUSE_ADDRESSES, config.getBoolean("undertow.socket.reuseAddresses")) + .setSocketOption(org.xnio.Options.READ_TIMEOUT, config.getInt("undertow.socket.readTimeout")) + .setSocketOption(org.xnio.Options.WRITE_TIMEOUT, config.getInt("undertow.socket.writeTimeout")) + .setServerOption(UndertowOptions.ENABLE_HTTP2, config.getBoolean("undertow.server.enableHttp2")) + .setServerOption(UndertowOptions.ALWAYS_SET_DATE, config.getBoolean("undertow.server.alwaysSetDate")) + .setServerOption(UndertowOptions.ALWAYS_SET_KEEP_ALIVE, config.getBoolean("undertow.server.alwaysSetKeepAlive")) + .setServerOption(UndertowOptions.RECORD_REQUEST_START_TIME, config.getBoolean("undertow.server.recordRequestStartTime")) + .setServerOption(UndertowOptions.MAX_ENTITY_SIZE, config.getBytes("undertow.server.maxEntitySize")) + .setServerOption(UndertowOptions.MAX_BUFFERED_REQUEST_SIZE, config.getInt("undertow.server.maxBufferedRequestSize")) + .setHandler(handler); + + if (config.getBoolean("undertow.ssl.enabled")) { + try { int httpsPort = config.getInt("application.ports.https"); - if (System.getProperty("https.port") != null) - { + if (System.getProperty("https.port") != null) { httpsPort = Integer.parseInt(System.getProperty("https.port")); } @@ -461,14 +431,12 @@ public void buildServer() undertowBuilder.addHttpsListener(httpsPort, config.getString("application.host"), SecurityUtilities.createSSLContext(keyStore, trustStore, config.getString("undertow.ssl.keystorePassword"))); - } catch (Exception e) - { + } catch (Exception e) { log.error(e.getMessage(), e); } } - if (serverConfigurationFunction != null) - { + if (serverConfigurationFunction != null) { undertowBuilder = serverConfigurationFunction.apply(undertowBuilder); } @@ -482,8 +450,7 @@ public void buildServer() * @param serviceClass * @return the application */ - public ProteusApplication addService(Class serviceClass) - { + public ProteusApplication addService(Class serviceClass) { registeredServices.add(serviceClass); return this; @@ -495,8 +462,7 @@ public ProteusApplication addService(Class serviceClass) * @param controllerClass * @return the application */ - public ProteusApplication addController(Class controllerClass) - { + public ProteusApplication addController(Class controllerClass) { registeredControllers.add(controllerClass); return this; @@ -508,8 +474,7 @@ public ProteusApplication addController(Class controllerClass) * @param moduleClass * @return the application */ - public ProteusApplication addModule(Class moduleClass) - { + public ProteusApplication addModule(Class moduleClass) { registeredModules.add(moduleClass); return this; @@ -520,59 +485,46 @@ public ProteusApplication addModule(Class moduleClass) * * @param router */ - public ProteusApplication addDefaultRoutes(RoutingHandler router) - { + public ProteusApplication addDefaultRoutes(RoutingHandler router) { - if (config.hasPath("health.statusPath")) - { - try - { + if (config.hasPath("health.statusPath")) { + try { final String statusPath = config.getString("health.statusPath"); router.add(Methods.GET, statusPath, (final HttpServerExchange exchange) -> { exchange.getResponseHeaders().add(Headers.CONTENT_TYPE, MediaType.TEXT_PLAIN); - if (this.serviceManager.servicesByState().values().stream().allMatch(Service::isRunning)) - { + if (this.serviceManager.servicesByState().values().stream().allMatch(Service::isRunning)) { exchange.setStatusCode(200).getResponseSender().send("OK"); - } - else - { + } else { exchange.setStatusCode(500).getResponseSender().send("NOT_HEALTHY"); } }); this.registeredEndpoints.add(EndpointInfo.builder().withConsumes("*/*").withProduces("text/plain").withPathTemplate(statusPath).withControllerName("Internal").withMethod(Methods.GET).build()); - } catch (Exception e) - { + } catch (Exception e) { log.error("Error adding health status route.", e); } } - if (config.hasPath("application.favicon")) - { - try - { + if (config.hasPath("application.favicon")) { + try { final ByteBuffer faviconImageBuffer; final File faviconFile = new File(config.getString("application.favicon")); - if (!faviconFile.exists()) - { - try (final InputStream stream = this.getClass().getResourceAsStream(config.getString("application.favicon"))) - { + if (!faviconFile.exists()) { + try (final InputStream stream = this.getClass().getResourceAsStream(config.getString("application.favicon"))) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[4096]; int read = 0; - while (read != -1) - { + while (read != -1) { read = stream.read(buffer); - if (read > 0) - { + if (read > 0) { baos.write(buffer, 0, read); } } @@ -580,20 +532,15 @@ public ProteusApplication addDefaultRoutes(RoutingHandler router) faviconImageBuffer = ByteBuffer.wrap(baos.toByteArray()); } - } - else - { - try (final InputStream stream = Files.newInputStream(Paths.get(config.getString("application.favicon")))) - { + } else { + try (final InputStream stream = Files.newInputStream(Paths.get(config.getString("application.favicon")))) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[4096]; int read = 0; - while (read != -1) - { + while (read != -1) { read = stream.read(buffer); - if (read > 0) - { + if (read > 0) { baos.write(buffer, 0, read); } } @@ -608,8 +555,7 @@ public ProteusApplication addDefaultRoutes(RoutingHandler router) exchange.getResponseSender().send(faviconImageBuffer); }); - } catch (Exception e) - { + } catch (Exception e) { log.error("Error adding favicon route.", e); } } @@ -623,8 +569,7 @@ public ProteusApplication addDefaultRoutes(RoutingHandler router) * @param rootHandlerClass * @return the application */ - public ProteusApplication setRootHandlerClass(Class rootHandlerClass) - { + public ProteusApplication setRootHandlerClass(Class rootHandlerClass) { this.rootHandlerClass = rootHandlerClass; return this; @@ -636,8 +581,7 @@ public ProteusApplication setRootHandlerClass(Class rootH * @param rootHandler * @return the application */ - public ProteusApplication setRootHandler(HttpHandler rootHandler) - { + public ProteusApplication setRootHandler(HttpHandler rootHandler) { this.rootHandler = rootHandler; return this; @@ -648,8 +592,7 @@ public ProteusApplication setRootHandler(HttpHandler rootHandler) * * @param serverConfigurationFunction the serverConfigurationFunction */ - public ProteusApplication setServerConfigurationFunction(Function serverConfigurationFunction) - { + public ProteusApplication setServerConfigurationFunction(Function serverConfigurationFunction) { this.serverConfigurationFunction = serverConfigurationFunction; return this; @@ -658,8 +601,7 @@ public ProteusApplication setServerConfigurationFunction(Function getPorts() - { + public List getPorts() { return ports; } @@ -714,14 +653,12 @@ public List getListenerInfo() { /** * @return The Undertow server */ - public Undertow getUndertow() - { + public Undertow getUndertow() { return undertow; } - public void printStatus() - { + public void printStatus() { Config globalHeaders = config.getConfig("globalHeaders"); @@ -734,7 +671,7 @@ public void printStatus() List tableHeaders = Arrays.asList("Header", "Value"); List> tableRows = globalHeadersParameters.entrySet().stream().map(e -> Arrays.asList(e.getKey(), e.getValue())) - .collect(Collectors.toList()); + .collect(Collectors.toList()); TablePrinter printer = new TablePrinter(tableHeaders, tableRows); @@ -745,8 +682,8 @@ public void printStatus() tableHeaders = Arrays.asList("Method", "Path", "Consumes", "Produces", "Controller"); tableRows = this.registeredEndpoints.stream().sorted().map(e -> - Arrays.asList(e.getMethod().toString(), e.getPathTemplate(), String.format("[%s]", e.getConsumes()), String.format("[%s]", e.getProduces()), String.format("(%s.%s)", e.getControllerName(), e.getControllerMethod()))) - .collect(Collectors.toList()); + Arrays.asList(e.getMethod().toString(), e.getPathTemplate(), String.format("[%s]", e.getConsumes()), String.format("[%s]", e.getProduces()), String.format("(%s.%s)", e.getControllerName(), e.getControllerMethod()))) + .collect(Collectors.toList()); printer = new TablePrinter(tableHeaders, tableRows); @@ -759,9 +696,9 @@ public void printStatus() tableHeaders = Arrays.asList("Service", "State", "Startup Time"); tableRows = serviceStateMap.asMap().entrySet().stream().flatMap(e -> - e.getValue().stream().map(s -> - Arrays.asList(s.getClass().getSimpleName(), e.getKey().toString(), DurationFormatUtils.formatDurationHMS(serviceStartupTimeMap.get(s))))) - .collect(Collectors.toList()); + e.getValue().stream().map(s -> + Arrays.asList(s.getClass().getSimpleName(), e.getKey().toString(), DurationFormatUtils.formatDurationHMS(serviceStartupTimeMap.get(s))))) + .collect(Collectors.toList()); printer = new TablePrinter(tableHeaders, tableRows); @@ -770,19 +707,16 @@ public void printStatus() log.info(sb.toString()); } - protected java.nio.file.Path getTemporaryDirectoryPath() throws Exception - { + protected java.nio.file.Path getTemporaryDirectoryPath() throws Exception { String tmpDirLocation = System.getProperty("java.io.tmpdir"); java.nio.file.Path tmpPath = Paths.get(tmpDirLocation); - try - { + try { return Files.createDirectory(tmpPath.resolve(TMP_DIRECTORY_NAME)); - } catch (Exception e) - { + } catch (Exception e) { return tmpPath; } diff --git a/proteus-core/src/main/java/io/sinistral/proteus/protocol/MediaType.java b/proteus-core/src/main/java/io/sinistral/proteus/protocol/MediaType.java index c60787b..d32f5cf 100644 --- a/proteus-core/src/main/java/io/sinistral/proteus/protocol/MediaType.java +++ b/proteus-core/src/main/java/io/sinistral/proteus/protocol/MediaType.java @@ -20,8 +20,7 @@ import java.util.Optional; import java.util.stream.Collectors; -public class MediaType -{ +public class MediaType { private static final Map FILE_EXTENSIONS = new LinkedHashMap<>(); private static final String[] NO_ATTR = new String[0]; @@ -972,7 +971,7 @@ public class MediaType public static final MediaType IMAGE_HEIC = create("image/heic", "heic"); public static final MediaType IMAGE_GIF = create("image/gif", "gif"); public static final MediaType IMAGE_IEF = create("image/ief", "ief"); - public static final MediaType IMAGE_JPEG = create("image/jpeg", "jpg","jpeg", "jpe"); + public static final MediaType IMAGE_JPEG = create("image/jpeg", "jpg", "jpeg", "jpe"); public static final MediaType IMAGE_JBIG = create("image/jbig", "jbig", "jbg"); public static final MediaType IMAGE_KTX = create("image/ktx", "ktx"); public static final MediaType IMAGE_PCX = create("image/pcx", "pcx"); @@ -1031,19 +1030,25 @@ public class MediaType public static final MediaType MESSAGE_RFC822 = create("message/rfc822", "eml", "mime"); public static final MediaType MODEL_IGES = create("model/iges", "igs", "iges"); public static final MediaType MODEL_MESH = create("model/mesh", "msh", "mesh", "silo"); + public static final MediaType MODEL_MATERIAL = create("model/mtl", "mtl"); + public static final MediaType MODEL_GLTF_JSON = create("model/gltf+json", "gltf"); + public static final MediaType MODEL_GLTF_BINARY = create("model/gltf+binary", "glb"); + public static final MediaType MODEL_OBJ = create("model/obj", "obj"); + public static final MediaType MODEL_USD = create("model/usd", "usd"); public static final MediaType MODEL_VND_COLLADA_XML = create("model/vnd.collada+xml", "dae"); public static final MediaType MODEL_VND_DWF = create("model/vnd.dwf", "dwf"); public static final MediaType MODEL_VND_GDL = create("model/vnd.gdl", "gdl"); public static final MediaType MODEL_VND_GTW = create("model/vnd.gtw", "gtw"); public static final MediaType MODEL_VND_MTS = create("model/vnd.mts", "mts"); public static final MediaType MODEL_VND_VTU = create("model/vnd.vtu", "vtu"); + public static final MediaType MODEL_VND_USDZ_ZIP = create("model/vnd.usdz+zip", "usdz"); + public static final MediaType MODEL_VND_USDA = create("model/vnd.usda", "usda"); public static final MediaType MODEL_VRML = create("model/vrml", "wrl", "vrml"); public static final MediaType MODEL_X3D_BINARY = create("model/x3d+binary", "x3db", "x3dbz"); public static final MediaType MODEL_X3D_VRML = create("model/x3d+vrml", "x3dv", "x3dvz"); public static final MediaType MODEL_X3D_XML = create("model/x3d+xml", "x3d", "x3dz"); public static final MediaType TEXT_CACHE_MANIFEST = create("text/cache-manifest", "appcache", "manifest"); public static final MediaType TEXT_CALENDAR = create("text/calendar", "ics", "icz", "ifb"); - public static final MediaType TEXT_CSS_UTF8 = createUTF8("text/css", "css"); public static final MediaType TEXT_CSV_UTF8 = createUTF8("text/csv", "csv"); public static final MediaType TEXT_H323 = create("text/h323", "323"); @@ -1186,21 +1191,18 @@ public class MediaType /*******************************************************/ - public static synchronized MediaType create(String type, String... fileExtensisons) - { + public static synchronized MediaType create(String type, String... fileExtensisons) { return create(type, NO_ATTR, fileExtensisons); } - public static synchronized MediaType create(String type, String[] attributes, String... fileExtensisons) - { + public static synchronized MediaType create(String type, String[] attributes, String... fileExtensisons) { MediaType mt = new MediaType(type, attributes); - if(fileExtensisons == null) - { + if (fileExtensisons == null) { fileExtensisons = new String[]{}; } - if(!Arrays.stream(attributes).anyMatch(a -> a.equals(UTF8_ATTR[0]))) { + if (!Arrays.stream(attributes).anyMatch(a -> a.equals(UTF8_ATTR[0]))) { for (String ext : fileExtensisons) { FILE_EXTENSIONS.put(ext, mt); } @@ -1209,29 +1211,25 @@ public static synchronized MediaType create(String type, String[] attributes, St return mt; } - public static synchronized MediaType createUTF8(String type, String... fileExtensisons) - { - if(fileExtensisons == null) - { + public static synchronized MediaType createUTF8(String type, String... fileExtensisons) { + if (fileExtensisons == null) { fileExtensisons = new String[]{}; } for (String ext : fileExtensisons) { - if(!FILE_EXTENSIONS.containsKey(ext)) { + if (!FILE_EXTENSIONS.containsKey(ext)) { FILE_EXTENSIONS.put(ext, create(type, fileExtensisons)); } } return create(type, UTF8_ATTR, fileExtensisons); } - public static synchronized MediaType getByFileExtension(String fileExtension) - { + public static synchronized MediaType getByFileExtension(String fileExtension) { return FILE_EXTENSIONS.get(fileExtension); } - public static synchronized MediaType getByFileName(String filename) - { + public static synchronized MediaType getByFileName(String filename) { int dotPos = filename.lastIndexOf('.'); if (dotPos >= 0) { String ext = filename.substring(dotPos + 1); @@ -1241,18 +1239,15 @@ public static synchronized MediaType getByFileName(String filename) } } - public static synchronized MediaType getByMimeType(String type) - { + public static synchronized MediaType getByMimeType(String type) { return Optional.ofNullable(getTypeMap().get(type)).orElse(MediaType.DEFAULT); } - public String withCharset(String charset) - { + public String withCharset(String charset) { return charset != null ? String.format("%s; charset=%s", this.contentType, charset.toUpperCase()) : this.contentType; } - public static MediaType of(String contentType) - { + public static MediaType of(String contentType) { return new MediaType(contentType); } @@ -1261,70 +1256,59 @@ public static MediaType of(String contentType) private final String contentType; - private MediaType(String contentType) - { + private MediaType(String contentType) { this.bytes = contentType.getBytes(); this.contentType = contentType; } - private MediaType(String name, String[] attributes) - { + private MediaType(String name, String[] attributes) { this.bytes = join(name, attributes).getBytes(); this.contentType = new String(this.bytes); } - private String join(String name, String[] attributes) - { + private String join(String name, String[] attributes) { String attrs = Arrays.stream(attributes).collect(Collectors.joining(";")); return attrs.isEmpty() ? name : name + "; " + attrs; } - public byte[] getBytes() - { + public byte[] getBytes() { return bytes; } @JsonProperty("contentType") - public String contentType() - { + public String contentType() { return this.contentType; } @Override - public String toString() - { + public String toString() { return this.contentType; } - public String getFileExtension() - { - return Optional.ofNullable(getFileExtensionMap().get(this)).map( fe -> fe.get(0)).orElse(null); + public String getFileExtension() { + return Optional.ofNullable(getFileExtensionMap().get(this)).map(fe -> fe.get(0)).orElse(null); } - public List getFileExtensions() - { + public List getFileExtensions() { return Optional.ofNullable(getFileExtensionMap().get(this)).orElse(null); } - public String subType() - { - return this.contentType.substring(this.contentType.lastIndexOf("/") + 1, Math.max(this.contentType.lastIndexOf(";"),this.contentType.length())); + public String subType() { + return this.contentType.substring(this.contentType.lastIndexOf("/") + 1, Math.max(this.contentType.lastIndexOf(";"), this.contentType.length())); } - public String baseType() - { - return this.contentType.substring(0,this.contentType.lastIndexOf(";")); + public String baseType() { + return this.contentType.substring(0, this.contentType.lastIndexOf(";")); } - private static final Map TYPE_MAP = new HashMap<>(); + private static final Map TYPE_MAP = new HashMap<>(); - private static final Map> EXTENSION_MAP = new HashMap<>(); + private static final Map> EXTENSION_MAP = new HashMap<>(); - public static Map> getFileExtensionMap() - { - if(EXTENSION_MAP.size() == 0) { + public static Map> getFileExtensionMap() { + if (EXTENSION_MAP.size() == 0) { EXTENSION_MAP.putAll(FILE_EXTENSIONS.entrySet().stream().collect(Collectors.groupingBy(Map.Entry::getValue, Collectors.mapping(Map.Entry::getKey, Collectors.toList())))); } @@ -1332,21 +1316,18 @@ public static Map> getFileExtensionMap() return EXTENSION_MAP; } - public static Map getTypeMap() - { - if(TYPE_MAP.size() == 0) { + public static Map getTypeMap() { + if (TYPE_MAP.size() == 0) { Class clazz = MediaType.class; Field[] fields = clazz.getDeclaredFields(); - Arrays.stream(fields).filter(f -> f.getType().equals(MediaType.class)).forEach( f -> { + Arrays.stream(fields).filter(f -> f.getType().equals(MediaType.class)).forEach(f -> { - try - { - MediaType mt = (MediaType)f.get(MediaType.class); - TYPE_MAP.put(mt.contentType,mt); - } catch( Exception e ) - { + try { + MediaType mt = (MediaType) f.get(MediaType.class); + TYPE_MAP.put(mt.contentType, mt); + } catch (Exception e) { } }); @@ -1356,8 +1337,7 @@ public static Map getTypeMap() } @Override - public int hashCode() - { + public int hashCode() { final int prime = 31; int result = 1; result = prime * result + Arrays.hashCode(bytes); @@ -1365,8 +1345,7 @@ public int hashCode() } @Override - public boolean equals(Object obj) - { + public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) @@ -1379,8 +1358,7 @@ public boolean equals(Object obj) return true; } - public String info() - { + public String info() { if (this == HTML_UTF_8) { return "html"; } diff --git a/proteus-core/src/test/java/io/sinistral/proteus/test/server/StandardEndpointsTest.java b/proteus-core/src/test/java/io/sinistral/proteus/test/server/StandardEndpointsTest.java index 2af189a..baf6094 100644 --- a/proteus-core/src/test/java/io/sinistral/proteus/test/server/StandardEndpointsTest.java +++ b/proteus-core/src/test/java/io/sinistral/proteus/test/server/StandardEndpointsTest.java @@ -533,7 +533,7 @@ public void responseParseDouble() public void notFound() { - given().accept(ContentType.JSON).when().get("v1/tests/response/error/404").then().statusCode(404).log().body().content(containsString("No entity found")); + given().accept(ContentType.JSON).when().get("v1/tests/response/error/404").then().statusCode(404).body(containsString("No entity found")); } @@ -541,7 +541,7 @@ public void notFound() public void unauthorized() { - given().accept(ContentType.JSON).when().get("v1/tests/response/error/401").then().statusCode(401).log().body().content(containsString("Unauthorized")); + given().accept(ContentType.JSON).when().get("v1/tests/response/error/401").then().statusCode(401).body(containsString("Unauthorized")); } diff --git a/proteus-openapi/pom.xml b/proteus-openapi/pom.xml index 7852a48..d51f5b5 100644 --- a/proteus-openapi/pom.xml +++ b/proteus-openapi/pom.xml @@ -3,7 +3,7 @@ proteus-project io.sinistral - 0.5.2-SNAPSHOT + 0.6.0-SNAPSHOT 4.0.0 @@ -73,10 +73,20 @@ maven-release-plugin - - org.apache.maven.plugins - maven-compiler-plugin - + + org.apache.maven.plugins + maven-compiler-plugin + + ${java.version} + ${java.version} + -parameters + + -parameters + --add-opens=java.base/java.lang=ALL-UNNAMED --illegal-access=deny + + UTF-8 + +