我需要帮助,使用Java应用程序使用SOAP服务时遇到上述错误,但是我的SOAPUI能够使用它。 我已经生成了JKS令牌并提取了公共证书,并将其导入到JKS文件中,并确保错误不是来自那个天使。
public class TestSample {
public static void main(String[] args) {
List<TransactionExport> transactionExports = null;
TransactionExportTransactionType type = TransactionExportTransactionType.NEW;
try {
transactionExports = getTransactionExportTransactions(type.NEW, "adey20939", "hatteiir6434b");
} catch (Exception e) {
e.printStackTrace();
}
}
private static List<TransactionExport> getTransactionExportTransactions(TransactionExportTransactionType type, String companyUserName, String companyPassword) throws WebServiceException, WebServiceValidationException {
SimpleTransactionExportService service = new SimpleTransactionExportService();
SimpleTransactionExportServiceDelegate port = service.getSimpleTransactionExportServicePort();
((BindingProvider) port).getRequestContext().put("com.sun.xml.ws.transport.https.client.SSLSocketFactory", getSocketFactory());
return port.getTransactionExportTransactions(type, companyUserName, HashPassword.makeSHA1Hash(companyPassword));// this is the error point
}
public static SocketFactory getSocketFactory() {
char[] cert_password = "qweeqtyye".toCharArray();
System.setProperty("javax.net.debug", "ssl");
System.setProperty("com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump", "true");
TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException {
//
}
@Override
public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException {
// Trust always
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
}
};
SSLContext sc = null;
try { // Install the all-trusting trust manager
sc = SSLContext.getInstance("TLS");
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
KeyStore ks = KeyStore.getInstance("JKS");
ks.load(new FileInputStream("C:\\destop\\cert_211118\\token.jks"), cert_password);
kmf.init(ks, cert_password);
// Create empty HostnameVerifier
HostnameVerifier hv = new HostnameVerifier() {
public boolean verify(String string, SSLSession ssls) {
return true;
}
};
sc.init(kmf.getKeyManagers(), null, null);
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(hv);
} catch (Exception er) {
er.printStackTrace();
}
return sc.getSocketFactory();
}
}
错误:
com.sun.xml.internal.ws.client.ClientTransportException: The server sent HTTP status code 400: Bad Request
at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.checkStatusCode(HttpTransportPipe.java:310)
at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.createResponsePacket(HttpTransportPipe.java:259)
at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:217)
at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:130)
at com.sun.xml.internal.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:95)
at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:1121)
at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:1035)
at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:1004)
at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:862)
at com.sun.xml.internal.ws.client.Stub.process(Stub.java:448)
at com.sun.xml.internal.ws.client.sei.SEIStub.doProcess(SEIStub.java:178)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:93)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:77)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:147)
at com.sun.proxy.$Proxy38.getTransactionExportTransactions(Unknown Source)
at com.union.ucollect.services.TestSample.getTransactionExportTransactions(TestSample.java:51)
at com.union.ucollect.services.TestSample.main(TestSample.java:41)
我不知道为什么会出现上述错误。请我需要帮助,我需要快速。预先感谢。