B4J Question HTTPjob

Philip Prins

Active Member
Licensed User
Longtime User
I use the same code as with B4A but get a authentication error
B4X:
 gDeviceType.Initialize("gDeviceType", Me)
    gDeviceType.Username= User
    gDeviceType.Password= Password
    gDeviceType.Download("https://backend.sigfox.com/api/devicetypes/"& ID & "/devices?")

Error
Program started.

javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
at sun.security.ssl.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:397)
at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:128)
at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:339)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:123)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:147)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:101)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:381)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:576)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:554)
at anywheresoftware.b4a.http.HttpClientWrapper.executeWithTimeout(HttpClientWrapper.java:309)
at anywheresoftware.b4a.http.HttpClientWrapper.access$0(HttpClientWrapper.java:307)
at anywheresoftware.b4a.http.HttpClientWrapper$ExecuteHelper.run(HttpClientWrapper.java:208)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
JobName = gDevices, Success = false
Error: javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated

Is there a difference between authentication on B4A and B4J?
(Firewall and antivirus disabled)
 

Philip Prins

Active Member
Licensed User
Longtime User
You can call HttpClient.InitializeAcceptAll. Add HttpUtils2 modules instead of HttpUtils2 library and change HttpUtils2Service.Initialize.
Hello Erel,

Still get an error, can you look at my code?
Program started.
httputils2service._initialize (java line: 79)
java.lang.NoSuchMethodException: org.apache.http.conn.ssl.SSLSocketFactory.<init>(javax.net.ssl.SSLSocketFactory)
at java.lang.Class.getConstructor0(Class.java:2810)
at java.lang.Class.getConstructor(Class.java:1718)
at anywheresoftware.b4a.http.HttpClientWrapper.InitializeAcceptAll(HttpClientWrapper.java:125)
at b4j.example.httputils2service._initialize(httputils2service.java:79)
at b4j.example.httpjob._initialize(httpjob.java:178)
at b4j.example.main._appstart(main.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
at b4j.example.main.start(main.java:33)
at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:216)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:176)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:176)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:17)
at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:67)
at java.lang.Thread.run(Thread.java:744)


Sub Process_Globals
Private hc As HttpClient
Private TaskIdToJob As Map
Public TempFolder As String
Private taskCounter As Int
End Sub

Sub Initialize
If hc.IsInitialized = False Then
TempFolder = File.DirTemp
'hc.Initialize("hc")
hc.InitializeAcceptAll("hc")
TaskIdToJob.Initialize
End If
End Sub
 
Upvote 0
Top