Page 1 of 1

How to connect to an XML-RPC service

PostPosted: Fri Apr 07, 2017 12:52 pm
by Juan Etec
Hi all,
I'm trying to connect to an XML-RPC service via the Http plugin without success.

My response comes as a null value.

Code: Select all
   var urlServer = "https://www.mensajerianegocios.movistar.es/SrvConexion"; // --- Por defecto es producción.
   var _request
   var _poster = plugins.http.createNewHttpClient();
   _request = _poster.createPostRequest(urlServer);

   _request.addHeader("Content-Type", "text/xml");
   _request.addHeader("User-Agent","myXMLRPCClient/1.0");
   
   myXml = '<?xml version="1.0" encoding="ISO-8859-15"?>\
           <methodCall>\
             <methodName>MensajeriaNegocios.enviarSMS</methodName>\
             <params>\
               <param>\
                  <value><string>USERNAME</string></value>\
               </param>\
               <param>\
                  <value><string>MYPASSWORD</string></value>\
               </param>\
              <param>\
                 <value>\
                  <array>\
                     <data>\
                        <value>\
                           <array>\
                              <data>\
                                 <value><int>678535170</int></value>\
                                 <value><string>Texto SMS 1</string></value>\
                                 <value><int>217812</int></value>\
                                 <value><string>JuanETEC</string></value>\
                              </data>\
                           </array>\
                        </value>\
                        <value>\
                           <array>\
                              <data>\
                                 <value><int>678535170</int></value>\
                                 <value><string>Texto SMS 2</string></value>\
                                 <value><string>MiRemitente</string></value>\
                              </data>\
                           </array>\
                        </value>\
                     </data>\
                  </array>\
               </value>\
               </param>\
             </params>\
           </methodCall>'

   _request.addParameter(null, myXml);
   //_request.setBodyContent(myXml,"text/xml")
   var _response = _request.executeRequest()


I have been following this instructions : https://www.tutorialspoint.com/xml-rpc/ ... equest.htm

Can anyone please give me a hand?

Thanks in advance.

Re: How to connect to an XML-RPC service

PostPosted: Fri Apr 07, 2017 1:35 pm
by patrick
Do you have an error in the log? It is very likely a certificate problem.

Re: How to connect to an XML-RPC service

PostPosted: Fri Apr 07, 2017 4:40 pm
by Juan Etec
Yes Patrick this is a certificate problem.
What can I do?
Could you guide me?
I'm Launching the process y a bachtprocessor from a servoy server with a SSL certificate.


Code: Select all
2017-04-07 15:28:27,125 ERROR [BatchProcess: HC_server] com.servoy.j2db.util.Debug - Throwable [A29D9DD3-3DCC-4E33-BE13-4E3CA955832B HC_server]
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(Unknown Source)
   at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
   at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
   at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
   at sun.security.ssl.ClientHandshaker.serverCertificate(Unknown Source)
   at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source)
   at sun.security.ssl.Handshaker.processLoop(Unknown Source)
   at sun.security.ssl.Handshaker.process_record(Unknown Source)
   at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
   at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
   at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
   at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
   at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:535)
   at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:403)
   at com.servoy.extensions.plugins.http.HttpClient$1.connectSocket(HttpClient.java:105)
   at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:177)
   at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:304)
   at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:611)
   at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:446)
   at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:863)
   at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
   at com.servoy.extensions.plugins.http.BaseRequest.executeRequest(BaseRequest.java:212)
   at com.servoy.extensions.plugins.http.BaseRequest.js_executeRequest(BaseRequest.java:138)
   at com.servoy.extensions.plugins.http.BaseRequest.js_executeRequest(BaseRequest.java:124)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:158)
   at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:312)
   at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1774)
   at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:837)
   at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:158)
   at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:406)
   at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3204)
   at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:156)
   at com.servoy.j2db.scripting.ScriptEngine.executeFunction(ScriptEngine.java:664)
   at com.servoy.j2db.scripting.ScopesScope.executeGlobalFunction(ScopesScope.java:193)
   at com.servoy.j2db.FormManager.makeSolutionSettings(FormManager.java:262)
   at com.servoy.j2db.server.headlessclient.WebFormManager.makeSolutionSettings(WebFormManager.java:81)
   at com.servoy.j2db.FormManager$1.run(FormManager.java:151)
   at com.servoy.j2db.server.headlessclient.SessionClient.invokeAndWait(SessionClient.java:931)
   at com.servoy.j2db.server.headlessclient.SessionClient.doInvokeLater(SessionClient.java:921)
   at com.servoy.j2db.ClientState.invokeLater(ClientState.java:1728)
   at com.servoy.j2db.FormManager.propertyChange(FormManager.java:147)
   at java.beans.PropertyChangeSupport.fire(Unknown Source)
   at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
   at javax.swing.event.SwingPropertyChangeSupport.firePropertyChange(Unknown Source)
   at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
   at com.servoy.j2db.J2DBGlobals.firePropertyChange(J2DBGlobals.java:92)
   at com.servoy.j2db.server.headlessclient.SessionClient.solutionLoaded(SessionClient.java:479)
   at com.servoy.j2db.ClientState.loadSolutionsAndModules(ClientState.java:1482)
   at com.servoy.j2db.server.headlessclient.SessionClient.loadSolution(SessionClient.java:286)
   at com.servoy.j2db.server.headlessclient.SessionClient.loadSolution(SessionClient.java:245)
   at com.servoy.j2db.server.headlessclient.HeadlessClientFactoryInternal$1.run(HeadlessClientFactoryInternal.java:86)
   at com.servoy.j2db.server.headlessclient.HeadlessClientFactoryInternal.createSessionBean(HeadlessClientFactoryInternal.java:109)
   at com.servoy.j2db.server.headlessclient.HeadlessClientFactoryInternal.createHeadlessClient(HeadlessClientFactoryInternal.java:52)
   at com.servoy.j2db.server.main.Zy.Zc(Zy.java:12)
   at com.servoy.j2db.server.main.Zx.run(Zx.java:2)
   at java.lang.Thread.run(Unknown Source)
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(Unknown Source)
   at sun.security.validator.PKIXValidator.engineValidate(Unknown Source)
   at sun.security.validator.Validator.validate(Unknown Source)
   at sun.security.ssl.X509TrustManagerImpl.validate(Unknown Source)
   at sun.security.ssl.X509TrustManagerImpl.checkTrusted(Unknown Source)
   at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source)
   at org.apache.http.conn.ssl.SSLContextBuilder$TrustManagerDelegate.checkServerTrusted(SSLContextBuilder.java:190)
   at sun.security.ssl.AbstractTrustManagerWrapper.checkServerTrusted(Unknown Source)
   ... 56 more

Re: How to connect to an XML-RPC service

PostPosted: Fri Apr 07, 2017 6:05 pm
by kwpsd
@Patrick - Just curious...how did you make the leap from 'null return' to 'certificate problem'. I would have interpreted a 'null return' as 'server unavailable' and would have never guessed 'certificate problem'.

Re: How to connect to an XML-RPC service

PostPosted: Fri Apr 07, 2017 6:12 pm
by patrick
Null suggests the connection couldn't even be made, otherwise you would have a response with a success or error. So it either was blocked or failed for other reasons. Https sounds like certificate.

Since you are posting, you will need the certificate, I think. I'm not an expert on this, but the certificate is required, I'd say. That has to be installed in the java environment, which can be done in the Java control panel, Security, Manage certificates. Edit: for web or headless client, that is. The smart client should actually ask you if you want to accept the certificate.

Re: How to connect to an XML-RPC service

PostPosted: Fri Apr 07, 2017 7:01 pm
by kwpsd
Https sounds like certificate.


Ah...I did not pick up on the 'https' in the URL. Now I understand the logic in your thinking. Thanks for the explanation!