B4J Question HttpJob and proxy (again)

udg

Expert
Licensed User
Longtime User
Hi All,
the need to comply with a specific "strict" proxy raised again.
To test I'm following what @Erel suggested here.

Since SetProxy and the Java code are on the MainPage of a B4xPages project, I modified the java declaration to "public class MyProxyAuthenticator " (i.e. no more static)
I have three simple questions:
- is it better to call SetProxy from MainPage.Initialize so when its Create method starts the proxy is already properly setup?
- using it in Create, could SetProxy be called in a Wait For statement if turned to a ResumableSub with trailing return Null?
- should I use the format "pa.InitializeNewInstance(GetType(Me) & "$MyProxyAuthenticator" instead of "pa.InitializeNewInstance("<myproject name as from Project/Build Configuration".main$MyProxyAuthenticator" ?
Eventually, to maintain the latter, is the trailing ".main" still valid? No, it should be ".b4xmainpage"

As an update to the original thread, the way we found to "escape" the strict control operated by the proxy was to encapsulate the binary message in a JSON packet.

udg
 
Last edited:

udg

Expert
Licensed User
Longtime User
Do you mean "leave it in Main as you did for the test app"?
That was an option I considered but didn't mention in my list above. I guess I'm too B4xPages-oriented these days..:)

BTW, should it be the first statement in AppStart or anyway preceed the PagesManager one? Thank you.
 
Last edited:
Upvote 0

udg

Expert
Licensed User
Longtime User
Thank you very much.
I asked about PagesManager because I guess that it's the starting point of the whole B4xPages chain.
Since, in my case, I have calls in the MainPage.Create event that make use of http, it should be safer to cal SetProxy before PagesManager.Initialize. At that point, to preserve visual uniformity with standard projects, I will put SetProxy as the first statement in AppStart, just before the "MainForm = Form1" statement
So, it wil go like this:
B4X:
Sub AppStart (Form1 As Form, Args() As String)
    #IF PUBLISH
    Try
        SetProxy("<proxy>.", <port>,"<user>","<password>")
    Catch
        'Log(LastException)
    End Try
    #END IF
    MainForm = Form1
    MainForm.SetFormStyle("UNDECORATED")
    MainForm.Show
    Dim PagesManager As B4XPagesManager
    PagesManager.Initialize(MainForm)
End Sub

ps: probably the try..catch is of little use since a failing proxy authentication makes the sw useless anyway and all the following http calls will fail with log errors.
 
Upvote 0
Top