本文主要是介绍JDK8升级JDK9 HTT2 TLS问题解决之路(艰辛),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
背景描述
s公告服务是雪球行情的公告抓取服务,主要负责从相关网站抓取A股、港股、美股公告,调用接口发贴。数据抓取是在该业务场景是行情数据的入口,影响以后的的处理逻辑。因此,通过代理池+proxy的方式接入网络代理,规避前期发现的因为单个代理频繁请求导致IP被封的问题。但是在接入后发现网络请求的可用性并没有提高,因此进一步排查问题,找到问题提的根本原因。
问题描述
- 在未使用代理的情况下,请求结果返回http的403错误码
- 在使用代理的情况下,请求反馈的http的403错误码的代理应该降低。返回403错误码的概率并没有降低,不符合预期。jdk8对http2的支持不好,偶发、高频请求情况下,会导致请求结果403异常。
解决方法1 JDK8升级JDK9
IDEA修改下环境
JAXB API是java EE 的API,因此在java SE 9.0 中不再包含这个 Jar 包。
java 9 中引入了模块的概念,默认情况下,Java SE中将不再包含java EE 的Jar包
而在 java 6/7 / 8 时关于这个API 都是捆绑在一起的
JAXB(Java Architecture for XML Binding简称JAXB)允许Java开发人员将Java类映射为XML表示方式。
JAXB提供两种主要特性:将一个Java对象序列化为XML,以及反向操作,将XML解析成Java对象。
换句话说,JAXB允许以XML格式存储和读取数据,而不需要程序的类结构实现特定的读取XML和保存XML的代码。
JAXB API被认为是Java EE API,因此不再包含在Java SE 9中的默认类路径中。在Java 11中,它们完全从JDK中删除。
Java 9引入了模块的概念,默认情况下,java.se聚合模块在类路径(或更确切地说,模块路径)上可用。正如其名称所暗示的,java.se汇聚模块并没有包括那些与Java 6/7/8传统上捆绑了Java EE的API。
幸运的是,JDK 6/7/8中提供的这些Java EE API仍然在JDK中,但它们默认情况下不在类路径上。以下模块中提供了额外的Java EE API:
java.activation
java.corba
java.transaction
java.xml.bind << This one contains the JAXB APIs
java.xml.ws
java.xml.ws.annotation
这也是为啥JDK9的API还能搜到:
https://docs.oracle.com/javase/9/docs/api/javax/xml/bind/JAXB.html
第一个异常解决了
Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/ValidationException
at java.base/java.lang.ClassLoader.defineClass1(Native Method) ~[na:na]
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1007) ~[na:na]
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174) ~[na:na]
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:801) ~[na:na]
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:699) ~[na:na]
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:622) ~[na:na]
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:580) ~[na:na]
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496) ~[na:na]
at org.hibernate.validator.internal.engine.ConfigurationImpl.<init>(ConfigurationImpl.java:129) ~[hibernate-validator-5.2.4.Final.jar:5.2.4.Final]
at org.hibernate.validator.internal.engine.ConfigurationImpl.<init>(ConfigurationImpl.java:96) ~[hibernate-validator-5.2.4.Final.jar:5.2.4.Final]
at org.hibernate.validator.HibernateValidator.createGenericConfiguration(HibernateValidator.java:31) ~[hibernate-validator-5.2.4.Final.jar:5.2.4.Final]
at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:276) ~[validation-api-1.1.0.Final.jar:na]
at org.springframework.validation.beanvalidation.LocalValidatorFactoryBean.afterPropertiesSet(LocalValidatorFactoryBean.java:250) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor$LocalValidatorFactory.run(ConfigurationPropertiesBindingPostProcessor.java:441) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.getValidator(ConfigurationPropertiesBindingPostProcessor.java:375) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.determineValidator(ConfigurationPropertiesBindingPostProcessor.java:358) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.postProcessBeforeInitialization(ConfigurationPropertiesBindingPostProcessor.java:317) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.postProcessBeforeInitialization(ConfigurationPropertiesBindingPostProcessor.java:289) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:409) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1620) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
... 40 common frames omitted
其中一个解决方式,引入工具包:
<!-- 解决JDK8升级JDK9带来的问题,版本先写死 -->
<dependency><groupId>javax.xml.bind</groupId><artifactId>jaxb-api</artifactId><version>2.3.0</version>
</dependency><!-- 有的地方还引入了下面几个,具体作用还不知道,备注下不用 -->
<dependency><groupId>com.sun.xml.bind</groupId><artifactId>jaxb-impl</artifactId><version>2.3.0</version>
</dependency>
<dependency><groupId>com.sun.xml.bind</groupId><artifactId>jaxb-core</artifactId><version>2.3.0</version>
</dependency>
<dependency><groupId>javax.activation</groupId><artifactId>activation</artifactId><version>1.1.1</version>
</dependency><!-- JDK升级到11,还得需要下面这个 -->
<dependency><groupId>org.glassfish.jaxb</groupId><artifactId>jaxb-runtime</artifactId>
</dependency>
另外一种的实现方式在JDK9运行时(抛弃)
在JVM的运行脚本参数VMOption增加:--add-modules java.xml.bind(这个流程不会引起网络下载,看上一步就知道)
这个不靠谱:
1.SRE那边的JDK、docker后续变更,这个玩意支持度有多大
2.这个玩意后续的传承性有多大,大家接入理解程度
第二个异常出来了:
IDAEcheck报出来的:JavaFX not support
<plugin><inherited>true</inherited><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>2.5.1</version><configuration><source>9</source><target>9</target></configuration>
</plugin>
maven plugin的问题
https://qa.1r1g.com/sf/ask/3316364551/
第三个异常出来了:
IDAEcheck报出来的:Lombok报classNotFind
https://projectlombok.org/changelog
看下changeLog,升级下版本就能解决
第四个异常伴随着出来了:
Caused by: java.lang.ClassCastException: [B cannot be cast to [C
at com.twitter.finagle.thrift.Protocols$TFinagleBinaryProtocol.writeString(Protocols.scala:162) ~[finagle-thrift_2.10-6.26.0.jar:6.26.0]
at org.apache.thrift.protocol.TBinaryProtocol.writeMessageBegin(TBinaryProtocol.java:92) ~[libthrift-0.5.0.jar:na]
at com.twitter.finagle.thrift.ThriftClientPreparer.prepareService(ThriftClientFramedCodec.scala:128) ~[finagle-thrift_2.10-6.26.0.jar:6.26.0]
at com.twitter.finagle.thrift.ThriftClientPreparer$$anonfun$prepare$1.apply(ThriftClientFramedCodec.scala:157) ~[finagle-thrift_2.10-6.26.0.jar:6.26.0]
at com.twitter.finagle.thrift.ThriftClientPreparer$$anonfun$prepare$1.apply(ThriftClientFramedCodec.scala:157) ~[finagle-thrift_2.10-6.26.0.jar:6.26.0]
at com.twitter.finagle.ServiceFactory$$anon$7$$anonfun$apply$2.apply(Service.scala:154) ~[finagle-core_2.10-6.26.0.jar:6.26.0]
at com.twitter.finagle.ServiceFactory$$anon$7$$anonfun$apply$2.apply(Service.scala:153) ~[finagle-core_2.10-6.26.0.jar:6.26.0]
at com.twitter.util.Future$$anonfun$flatMap$1.apply(Future.scala:893) ~[util-core_2.10-6.25.0.jar:6.25.0]
at com.twitter.util.Future$$anonfun$flatMap$1.apply(Future.scala:892) ~[util-core_2.10-6.25.0.jar:6.25.0]
at com.twitter.util.Promise$Transformer.liftedTree1$1(Promise.scala:100) ~[util-core_2.10-6.25.0.jar:6.25.0]
at com.twitter.util.Promise$Transformer.k(Promise.scala:100) ~[util-core_2.10-6.25.0.jar:6.25.0]
at com.twitter.util.Promise$Transformer.apply(Promise.scala:110) ~[util-core_2.10-6.25.0.jar:6.25.0]
at com.twitter.util.Promise$Transformer.apply(Promise.scala:91) ~[util-core_2.10-6.25.0.jar:6.25.0]
at com.twitter.util.Promise$$anon$3.run(Promise.scala:726) ~[util-core_2.10-6.25.0.jar:6.25.0]
at com.twitter.concurrent.LocalScheduler$Activation.run(Scheduler.scala:193) ~[util-core_2.10-6.25.0.jar:6.25.0]
at com.twitter.concurrent.LocalScheduler$Activation.submit(Scheduler.scala:140) ~[util-core_2.10-6.25.0.jar:6.25.0]
at com.twitter.concurrent.LocalScheduler.submit(Scheduler.scala:222) ~[util-core_2.10-6.25.0.jar:6.25.0]
at com.twitter.concurrent.Scheduler$.submit(Scheduler.scala:84) ~[util-core_2.10-6.25.0.jar:6.25.0]
at com.twitter.util.Promise.continue(Promise.scala:724) ~[util-core_2.10-6.25.0.jar:6.25.0]
at com.twitter.util.Promise$Responder$class.transform(Promise.scala:175) ~[util-core_2.10-6.25.0.jar:6.25.0]
at com.twitter.util.Promise.transform(Promise.scala:311) ~[util-core_2.10-6.25.0.jar:6.25.0]
at com.twitter.util.Future.flatMap(Future.scala:892) ~[util-core_2.10-6.25.0.jar:6.25.0]
at com.twitter.finagle.ServiceFactory$$anon$7.apply(Service.scala:153) ~[finagle-core_2.10-6.26.0.jar:6.26.0]
at com.twitter.finagle.ProxyServiceFactory$class.apply(Service.scala:203) ~[finagle-core_2.10-6.26.0.jar:6.26.0]
at com.twitter.finagle.Thrift$Client$$anon$2$$anon$1.apply(Thrift.scala:113) ~[finagle-thrift_2.10-6.26.0.jar:6.26.0]
排查
// this is based on the CharsetEncoder code at:
// http://psy-lob-saw.blogspot.co.nz/2013/04/writing-java-micro-benchmarks-with-jmh.html // we could probably do better than this via: // https://github.com/nitsanw/jmh-samples/blob/master/src/main/java/psy/lob/saw/utf8/CustomUtf8Encoder.java val u = unsafe.get val chars = u.getObject(str, StringValueOffset).asInstanceOf[Array[Char]]
----
private val unsafe: Option[sun.misc.Unsafe] = Option(getUnsafe)
http://ifeve.com/java-9-sun-misc-unsafe/
http://mail.openjdk.java.net/pipermail/jigsaw-dev/2015-August/004434.html
这个又是什么鬼,说JDK9是通过model支持unsafe,我的IDEA也引入了,槽 还是报错!!!
finagle也是有类似的HTTP2和TLS之类的问题
https://github.com/twitter/finagle/issues/650
业务上没有用到UC鉴权,排除依赖,问题算是解决了 <exclusion><artifactId>finagle-thrift_2.10</artifactId><groupId>com.twitter</groupId> </exclusion>
@Import里面的CommonConfig.class删除掉
第五个异常出来了:
21:29:45.502|ERROR|[ScheduledReporter.java:119]|RuntimeException thrown from MetricsLogger#report. Exception was suppressed.
java.lang.reflect.InaccessibleObjectException: Unable to make public long com.sun.management.internal.OperatingSystemImpl.getOpenFileDescriptorCount() accessible: module jdk.management does not "opens com.sun.management.internal" to unnamed module @662b4c69
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:337) ~[na:na]
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:281) ~[na:na]
at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:198) ~[na:na]
at java.base/java.lang.reflect.Method.setAccessible(Method.java:192) ~[na:na]
at com.codahale.metrics.jvm.FileDescriptorRatioGauge.invoke(FileDescriptorRatioGauge.java:48) ~[metrics-jvm-3.1.2.jar:3.1.2]
at com.codahale.metrics.jvm.FileDescriptorRatioGauge.getRatio(FileDescriptorRatioGauge.java:35) ~[metrics-jvm-3.1.2.jar:3.1.2]
at com.codahale.metrics.RatioGauge.getValue(RatioGauge.java:64) ~[metrics-core-3.1.2.jar:3.1.2]
at com.codahale.metrics.RatioGauge.getValue(RatioGauge.java:11) ~[metrics-core-3.1.2.jar:3.1.2]
at com.xueqiu.infra.xcommon.MetricsLogger.logGauge(MetricsLogger.java:348) ~[xcommon-3.9.jar:na]
at com.xueqiu.infra.xcommon.MetricsLogger.report(MetricsLogger.java:200) ~[xcommon-3.9.jar:na]
at com.codahale.metrics.ScheduledReporter.report(ScheduledReporter.java:162) ~[metrics-core-3.1.2.jar:3.1.2]
at com.codahale.metrics.ScheduledReporter$1.run(ScheduledReporter.java:117) ~[metrics-core-3.1.2.jar:3.1.2]
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:514) [na:na]
at java.base/java.util.concurrent.FutureTask.runAndReset$$$capture(FutureTask.java:305) [na:na]
at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java) [na:na]
这个是监控的依赖报的,监控信息的采集依赖于JAVA提供的management
https://stackoverflow.com/questions/55952859/unable-to-make-public-long-com-sun-management-internal-operatingsystemimpl-getop
要是不通过:--add-opens jdk.management/com.sun.management.internal=ALL-UNNAMED
这个JAVA启动命令来做,就要升级Dropwizard的依赖包:4.1.X(采用的这种,因为脚本不好传承)
https://github.com/dropwizard/metrics/pull/1236
<dependency><groupId>io.dropwizard.metrics</groupId><artifactId>metrics-jvm</artifactId><version>4.1.15</version>
</dependency>
第六个异常出来了
java.lang.NoSuchFieldException: loaderRef
at java.base/java.lang.Class.getDeclaredField(Class.java:2368) ~[na:na]
at org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesResourceBundles(WebappClassLoaderBase.java:2334) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.loader.WebappClassLoaderBase.clearReferences(WebappClassLoaderBase.java:1574) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.loader.WebappClassLoaderBase.stop(WebappClassLoaderBase.java:1496) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.loader.WebappLoader.stopInternal(WebappLoader.java:446) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:224) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5517) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:224) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.ContainerBase$StopChild.call(ContainerBase.java:1424) [tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.ContainerBase$StopChild.call(ContainerBase.java:1413) [tomcat-embed-core-8.0.32.jar:8.0.32]
at java.base/java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:264) [na:na]
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java) [na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) [na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) [na:na]
at java.base/java.lang.Thread.run(Thread.java:844) [na:na]
第七个异常出来了
Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.xueqiu.stock.newsfeed.announce.util.http.AnnounceHttpClientUtil
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:na]
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488) ~[na:na]
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:142) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:122) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:271) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
... 18 common frames omitted
当前状态我已经疯了。。。
放弃吧,换一条路
解决方法2 JDK8兼容HTTP2在ALPN实现
提要:
ALPN应用层协议协商:和http1/1的兼容协商机制
这个是ALPN协议协商的实现依赖包
HTTP/2协议的开发在TLS的握手层面需要进行协议协商,进行协议协商的`协议`被称作ALPN(应用层协议协商,https://tools.ietf.org/html/rfc7301)。
ALPN是TLS的扩展支持,使得客户端与服务端在TLS的加密通讯层可进行协议约定,举个例子:甲同乙沟通,甲用英文向乙说,你会说中文吗?
乙说我会讲,甲说那我们用中文来沟通吧,乙说可以的。如过乙说不会讲,甲乙继续保持英文交流.
在TLS链接层面ALPN支持任意协议协商,通常最广泛进行协商的协议是 HTTP/2、HTTP/1.1。
浏览器仅支持HTTP/2 over TLS,还有一种HTTP/2 overcleartext,前一种简称h2、后一种简称h2c。over TLS是加密链接,后一种未加密明文。如果你想让你的服务在浏览器层面支持HTTP/2,你需要配置你的服务器端支持TLS 和 ALPN。
https://www.eclipse.org/jetty/documentation/current/http2-configuring-haproxy.html
https://stackoverflow.com/questions/44243764/http-2-issue-with-jetty-invalid-preface
https://www.jianshu.com/p/7ddcdd3847d6
https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto-embedded-web-servers
https://www.eclipse.org/jetty/documentation/current/alpn-chapter.html
以下为apln-boot实现方案:
因为Java 8 以及以下版本不支持http 2,要想okhttp client能真正地走h2
协议(如果客户端和服务端一端不支持h2,会自动降级为http1.1) 你需要在maven仓库里下载alpn-boot这个jar包,并把它的配置写入到JVM_ARGS配置里。
需要注意的是:下载的apln-boot的版本必须跟你的java版本有对应关系。 比如jvm是1.8.0_144,需要对应alpn-boot和jvm版本的对照表,下载相应的apln-boot版本8.1.11.v20170118。
OpenJDK version ALPN version
1.7.0u40 7.1.0.v20141016
1.7.0u45 7.1.0.v20141016
1.7.0u51 7.1.0.v20141016
1.7.0u55 7.1.0.v20141016
1.7.0u60 7.1.0.v20141016
1.7.0u65 7.1.0.v20141016
1.7.0u67 7.1.0.v20141016
1.7.0u71 7.1.2.v20141202
1.7.0u72 7.1.2.v20141202
1.7.0u75 7.1.3.v20150130
1.7.0u76 7.1.3.v20150130
1.7.0u79 7.1.3.v20150130
1.7.0u80 7.1.3.v20150130
1.8.0 8.1.0.v20141016
1.8.0u05 8.1.0.v20141016
1.8.0u11 8.1.0.v20141016
1.8.0u20 8.1.0.v20141016
1.8.0u25 8.1.2.v20141202
1.8.0u31 8.1.3.v20150130
1.8.0u40 8.1.3.v20150130
1.8.0u45 8.1.3.v20150130
1.8.0u51 8.1.4.v20150727
1.8.0u60 8.1.5.v20150921
1.8.0u65 8.1.6.v20151105
1.8.0u66 8.1.6.v20151105
1.8.0u71 8.1.7.v20160121
1.8.0u72 8.1.7.v20160121
1.8.0u73 8.1.7.v20160121
1.8.0u74 8.1.7.v20160121
1.8.0u77 8.1.7.v20160121
1.8.0u91 8.1.7.v20160121
1.8.0u92 8.1.8.v20160420
1.8.0u101 8.1.9.v20160720
1.8.0u102 8.1.9.v20160720
1.8.0u111 8.1.9.v20160720
1.8.0u112 8.1.10.v20161026
1.8.0u121 8.1.11.v20170118
对照表还是国内找的,eclipse官网找不到。。。
https://www.jianshu.com/p/2e69cfb99f95?utm_campaign=maleskine
准备:
1.8.0_45.dmg
https://www.oracle.com/java/technologies/javase/javase8-archive-downloads.html
java -version
Picked up _JAVA_OPTIONS: -Djava.net.preferIPv4Stack=true -Dfile.encoding=UTF-8
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
1.8.0u45 8.1.3.v20150130
https://mvnrepository.com/artifact/org.mortbay.jetty.alpn/alpn-boot/8.1.3.v20150130
按照github上okhttp3来尝试
https://github.com/square/okhttp/issues/2837
代码测试验证:
log.info("请求完成, protocol={}, code={}", response.protocol(),response.code);
要是就是协议打印出来跟JDK9一样
15:23:37.630|INFO|[XqProxySelectTest.java:66]|请求完成, protocol=h2, code=200
15:23:45.371|INFO|[XqProxySelectTest.java:66]|请求完成, protocol=h2, code=200
15:23:47.898|INFO|[XqProxySelectTest.java:66]|请求完成, protocol=h2, code=200
15:23:50.471|INFO|[XqProxySelectTest.java:66]|请求完成, protocol=h2, code=200
15:23:53.735|INFO|[XqProxySelectTest.java:66]|请求完成, protocol=h2, code=200
15:24:00.722|INFO|[XqProxySelectTest.java:66]|请求完成, protocol=h2, code=200
15:24:07.203|INFO|[XqProxySelectTest.java:66]|请求完成, protocol=h2, code=200
15:24:16.924|INFO|[XqProxySelectTest.java:66]|请求完成, protocol=h2, code=200
这个是JDK8的
15:24:59.605|INFO|[XqProxySelectTest.java:66]|请求完成, protocol=http/1.1, code=200
15:25:01.625|INFO|[XqProxySelectTest.java:66]|请求完成, protocol=http/1.1, code=403
15:25:03.652|INFO|[XqProxySelectTest.java:66]|请求完成, protocol=http/1.1, code=403
15:25:05.754|INFO|[XqProxySelectTest.java:66]|请求完成, protocol=http/1.1, code=200
15:25:07.882|INFO|[XqProxySelectTest.java:66]|请求完成, protocol=http/1.1, code=200
15:25:09.915|INFO|[XqProxySelectTest.java:66]|请求完成, protocol=http/1.1, code=403
15:25:11.970|INFO|[XqProxySelectTest.java:66]|请求完成, protocol=http/1.1, code=403
15:25:13.996|INFO|[XqProxySelectTest.java:66]|请求完成, protocol=http/1.1, code=403
15:25:16.030|INFO|[XqProxySelectTest.java:66]|请求完成, protocol=http/1.1, code=403
add JAVA VMOption:
-Xbootclasspath/p:${BASE}/lib/alpn-boot-8.1.3.v20150130.jar
15:36:09.078|INFO|[XqProxySelectTest.java:66]|请求完成, protocol=h2, code=200
15:36:11.382|INFO|[XqProxySelectTest.java:66]|请求完成, protocol=h2, code=200
15:36:13.722|INFO|[XqProxySelectTest.java:66]|请求完成, protocol=h2, code=200
15:36:16.064|INFO|[XqProxySelectTest.java:66]|请求完成, protocol=h2, code=200
15:36:18.389|INFO|[XqProxySelectTest.java:66]|请求完成, protocol=h2, code=200
15:36:20.716|INFO|[XqProxySelectTest.java:66]|请求完成, protocol=h2, code=200
15:36:23.030|INFO|[XqProxySelectTest.java:66]|请求完成, protocol=h2, code=200
15:36:25.362|INFO|[XqProxySelectTest.java:66]|请求完成, protocol=h2, code=200
15:36:27.676|INFO|[XqProxySelectTest.java:66]|请求完成, protocol=h2, code=200
15:36:29.994|INFO|[XqProxySelectTest.java:66]|请求完成, protocol=h2, code=200
15:36:32.331|INFO|[XqProxySelectTest.java:66]|请求完成, protocol=h2, code=200
15:36:34.647|INFO|[XqProxySelectTest.java:66]|请求完成, protocol=h2, code=200
15:36:36.985|INFO|[XqProxySelectTest.java:66]|请求完成, protocol=h2, code=200
完成!!!!!
这篇关于JDK8升级JDK9 HTT2 TLS问题解决之路(艰辛)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!