javax.net.ssl.SSLException: 无效的填充长度
javax.net.ssl.SSLException: Invalid Padding length
我在尝试通过 https 执行网络服务时遇到此异常。此异常发生在我尝试获取服务实例的动作中。
我按照以下步骤使用 wsImport.exe 工具生成 Web 服务客户端。
我从站点手动下载了 wsdl
使用 wsImport 工具生成客户端 java 文件
- 将 java 文件添加到我在 eclipse 中的项目
编写如下测试客户端来测试服务实例
public static void main(String[] args) {
String certificatesTrustStorePath = "c:/Apps/Java/jdk1.8.0_25/jre/lib/security/cacerts";
// if I don't set the store path, I get below error
//javax.net.ssl.SSLHandshakeException:
//sun.security.validator.ValidatorException: PKIX path building failed:
//sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
System.setProperty("javax.net.ssl.trustStore", certificatesTrustStorePath);
URL wsdlLocation = null;
String https_url ="https://localhost/services/WebService/wsdl/WebService.wsdl";
try {
wsdlLocation = new URL(https_url);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//This is the line where I get the below execption
WebServiceService webServiceService = new WebServiceService(wsdlLocation,
new QName("http://webservice.com", "WebServiceService"));
}
使用上面的代码我下面执行
Exception in thread "main" com.sun.xml.internal.ws.wsdl.parser.InaccessibleWSDLException: 2 counts of InaccessibleWSDLException.
javax.net.ssl.SSLException: Invalid Padding length: 76
javax.net.ssl.SSLException: Invalid Padding length: 50
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(Unknown Source)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(Unknown Source)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(Unknown Source)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.parseWSDL(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(Unknown Source)
at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(Unknown Source)
at javax.xml.ws.Service.<init>(Unknown Source)
at com.webservice.WebServiceService.<init>(WebServiceService.java:42)
at com.client.Client.main(Client.java:46)
每次执行时,“Invalid Pad length”前面的数字都不一样。这次是 76 和 50。另一次是 67、106。等等
请帮忙,
我使用的是 Java 的最新版本,即 1.8.0_51.
好像是这个问题:https://community.oracle.com/thread/2506695
您尝试过使用 bouncycastle 吗?
Java 8 有这个问题...用 Java 7 测试。相同的代码工作正常。
我在尝试通过 https 执行网络服务时遇到此异常。此异常发生在我尝试获取服务实例的动作中。 我按照以下步骤使用 wsImport.exe 工具生成 Web 服务客户端。
我从站点手动下载了 wsdl
使用 wsImport 工具生成客户端 java 文件
- 将 java 文件添加到我在 eclipse 中的项目
编写如下测试客户端来测试服务实例
public static void main(String[] args) { String certificatesTrustStorePath = "c:/Apps/Java/jdk1.8.0_25/jre/lib/security/cacerts"; // if I don't set the store path, I get below error //javax.net.ssl.SSLHandshakeException: //sun.security.validator.ValidatorException: PKIX path building failed: //sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target System.setProperty("javax.net.ssl.trustStore", certificatesTrustStorePath); URL wsdlLocation = null; String https_url ="https://localhost/services/WebService/wsdl/WebService.wsdl"; try { wsdlLocation = new URL(https_url); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } //This is the line where I get the below execption WebServiceService webServiceService = new WebServiceService(wsdlLocation, new QName("http://webservice.com", "WebServiceService")); }
使用上面的代码我下面执行
Exception in thread "main" com.sun.xml.internal.ws.wsdl.parser.InaccessibleWSDLException: 2 counts of InaccessibleWSDLException.
javax.net.ssl.SSLException: Invalid Padding length: 76
javax.net.ssl.SSLException: Invalid Padding length: 50
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(Unknown Source)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(Unknown Source)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(Unknown Source)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.parseWSDL(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(Unknown Source)
at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(Unknown Source)
at javax.xml.ws.Service.<init>(Unknown Source)
at com.webservice.WebServiceService.<init>(WebServiceService.java:42)
at com.client.Client.main(Client.java:46)
每次执行时,“Invalid Pad length”前面的数字都不一样。这次是 76 和 50。另一次是 67、106。等等
请帮忙, 我使用的是 Java 的最新版本,即 1.8.0_51.
好像是这个问题:https://community.oracle.com/thread/2506695
您尝试过使用 bouncycastle 吗?
Java 8 有这个问题...用 Java 7 测试。相同的代码工作正常。