1 Reply Latest reply on Oct 19, 2007 4:06 PM by Paul Gillen

    EJB3 Initialization Parameter

    Paul Gillen Newbie

      What is the standard way to pass an initialization parameter to an EJB3 Stateless Session Bean?

        • 1. Re: EJB3 Initialization Parameter
          Paul Gillen Newbie

          -------- in ejb-jar.xml -------------------------------------

          -------- inside the tag defining the EJB -------------

          <env-entry>

          <env-entry-name>SECURITY_PRINCIPAL</env-entry-name>

          <env-entry-type>java.lang.String</env-entry-type>

          <env-entry-value>foo</env-entry-value>

          </env-entry>

          <env-entry>

          <env-entry-name>SECURITY_CREDENTIALS</env-entry-name>

          <env-entry-type>java.lang.String</env-entry-type>

          <env-entry-value>bar</env-entry-value>

          </env-entry>

          -------- inside my EJB -------------------------

          @Resource

          (

          name="SECURITY_PRINCIPAL",

          type=java.lang.String.class,

          shareable=true

          )

          String secPrincipal;



          @Resource

          (

          name="SECURITY_CREDENTIALS",

          type=java.lang.String.class,

          shareable=true

          )

          String secCredentials;

          private InitialContext secureCtx = null;

          ---- then the method --------

          private void getSecurityContext()

          throws Exception

          {

          Properties sctxProps = new Properties();

          sctxProps.setProperty(InitialContext.SECURITY_PRINCIPAL, secPrincipal);

          sctxProps.setProperty(InitialContext.SECURITY_CREDENTIALS, secCredentials);

          sctxProps.setProperty(InitialContext.INITIAL_CONTEXT_FACTORY,

          "org.jboss.security.jndi.JndiLoginInitialContextFactory");

          secureCtx = new InitialContext(sctxProps);

          }

          --- and then inside the other method

          try

          {

          getSecurityContext();

          Object fbObj = secureCtx.lookup("foo/bar/Manager");

          tem = (FooBar) PortableRemoteObject.narrow(fbObj,

          FooBar.class);

          }

          catch(Exception e)

          {

          e.printStackTrace();

          throw new RemoteException(""+e);

          }

          ------------------