HTTPS経由でSOAPサービスを利用したい。私はそれを行うためのクライアントを作成しました。ターゲットサービスは複数のシステムで実行されるため、実行時にサービスURLが変更されるため、自動クラス生成は使用しませんでした。
これは、JAX-WSを使用した実装です。
public class SAPClient implements Callable<...> {
private Service service = null;
private SOAPMessage response = null;
private boolean submitted = false;
private boolean successfull = false;
private QName serviceName;
private QName portName;
private SAPResult result = new SAPResult();
private Dispatch<SOAPMessage> dispatch = null;
private SOAPBody resBody = null;
private SapConnector connector;
public SAPClient(EricAgent agent, SapConnector connector) {
this.connector = connector;
serviceName = new QName(connector.getUrl(), Environment.SAP_CLIENT_SERVICE_NAME);
portName = new QName(connector.getUrl(), Environment.SAP_CLIENT_PORT);
this.service = Service.create(serviceName);
service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, connector.getUrl());
this.successfull = false;
}
(...)
public synchronized void invoke() throws SOAPException {
try {
dispatch = service.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE);
MessageFactory mf = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
SOAPMessage message = mf.createMessage();
SOAPPart part = message.getSOAPPart();
SOAPEnvelope env = part.getEnvelope();
SOAPBody body = env.getBody();
SOAPElement operation = body.addChildElement(
Environment.SAP_CLIENT_OPERATION_NAME,
Environment.SAP_CLIENT_TARGET_NAMESPACE.getPrefix(),
Environment.SAP_CLIENT_TARGET_NAMESPACE.getURI());
// Add ticket
SOAPElement ticketValue = operation.addChildElement("ITicket");
ticketValue.addTextNode(...);
// Add "Informationsprotokoll"
String resultString = buildEricResultString(agent);
SOAPElement xmlValue = operation.addChildElement("IXml");
xmlValue.addTextNode(resultString);
message.saveChanges();
Response<SOAPMessage> sapResponse = dispatch.invokeAsync(message);
long waitingTime = 0;
while (true) {
if (waitingTime > Environment.SAP_CLIENT_TIME_OUT) {
//... handle timeout
}
if (sapResponse.getContext() != null) {
Environment.LOGGER.debug("got response");
response = sapResponse.get();
submitted = true;
successfull = result.returnCode.equals("0");
//...
break;
}
wait(1000);
waitingTime += 1000;
}
} catch (Throwable ex) {
Environment.LOGGER.error(null, ex);
this.submitted = false;
this.successfull = false;
}
}
}
今SSL経由でこのサービスを利用したいです。Service
特定の証明書を使用するようにクラスに指示する方法を教えてください。たとえば、キーストアを渡すにはどうすればよいですか...グーグルで検索しても、満足のいく結果が見つかりませんでした。前もって感謝します!
更新1:
追加することにより:
System.setProperty("javax.net.ssl.keyStore", certPath);
System.setProperty("javax.net.ssl.keyStorePassword", certPass);
SSLを機能させることができました-zuxqojに感謝します!
出力はこのように見え、接続がタイムアウトしました:
keyStore type is : jks
keyStore provider is :
init keystore
init keymanager of type SunX509
trustStore is: ***
trustStore type is : jks
trustStore provider is :
init truststore
adding as trusted cert:
Subject: CN=***, OU=I0020498236, OU=SAP Web AS, O=SAP Trust Community, C=DE
Issuer: CN=***, OU=I0020498236, OU=SAP Web AS, O=SAP Trust Community, C=DE
Algorithm: RSA; Serial number: 0x20120718050810
Valid from Wed Jul 18 07:08:10 CEST 2012 until Fri Jan 01 01:00:01 CET 2038
trigger seeding of SecureRandom
done seeding SecureRandom
Ignoring unavailable cipher suite: TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
Ignoring unavailable cipher suite: TLS_DHE_RSA_WITH_AES_256_CBC_SHA
Ignoring unavailable cipher suite: TLS_ECDH_RSA_WITH_AES_256_CBC_SHA
Ignoring unsupported cipher suite: TLS_DHE_DSS_WITH_AES_128_CBC_SHA256
Ignoring unsupported cipher suite: TLS_DHE_DSS_WITH_AES_256_CBC_SHA256
Ignoring unsupported cipher suite: TLS_DHE_RSA_WITH_AES_128_CBC_SHA256
Ignoring unsupported cipher suite: TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256
Ignoring unsupported cipher suite: TLS_DHE_RSA_WITH_AES_256_CBC_SHA256
Ignoring unsupported cipher suite: TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
Ignoring unsupported cipher suite: TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384
Ignoring unsupported cipher suite: TLS_RSA_WITH_AES_256_CBC_SHA256
Ignoring unavailable cipher suite: TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
Ignoring unsupported cipher suite: TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
Ignoring unsupported cipher suite: TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384
Ignoring unavailable cipher suite: TLS_DHE_DSS_WITH_AES_256_CBC_SHA
Ignoring unsupported cipher suite: TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384
Ignoring unsupported cipher suite: TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256
Ignoring unsupported cipher suite: TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256
Ignoring unavailable cipher suite: TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA
Ignoring unavailable cipher suite: TLS_RSA_WITH_AES_256_CBC_SHA
Ignoring unsupported cipher suite: TLS_RSA_WITH_AES_128_CBC_SHA256
タイムアウトを渡すには、このプロパティをJVMに渡す必要があり、http(s)リクエストは次のように処理されました。
-Djava.net.preferIPv4Stack=true