Wildfly:如何使用JAXWS-RI而不是Apache CXF(仅限WebService客户端) [英] Wildfly: How to use JAXWS-RI instead of Apache CXF (WebService client only)

查看:577
本文介绍了Wildfly:如何使用JAXWS-RI而不是Apache CXF(仅限WebService客户端)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的环境是Maven Project和Wildfly(8.2.1)作为Application Server。我需要的是使用SOAP将传入的REST调用连接到第三方服务器。我需要SSL客户端身份验证;因此,我有自己的KeyStore和TrustStore。因此我创建了自己的SSLContext,并且需要让WebService使用这个SSLContext。

My environment is a Maven Project and Wildfly (8.2.1) as Application Server. What I need is to connect wihin a incoming REST call to a third party server using SOAP. I need SSL Client Authentication; therefore, I have my own KeyStore and TrustStore. I create therefore my own SSLContext and need to let the WebService use this SSLContext.

所有看起来像这样:

// Build SSL context with own KeyManager / TrustManager
SSLContext sc = SSLContext.getInstance("TLS");

KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());

KeyStore ks = KeyStore.getInstance("JKS");
String password = "changeit";
ks.load(getClass().getResourceAsStream("/keystore"), password.toCharArray());

kmf.init(ks, password.toCharArray());

TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(ks);

sc.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);

// Now build webservice client
MyWS_Service service = new MyWS_Service(null, new QName("http://...", "MyWS"));
MyWS port = service.getMyWSSOAP();

BindingProvider bindingProvider = (BindingProvider) port;

// set to use own SSLContext
bindingProvider.getRequestContext().put("com.sun.xml.internal.ws.transport.https.client.SSLSocketFactory", sc.getSocketFactory());
// set endpoint
bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "https://hostname:443/.../...");

// perform request
respObj = port.myRequest(myRequestObj);

如果我从JUnit测试中调用此代码,一切正常。它使用来自JRE的JAXWS-RI。

If I call this code from a JUnit test, all works fine. It uses JAXWS-RI from the JRE.

如果我从Wildfly调用此代码,即从我的传入REST调用,我最终需要触发此请求,它确实不起作用,因为它不使用自己的SSLContext。它使用默认的SSLContext,当然这被第三方SOAP服务器拒绝。我看到它不使用JAXWS-RI而是使用Apache CXF作为JAXWS实现。所以我猜测 bindingProvider.getRequestContext()。put(com.sun.xml.internal.ws.transport.https.client.SSLSocketFactory,sc.getSocketFactory()); 被忽略[为什么?]并没有效果。 (我还尝试了属性名称 com.sun.xml.ws.transport.https.client.SSLSocketFactory [不含内部] - 也没有运气。)

If I call this code from Wildfly, i.e. from my incoming REST call, where I finally need to fire this request, it does not work because it does not use the own SSLContext. It uses the default SSLContext, which of course is rejected by the third party SOAP server. What I see is that it does not use JAXWS-RI but Apache CXF as JAXWS implementation. So I do guess that bindingProvider.getRequestContext().put("com.sun.xml.internal.ws.transport.https.client.SSLSocketFactory", sc.getSocketFactory()); is simply ignored [Why?] and has no effect. (I also tried the property name com.sun.xml.ws.transport.https.client.SSLSocketFactory [without internal] - also with no luck.)

我知道我可以使用 HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory())甚至使用JVM参数 javax.net.ssl.trustStore javax.net.ssl.keyStore (及其相应的密码属性)。由于这会影响所有连接,因此使用此解决方案是不可讨论的;但是,如果我仍然使用它,让我们看看hapens:

I know that I could use HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()) or even use the JVM parameters javax.net.ssl.trustStore, javax.net.ssl.keyStore (and their corresponding password properties). Since this affects all connections, it is out of discussion to use this solution; however, lets look what hapens, if I use it anyway:


  • JUnit用例:它也有效

  • JUnit use case: It also works

Wildfly用例:似乎JAXWS采用SSLContext,但存在SSL异常(来自服务器的警报,CA未知)。这表明在如何建立连接方面甚至存在差异。如果使用JUnit执行代码,为什么它可以工作?这证明KeyStore / TrustStore使用正确的证书正确设置。不是吗?

Wildfly use case: It seems that JAXWS takes the SSLContext, but there is a SSL exception (alert from Server that CA is unknown). This shows that there is even a difference in how to establish the connection. Why is it working, if the code is executed with JUnit? This proofes that the KeyStore / TrustStore is correctly set up with the correct certificates. Isn't it?

编辑:
还有一个证明,问题是Wildfly使用的JAXWS实现:如果我只是执行一个简单的HttpsConnection,它甚至可以在Wildfly中使用我自己的KeyStore / TrustStore:

There is one more proof, that the problem is the JAXWS implementation Wildfly uses: If I just perform a simple HttpsConnection, it even works with my own KeyStore / TrustStore in Wildfly:

url = new URL("https://hostname:443/.../...");
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
con.setSSLSocketFactory(sc.getSocketFactory());
System.out.println(Utils.inputStreamToString(con.getInputStream()));

那么最好做什么? - >作为问题标题,我想尝试使Wildfly也使用JAXWS-RI而不是Apache CXF。但是直到现在我才开始工作。我试图将以下依赖项放在pom中:

So what is the best to do? -> As the question titles, I would like to try to bring Wildfly to also use JAXWS-RI rather than Apache CXF. But I got it not to work until now. I tried to put the following dependency in the pom:

    <dependency>
        <groupId>com.sun.xml.ws</groupId>
        <artifactId>jaxws-rt</artifactId>
        <version>2.2.10</version>
    </dependency>

但是这给了我以下例外:

But this gives me the following exception:

java.util.ServiceConfigurationError: javax.xml.ws.spi.Provider: Provider com.sun.xml.ws.spi.ProviderImpl could not be instantiated
    at java.util.ServiceLoader.fail(ServiceLoader.java:232) ~[?:1.8.0_92]

什么是错的?如何以相同的方式使Wildfly工作,就好像代码是从同一个项目执行但作为JUnit测试?

What is wrong? How can I bring Wildfly to work the same way, as if the code is executed from the same project but "as a JUnit Test"?

编辑:
如果您有一个提示如何以不同的方式达到目标(使用带有客户端身份验证的SSL在Wildfly 8.2.1上发送SOAP请求)(前提是它是一个干净的Java EE解决方案 - 即不发送拥有自己的XML机构:-)而不是像Axis 1那样过于古老的framworks,也欢迎! 我确实需要一个解决方案 - 我已经好几天了...

推荐答案

好的,最后,我放弃了尝试替换使用的JAX-WS实现。我得到了正确设置Apache CXF。

OK, finally, I gave up to try to replace the JAX-WS implementation used. I got it to correctly setup Apache CXF.

https:// stackoverflow。 com / a / 37268853/4106030

这篇关于Wildfly:如何使用JAXWS-RI而不是Apache CXF(仅限WebService客户端)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆