我试图从一个独立的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服务器吗?但是这个应用程序没有Web服务器。
答案 0 :(得分:3)
我不得不深入研究解决这个问题。我遇到的问题是可信证书问题。首先,我得到了调用服务所需的证书(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");
以上几行代码确保在WS调用期间为SSL调用设置trustStore
和keyStore
。
这并不容易,因此我在这里提供了解释和答案,以便在某些人确实遇到同样问题的情况下,他/她可以将其作为参考来缓解他们的问题。干杯!
答案 1 :(得分:2)
将以下行作为程序的第一行。这将解决问题。 System.setProperty(“com.ibm.SSL.ConfigURL”,“file:C:\ IBM \ WebSphere \ AppServer \ profiles \ AppSrv01 \ properties \ ssl.client.props”);
答案 2 :(得分: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"));
}
}
WeberviceClient代码
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;
}