gpt4 book ai didi

java - 在 Java 6 上使用 https 连接到服务的 Jersey 错误

转载 作者:太空宇宙 更新时间:2023-11-03 14:07:26 25 4
gpt4 key购买 nike

我在 Wildfly 9 上使用 https 和使用此 configuration 的自签名证书运行 REST 服务。

为了绕过 ssl 验证,我使用了这段代码:

public static Client createIgnoreSSLClient() {
ClientConfig clientConfig = new ClientConfig();
clientConfig.connectorProvider(new HttpUrlConnectorProvider());
SSLContext sslcontext;
try {
sslcontext = SSLContext.getInstance("SSL");
sslcontext.init(null, new TrustManager[]{new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {}
public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {}
public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; }

}}, new java.security.SecureRandom());
} catch (Exception e) {
throw new RuntimeException(e);
}
return ClientBuilder.newBuilder()
.sslContext(sslcontext)
.hostnameVerifier(createDummyHostnameVerifier())
.withConfig(clientConfig)
.build();
}

我使用 Jersey 2.6 来保持与 Java 6 的兼容性(一些应用程序在 Jboss 4 中运行)。

<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.6</version>
</dependency>

<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
<version>2.6</version>
</dependency>

使用 Java 8 和 7 一切正常。使用 Java 6 我收到此错误:

21/07/2016 16:38:36 org.glassfish.jersey.client.ClientRequest writeEntity
SEVERE: Error while committing the request output stream.
javax.net.ssl.SSLException: Received fatal alert: unexpected_message
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:190)
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:136)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1682)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:932)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1112)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1139)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1123)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:434)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:166)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:904)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:230)
at org.glassfish.jersey.client.HttpUrlConnector$3.getOutputStream(HttpUrlConnector.java:312)
at org.glassfish.jersey.message.internal.CommittingOutputStream.commitStream(CommittingOutputStream.java:200)
at org.glassfish.jersey.message.internal.CommittingOutputStream.commitStream(CommittingOutputStream.java:194)
at org.glassfish.jersey.message.internal.CommittingOutputStream.commit(CommittingOutputStream.java:262)
at org.glassfish.jersey.message.internal.OutboundMessageContext.commitStream(OutboundMessageContext.java:812)
at org.glassfish.jersey.client.ClientRequest.writeEntity(ClientRequest.java:543)
at org.glassfish.jersey.client.HttpUrlConnector._apply(HttpUrlConnector.java:315)
at org.glassfish.jersey.client.HttpUrlConnector.apply(HttpUrlConnector.java:227)
at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:225)
at org.glassfish.jersey.client.JerseyInvocation$2.call(JerseyInvocation.java:671)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:423)
at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:667)
at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:423)
at org.glassfish.jersey.client.JerseyInvocation$Builder.put(JerseyInvocation.java:311)
at com.oki.casi.client.TesteLogin.testeLoginHttps(TesteLogin.java:79)
at com.oki.casi.client.TesteLogin.main(TesteLogin.java:58)
Exception in thread "main" javax.ws.rs.WebApplicationException: HTTP 500 Internal Server Error
at org.eclipse.persistence.jaxb.rs.MOXyJsonProvider.writeTo(MOXyJsonProvider.java:810)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.invokeWriteTo(WriterInterceptorExecutor.java:263)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:250)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162)
at org.glassfish.jersey.message.internal.MessageBodyFactory.writeTo(MessageBodyFactory.java:1154)
at org.glassfish.jersey.client.ClientRequest.writeEntity(ClientRequest.java:500)
at org.glassfish.jersey.client.HttpUrlConnector._apply(HttpUrlConnector.java:315)
at org.glassfish.jersey.client.HttpUrlConnector.apply(HttpUrlConnector.java:227)
at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:225)
at org.glassfish.jersey.client.JerseyInvocation$2.call(JerseyInvocation.java:671)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:423)
at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:667)
at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:423)
at org.glassfish.jersey.client.JerseyInvocation$Builder.put(JerseyInvocation.java:311)
at com.oki.casi.client.TesteLogin.testeLoginHttps(TesteLogin.java:79)
at com.oki.casi.client.TesteLogin.main(TesteLogin.java:58)
Caused by: javax.xml.bind.MarshalException

编辑:我试图通过测试客户端访问两台服务器 Jboss 7.1.1 和 Wildfly 9.0.2 来解决这个问题。

在 Jboss 7 中,我可以让客户端使用 https 将协议(protocol)从 TLSv1 更改为 SSL:

<connector name="https" protocol="HTTP/1.1" scheme="https" socket-binding="https" secure="true">
<ssl name="ciac-ssl" key-alias="ciac-cert" password="123456" certificate-key-file="../standalone/configuration/ciac-cert.keystore" protocol="SSL"/>
</connector>

如何在 Wildfly 中更改此配置?

最佳答案

如果我理解正确,您会在运行于 Java 6 的客户端应用程序中得到 SSLException。在此客户端中,您正尝试访问 Wildfly 9 上托管的服务,该服务使用 Java 7 或更高。这意味着服务器正在使用不同的安全机制。 I stumbled upon the same earlier如您所见,该帖子也没有结论。

如果您仔细想想,为什么要让开发人员创建使用过时且不安全的安全机制的服务成为可能?

最终我们决定更新 JDK。您还可以尝试在 JDK7 下托管 JBoss 4。例如here你可以找到一些关于这个主题的有趣文章。

关于java - 在 Java 6 上使用 https 连接到服务的 Jersey 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38513089/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com