Results 1 to 3 of 3

Thread: How best to invoke Spring-enabled POJOs from a scheduler

  1. #1

    Default How best to invoke Spring-enabled POJOs from a scheduler

    I'm most of the way through reworking an EJB application into a Spring application. Some of the ex-ejbs need to be invoked by a scheduler rather than by a web controller, and I'd like to find out how people in the forum usually do this. (We may use Quartz scheduler in the future, but for now the scheduler is Web Methods.)

    When the app used to use ejbs, the scheduler had in its classpath a jndi.properties file that had the server, jndi-port, etc., and that also had username and password. This allowed the scheduler to invoke the ejbs under a particular role.

    That's the functionality I want to replicate. To avoid misunderstanding, let me mention that the problem is not how to protect my ex-ejbs against access by someone whose not in the correct role. I now use acegi rather than ejb-specific security, so that's taken care of.

    My problem is much more trivial. I'd like to deploy these scheduler-invoked POJOs in a way that lets the scheduler log in and then use them, and I'd like to do it in some sort of standard way.

    I thought briefly about using HttpInvoker, but the thing that strikes me is there's really no reason these beans need to be remote relative to the scheduler. I'd probably prefer that the scheduler simply grab the ApplicationContext locally, somehow log in, and get the desired bean.

    But enough of what I'd prefer. What would you do in this situation?

  2. #2
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    2,768

    Default

    You use org.springframework.scheduling.timer.ScheduledTime rTask to launch a timerTask bean. The timerTask bean typically is an extension of java.util.TimerTaskm which provides a public void run(); method. You put your logic into run().

    As you're using Acegi Security, you can modify which username and password to run under quite easily. Try this code (0.8.2 specific, from 0.9.0 and current CVS you'll need to change the class name used for the ContextHolder as per the upgrade-080-090.txt file that will be in the root of the Acegi Security distribution):

    Code:
    public void run() {
      Authentication auth = new UsernamePasswordAuthenticationToken(username, password);
      SecureContext sc = new SecureContextImpl();
      sc.setAuthentication(auth);
      ContextHolder.setContext(sc);
      try {
        // I now have security identity, so run my protected bean
        runCode();
      } catch (Exception ignored) {}
      } finally {
        ContextHolder.setContext(null);
      }
    }
    
    private void runCode() {
      this.myCollaboratingBean.doSomethingUseful();
    }
    HTH get you on the right track.

  3. #3

    Default

    Thanks. Just what I need.

Similar Threads

  1. Spring MVC Web Framework versus Struts
    By biguniverse in forum Web Flow
    Replies: 27
    Last Post: Aug 29th, 2012, 03:57 AM
  2. Spring and JtaTransactionManager with POJO's
    By kshacks in forum Container
    Replies: 2
    Last Post: Mar 15th, 2010, 02:41 AM
  3. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  4. Replies: 14
    Last Post: Feb 21st, 2005, 05:41 PM
  5. Replies: 2
    Last Post: Jan 21st, 2005, 04:17 AM

Posting Permissions

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