В настоящее время я работаю над SOAP Service Automation в моем продукте.Сервисы SOAP с поддержкой WS-Security.
Это похоже на инструмент SOAP UI, где QE будет тестировать сервисы, мы используем JAVA для достижения автоматизации.
Мне нужно написать отдельный клиент, которыйберет сообщение SOAP из плоского файла (.. \ testdata \ detailInquiry.xml) и DynamillCay добавляет входные данные из таблицы Excel.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<cus:DetailInquiry>
<request>
<com:RequestUID>testdata1</com:RequestUID>
<com:BaseServiceRqVersion>3</com:BaseServiceRqVersion>
<ser:CustomerIdent>testdata2</ser:CustomerIdent>
<ser:CustomerDetailInquiryRqVersion>1</ser:CustomerDetailInquiryRqVersion>
</request>
</cus:DetailInquiry>
</soapenv:Body>
</soapenv:Envelope>
Используемые банки: wss4j-1.6.9.jar, xmlsec-1.3.0.jar Пожалуйста, найдите код Java для чтения плоского файла и добавления заголовка ws-security для связи со службой SOAP.
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
soapPart.setContent(new StreamSource(new FileInputStream("..\\testdata\\detailInquiry.xml")));
Document doc = toDocument(soapMessage); // Question doc is coming as null, why ?
WSSecSignature builder = new WSSecSignature();
WSSecTimestamp timestamp = new WSSecTimestamp();
WSSecHeader wsSecHeader = new WSSecHeader();
wsSecHeader.setMustUnderstand(true);
wsSecHeader.insertSecurityHeader(doc);
WSSecTimestamp wsSecTimeStamp = new WSSecTimestamp();
wsSecTimeStamp.prepare(soapPart);
// wsSecTimeStamp.prependToHeader(wsSecHeader);
Properties cxfProps = new Properties();
cxfProps.setProperty("org.apache.ws.security.crypto.provider", "org.apache.ws.security.components.crypto.Merlin");
cxfProps.setProperty("org.apache.ws.security.crypto.merlin.keystore.type", "jks");
cxfProps.setProperty("org.apache.ws.security.crypto.merlin.keystore.alias", CLIENT_KEYSTORE_ALIAS);
cxfProps.setProperty("org.apache.ws.security.crypto.merlin.keystore.password", CLIENT_KEYSTORE_PASSWORD);
cxfProps.setProperty("org.apache.ws.security.crypto.merlin.keystore.file", CLIENT_KEYSTORE_PATH);
Crypto crypto1 = CryptoFactory.getInstance(cxfProps);
String bstId = builder.getBSTTokenId();
builder.appendBSTElementToHeader(wsSecHeader);
builder.setUserInfo(SIG_USERNAME, SIG_PASSWORD);
// builder.setX509Certificate(cert);
builder.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
builder.setSignatureAlgorithm("http://www.w3.org/2001/04/xmldsig-more#rsa-sha256");
builder.setSigCanonicalization(WSConstants.C14N_EXCL_OMIT_COMMENTS);
builder.setDigestAlgo(WSConstants.SHA1);
builder.setUseSingleCertificate(true);
builder.build(soapPart, crypto1, wsSecHeader);
soapMessage.saveChanges();
soapMessage.writeTo(httpsURLConnection.getOutputStream());
ByteArrayOutputStream out = new ByteArrayOutputStream();
soapMessage.writeTo(out);
message = new String(out.toByteArray(),"UTF-8");
StringBuffer xmlBuf = new StringBuffer(message);
// StringBuffer xmlBuf = new StringBuffer(soapMessage.writeTo());
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
httpsURLConnection.getOutputStream()), xmlBuf.length());
System.out.println("Request: \n" + xmlBuf.toString());
writer.write(xmlBuf.toString());
writer.close();
System.out.println("Request Writer closed");
я получаю следующее исключение:
16:48:32.490 [main] DEBUG org.apache.ws.security.WSSConfig - The provider BC could not be added: org.bouncycastle.jce.provider.BouncyCastleProvider
java.lang.ClassNotFoundException: org.bouncycastle.jce.provider.BouncyCastleProvider
at java.lang.Class.forNameImpl(Native Method)
at java.lang.Class.forName(Class.java:278)
at org.apache.ws.security.util.Loader.loadClass2(Loader.java:271)
at org.apache.ws.security.util.Loader.loadClass(Loader.java:265)
at org.apache.ws.security.util.Loader.loadClass(Loader.java:245)
at org.apache.ws.security.WSSConfig.addJceProvider(WSSConfig.java:817)
at org.apache.ws.security.WSSConfig$4.run(WSSConfig.java:404)
at org.apache.ws.security.WSSConfig$4.run(WSSConfig.java:402)
at java.security.AccessController.doPrivileged(AccessController.java:594)
at org.apache.ws.security.WSSConfig.init(WSSConfig.java:401)
at org.apache.ws.security.WSSConfig.getNewInstance(WSSConfig.java:435)
at org.apache.ws.security.message.WSSecBase.getWsConfig(WSSecBase.java:118)
at org.apache.ws.security.message.WSSecTimestamp.prepare(WSSecTimestamp.java:72)
at com.aci.sat.HTTPSSenderUpdatedSSL.sendRequest(HTTPSSenderUpdatedSSL.java:252)
at com.aci.sat.HTTPSSenderUpdatedSSL.main(HTTPSSenderUpdatedSSL.java:119)
16:48:32.491 [main] DEBUG org.apache.ws.security.WSSConfig - The provider STRTransform was added at position: 11
16:48:32.501 [main] DEBUG org.apache.ws.security.components.crypto.CryptoFactory - Using Crypto Engine [class org.apache.ws.security.components.crypto.Merlin]
16:48:32.504 [main] DEBUG org.apache.ws.security.util.Loader - Trying to find [C:/Users/kthumu/Desktop/Saturn/SOATestProject_SoapUI/ClientKeyDev.jks] using sun.misc.Launcher$AppClassLoader@c37ed64b class loader.
16:48:32.504 [main] DEBUG org.apache.ws.security.util.Loader - Trying to find [C:/Users/kthumu/Desktop/Saturn/SOATestProject_SoapUI/ClientKeyDev.jks] using sun.misc.Launcher$AppClassLoader@c37ed64b class loader.
16:48:32.505 [main] DEBUG org.apache.ws.security.util.Loader - Trying to find [C:/Users/kthumu/Desktop/Saturn/SOATestProject_SoapUI/ClientKeyDev.jks] using ClassLoader.getSystemResource().
16:48:32.507 [main] DEBUG org.apache.ws.security.components.crypto.Merlin - The KeyStore C:/Users/kthumu/Desktop/Saturn/SOATestProject_SoapUI/ClientKeyDev.jks of type jks has been loaded
16:48:32.507 [main] DEBUG org.apache.ws.security.message.WSSecSignature - Beginning signing...
Oct 03, 2018 4:48:32 PM com.sun.xml.internal.messaging.saaj.soap.ver1_2.SOAPPart1_2Impl createEnvelopeFromSource
SEVERE: SAAJ0415: InputStream does not represent a valid SOAP 1.2 Message
Exception sending request: General security error (No certificates for user SystemAdmin were found for signature)
Exception in thread "main" org.apache.ws.security.WSSecurityException: General security error (No certificates for user SystemAdmin were found for signature)
at org.apache.ws.security.message.WSSecSignature.getSigningCerts(WSSecSignature.java:790)
at org.apache.ws.security.message.WSSecSignature.prepare(WSSecSignature.java:168)
at org.apache.ws.security.message.WSSecSignature.build(WSSecSignature.java:362)
at com.aci.sat.HTTPSSenderUpdatedSSL.sendRequest(HTTPSSenderUpdatedSSL.java:274)
at com.aci.sat.HTTPSSenderUpdatedSSL.main(HTTPSSenderUpdatedSSL.java:119)
Может кто-нибудь, пожалуйста, помогите мне в том, что я делаю неправильно. Я работаю над SAAJ, WS-Security дляпервый раз.Пожалуйста, также предложите лучший способ выполнить мое требование, если я нахожусь в неправильном направлении.
Пожалуйста, дайте мне знать, если потребуется, какие-либо дополнительные материалы, чтобы понять проблему.