1 Reply Latest reply on Sep 19, 2002 10:50 AM by rndgatewaynet

    Jboss 3.0.1 Scheduler Mbean calling Schedulable accessing EJ

    rndgatewaynet

      Hi,
      My situation is as follws:
      The Scheduler mbean uses a custom Schedulable class which accesses
      an EJB.
      I resolved the security issue just by populating the LoginContext
      prior to looking up my EJB and calling findByPrimaryKey finder method
      on the Home interface.
      The Scheduler bean depends on this EJB.
      However, if i redeploy my ear containg this EJB i get a ClassCastException.
      /*
      This is the Scheduler Mbean
      */

      jboss.j2ee:service=EJB,jndiName=vessel
      true
      com.gatewaynet.SMASchedulable
      foouser,foopass
      java.lang.String,java.lang.String
      0
      60000
      -1

      /*
      Here is my Schedulable class
      */

      package com.gatewaynet;

      import java.util.Date;

      import org.jboss.logging.Logger;
      import org.jboss.varia.scheduler.Schedulable;
      import org.jboss.security.auth.callback.UsernamePasswordHandler;
      import javax.naming.*;
      import javax.rmi.*;
      import javax.security.auth.login.*;

      import vessel;
      import vesselHome;

      public class SMASchedulable
      implements Schedulable {
      /** Class logger. */
      private static final Logger log = Logger.getLogger(SMASchedulable.class);

      private String username;
      private String password;
      private String vslname57;
      javax.ejb.Handle vslHandle57;
      public SMASchedulable(String user, String pass) {
      username = user;
      password = pass;

      /********/
      try {
      this.login(username,password);
      try {
      InitialContext ic = new InitialContext();
      Object objref = ic.lookup("vessel");
      vesselHome vslhome = (vesselHome)PortableRemoteObject.narrow(objref, vesselHome.class);
      vessel vsl = vslhome.findByPrimaryKey("57");
      vslHandle57 = vsl.getHandle();
      //vslname57 = vsl.getName();
      }
      catch (Exception e) {
      System.out.println("ERROR DYNA "+e.getMessage());
      e.printStackTrace();
      throw new Exception("Accessing the vessel EJB failed");
      }
      }
      catch (Exception e) {
      System.out.println(e.getMessage());
      }
      }

      private void login(String username,String password) throws javax.security.auth.login.LoginException {
      try {
      UsernamePasswordHandler handler = new UsernamePasswordHandler(username, password.toCharArray());
      LoginContext lc = new LoginContext("client-login", handler);
      System.out.println("Created LoginContext");
      lc.login();
      System.out.println("Login completed");
      }
      catch (LoginException le) {
      System.out.println("Login failed");
      le.printStackTrace();
      throw new javax.security.auth.login.LoginException("Login failed");
      }
      }

      public void perform(Date pTimeOfCall, long pRemainingRepetitions) {
      java.util.Calendar cal = java.util.Calendar.getInstance();
      cal.setTime(pTimeOfCall);
      int hourOfDay = cal.get(java.util.Calendar.HOUR_OF_DAY);
      int mins = cal.get(java.util.Calendar.MINUTE);
      int secs = cal.get(java.util.Calendar.SECOND);
      if (hourOfDay == 9 && mins == 30 && secs ==0) {
      log.info("do yer thang " + pTimeOfCall);
      log.info("do yer thang " + hourOfDay+":"+mins+":"+secs);
      try {
      this.login(username,password);
      System.out.println(((vessel)(vslHandle57.getEJBObject())).getName());
      }
      catch (java.rmi.RemoteException re) {
      System.out.println("Remote Exception DYNA is " + re.getMessage());
      }
      catch (javax.security.auth.login.LoginException le) {
      System.out.println("Login Exception DYNA is " + le.getMessage());
      }
      }
      else {
      log.info("Schedulable Examples is called at: " + pTimeOfCall +
      ", remaining repetitions: " + pRemainingRepetitions);
      try {
      this.login(username,password);
      System.out.println(((vessel)(vslHandle57.getEJBObject())).getName());
      }
      catch (java.rmi.RemoteException re) {
      System.out.println("Remote Exception DYNA is " + re.getMessage());
      }
      catch (javax.security.auth.login.LoginException le) {
      System.out.println("Login Exception DYNA is " + le.getMessage());
      }
      }
      //System.out.println(vslname57);

      }
      }

      When i redeploy (just touch Dynacom.ear file that includes the vessel EJB)
      i get
      13:25:22,124 INFO [STDOUT] Created LoginContext
      13:25:22,125 INFO [STDOUT] Login completed
      13:25:22,129 INFO [STDOUT] ERROR DYNA null
      13:25:22,129 ERROR [STDERR] java.lang.ClassCastException
      13:25:22,129 ERROR [STDERR] at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:296)
      13:25:22,129 ERROR [STDERR] at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
      13:25:22,130 ERROR [STDERR] at com.gatewaynet.SMASchedulable.(SMASchedulable.java:34)
      13:25:22,130 ERROR [STDERR] at java.lang.reflect.Constructor.newInstance(Native Method)
      13:25:22,130 ERROR [STDERR] at org.jboss.varia.scheduler.Scheduler.startSchedule(Scheduler.java:299)
      13:25:22,130 ERROR [STDERR] at org.jboss.varia.scheduler.Scheduler.startService(Scheduler.java:1009)
      13:25:22,130 ERROR [STDERR] at org.jboss.system.ServiceMBeanSupport.start(ServiceMBeanSupport.java:164)
      13:25:22,130 ERROR [STDERR] at java.lang.reflect.Method.invoke(Native Method)
      13:25:22,131 ERROR [STDERR] at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
      13:25:22,131 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:491)
      13:25:22,131 ERROR [STDERR] at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:967)
      13:25:22,131 ERROR [STDERR] at $Proxy6.start(Unknown Source)
      13:25:22,131 ERROR [STDERR] at org.jboss.system.ServiceController.start(ServiceController.java:396)
      13:25:22,131 ERROR [STDERR] at java.lang.reflect.Method.invoke(Native Method)
      13:25:22,132 ERROR [STDERR] at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
      13:25:22,132 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:491)
      13:25:22,132 ERROR [STDERR] at org.jboss.util.jmx.MBeanProxy.invoke(MBeanProxy.java:174)
      13:25:22,132 ERROR [STDERR] at $Proxy3.start(Unknown Source)
      13:25:22,132 ERROR [STDERR] at org.jboss.deployment.SARDeployer.start(SARDeployer.java:249)
      13:25:22,132 ERROR [STDERR] at org.jboss.deployment.MainDeployer.start(MainDeployer.java:796)
      13:25:22,133 ERROR [STDERR] at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:616)
      13:25:22,133 ERROR [STDERR] at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:580)
      13:25:22,133 ERROR [STDERR] at java.lang.reflect.Method.invoke(Native Method)
      13:25:22,133 ERROR [STDERR] at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
      13:25:22,133 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:491)
      13:25:22,133 ERROR [STDERR] at org.jboss.util.jmx.MBeanProxy.invoke(MBeanProxy.java:174)
      13:25:22,134 ERROR [STDERR] at $Proxy4.deploy(Unknown Source)
      13:25:22,134 ERROR [STDERR] at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:427)
      13:25:22,134 ERROR [STDERR] at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:553)1
      13:25:22,134 ERROR [STDERR] at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:202)
      13:25:22,134 ERROR [STDERR] at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:191)
      13:25:22,134 INFO [STDOUT] Accessing the vessel EJB failed
      13:25:22,148 INFO [Scheduler] Started

      Thanx ,

      Achilleus

        • 1. Re: Jboss 3.0.1 Scheduler Mbean calling Schedulable accessin
          rndgatewaynet



          I figured out what i gotta do.
          The point is how :)
          Currently the Scheduler Mbean depends on the vessel EJB deployment.
          What I should do is have my dynasched.jar (in the deploy dir, which contains
          the Schedulable class) to
          depend on the vessel EJB deployment, and the Scheduler Mbean to
          depend on the dynasched.jar.

          Anyone knows how to make dynasched.jar redeploy every time
          i redeploy my vessel EJB, and how to make the Scheduler-service.xml
          redeploy every time the dynasched.jar is deployed??

          Thanx
          Achilleus