泽西 JAX_RS 中的错误 JDK 中的选项 header > 8?
Bug in Jersey JAX_RS with OPTIONS header in JDK > 8?
我跟踪了将我的 JDK 8 升级到 9 甚至 10 后遇到的问题,并创建了这个小示例来重现它。
如果我提出要求
curl -i -X OPTIONS http://localhost:8088/test/test
使用 OpenJDK 8 没问题。在 OpenJDK 9 或 10(未尝试 11 或 7)中出现异常。
org.glassfish.jersey.internal.Errors logErrors
WARNUNG: The following warnings have been detected: WARNING: Unknown HK2 failure detected:
MultiException stack 1 of 2
javax.ws.rs.ProcessingException: Error creating a JAXBContext for wadl processing.
at org.glassfish.jersey.server.wadl.internal.WadlApplicationContextImpl.<init>(WadlApplicationContextImpl.java:120)
...
运行 Debian 10.2.
GET 请求在所有 JDK 中都可以。
这是我的样本。
我通过简单地设置 maven-compiler-plugin 中 pom.xml 的末尾来更改 JDK(现在是 10,对我来说只适用于 8)。
希望有人能给我提示。谢谢!
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>MyTest</groupId>
<artifactId>MyTest</artifactId>
<packaging>jar</packaging>
<version>0.1</version>
<name>MyTest</name>
<url>http://maven.apache.org</url>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>2.29</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-grizzly2-http</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-jdk-http</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>10</source>
<target>10</target>
</configuration>
</plugin>
</plugins>
</build>
MyTest.java
package MyTest.MyTest;
import java.net.*;
import org.glassfish.grizzly.http.server.*;
import org.glassfish.jersey.grizzly2.httpserver.*;
import org.glassfish.jersey.jdkhttp.*;
import org.glassfish.jersey.logging.*;
import org.glassfish.jersey.server.*;
public class MyTest
{
public static void main (String [] args) throws Exception
{
final String uri = "http://localhost:8088/"; // listening
ResourceConfig rc = new ResourceConfig ();
rc.packages (MyTest.class.getPackage ().getName ());
rc.property (LoggingFeature.LOGGING_FEATURE_LOGGER_LEVEL, "INFO");
rc.property (LoggingFeature.LOGGING_FEATURE_VERBOSITY_SERVER, LoggingFeature.Verbosity.PAYLOAD_TEXT);
// Grizzly-HTTP-Server
org.glassfish.grizzly.http.server.HttpServer hs = GrizzlyHttpServerFactory.createHttpServer (URI.create (uri), rc);
// tried JDK-HTTP as a 2nd container - but with ame effect problem
//com.sun.net.httpserver.HttpServer hs = JdkHttpServerFactory.createHttpServer (URI.create (uri), rc);
for (int i = 0; i < 100; i ++)
{
Thread.sleep (10000); // 10s
}
}
}
Handler.java
package MyTest.MyTest;
import javax.ws.rs.*;
import javax.ws.rs.core.*;
@Path ("test")
public class Handler
{
@GET
@javax.ws.rs.Path ("/test")
@Produces (MediaType.TEXT_HTML)
public String list () throws Exception
{
System.out.println("test");
return "OK";
}
}
发现问题似乎出在自 JDK 9.
以来缺少的 JAXB
https://www.jesperdj.com/2018/09/30/jaxb-on-java-9-10-11-and-beyond/
如果我添加一个依赖项,它会再次工作。
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.2</version>
</dependency>
我跟踪了将我的 JDK 8 升级到 9 甚至 10 后遇到的问题,并创建了这个小示例来重现它。
如果我提出要求
curl -i -X OPTIONS http://localhost:8088/test/test
使用 OpenJDK 8 没问题。在 OpenJDK 9 或 10(未尝试 11 或 7)中出现异常。
org.glassfish.jersey.internal.Errors logErrors
WARNUNG: The following warnings have been detected: WARNING: Unknown HK2 failure detected:
MultiException stack 1 of 2
javax.ws.rs.ProcessingException: Error creating a JAXBContext for wadl processing.
at org.glassfish.jersey.server.wadl.internal.WadlApplicationContextImpl.<init>(WadlApplicationContextImpl.java:120)
...
运行 Debian 10.2.
GET 请求在所有 JDK 中都可以。
这是我的样本。 我通过简单地设置 maven-compiler-plugin 中 pom.xml 的末尾来更改 JDK(现在是 10,对我来说只适用于 8)。
希望有人能给我提示。谢谢!
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>MyTest</groupId>
<artifactId>MyTest</artifactId>
<packaging>jar</packaging>
<version>0.1</version>
<name>MyTest</name>
<url>http://maven.apache.org</url>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>2.29</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-grizzly2-http</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-jdk-http</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>10</source>
<target>10</target>
</configuration>
</plugin>
</plugins>
</build>
MyTest.java
package MyTest.MyTest;
import java.net.*;
import org.glassfish.grizzly.http.server.*;
import org.glassfish.jersey.grizzly2.httpserver.*;
import org.glassfish.jersey.jdkhttp.*;
import org.glassfish.jersey.logging.*;
import org.glassfish.jersey.server.*;
public class MyTest
{
public static void main (String [] args) throws Exception
{
final String uri = "http://localhost:8088/"; // listening
ResourceConfig rc = new ResourceConfig ();
rc.packages (MyTest.class.getPackage ().getName ());
rc.property (LoggingFeature.LOGGING_FEATURE_LOGGER_LEVEL, "INFO");
rc.property (LoggingFeature.LOGGING_FEATURE_VERBOSITY_SERVER, LoggingFeature.Verbosity.PAYLOAD_TEXT);
// Grizzly-HTTP-Server
org.glassfish.grizzly.http.server.HttpServer hs = GrizzlyHttpServerFactory.createHttpServer (URI.create (uri), rc);
// tried JDK-HTTP as a 2nd container - but with ame effect problem
//com.sun.net.httpserver.HttpServer hs = JdkHttpServerFactory.createHttpServer (URI.create (uri), rc);
for (int i = 0; i < 100; i ++)
{
Thread.sleep (10000); // 10s
}
}
}
Handler.java
package MyTest.MyTest;
import javax.ws.rs.*;
import javax.ws.rs.core.*;
@Path ("test")
public class Handler
{
@GET
@javax.ws.rs.Path ("/test")
@Produces (MediaType.TEXT_HTML)
public String list () throws Exception
{
System.out.println("test");
return "OK";
}
}
发现问题似乎出在自 JDK 9.
以来缺少的 JAXBhttps://www.jesperdj.com/2018/09/30/jaxb-on-java-9-10-11-and-beyond/
如果我添加一个依赖项,它会再次工作。
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.2</version>
</dependency>