XML-RPC over SSL in MATLAB

조회 수: 17 (최근 30일)
Benjamin Sunderland
Benjamin Sunderland 2018년 8월 15일
답변: Feyza Boyun 2021년 7월 18일
Hello. I am trying to access a server that uses a xml-rpc communication layer with ssl. The only documentation I have found for xmlrpc in MATLAB is here: https://wiki.nbic.nl/index.php/Matlab_XMLRPC. I have downloaded the following JAR files and added their paths to $matlabroot/toolbox/local/classpath.txt:
  • ws-commons-util-1.0.2.jar
  • xmlrpc-client-3.1.3.jar
  • xmlrpc-common-3.1.3.jar
  • xmlrpc-server-3.1.3.jar
My code looks something like this:
username = 'username';
password = 'password';
ip = '55.555.55.555';
port = 8080;
xmlrpc_url = sprintf('https://%s:%s@%s:%i/',...
username,password,ip,port);
client = javaObject('org.apache.xmlrpc.client.XmlRpcClient')
config = javaObject('org.apache.xmlrpc.client.XmlRpcClientConfigImpl')
url = javaObject('java.net.URL', xmlrpc_url)
config.setServerURL(url)
client.setConfig(config)
client.execute('list.Methods', '')
When I run it I get the following errors:
Java exception occurred:
org.apache.xmlrpc.XmlRpcException: Failed to read server's response:
java.security.cert.CertificateException: No subject alternative names
present
at
org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:161)
at
org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:143)
at
org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java:69)
at
org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:56)
at
org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:167)
at
org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:158)
at
org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:147)
Caused by: javax.net.ssl.SSLHandshakeException:
java.security.cert.CertificateException: No subject alternative names
present
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1959)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:296)
at
sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1514)
at
sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:216)
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:1026)
at sun.security.ssl.Handshaker.process_record(Handshaker.java:961)
at
sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1072)
at
sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1385)
at
sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1413)
at
sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1397)
at
sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
at
sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at
sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1316)
at
sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1291)
at
sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250)
at
org.apache.xmlrpc.client.XmlRpcSunHttpTransport.writeRequest(XmlRpcSunHttpTransport.java:104)
at
org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:151)
... 6 more
Caused by: java.security.cert.CertificateException: No subject
alternative names present
at
sun.security.util.HostnameChecker.matchIP(HostnameChecker.java:145)
at
sun.security.util.HostnameChecker.match(HostnameChecker.java:94)
at
sun.security.ssl.X509TrustManagerImpl.checkIdentity(X509TrustManagerImpl.java:455)
at
sun.security.ssl.X509TrustManagerImpl.checkIdentity(X509TrustManagerImpl.java:436)
at
sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:200)
at
sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:124)
at
sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1496)
... 20 more
Caused by:
javax.net.ssl.SSLHandshakeException:
java.security.cert.CertificateException: No subject alternative names
present
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1959)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:296)
at
sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1514)
at
sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:216)
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:1026)
at sun.security.ssl.Handshaker.process_record(Handshaker.java:961)
at
sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1072)
at
sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1385)
at
sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1413)
at
sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1397)
at
sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
at
sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at
sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1316)
at
sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1291)
at
sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250)
at
org.apache.xmlrpc.client.XmlRpcSunHttpTransport.writeRequest(XmlRpcSunHttpTransport.java:104)
at
org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:151)
at
org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:143)
at
org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java:69)
at
org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:56)
at
org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:167)
at
org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:158)
at
org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:147)
Caused by: java.security.cert.CertificateException: No subject
alternative names present
at
sun.security.util.HostnameChecker.matchIP(HostnameChecker.java:145)
at
sun.security.util.HostnameChecker.match(HostnameChecker.java:94)
at
sun.security.ssl.X509TrustManagerImpl.checkIdentity(X509TrustManagerImpl.java:455)
at
sun.security.ssl.X509TrustManagerImpl.checkIdentity(X509TrustManagerImpl.java:436)
at
sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:200)
at
sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:124)
at
sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1496)
... 20 more
I believe I need to somehow specify the use of SSL, but I know very little about networking or the use of Java classes/methods (much less in a MATLAB environment). Any advice?

답변 (2개)

Benjamin Sunderland
Benjamin Sunderland 2018년 8월 21일
Does anyone have any experience using these xmlrpc JARs in MATLAB? I am able to implement this in Python using the built-in xml-rpc client library, but unfortunately I also need to do it in MATLAB. If it helps provide any context for what I'm trying to do, my solution in Python is of the following form:
import ssl
import xmlrpc.client
username = 'username'
password = 'password'
ip = '55.555.55.555'
port = 8080
context = ssl._create_unverified_context()
transport = xmlrpc.client.SafeTransport(context=context)
api = xmlrpc.client.ServerProxy('https://%s:%s@%s:%d/'%( username, password, ip, port ), transport )
Methods = api.list.methods()
Where list.methods() is just one of the rpc functions for the site I'm trying to access. I just don't know how to configure the xmlrpc client the same way in a MATLAB environment using these JARs.

Feyza Boyun
Feyza Boyun 2021년 7월 18일
fileplace='/location/of/your/jar/files/';
dpath={[fileplace, 'commons-logging-1.1.jar'], ...
[fileplace, 'ws-commons-util-1.0.2.jar'], ...
[fileplace, 'xmlrpc-common-3.1.3.jar'], ...
[fileplace, 'xmlrpc-client-3.1.3.jar'], ...
[fileplace, 'xmlrpc-server-3.1.3.jar'] ...
};
javaclasspath(dpath)
% Setting up the client
client = javaObject('org.apache.xmlrpc.client.XmlRpcClient')
config = javaObject('org.apache.xmlrpc.client.XmlRpcClientConfigImpl')
url = javaObject('java.net.URL', 'http://localhost:(9000/')
config.setServerURL(url)
config.setEnabledForExtensions(true);
config.setConnectionTimeout(60 * 1000);
config.setReplyTimeout(60 * 1000);
client.setConfig(config)
try this, it works for me.

카테고리

Help CenterFile Exchange에서 Call Web Services from MATLAB Using HTTP에 대해 자세히 알아보기

태그

제품


릴리스

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by