B4J Tutorial [Server] Building web servers with B4J

Discussion in 'B4J Tutorials' started by Erel, Jan 27, 2014.

Thread Status:
Not open for further replies.
  1. AscySoft

    AscySoft Active Member Licensed User

    Is there a way to register jar file as a windows service and then monitor it?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

  3. AscySoft

    AscySoft Active Member Licensed User

    Last edited: Jun 26, 2014
  4. AscySoft

    AscySoft Active Member Licensed User

    I was able to create a exe, register it as a new service using Erel's link, but as a exe is working fine, not as a service. It cannot start.
     
  5. AscySoft

    AscySoft Active Member Licensed User

    Last edited: Jun 27, 2014
  6. Erel

    Erel Administrator Staff Member Licensed User

  7. AscySoft

    AscySoft Active Member Licensed User

    As I mentioned in post #44 I was able to create an exe from jar file. It works OK like this. However using apache.common.procrun tool, (see link #45 in this post) I was able to install a working windows service that point to my jar server app, without converting this to an exe. Read carefully the syntax on that page for more info.

    The only thing that is not working to well is the "stop" service command. So I must ask Erel (when he have time of course) to modify the main java class generated by build command to include a StopClass signature as in procrun documentation, if it's possible. Erel please see this:<<--StopMethod -default Main -Name of method to be called when service is stopped. It must be static void and have argument (String args[]). Only applies to jvm mode.>>

    I was able to bypass this by setting a 10 sec timeout on stop command, but this is taking >1 minute to stop, generating errors (see stderr logs if you want).

    If somebody wants to install a service this way, I can provide full working batch cmd script.
     
  8. Erel

    Erel Administrator Staff Member Licensed User

  9. AscySoft

    AscySoft Active Member Licensed User

    I see. So easy! I will try at home. Thanks.
    EDIT: Yes it's working real fine. Thanks for pointing me up.
     
    Last edited: Jul 1, 2014
  10. sulsys

    sulsys Member Licensed User

    This works really well. Things I found.
    - If I run the batch file from the jre7\bin directory it works. If I run from another directory pointing back to bin\java.exe I receive a java error.

    - I would like to control the output file path. Is is relative to where the java.exe is located? Can the path be very specific? Such as "D:\uploads"
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    You should be able to start the server from anywhere you like. Which error do you get?
     
  12. avacondios

    avacondios Active Member Licensed User

    Hi , is it possible to use the web server as rest api server? any example?
     
  13. Erel

    Erel Administrator Staff Member Licensed User

  14. avacondios

    avacondios Active Member Licensed User

    hi again, does it supports any type for user authentication ?
    Thanks Erel, how about the webclient authentication, before to access a Restful API server, written on B4J ? Do we have any example ? The scenario is the following : User to call the GetAuthentication API function and the B4J, to return a unique token, so to evaluate for the next restful API calls ( example, GetCustomers)

    BR/Antonis
     
  15. Erel

    Erel Administrator Staff Member Licensed User

    You will need to implement the authentication process. You can use sessions to "remember" that the user has authenticated.

    There is a secure log-in example as part of the examples.
     
  16. aaronk

    aaronk Well-Known Member Licensed User

    I understand that the code/example in post 1 doesn't work with PHP scripts but is there a way to allow PHP scripts ?
     
  17. Erel

    Erel Administrator Staff Member Licensed User

    Not sure that I understand your question. B4J servers cannot run PHP scripts.
     
  18. aaronk

    aaronk Well-Known Member Licensed User

    I think you answered my question. I was hoping to use PHP with this but looks like it can't be done.

    Is there a way to replace text on the page before it gets sent to the user in the browser?
    For example, if I have a page with the following HTML code, how would you replace $test$ with something else before it gets sent to the browser?

    Within the B4J app make it so that the app replaces $test$ with 'hello' before it sends it to the browser

    HTML:
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    </head>
    <body>
        <h1>This is a static page</h1>
        <h1>$test$</h1>
        <a href='/'>Back</a>
    </body>
     
  19. rwblinn

    rwblinn Well-Known Member Licensed User

    Hi,

    have a look at the HelloWorld example in the post here.

    The WebApp is what you are looking for. The principle is that you need to define a selector in the HTML code (as DIV) and then replace during Websocket connection.

    HTML
    Code:
    ...
    <div 
    id="lblhelloworld"></div>
    ...
    B4J
    Code:
    Sub Class_Globals
        
    Private ws As WebSocket
        
    Private lblhelloworld As JQueryElement    'Label showing Hello World
    End Sub
    Code:
    Private Sub WebSocket_Connected (WebSocket1 As WebSocket)
        ws = WebSocket1
        lblhelloworld.setHtml(
    "<H3>Hello World</H3><P>" & DateTime.Date(DateTime.Now) & "&nbsp;" & DateTime.Time(DateTime.Now))
    End Sub
     
    ZJP likes this.
  20. vfafou

    vfafou Active Member Licensed User

    Hello!
    Is it possible to upgrade c3p0 library to 0.9.5 version?
    I have the problem of slow test queries with MySQL.
    Thank you in advance!
     
Thread Status:
Not open for further replies.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice