我们正在用java开发一个应用程序,几周前我们遇到了一个无法解决的问题。它是对Web服务的调用,以获取带有证书的一系列数据。我们已按照以下步骤创建工件和后续调用
1.我们在windows cmd wsimport -keep https://xxx/xxx/xxx.svc中启动wsimport命令? SingleWsdl -s C:\ Users \ mvelasco \ Documents \ xx \ xxxx \ src \ main \ java -Xauthfile C:\ Users \ mvelasco \ authwsdl.txt它生成一系列具有ws和datacontract结构的类。 enter image description here
keytool -importcert -keystore“C:\ Program Files \ java \ jdk1.7.0_60 \ jre \ lib \ security \ cacerts”-file -alias x
我们使用以下ws调用方法
创建了一个类private static void llamadaAlServicio(){ IDocumentosService port =(new DocumentosService()) .getBasicHttpBindingIDocumentosService(); BindingProvider prov =(BindingProvider)端口; log.error(“Username:”+ ContextProperties.getAsiturWsUsuario()); log.error(“密码:”+ ContextProperties.getAsiturWsPassword());
prov.getRequestContext().put(BindingProvider.USERNAME_PROPERTY,
ContextProperties.getAsiturWsUsuario());
prov.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY,
ContextProperties.getAsiturWsPassword());
ArrayOfAttachmentDTO arrAttachmentDTO = port
.getAllAttachments("1234567");
}
DocumentosService类由JAX-WS
生成@WebServiceClient(name = "DocumentosService", targetNamespace = "http://tempuri.org/", wsdlLocation = "https://xxx/xxx/xxx.svc?singleWsdl") public class DocumentosService extends Service {
private final static URL DOCUMENTOSSERVICE_WSDL_LOCATION;
private final static WebServiceException DOCUMENTOSSERVICE_EXCEPTION;
private final static QName DOCUMENTOSSERVICE_QNAME = new QName("http://tempuri.org/", "DocumentosService");
static {
URL url = null;
WebServiceException e = null;
try {
url = new URL("https://xxx/xxx/xxx.svc?singleWsdl");
} catch (MalformedURLException ex) {
e = new WebServiceException(ex);
}
DOCUMENTOSSERVICE_WSDL_LOCATION = url;
DOCUMENTOSSERVICE_EXCEPTION = e;
}
public DocumentosService() {
super(__getWsdlLocation(), DOCUMENTOSSERVICE_QNAME);
}
public DocumentosService(WebServiceFeature... features) {
super(__getWsdlLocation(), DOCUMENTOSSERVICE_QNAME, features);
}
public DocumentosService(URL wsdlLocation) {
super(wsdlLocation, DOCUMENTOSSERVICE_QNAME);
}
public DocumentosService(URL wsdlLocation, WebServiceFeature... features) {
super(wsdlLocation, DOCUMENTOSSERVICE_QNAME, features);
}
public DocumentosService(URL wsdlLocation, QName serviceName) {
super(wsdlLocation, serviceName);
}
public DocumentosService(URL wsdlLocation, QName serviceName, WebServiceFeature... features) {
super(wsdlLocation, serviceName, features);
}
/**
*
* @return
* returns IDocumentosService
*/
@WebEndpoint(name = "BasicHttpBinding_IDocumentosService")
public IDocumentosService getBasicHttpBindingIDocumentosService() {
return super.getPort(new QName("http://tempuri.org/", "BasicHttpBinding_IDocumentosService"), IDocumentosService.class);
}
/**
*
* @param features
* A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy. Supported features not in the <code>features</code> parameter will have their default values.
* @return
* returns IDocumentosService
*/
@WebEndpoint(name = "BasicHttpBinding_IDocumentosService")
public IDocumentosService getBasicHttpBindingIDocumentosService(WebServiceFeature... features) {
return super.getPort(new QName("http://tempuri.org/", "BasicHttpBinding_IDocumentosService"), IDocumentosService.class, features);
}
private static URL __getWsdlLocation() {
if (DOCUMENTOSSERVICE_EXCEPTION!= null) {
throw DOCUMENTOSSERVICE_EXCEPTION;
}
return DOCUMENTOSSERVICE_WSDL_LOCATION;
}
2018-02-21 18:35:15,614 [Thread-22] [ WARN] (com.sun.xml.internal.ws.wspolicy.EffectiveAlternativeSelector:255) ->
WSP0075:政策断言 “{http://schemas.microsoft.com/ws/06/2004/policy/http} BasicAuthentication” 被评为“未知”。 2018-02-21 18:35:15,615 [Thread-22] [ 警告] (com.sun.xml.internal.ws.wspolicy.EffectiveAlternativeSelector:255) - &gt; WSP0019:在客户端选择的次优策略备选 与健身“未知”。 2018-02-21 18:35:15,666 [Thread-22] [ERROR] (com.noaris.agis.util.DocumentosServiceUtil:116) - &gt; Usernamejavax.xml.ws.security.auth.username 2018-02-21 18:35:15,667 [Thread-22] [ERROR](com.noaris.agis.util.DocumentosServiceUtil:117) - &GT; Passwordjavax.xml.ws.security.auth.password 2018-02-21 18:35:15,667 [Thread-22] [ERROR](com.noaris.agis.util.DocumentosServiceUtil:44) - &gt; Llamada al servicio GetAttachment con los datos:593718000029818 2018-02-21 18:35:15,741 [Thread-22] [ERROR] (com.noaris.agis.util.DocumentosServiceUtil:63) - &gt; HTTP传输 错误:javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException:PKIX路径构建失败: sun.security.provider.certpath.SunCertPathBuilderException:无法 找到所请求目标的有效证书路径2018-02-21 18:35:15,742 [Thread-22] [ERROR] (com.noaris.agis.screens.expedientes.DetalleExpediente_DocumentacionVM:1040) - &GT;错误inesperado durante la obtenci?n datos del servicio DocumentosService para el expediente593718000029818 com.noaris.agis.exception.BusinessException at com.noaris.agis.util.DocumentosServiceUtil.getComunicaciones(DocumentosServiceUtil.java:65)在 com.noaris.agis.screens.expedientes.DetalleExpediente_DocumentacionVM $ DocumentosServiceThread.run(DetalleExpediente_DocumentacionVM.java:1028)
The certificates in the preproduction machines are well installed in the java carcets. Therefore the exception unable to find valid certification path to requested target, we can not understand why it is launched.
On the other hand, two warn "UNKNOWN" appear when it enters the DocumentService class. We think that maybe this may be because when we enter the wsdl we need to get credit in advance. In this case we do not know how to insert the username and password before calling the wsdl ... if necessary.
我们几周来一直坚持这个问题。任何形式的帮助将不胜感激。问候和谢谢
答案 0 :(得分:0)
我认为您的问题在此行中突出显示: SSLHandshakeException:sun.security.validator.ValidatorException:PKIX路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到所请求目标的有效证书路径
在本地Windows计算机上,您具有对密钥库的内置访问权限。但是,从远程计算机上看,此证书不可见。
要快速查看是否属实,请在该网站上放置“hello.html”页面,然后在任何浏览器中检查“https://yourwebpage.com/hello.html”返回的证书。在此之前返回您的预期证书,您的代码将无效。
HTH,Jim