env-entry and InitialContext

Hi
I have put a String value, named "myval" into my web.xml file using
<env-entry> tags. In my code I use the following:
// assume this gets with default values...
InitialContext ctxt = new InitialContext();
String myval = (String) ctxt.lookup("java:comp/env/myval");
and that usually extracts myval with no problems if I do it within a Web
context, i.e. from a JSP or a class referenced initially from a JSP.
However, it fails to extract myval when I do it within an EJB context, i.e.
call from an EJB.
Also, new InitialContext() sometimes goes into an infinite loop.
So, I have two problems, can anyone clarify them?
1. At random (not repeatable) the new InitialContext() call goes into an
infinite loop. The WebLogic debug file just shows it looping and looping
indefinitely, ending with a "Problematic thread" error!!! This is from a Web
context or Servlet Context (not sure of what this is called)
2. The EJB I use in another part of the application cannot get the
InitialContext(). When I try to do this I get NamingException thrown.
Fran

Thanks for this Mahendra.
Does anybody have any idea as to the first problem? i.e. looping error?
I'm calling this code many times, so maybe it's getting 'confused' but
that's not really a good explanation of the problem!
Many thanks again
Fran
"Mahendra Dhamdhere" <[email protected]> wrote in message
news:3a96799a$[email protected]..
As per my knowledge,
env-entrys defined in web.xml are local to that container, a Container in
which your servlet is deployed. For each web application, weblogic createsa
ServletContainer and a ServletContext. That's why we can use differentlocal
names from same global resources.
As your servlet container and ejb container are different container andthey
have different environment, to solve your problem, you can defineenv-entry
in your deployment descriptor file(ejb-jar.xml).
HTH,
Mahendra
Fran <[email protected]> wrote in message
news:[email protected]..
Hi
I have put a String value, named "myval" into my web.xml file using
<env-entry> tags. In my code I use the following:
// assume this gets with default values...
InitialContext ctxt = new InitialContext();
String myval = (String) ctxt.lookup("java:comp/env/myval");
and that usually extracts myval with no problems if I do it within a Web
context, i.e. from a JSP or a class referenced initially from a JSP.
However, it fails to extract myval when I do it within an EJB context,i.e.
call from an EJB.
Also, new InitialContext() sometimes goes into an infinite loop.
So, I have two problems, can anyone clarify them?
1. At random (not repeatable) the new InitialContext() call goes into an
infinite loop. The WebLogic debug file just shows it looping and looping
indefinitely, ending with a "Problematic thread" error!!! This is from aWeb
context or Servlet Context (not sure of what this is called)
2. The EJB I use in another part of the application cannot get the
InitialContext(). When I try to do this I get NamingException thrown.
Fran

Similar Messages

  • Move env-entry from web.xml into deployment plan

    I have:
    <env-entry>
    <env-entry-name>USERNAME</env-entry-name>
    <env-entry-value>someUser</env-entry-value>
    <env-entry-type>java.lang.String</env-entry-type>
    </env-entry>
    and I'd like to move it from web.xml into my_app_plan.dat. Is it possible? How?
    Thank you in advance!

    Let me describe my case in few more words...
    I have some kind of client-server app. Clients have OC4J installed and they download myApp.ear and myApp_plan.dat files and by using script (Windows CMD batch file) clients install those files with admin_client.jar, OC4J's admin utility. The problem is that I have 2 different types of clients and I have client specific settings set in web.xml file and each time I compile myApp.ear I have to uncomment/comment some lines in web.xml.
    So, to make a long story short, I need a way to deploy those settings separated from (outside of) myApp.ear. By following you link, I have read that orion-web.xml should reside inside WEB-INF folder of myApp.ear, which is not good for me.

  • Accessing env-entry value from a java class

    Hi,
    I have my env-entry element declared in ejb-jar.xml like this
    <env-entry>
    <env-entry-name>ConfigFile</env-entry-name>
    <env-entry-type>java.lang.String</env-entry-type>
    <env-entry-value>centaur</env-entry-value>
    </env-entry>
    and if I access that value from the EJB of that ejb-jar.xml, it is giving the right value. But when I am trying to retrieve the same from a java class, that is throwing exception "javax.naming.NameNotFoundException: Unable to resolve 'ConfigFile' Resolved ; remaining name 'ConfigFile'"
    I think this is because env-entry has access to only EJB to maintain security?
    or can env-entry elemenets cab be accessed outside the EJB and some thing I am doing wrong here?
    can some one help me here?

    Hey Frank,
    The JCo, DI API and DB are all on PL 18. I have found that the error only occurs for one business partner, and that business partner had a service contract added to it the day before the error started to occur. Also the business partner in question is the only business partner with a service contract which would explain why it is the only one experiencing these problems. It could be a coincidence but I will let you know what the outcome is.
    Carla

  • Accessing env-entry from out side bean

    Hi,
              I have my env-entry element declared in ejb-jar.xml like this
              <env-entry>
              <env-entry-name>ConfigFile</env-entry-name>
              <env-entry-type>java.lang.String</env-entry-type>
              <env-entry-value>centaur</env-entry-value>
              </env-entry>
              and if I access that value from the EJB(MDB) of that ejb-jar.xml, it is giving the right value. But when I am trying to retrieve the same from a java class, that is throwing exception "javax.naming.NameNotFoundException: Unable to resolve 'ConfigFile' Resolved ; remaining name 'ConfigFile'"
              I think this is because env-entry has access to only EJB or MDB to maintain security?
              or can env-entry elemenets cab be accessed outside the EJB and some thing I am doing wrong here?
              can some one help me here?

    The java:comp/env namespace is local to the J2EE component (ie the EJB).
              You could certainly have a business method that returned the value and call the business method from a java class.
              Or your EJB could lookup the env-entry in JNDI and store it in another data structure.
              -- Rob
              WLS Blog http://dev2dev.bea.com/blog/rwoollen/

  • Accessing env-entry value from outside a bean

    Hi,
    I have my env-entry element declared in ejb-jar.xml like this
    <env-entry>
    <env-entry-name>ConfigFile</env-entry-name>
    <env-entry-type>java.lang.String</env-entry-type>
    <env-entry-value>centaur</env-entry-value>
    </env-entry>
    and if I access that value from the EJB of that ejb-jar.xml, it is giving the right value. But when I am trying to retrieve the same from a java class, that is throwing exception "javax.naming.NameNotFoundException: Unable to resolve 'ConfigFile' Resolved ; remaining name 'ConfigFile'"
    I think this is because env-entry has access to only EJB to maintain security?
    or can env-entry elemenets cab be accessed outside the EJB and some thing I am doing wrong here?
    can some one help me here?

    The java:comp/env namespace is local to the J2EE component (ie the EJB).
              You could certainly have a business method that returned the value and call the business method from a java class.
              Or your EJB could lookup the env-entry in JNDI and store it in another data structure.
              -- Rob
              WLS Blog http://dev2dev.bea.com/blog/rwoollen/

  • @Resource and env-entry

    I used the JSF2 GuessNumber example as the basis for my project. I'm running a simple JSF2 application (my first, although I'm very familiar with JSF1) on Tomcat 7.0.16.
    I have the following bean:
    @ManagedBean
    @SessionScoped
    public class ConfigBean {
         @Resource
         private String dataDirectory;
         public String getDataDirectory() {
              return dataDirectory;
         public void setDataDirectory(String dataDirectory) {
              this.dataDirectory = dataDirectory;
    }I want to access the data directory property in a .xhtml file as follows:
    #{configBean.dataDirectory}To populate the property, I have the following in web.xml:
    <env-entry>
      <env-entry-name>dataDirectory</env-entry-name>
      <env-entry-type>java.lang.String</env-entry-type>
      <env-entry-value>D:\Users\kdean\projects\DemoJSF2\data</env-entry-value>
    </env-entry>I put a breakpoint in getDataDirectory() to confirm that it's being called (it is) but the value is always null.
    What am I missing? Thanks.

    Hi,
    JDeveloper 10.1.3 is using JEE 1.4, not JEE 1.5. JDeveloper 11 would be the build to use and I am currently testing if it works in here
    Frank

  • Env-entry in web.xml and 6.0 sp4

    Does anyone know if iws 6.0 sp4 supports env-entry elements in web.xml???
    According to servlet specs 2.2 it should support it since it has JSP support.
    From 2.3 specs:
    "The following addtional elements exist in the web application deployment
    descriptor to meet the requirements of web containers that are JSP enabled or part
    of a J2EE application server. They are not required to be supported by containers
    wishing to support only the servlet specification.:
    � taglib
    � syntax for looking up JNDI objects (env-entry, ejb-ref, ejb-local-ref, resourceref,
    resource-env-ref)
    See the DTD comments for further description of these elements."

    Additional info...actually the code throws a NamingException.

  • Issue with [env-entry] element in web.xml

    I know it's possible to define [env-entry] elements in web.xml for environment
    properties of a web application. But how do you access [env-entry] elements from
    classes that do not exist within a web application? In other words, this is my
    problem:
    I have an EAR file, enterprise.ear, which contains the following...
    employee.jar
    employeeSearchEJB.jar
    webApp1.war
    META-INF/
    application.xml
    The employee.jar file is a utility archive that contains common classes, one of
    which is a class called LogManager. LogManager needs to read environment properties
    in order to initialize itself. Currently, LogManager reads these properties from
    a property file, and therefore it needs to know the name of the property file
    in order to access it. I dont like this approach because I'm forced to hard-code
    the name of the property file in LogManager. I would rather leverage the power
    of J2EE deployment descriptors and use the [env-entry] element to define the environment
    properties for the LogManager class. Then, I would simply use JNDI to get the
    values of the [env-entry] elements without ever having to specify their location
    aside from the default JNDI context; java:comp/env, which is standard anyway.
    The problem I'm having is that you can define the [env-entry] element in only
    2 types of deployment descriptors; namely, web.xml and ejb-jar.xml, neither of
    which are available to LogManager because LogManager exists at the EAR root level.
    I was hoping application.xml supported the [env-entry] element, but it doesn't.
    Any suggestions?
    SAF

    SAF,
    I am not sure if this applies to you situation but if you create an initial context
    instance and then grab the value using the jndi name within that context then
    you should be able to grab that environment variable.
    I have a helper class that is used as part of a deployed application. The helper
    class doesn't have access to the Servlet context but it is created as part of
    the application workflow. When it gets initiated it grabs an env-entry created
    in the web.xml deployment descriptor to find the default url for a content path.
    After I create an initialContext, I perform a initContext.lookup("jndi.env.entry.here")
    where "jndi.env.entry.here" is the name specified in the env-entry tag.
    This returns the value of the entry.
    This works under both Jrun and Weblogic so my guess is it should work for you.
    Again, I am assuming that your class will at least be able to grab a context
    object to communicate back to the server.
    Hope this helps,
    Troy
    "SAF" <[email protected]> wrote:
    >
    I know it's possible to define [env-entry] elements in web.xml for environment
    properties of a web application. But how do you access [env-entry] elements
    from
    classes that do not exist within a web application? In other words, this
    is my
    problem:
    I have an EAR file, enterprise.ear, which contains the following...
    employee.jar
    employeeSearchEJB.jar
    webApp1.war
    META-INF/
    application.xml
    The employee.jar file is a utility archive that contains common classes,
    one of
    which is a class called LogManager. LogManager needs to read environment
    properties
    in order to initialize itself. Currently, LogManager reads these properties
    from
    a property file, and therefore it needs to know the name of the property
    file
    in order to access it. I dont like this approach because I'm forced to
    hard-code
    the name of the property file in LogManager. I would rather leverage
    the power
    of J2EE deployment descriptors and use the [env-entry] element to define
    the environment
    properties for the LogManager class. Then, I would simply use JNDI to
    get the
    values of the [env-entry] elements without ever having to specify their
    location
    aside from the default JNDI context; java:comp/env, which is standard
    anyway.
    The problem I'm having is that you can define the [env-entry] element
    in only
    2 types of deployment descriptors; namely, web.xml and ejb-jar.xml, neither
    of
    which are available to LogManager because LogManager exists at the EAR
    root level.
    I was hoping application.xml supported the [env-entry] element, but it
    doesn't.
    Any suggestions?
    SAF

  • Use of env-entry in ejb-jar

    In my ejb-jar.xml I have a Session bean with a env-entry:
    <env-entry>
    <env-entry-name>xslNameFile</env-entry-name>
    <env-entry-type>java.lang.String</env-entry-type>
    <env-entry-value>pdftemplate.xsl</env-entry-value>
    </env-entry>
    In a class where I use the bean I make a lookup of this env-entry (using the same
    context):
    Context environment = (Context)ctx.lookup("java:comp/env/");
    val = (String)environment.lookup("xslNameFile");
    And I have the following Exception:
    javax.naming.NameNotFoundException: Unable to resolve 'comp/env/xslNameFile' Reso
    lved: 'comp/env' Unresolved:'xslNameFile' ; remaining name 'xslNameFile'
    What I m doing wrong??
    Could anyone help me?
    Thanks
    F.Canonica

    HI ,
    The Primary Purpose of <env-entry> tag
    is used to Customize your bean at Runtime
    and to Make your bean as an DataDriven one.
    ( instead of Storing it in DataBase )
    Regards
    Karthikeyan Gangadharan
    "Deepak Vohra" <[email protected]> wrote:
    >
    >
    >
    InitialContext ic = new InitialContext();
    String val = (String) ic.lookup("java:/comp/env/xslNameFile");
    "canonica" <[email protected]> wrote:
    In my ejb-jar.xml I have a Session bean with a env-entry:
    <env-entry>
    <env-entry-name>xslNameFile</env-entry-name>
    <env-entry-type>java.lang.String</env-entry-type>
    <env-entry-value>pdftemplate.xsl</env-entry-value>
    </env-entry>
    In a class where I use the bean I make a lookup of this env-entry (using
    the same
    context):
    Context environment = (Context)ctx.lookup("java:comp/env/");
    val = (String)environment.lookup("xslNameFile");
    And I have the following Exception:
    javax.naming.NameNotFoundException: Unable to resolve 'comp/env/xslNameFile'
    Reso
    lved: 'comp/env' Unresolved:'xslNameFile' ; remaining name 'xslNameFile'
    What I m doing wrong??
    Could anyone help me?
    Thanks
    F.Canonica

  • Naming exception when using env-entry

    My ejb.jar.xml file contains:
    <env-entry>
    <env-entry-name>iorFileName</env-entry-name>
    <env-entry-type>java.lang.String</env-entry-type>
    <env-entry-value>d:\\planadminserver.ior</env-entry-value>
    </env-entry>
    I use the following code to do a lookup:
    InitialContext ic = new InitialContext();
    String filename =
         (String) ic.lookup("java:comp/env/iorFileName");
    This works fine on my machine. But when we moved the code to
    another machine, we get a NamingException. Any ideas as to why
    this should be?

    Hi DP,
    The problem is not with the EntryProcessor but probably, with the coherence server (storage node) and proxy server that went down during request processing.
    2012-03-15 12:06:59.319/56.479 Oracle Coherence GE 3.7.1.0 <D5> (thread=Cluster, member=2): Member 1 left service CoherenceCache with senior member 2
    2012-03-15 12:06:59.319/56.479 Oracle Coherence GE 3.7.1.0 <D5> (thread=Proxy:DistributedProxy:TcpAcceptorWorker:3, member=2): An exception occurred while processing a InvokeRequest for Service=Proxy:DistributedProxy:TcpAcceptor: (Wrapped: Failed request execution for CoherenceCache service on Member(Id=2, Timestamp=2012-03-15 12:06:09.858, Address=10.38.45.253:8090, MachineId=36960, Location=site:,machine:KN3M9434,process:8224, Role=CoherenceServer) (Wrapped: Failed to load key="1") null) java.lang.NullPointerExceptionEnsure that the storage node and proxy is up and running.
    Hope this helps!
    Cheers,
    NJ

  • How to retrieve "env-entry" in servlet code

    i have a pretty straight-forward web app, which contains a servlet, among other things. the web app is packaged in .war, and it in turn is part of a .ear file. i am using WAS 640 sneak preview on windows xp.
    in the web.xml file, i added the following lines:
    <env-entry>
      <description>some texts</description>
      <env-entry-name>myapp.home</env-entry-name>
      <env-entry-type>java.lang.String</env-entry-type>
      <env-entry-value>c:/myapp</env-entry-value>
    </env-entry>
    in my servlet code, i try to retrieve the value for "myapp.home" like this:
    try
    Context ctx = new InitialContext();
    home = (String) ctx.lookup("java:comp/env/myapp.home");
    } catch (Exception ex) {
    ex.printStackTrace();
    after .ear is deployed, i can see in the JDNI Registry (using Visual Admin Tool), myapp.home is added to the tree:
    webContainer
      -applications
        --myCompany.com
          ---myEarFileName
    myWebAppRoot
    java:comp
    env
    myapp.home
    the entry has the correct class name and object value.
    when the servlet code that performs the jndi lookup is called, i get an exception:
    com.sap.engine.services.jndi.persistent.exceptions.NameNotFoundException: Path to object does not exist at : java:comp
    ??? QUESTIONS:
    #1 what am i doing wrong?
    #2 if the lookup name must contain the entire jndi tree as listed above, then how can this code be portable to other app servers?
    thoughts are greatly appreciated.

    thanks for the hints, but unfortunately they didn't work.
    1. after switching the order of value and type in env-entry, rebuild/redeplpoy, same exception. the ordering  probably didn't matter since even with the reversed order, the name and value showed up correctly under the jndi tree.
    2. well, i tried giving it the full path, starting with 'webContainer', then 'applications' etc, separated by forward slash. now the exception says path to webContainer is not found.
    so what gives? are there no standards?

  • Can't access env-entry s in init()

              Hi all,
              How can I access the <env-entry>'s I have in my deployment descriptor in my servlet's
              "init()" method? I'm not getting the values from there.
              Should I pass parameters to my "new InitialContext(...)" call? What params do
              I pass?
              Thanks,
              Boogie
              

    Then it is probably a WebLogic bug.
              boogie <[email protected]> wrote:
              > yes, that's how my code looks like.
              > except when it's in "init()", i don't get any values back.
              > so now i have to put it in another method which gets called the first time my
              > servlet processes a response. as you might imagine, it isn't very elegant (it's
              > a hack, actually) and it sorta defeats the purpose of having an "init()" method.
              > Dimitri Rakitine <[email protected]> wrote:
              >>boogie <[email protected]> wrote:
              >>
              >>> Hi all,
              >>
              >>> How can I access the <env-entry>'s I have in my deployment descriptor
              >>in my servlet's
              >>> "init()" method? I'm not getting the values from there.
              >>> Should I pass parameters to my "new InitialContext(...)" call? What
              >>params do
              >>> I pass?
              >>
              >>None - everything is set up by the container. env-entries are in java:comp/env
              >>subcontext,
              >>for example, if you define env-entry named Foo, you can access is like
              >>this:
              >>
              >>Context ctx = new InitialContext();
              >>ctx.lookup("java:comp/env/Foo");
              >>
              >>> Thanks,
              >>> Boogie
              >>
              >>--
              >>Dimitri
              Dimitri
              

  • Changing env-entry after deployment

    Hi,
    I was wondering how I can change the value of an env-entry after deployment? Do I have to change the value in the ejb-jar.xml, redeploy the application, or is there a utility I can use?
    thanks
    Steve

    Okay gentlemen, I dug around and couldn't find anything on this concept of defining an env-entry after deployment using Sun Java System Application Server 8.1 - so I just came up with my own hack. Thought I'd share it in case others have the same question and can't find the answer.
    Just to restate the problem: In SJAS you can't seem to define an environment entry that you can just look up via JNDI (you can do this in Tomcat pretty easy though using the context.xml file and an env-entry like syntax) - the benefit of this being of course that you can easily define deployment-time variables which a system administrator can set based on his setup. There seems to be no way to do this is SJAS 8.1
    As a workaround, you can create your own custom JNDI resource which will expose the properties that you set in the Admin Console as a simple java.util.Map that you can use from your app.
    Here's the blow by blow:
    2. Create a JNDIProperties object that implements java.util.Map but does NOT implement java.io.Serializable:
    package helpers.jndi;
    import java.util.Collection;
    import java.util.Map;
    import java.util.Set;
    public final class JNDIProperties implements Map {
        private Map map;
        public JNDIProperties(Map aMap) { map = aMap; }
        public boolean containsKey(Object key) { return map.containsKey(key); }
        public void clear() { map.clear(); }
        public Object get(Object key) { return map.get(key); }
        public boolean containsValue(Object value) { return map.containsValue(value); }
        public Set entrySet() { return map.entrySet(); }
        public boolean isEmpty() { return map.isEmpty(); }
        public Set keySet() { return map.keySet(); }
        public Object put(Object key, Object value) { return map.put(key, value); }
        public void putAll(Map t) { map.putAll(t); }
        public Object remove(Object key) { return map.remove(key); }
        public int size() { return map.size(); }
        public Collection values() { return map.values(); }
    }2. Create an object that implements javax.naming.spi.ObjectFactory and returns an instance of JNDIProperties containing the properties defined in the container:
    package helpers.jndi;
    import java.util.Enumeration;
    import java.util.Hashtable;
    import java.util.Map;
    import javax.naming.Context;
    import javax.naming.Name;
    import javax.naming.RefAddr;
    import javax.naming.Reference;
    import javax.naming.spi.ObjectFactory;
    public class PropertyFactory implements ObjectFactory {
        public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable environment) throws Exception {
            Map myMap = new Hashtable();
            Reference myReference = (Reference)obj;
            Enumeration myEnumeration = myReference.getAll();
            while (myEnumeration.hasMoreElements()) {
                RefAddr myRefAddr = (RefAddr)myEnumeration.nextElement();
                myMap.put(myRefAddr.getType(), myRefAddr.getContent());
            JNDIProperties myJNDIProperties = new JNDIProperties(myMap);
            return myJNDIProperties;
    }3. Build this and copy the jar to $SJAS_HOME/domains/domain1/lib/ext/ (or other appropriate folder for your setup), then restart the app server to get to load the jar.
    4. Go to the admin console and go to Resources -> JNDI -> Custom Resources -> New. Give it a sensible JNDI name (I'll use "testproperties" in this example), enter java.util.Map as the resource type and the name of your factory class for the "factory class" field, e.g. "helpers.jndi.PropertyFactory". Below that under "Additional Properties", add in each of the properties that you want to expose, for example enter a property named "testproperty1" with the value of "my test".
    5. You can now get a java.util.Map that contains the properties that you set for your custom JNDI resource by doing something like the following (example in JSP):
    <%
    Context myContext = new InitialContext();
    Context myEnvContext = (Context)myContext.lookup("java:comp/env");
    Map myMap = (Map)myEnvContext.lookup("testproperties");
    %>
    <%=myMap.get("testproperty1")%>Output is:
    my testNOTE: If this sounds convoluted - I agree, it is. If anyone's got a better idea, please post it; as I could not find another solution to this seemingly simple problem.

  • MDB env-entry

    Hi all!
    how can i get access through java code to the env-entry's in the deplomentdecriptor of my MDB
    here my bean descriptor and i want get access to the <env-entry-name>MESSAGEPROCESSOR</env-entry-name> :
    <message-driven id="MyMDB">
    <ejb-name>JMSContQueueProcessor-1</ejb-name>
    <ejb-class>com.mycompany.jms.JMSContQueueProcessor</ejb-class>
    <transaction-type>Container</transaction-type>
    <message-driven-destination>
    <destination-type>javax.jms.Queue</destination-type>
    </message-driven-destination>
    <env-entry>
    <env-entry-name>MESSAGEPROCESSOR</env-entry-name>
    <env-entry-type>java.lang.String </env-entry-type>
    <env-entry-value>QueueToMaximoProcessor</env-entry-value>
    </env-entry>
    </message-driven>
    Thanks

    InitialContext initContext = new InitialContext();
    String MESSAGEPROCESSOR = (String) initContext.lookup ("MESSAGEPROCESSOR");

  • Weblogic jndi env entries

    Hi,
    I have a little problem. i have a webapplication deployed in weblogic 6.1, now i tried to create an env entriy (in the web.xml) and now i want to access this env entry from within my jsp page.
    I have created a new InitialContext and then just called
    System.out.println(ctx.lookup("myenv"));
    But weblogi can't find the environment myenv. -> NameNotFoundException
    is there another way to access those env entries like in j2ee "java:comp/env/myenv" ????

    everything ok now..it is "java:comp/env"! i had to reinstall weblogic before it worked.. don't ask me why.

Maybe you are looking for