Error on HTTP API Request

Forum to discuss the new web client version of Servoy.

Error on HTTP API Request

Postby derk.hulshof » Fri May 17, 2019 9:37 am

Hi all,
I connect to an external API url to resolve some data.

Now in my Developer it works fine. On a test server with same it works fine.
When I use it on my production server it gives me errors.

Servoy 8.1.4 (cannot use 2019.03 because of logging incompatibility)
Apache Tomcat/8.0.28

What could be the problem?

My code is:
var _url = "https://api.somesite.com";
var _client = plugins.http.createNewHttpClient()
var _post = _client.createPostRequest( _url )
var _xmlpost = '<?xml version="1.0" encoding="utf-8"?>' +
'<request>'+
'<client>[AUTHCLEINT]</client>' +
'<username>[USERNAME]</username>' +
'<password>[PASSWORD]</password>' +
'</request>';
_post.setBodyContent( _xmlpost , 'text/xml' )
var _response = _post.executeRequest();
var _answer = _response.getResponseBody();

// handle data from _answer variable .................



Error:
org.mozilla.javascript.EcmaError: TypeError: Cannot call method "getResponseBody" of (app_core/scopes/api/API_Connect#83)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3772)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3756)
at org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3777)
at org.mozilla.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3793)
at org.mozilla.javascript.ScriptRuntime.undefCallError(ScriptRuntime.java:3809)
at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThisHelper(ScriptRuntime.java:2289)
at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2283)
at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1543)
at script.API_Connect(app_core/scopes/api/API_Connect:83)
derk.hulshof
 
Posts: 108
Joined: Tue Dec 03, 2013 9:18 am
Location: Netherlands

Re: Error on HTTP API Request

Postby rgansevles » Fri May 17, 2019 10:31 am

When an error occurs in the posting, the http plugin seems to log the error and return null.

You should see an error on the admin page or in the servoy_log.txt file.

Rob
Rob Gansevles
Servoy
User avatar
rgansevles
 
Posts: 1927
Joined: Wed Nov 15, 2006 6:17 pm
Location: Amersfoort, NL

Re: Error on HTTP API Request

Postby derk.hulshof » Fri May 17, 2019 10:49 am

Hi Rob,
I checked the servoy_log and at the same time with same seconds there was another error.

The production server runs with a SSL certificate and the test doesnt.
Could this be the problem?
Whats the best way to solve this?

I found something on installing a certificate in the Java environment, but should this be the SSL certificate of the tomcat server, or the api server. The api server doensnt have a SSL certificate or something like that.

EDIT: I installed the api site certificate in java. Hopefully after a restart this weekend it will work

2019-05-17 09:48:39,203 ERROR [Executor,uuid:524e070f-d1ec-427b-bd9d-b8860d516f17] com.servoy.j2db.util.Debug - Throwable [516A3A7E-CA43-44AA-8362-B8074D342FA2 ibisng]
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.server.ngclient.component.EventExecutor.executeEvent(EventExecutor.java:215)
at com.servoy.j2db.server.ngclient.DataAdapterList.executeEvent(DataAdapterList.java:111)
at com.servoy.j2db.server.ngclient.WebFormComponent$FormcomponentEventHandler.executeEvent(WebFormComponent.java:257)
at org.sablo.BaseWebObject.doExecuteEvent(BaseWebObject.java:143)
at org.sablo.BaseWebObject.executeEvent(BaseWebObject.java:132)
at org.sablo.services.server.FormServiceHandler.executeEvent(FormServiceHandler.java:137)
at com.servoy.j2db.server.ngclient.NGFormServiceHandler.executeEvent(NGFormServiceHandler.java:443)
at org.sablo.services.server.FormServiceHandler.executeMethod(FormServiceHandler.java:84)
at com.servoy.j2db.server.ngclient.NGFormServiceHandler.executeMethod(NGFormServiceHandler.java:431)
at org.sablo.websocket.WebsocketEndpoint$5.run(WebsocketEndpoint.java:323)
at org.sablo.eventthread.Event$1.run(Event.java:100)
at org.sablo.websocket.CurrentWindow.runForWindow(CurrentWindow.java:77)
at org.sablo.eventthread.Event.execute(Event.java:90)
at org.sablo.eventthread.EventDispatcher.dispatch(EventDispatcher.java:125)
at org.sablo.eventthread.EventDispatcher.run(EventDispatcher.java:89)
at com.servoy.j2db.server.ngclient.eventthread.NGEventDispatcher.run(NGEventDispatcher.java:55)
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)
... 50 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.provider.certpath.SunCertPathBuilder.build(Unknown Source)
at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(Unknown Source)
at java.security.cert.CertPathBuilder.build(Unknown Source)
... 58 more
2019-05-17 09:48:39,203 ERROR [Executor,uuid:524e070f-d1ec-427b-bd9d-b8860d516f17] com.servoy.j2db.util.Debug - Throwable, script stacktrace:
at app_core/scopes/api/API_Connection_Authenticate:144 (API_Connection_Authenticate)
at app_core/scopes/api/API_Connect:78 (API_Connect)
at app_core/scopes/api/apiGetList_Bookings:899 (apiGetList_Bookings)
at ibisng/forms/agenda_vw/onActionImportWeek:296 (onActionAPIImportWeek)
[516A3A7E-CA43-44AA-8362-B8074D342FA2 ibisng]
2019-05-17 09:48:39,203 ERROR [Executor,uuid:524e070f-d1ec-427b-bd9d-b8860d516f17] com.servoy.j2db.util.Debug - TypeError: Cannot call method "getResponseBody" of (app_core/scopes/api/API_Connect#83) [516A3A7E-CA43-44AA-8362-B8074D342FA2 ibisng]
org.mozilla.javascript.EcmaError: TypeError: Cannot call method "getResponseBody" of (app_core/scopes/api/API_Connect#83)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3772)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3756)
at org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3777)
at org.mozilla.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3793)
at org.mozilla.javascript.ScriptRuntime.undefCallError(ScriptRuntime.java:3809)
at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThisHelper(ScriptRuntime.java:2289)
at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2283)
etc................................................
derk.hulshof
 
Posts: 108
Joined: Tue Dec 03, 2013 9:18 am
Location: Netherlands

Re: Error on HTTP API Request

Postby derk.hulshof » Mon Oct 14, 2019 11:58 am

Still have this problem.
Only from https (production server) to https (external api call)

I can only discover the following log message:
Exception, see log file for full details: 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

I have the site certificate in my jvm cacert.
Anyone got any clue?
derk.hulshof
 
Posts: 108
Joined: Tue Dec 03, 2013 9:18 am
Location: Netherlands


Return to Servoy NGClient

Who is online

Users browsing this forum: No registered users and 4 guests