如何从独立的Java文件调用JAX WS?

The*_*ght 5 java web-services jax-ws

我试图从独立的Java类(包含main方法)调用jax ws Web服务。我已经在SOAP UI中尝试过此方法,并且它返回了响应。

我的Java代码:main()方法内部:

GInformation getGMInfo = new GInformation();
GInformationResult getGMResult = new GInformationResult();

GKService GKProxy = getProxy();

//Set the Request
XMLGregorianCalendar xmlGreg = null;
getGMInfo.setRequestId("");
getGMInfo.setMessageDateTime(xmlGreg);

try {
    //Get the response
    getGMResult = GKProxy.getGInformation(getGMInfo);
    System.out.println("Address: "+getGMResult.getInfo());
} catch (OperationFaultException e) {
    e.printStackTrace();
} catch (SystemFaultException e) {
    e.printStackTrace();
} 
Run Code Online (Sandbox Code Playgroud)

但是它失败并显示如下错误:

org.apache.axis2.AxisFault: WSWS7130E: No Secure Sockets Layer (SSL) configuration is available for the https://mklip.verd.Gin/WS/v2.8 endpoint.

很长时间以来,我一直在试图纠正这一问题,并且濒临发疯的状态。 有人可以告诉我我在做什么错吗?是否有可能从一个独立的Java类调用jax-ws或为此需要Web服务器?但是此应用程序没有Web服务器。

The*_*ght 4

我必须越来越深入地研究才能解决这个问题。我遇到的问题是受信任的证书问题。首先,我获得了调用服务所需的证书(cert1.cer、cert2.cer)。

然后我使用以下步骤在本地集成证书:

1. Place the below cry certificates in the path "C:\Program Files\IBM\SDP\jdk\jre\lib\security"

   cert1.cer, cert2.cer 

2. cacerts is the trusStore file. It's present in :
   C:/Program Files/IBM/SDP/jdk/jre/lib/security/cacerts

3. In command prompt perform the below execution
C:\Program Files\IBM\SDP\jdk\jre\lib\security>"C:\Program Files\IBM\SDP\jdk\jre\bin\keytool" -import -alias cert1 -file cert1.cer -keystore cacerts

4. If it asks keystore password, mention changeit, which is the default keystore password

Enter keystore password: changeit

Trust this certificate? [no]:  yes
Certificate was added to keystore

5. Peform the steps 3 and 4 for the second certificate(cert2.cer).
Run Code Online (Sandbox Code Playgroud)

但这还不够。javax.net.ssl我必须像这样以编程方式设置:

System.setProperty("javax.net.ssl.trustStore", "C:\\Program Files\\IBM\\SDP\\jdk\\jre\\lib\\security\\cacerts");
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
System.setProperty("javax.net.ssl.keyStore", "C:\\Program Files\\IBM\\SDP\\jdk\\jre\\lib\\security\\cacerts");
System.setProperty("javax.net.ssl.keyStorePassword", "changeit");
Run Code Online (Sandbox Code Playgroud)

上述几行代码确保trustStorekeyStore已在 WS 调用期间为 SSL 调用进行设置。

这来之不易,因此我在这里提供了解释和答案,以便万一有人遇到同样的问题,那么他/她可以将其作为参考来缓解他们的问题。干杯!