cancel
Showing results for 
Search instead for 
Did you mean: 

JNDI: How to configure an URL ressouce under java:comp/env/...?

Former Member
0 Kudos

Hi,

I'm looking for a possibility to configure an URL resource in the CE 7.1 Java WAS.

The application needs to lookup an URL resource. The URL resource should be provided

by the application server under the JNDI tree, let's say: "java:comp/env/myURL"

Question: Is this possible with the CE 7.1 Java WAS to register a simple URL resource

in the JNDI tree? If yes, how? Or is it possible to register a custom resource type,

providing an factory class and so on?

It is possible with other JEE application server, such as BEA WebLogic,

Sun Application Server, now known as Glassfish, JBoss or even with an

ordinary servlet container, such as Tomcat.

thanks in advance,

Ben

Accepted Solutions (1)

Accepted Solutions (1)

Vlado
Advisor
Advisor
0 Kudos

Hi Ben,

This is a standard Java EE feature, and as such is supported by all compliant Java EE servers - so this means NW AS Java too.

You can have this entry created for your EJB or web component by declaring a reference - either via annotations or in the DD. For example:


@Resource(name="myURL", mappedName="http://sdn.sap.com")
URL myURL;

This also declares an injection point.

Note that usage of mappedName is not portable, however it's supported by most app servers.

HTH!

-- Vladimir

Former Member
0 Kudos

Hi Vladimir,

As you mentioned, the URL is not portable with the normal JEE injection mechanism and that's the point.

At the moment, the application runs under several OSs, like Linux, Solaris and Windows

and under different application servers (JBoss, Bea and Sun).

Several parameters in the application are OS depend, e.g. a file URL for storing the uploaded files.

The file URL in Windows is configured as "foo.uploadUrl=c:/filestorage/baa", under a Unix like OS

the file URL looks like "foo.uploadUrl=/filestorage/baa".

At the moment, there's one EAR for all OSses. The OS depend variables are resolved at runtime via JNDI environment entries, such as: "java:comp/env/foo.uploadUrl". The enviromnent entries can be configured as simple Java string, or as Java property or as Java file URL.

Now the application should run on the SAP WAS JEE 5, so it would be nice, if the SAP WAS provides a similar mechanism.

An other solution is to specify the parameters via Java properties in JVM, but this solution is not preferred.

thanks in advance,

ben

Vlado
Advisor
Advisor
0 Kudos

Well, this portability issue is different from what I meant above. For sure, declarations of resource refs, and environment entries in general, are portable and supported by all Java EE compliant servers. (It's the linking of the reference to the actual resource that's not portable in certain cases.)

That said, you could certainly go for the simple string env entry and create the URL object yourself after having looked up its value. You create the env entry either in the ejb-jar.xml or via the @Resource annotation. What's even better is that if you're using EJBs you can change (customize) the value at runtime, without the need for redeployment of your app.

For more information: [Editing EJB Environment|http://help.sap.com/saphelp_nwce711/helpdata/en/72/ad92c5806d44899b9c3c187469d63f/frameset.htm] (Note: this comes with EHP1 for CE 7.1).

HTH!

-- Vladimir

Answers (0)