[英]com.sun.xml.ws.client.ClientTransportException: HTTP transport error: java.lang.ClassCastException
[英]Wildfly's JAXWS implementation seems to ignore bindingProvider property com.sun.xml.ws.transport.https.client.SSLSocketFactory
我的環境是Maven Project和Wildfly(8.2.1)作為Application Server。 我需要的是使用SOAP將傳入的REST調用連接到第三方服務器。 我需要SSL客戶端身份驗證; 因此,我有自己的KeyStore和TrustStore。 因此,我創建了自己的SSLContext,並且需要讓WebService使用此SSLContext。
Wildfly有一個問題,它使用了JAXWS(Apache CXF?)的實現 - 我在這里描述了它(但是用另一個方法來解決問題;因此它不是重復的帖子! ):
Wildfly:如何使用JAXWS-RI而不是Apache CXF(僅限WebService客戶端)
其中一個主要問題似乎是Wildfly中使用的JAXWS似乎忽略了使用屬性com.sun.xml.internal.ws.transport.https.client.SSLSocketFactory
設置自己的SSLContext:
MyWS_Service service = new MyWS_Service(null, new QName("http://...", "MyWS"));
MyWS port = service.getMyWSSOAP();
BindingProvider bindingProvider = (BindingProvider) port;
bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "https://hostname:443/.../...");
// the following setting is ignored!
bindingProvider.getRequestContext().put("com.sun.xml.internal.ws.transport.https.client.SSLSocketFactory", mySslSocketFactory);
// in some posts, we see that we need to eliminate 'internal' in the property. This does not help!
bindingProvider.getRequestContext().put("com.sun.xml.ws.transport.https.client.SSLSocketFactory", mySslSocketFactory);
忽略它的證據是,如果我使用HttpsURLConnection.setDefaultSSLSocketFactory(mySslSocketFactory)
來設置SSLContext,它確實有效 - 意味着SSL連接已建立,這要歸功於導入的根CA到SSLContext中的自定義TrustStore設置。
如果我們查看其他帖子(例如, 如何以編程方式設置JAX-WS客戶端的SSLContext? ),這個屬性應該可以工作(即使對Wildfly也有一些評論)。 但它不適合我的情況。 這可能是什么原因?
問題是Apache CXF忽略了這個問題
bindingProvider.getRequestContext().put(
"com.sun.xml.[internal.]ws.transport.https.client.SSLSocketFactory", mySslSocketFactory);
在某些評論的相反位置。
所以我的最終解決方案是以編程方式設置所使用的HTTPConduit
(而不是在cxf.xml
文件中設置配置)。
// Set custom SSLContext.
HTTPConduit conduit = (HTTPConduit) ClientProxy.getClient(port).getConduit();
TLSClientParameters tlsClientParameters = new TLSClientParameters();
tlsClientParameters.setSSLSocketFactory(customSSLContext.getSocketFactory());
conduit.setTlsClientParameters(tlsClientParameters);
我希望這可以幫助有類似問題的人......
使用Wildfly 10的HTTPConduit
解決方案時,我不得不添加jboss-deployment-structure.xml
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="org.jboss.ws.cxf.jbossws-cxf-client" services="import" />
<module name="org.apache.cxf.impl" export="true">
<imports>
<include path="META-INF" />
<include path="META-INF/cxf" />
<include path="META-INF/services" />
</imports>
</module>
</dependencies>
</deployment>
</jboss-deployment-structure>
我對Widfly 8.2.1的解決方案:
1)使用com.sun.xml.ws.spi.ProviderImpl行添加文件src / main / resources / META-INF / services / javax.xml.ws.spi.Provider
2)添加maven依賴:
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.2.8</version>
</dependency>
3)以這種方式添加SSLSocketFactory:
bindingProvider.getRequestContext().put("com.sun.xml.ws.transport.https.client.SSLSocketFactory", mySslSocketFactory);
Apache CXF忽略JAX-WS屬性。 您可以通過以下方式以編程方式指定TLS客戶端參數:
TLSClientParameters tlsParams = new TLSClientParameters();
tlsParams.setUseHttpsURLConnectionDefaultSslSocketFactory(false);
tlsParams.setSSLSocketFactory(sslSocketFactory);
bindingProvider.getRequestContext().put(TLSClientParameters.class.getName(), tlsParams);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.