我正在使用Java和Netbeans從http://webservices.nbs.rs/CommunicationOfficeSiteDoc/SerCyrl/default.html上給出的web服務中獲取數據,我使用的是https://webservices.nbs.rs/CommunicationOfficeService1_0/CompanyAccountXmlService.asmx?WSDL這是一個。它是公司用來獲取有關塞爾維亞國家銀行Web服務。 我從他們那裏得到了一個用戶名密碼和一個許可證密鑰。我早先在php中做過這樣的事情,所以我有一些庫,一切都很好,現在仍然如此。現在我需要在一個java桌面應用程序中做這個...在使用php的同時,我不需要任何證書來安裝,現在我認爲我這樣做是通過使用keytool -import -keystore cacerts -file Bank.cer
將證書導入到可信的jar證書中。 這些步驟如下:java Netbeans web服務WSDL客戶端
詞根記憶中的Java項目新的Web服務
2.Now NetBeans將生成Web服務接入代碼
3.我把我從銀行 在生成的類得到了數據
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "AuthenticationHeader", propOrder = {
"This is where I put mu userName",
"This is where I put mu userName password",
"This is where I put mu userName licenceID"
})
4.I拖動的方法,我需要我得到生成的代碼,而我添加的代碼
public class BankWebService {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String mycompany=getCompanyAccountByNationalIdentificationNumber(107286472);
System.out.println(mycompany);
// TODO code application logic here
}
private static String getCompanyAccountByNationalIdentificationNumber(long nationalIdentificationNumber) {
rs.nbs.communicationoffice.CompanyAccountXmlService service = new rs.nbs.communicationoffice.CompanyAccountXmlService();
rs.nbs.communicationoffice.CompanyAccountXmlServiceSoap port = service.getCompanyAccountXmlServiceSoap();
return port.getCompanyAccountByNationalIdentificationNumber(nationalIdentificationNumber);
}
}
了幾行,我得到一個不錯的結果爲:
Exception in thread "main" com.sun.xml.internal.ws.client.ClientTransportException: HTTP transport 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
at com.sun.xml.internal.ws.transport.http.client.HttpClientTransport.getOutput(HttpClientTransport.java:117)
at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:194)
at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:122)
at com.sun.xml.internal.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:95)
at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:626)
at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:585)
at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:570)
at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:467)
at com.sun.xml.internal.ws.client.Stub.process(Stub.java:308)
at com.sun.xml.internal.ws.client.sei.SEIStub.doProcess(SEIStub.java:146)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:98)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:129)
at com.sun.proxy.$Proxy30.getCompanyAccountByNationalIdentificationNumber(Unknown Source)
at bankwebservice.BankWebService.getCompanyAccountByNationalIdentificationNumber(BankWebService.java:25)
at bankwebservice.BankWebService.main(BankWebService.java:17)
Caused by: 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
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1886)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:276)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:270)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1341)
at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:153)
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:868)
at sun.security.ssl.Handshaker.process_record(Handshaker.java:804)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1016)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1312)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1339)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1323)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:515)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1090)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250)
at com.sun.xml.internal.ws.transport.http.client.HttpClientTransport.getOutput(HttpClientTransport.java:105)
... 15 more
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:385)
at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:292)
at sun.security.validator.Validator.validate(Validator.java:260)
at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:326)
at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:231)
at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:126)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1323)
... 27 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:196)
at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:268)
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:380)
... 33 more
IS有一個簡單的方法來做到這一點在NETBEANS,並使其工作!