Skip to content

Commit

Permalink
Improve jdk compatibility。
Browse files Browse the repository at this point in the history
  • Loading branch information
gudaoxuri committed Oct 17, 2023
1 parent 542800d commit 31253b5
Show file tree
Hide file tree
Showing 11 changed files with 269 additions and 234 deletions.
11 changes: 1 addition & 10 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ Dew Common的理念是简化Java开发中最常用的操作,同时尽可能少
. 脚本处理
. 响应处理及分页模型
. Tuple支持
. Java11支持
. GraalVM支持

== 使用
Expand All @@ -33,19 +32,11 @@ NOTE: 文档地址: http://gudaoxuri.github.io/dew-common/[http://gudaoxuri.gi

[source,xml]
----
<!-- >= JDK11 -->
<dependency>
<groupId>com.ecfront.dew</groupId>
<artifactId>common</artifactId>
<version>3.0.2</version>
</dependency>
<!-- < JDK11 -->
<dependency>
<groupId>com.ecfront.dew</groupId>
<artifactId>common</artifactId>
<version>1.5.0</version>
</dependency>
----

=== Json与Java对象互转($.json)
Expand Down Expand Up @@ -342,7 +333,7 @@ String conf=$.file.readAllByClassPath("conf1.json","UTF-8");

TIP: 更多示例见`FileHelperTest.java`

=== 常用字段操作($.amount)
=== 常用金额操作($.amount)

[source,java]
----
Expand Down
6 changes: 3 additions & 3 deletions it/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@

<maven.install.skip>true</maven.install.skip>
<maven.deploy.skip>true</maven.deploy.skip>
<junit.version>5.8.2</junit.version>
<junit.version>5.10.0</junit.version>

<graalvm.version>21.3.0</graalvm.version>
<graalvm.version>23.0.1</graalvm.version>

<mainClass>com.ecfront.dew.common.test.graalvm.NativeImageMain</mainClass>
<imageName>NativeImageTest</imageName>
Expand All @@ -50,7 +50,7 @@
<dependency>
<groupId>com.ecfront.dew</groupId>
<artifactId>common</artifactId>
<version>3.0.0-beta4</version>
<version>3.0.4</version>
<exclusions>
<!-- 去除 HotSpot 兼容处理 -->
<exclusion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.ecfront.dew.commonit.test;

import com.ecfront.dew.common.test.graalvm.NativeImageMain;
import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
* The type Native image test.
Expand Down
18 changes: 9 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<description>Dew公共模块</description>
<url>https://github.com/gudaoxuri/dew-common</url>
<packaging>jar</packaging>
<version>3.0.3</version>
<version>3.0.4</version>

<properties>
<java.version>11</java.version>
Expand All @@ -36,19 +36,19 @@
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<maven.compiler.compilerVersion>${java.version}</maven.compiler.compilerVersion>
<jackson.version>2.14.2</jackson.version>
<jackson.version>2.15.3</jackson.version>
<beanutils.version>1.9.4</beanutils.version>
<jbcrypt.version>0.4</jbcrypt.version>
<slf4j.version>2.0.6</slf4j.version>
<junit.version>5.9.2</junit.version>
<checkstyle.version>10.7.0</checkstyle.version>
<slf4j.version>2.0.9</slf4j.version>
<junit.version>5.10.0</junit.version>
<checkstyle.version>10.12.4</checkstyle.version>

<asciidoctor.maven.plugin.version>2.2.2</asciidoctor.maven.plugin.version>
<asciidoctorj.version>2.5.7</asciidoctorj.version>
<jruby.version>9.3.2.0</jruby.version>

<graalvm.version>22.3.1</graalvm.version>
<graalvm.plugin.version>22.3.1</graalvm.plugin.version>
<graalvm.version>23.0.1</graalvm.version>
<graalvm.plugin.version>23.0.1</graalvm.plugin.version>
<mainClass></mainClass>
<imageName></imageName>
</properties>
Expand Down Expand Up @@ -138,8 +138,8 @@
<developer>
<name>gudaoxuri</name>
<email>i@sunisle.org</email>
<organization>ecfront</organization>
<organizationUrl>http://www.ecfront.com</organizationUrl>
<organization>idealworld</organization>
<organizationUrl>https://idealworld.group/</organizationUrl>
</developer>
</developers>

Expand Down
23 changes: 8 additions & 15 deletions src/main/java/com/ecfront/dew/common/HttpHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.ecfront.dew.common.exception.RTException;
import com.ecfront.dew.common.exception.RTGeneralSecurityException;
import com.ecfront.dew.common.exception.RTIOException;
import com.ecfront.dew.common.exception.RTReflectiveOperationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -73,25 +72,19 @@ public class HttpHelper {
var allowAllHeaders = ManagementFactory.getRuntimeMXBean().getInputArguments().stream().anyMatch(arg ->
arg.contains("--add-opens=java.net.http/jdk.internal.net.http.common"));
if (allowAllHeaders) {
/*
解决JDK11对请求头限制的Bug.
<p>
如果请求头有包含 "connection", "content-length", "date", "expect", "from", "host", "upgrade", "via", "warning" 字段,
则需要调用此方法解除限制。
<p>
NOTE: 需要在运行参数中添加 --add-opens java.net.http/jdk.internal.net.http.common=ALL-UNNAMED
@return the resp
* @see <a href="https://bugs.openjdk.java.net/browse/JDK-8213696">JDK-8213696</a>
*/
try {
var disallowedHeads = jdk.internal.net.http.common.Utils.class.getDeclaredField("DISALLOWED_HEADERS_SET");
// 解决JDK11对请求头限制的Bug.
// 如果请求头有包含 "connection", "content-length", "date", "expect", "from", "host", "upgrade", "via", "warning" 字段,
// 则需要调用此方法解除限制。
// NOTE: 需要在运行参数中添加 --add-opens java.net.http/jdk.internal.net.http.common=ALL-UNNAMED
// @see <a href="https://bugs.openjdk.java.net/browse/JDK-8213696">JDK-8213696</a>
var jdkUtilsClazz = Class.forName("jdk.internal.net.http.common.Utils");
var disallowedHeads = jdkUtilsClazz.getDeclaredField("DISALLOWED_HEADERS_SET");
var modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(disallowedHeads, disallowedHeads.getModifiers() & ~Modifier.FINAL);
$.bean.setValue(null, disallowedHeads, new HashSet<String>());
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RTReflectiveOperationException(e);
} catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException ignore) {
}
}
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
[
{
"name":"java.lang.Boolean",
"methods":[{"name":"getBoolean","parameterTypes":["java.lang.String"] }]}
,
{
"name":"java.lang.ClassLoader",
"methods":[
{"name":"getPlatformClassLoader","parameterTypes":[] },
{"name":"loadClass","parameterTypes":["java.lang.String"] }
]}
,
{
"name":"jdk.internal.loader.ClassLoaders$PlatformClassLoader"}

"methods":[{"name":"getBoolean","parameterTypes":["java.lang.String"] }]
}
]
Loading

0 comments on commit 31253b5

Please sign in to comment.