B4J Question Web Service connection Error

StarinschiAndrei

Active Member
Licensed User
Longtime User
Hello everybody,
I try to send a request to a web service based on the below description :
Can anybody help me? what is wrong?
Web Service URL (POST):
https://webservicesp.anaf.ro/PlatitorTvaRest/api/v3/ws/tva
Post Body:
[
{
"cui": _Numar_, "data":"_Data interogarii_"
},
{
"cui": _Numar_, "data":"_Data interogarii_"
}
]
Example :
Content-Type: application/json

[
{
"cui": 1234,
"data": "2015-02-14"
},
{
"cui": 5678,
"data": "2015-02-14"
}
]
My code :
B4X:
Sub Submit_Action
    Dim j As HttpJob
    j.Initialize("",Me )
    j.PostMultipart("https://webservicesp.anaf.ro/PlatitorTvaRest/api/v3/ws/tva",CreateMap("cui": 39462862,"data":"2018-08-30"),Null)
    Wait For(j) JobDone(j As HttpJob)
    If j.Success Then
        Log(j.GetString)
    Else
        Log(j.ErrorMessage)     
    End If
    j.Release
End Sub
I receive the following error:
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(Alerts.java:192)
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1964)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:328)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:322)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1614)
at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:216)
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:1052)
at sun.security.ssl.Handshaker.process_record(Handshaker.java:987)
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 okhttp3.internal.connection.RealConnection.connectTls(RealConnection.java:242)
at okhttp3.internal.connection.RealConnection.establishProtocol(RealConnection.java:200)
at okhttp3.internal.connection.RealConnection.buildConnection(RealConnection.java:174)
at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:114)
at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:196)
at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:132)
at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:101)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:120)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:179)
at okhttp3.RealCall.execute(RealCall.java:63)
at anywheresoftware.b4h.okhttp.OkHttpClientWrapper.executeWithTimeout(OkHttpClientWrapper.java:156)
at anywheresoftware.b4h.okhttp.OkHttpClientWrapper.access$0(OkHttpClientWrapper.java:153)
at anywheresoftware.b4h.okhttp.OkHttpClientWrapper$ExecuteHelper.run(OkHttpClientWrapper.java:201)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
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(PKIXValidator.java:397)
at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:302)
at sun.security.validator.Validator.validate(Validator.java:260)
at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:324)
at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:229)
at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:124)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1596)
... 35 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:141)
at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:126)
at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:280)
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:392)
... 41 more
ResponseError. Reason: 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, Response:
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
 

OliverA

Expert
Licensed User
Longtime User
Has nothing to do with the data your posting (even though that is wrong). It has to do with SSL. The site seems to have a valid certificate, but Java does not seem to like it. What version of Java are you using? As to the other error (that has nothing to do with the error you are posting), a map is not a JSON structure.

Edit: See point# 7 in this link (near the bottom of the page): https://confluence.atlassian.com/kb...e-to-pkix-path-building-failed-779355358.html
 
Last edited:
Upvote 0

StarinschiAndrei

Active Member
Licensed User
Longtime User
Has nothing to do with the data your posting (even though that is wrong). It has to do with SSL. The site seems to have a valid certificate, but Java does not seem to like it. What version of Java are you using? As to the other error (that has nothing to do with the error you are posting), a map is not a JSON structure.

Edit: See point# 7 in this link (near the bottom of the page): https://confluence.atlassian.com/kb...e-to-pkix-path-building-failed-779355358.html
Hi , I'm using java version "1.8.0_172". Thank you
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Latest 1.8.0 version is 181
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Well, even version 10 of Java does not like that certificate issued by CertSIGN. You may need to add it as per these instructions: http://onjavadev.com/?p=1197
 
Upvote 0

StarinschiAndrei

Active Member
Licensed User
Longtime User
Hi Oliver , i followed the instruction from you indicated page , and now i receive this error :
ResponseError. Reason: Unsupported Media Type, Response:
Unsupported Media Type
Thank you Oliver for your help , now it's working .
B4X:
Dim j As HttpJob
    j.Initialize("",Me )
    j.PostString("https://webservicesp.anaf.ro/PlatitorTvaRest/api/v3/ws/tva",$"[{"cui": 39462862,"data":"2018-09-02"}]"$)
    j.GetRequest.SetContentType("application/json")
    Wait For(j) JobDone(j As HttpJob)
    If j.Success Then
        Log(j.GetString)
    Else
        Log(j.ErrorMessage)       
    End If
    j.Release
 
Upvote 0
Top