Results 1 to 6 of 6
Like Tree2Likes
  • 1 Post By jashburn
  • 1 Post By gimbal2

Thread: Automaticlly getting a web service

  1. #1
    smacker is offline Member
    Join Date
    Jan 2011
    Posts
    46
    Rep Power
    0

    Default Automaticlly getting a web service

    Hello all ,

    i'm trying to make a dynamic web server that will get a specific web service from somewhere once a day +-
    i'm pretty new at the dynamic web thing and not sure on how to make it happen ,
    it supposed to run in the background and updating the DB with it , the DB part will be easy enough
    i used SOAP once but it wasn't automaticlly like in this case ...

    any ideas ?

    thanks to all helpers !

  2. #2
    jashburn is offline Senior Member
    Join Date
    Feb 2014
    Posts
    219
    Rep Power
    1

    Default Re: Automaticlly getting a web service

    On the basic level this can be done by:
    • adding a ServletContextListener to your web server
    • within the ServletContextListener's contextInitialized method, use a scheduler (e.g., ScheduledExecutorService) to execute the code that retrieves data from the web service
    • add code within the contextDestroyed method to shut down the scheduler cleanly when, say, the web server is being restarted, or the web app is being redeployed

    See:

    An Internet search using the search term "run task periodically in web server java" will also give you relevant results.

    Another way is to add the scheduler code to a servlet's init method, and specify the servlet's startup order on web server startup using the load-on-startup element in web.xml. See Web.xml Servlet Configuration.

    For the scheduler, besides ScheduledExecutorService, you can also use a full-blown scheduler such as Quartz.
    smacker likes this.

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,079
    Rep Power
    6

    Default Re: Automaticlly getting a web service

    I don't see any compelling reason to do this using a web server though, using a scheduling application or the scheduling services of the OS to invoke a basic Java application works just as well for the purposes mentioned here.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    smacker is offline Member
    Join Date
    Jan 2011
    Posts
    46
    Rep Power
    0

    Default Re: Automaticlly getting a web service

    i'll try the "the load-on-startup element in web.xml" seems simple enough

    gimbal2 i didn't quite get what you were saying , i'm using a web server because there is a web site one it , did you mean make a diffrent project and make the OS run it on startup ?
    also , thanks to you both !

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,079
    Rep Power
    6

    Default Re: Automaticlly getting a web service

    When did I ever mention anything about server startup? You want to run this at a specific moment of the day don't you? I said -scheduling services-, not server startup :/ The windows scheduler, or the linux cron tool, whatever.

    Just because you have a webserver does not mean that it MUST do your web service-database updating stuff there too, I don't see any relation between this job and your web application unless you have more requirement details you're not telling. If you keep them isolated from each other, you can deploy and run them isolated too. For example: the web server can be offline for maintenance but the tool doing the soap call can still run at its scheduled moment. If either of them misbehaves such as eating up all memory, it won't generally affect the other.
    smacker likes this.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #6
    smacker is offline Member
    Join Date
    Jan 2011
    Posts
    46
    Rep Power
    0

    Default Re: Automaticlly getting a web service

    oh i get it , the server startup was suggested by the other user ,

    but what you're saying makes sence .
    thanks again to you both

Similar Threads

  1. Taking photo automaticlly
    By regularny in forum Android
    Replies: 1
    Last Post: 06-19-2013, 02:56 PM
  2. Web service + sql
    By barbiess in forum NetBeans
    Replies: 3
    Last Post: 11-09-2010, 08:59 AM
  3. Web service
    By mousumidas in forum Advanced Java
    Replies: 3
    Last Post: 01-28-2010, 09:12 AM
  4. how to call service method inside another service
    By kirtichopra2003 in forum Web Frameworks
    Replies: 1
    Last Post: 10-24-2009, 02:19 AM
  5. Web Service from JSP
    By Eric in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 07-02-2007, 05:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •