5

我正在尝试从独立的 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();
} 

但它失败并出现如下错误:

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 服务器吗?但是这个应用程序没有网络服务器。

4

3 回答 3

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).

但这还不够。我必须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");

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

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

于 2013-09-11T08:42:13.240 回答
3

将以下行作为程序的第一行。这将解决问题。System.setProperty("com.ibm.SSL.ConfigURL", "file:C:\IBM\WebSphere\AppServer\profiles\AppSrv01\properties\ssl.client.props");

于 2016-04-06T18:37:29.537 回答
1

您是否尝试将端点地址设置为您的网络服务地址。就我而言,我使用客户端代码从 WSDL 文件生成 jar。

我的测试用例中的一个例子是

public static void main(String[] args){
          SecurityRefServiceLocator securityRefServiceLocator = new SecurityRefServiceLocator();
            securityRefServiceLocator.setSecurityrefPortEndpointAddress("http://xxxxx:13600/my_ss/webservice/refreshSecurity?wsdl");
            WebserviceClient webserviceClient = new WebserviceClient();
            webserviceClient.setSecurityRefServiceLocator(securityRefServiceLocator);
            System.out.println(webserviceClient.refreshSecurity(8798789l,"1114"));

}

}

Webervice客户端代码

public WebServiceReturnCode refreshSecurity(Long securityId, String productId) {

    try{
        SecurityRef securityRef = securityRefServiceLocator.getSecurityrefPort();

        SecurityServiceBindingStub  securityServiceBindingStub=
            (SecurityServiceBindingStub) securityRef;

        securityServiceBindingStub.setUsername("user");
        securityServiceBindingStub.setPassword("password");

        securityServiceBindingStub.setTimeout(timeout);

        SecurityServiceRequest parameter = new SecurityServiceRequest();

        parameter.setMessageId("MSG-" + securityId);
        parameter.setSecurityId(securityId.toString());
        SecurityServiceResponse refreshSecurity = securityRef.refreshSecurity(parameter);
        ResponseType msgResponse = refreshSecurity.getMsgResponse();
        //evaluate msg response and send E200; if fail
        if(msgResponse.equals(ResponseType.SUCCESS)){
            return WebServiceReturnCode.SUCCESS;
        }
        // Response was not favorable
        return "WSE200";

    }catch(Exception e){
        // Exception occurred. Mark this as technical failure to webservice call.
        return "WSE100";
    }finally{
}
}

public SecurityRefServiceLocator getSecurityRefServiceLocator() {
    return securityRefServiceLocator;
}

public void setSecurityRefServiceLocator(
        SecurityRefServiceLocator securityRefServiceLocator) {
    this.securityRefServiceLocator = securityRefServiceLocator;
}
于 2013-09-10T11:48:20.857 回答