2 Replies Latest reply on Mar 25, 2006 12:56 PM by starksm64

    setEntityContext method in EntityBean EJBs.

      Hi All,
      I have an EJB that implements EntityBean.
      public void setEntityContext( EntityContext ejbCtx ) throws RemoteException
      {
      this.ejbCtx = ejbCtx; //this.ejbCtx is an EJBContext object.
      }

      I am trying to print several values of the 'EntityContext' that is being passed <please see the code pasted at the end>.

      Is this approach wrong? I am getting error while trying to print the values.
      If I am not wrong does the EJB Container sets the EJB context while calling the setEntityContext method automatically??
      Does JBoss AS provides the context to the EJB container, as the EJB container is managed by the JBoss AS?

      Please suggest.


      public void setEntityContext( EntityContext ejbCtx ) throws RemoteException
      {
      this.ejbCtx = ejbCtx;
      //Get the caller identity.
      java.security.Identity identity = ejbCtx.getCallerIdentity();
      System.out.println("identity for this ejb context is ::"+identity.toString());
      //Get the environment properties for the enterprise bean.
      System.out.println("---EJB Properties STARTS---");
      java.util.Properties pr= ejbCtx.getEnvironment();
      Enumeration en= pr.propertyNames();
      while(en.hasMoreElements())
      {
      String key = en.nextElement().toString();
      String value = pr.getProperty(key,"---NONE---");
      System.out.println("KEY ::"+key+"-->VALUE ::"+value);
      }
      System.out.println("---EJB Properties ENDS---");
      System.out.println("---caller principal STARTS---");
      java.security.Principal principal=ejbCtx.getCallerPrincipal();
      System.out.println("Principal name is ::"+principal.getName());
      System.out.println("---caller principal ENDS---");
      }