aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes java.net.URL binding to JNDI in weblogic & use in EJB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "java.net.URL binding to JNDI in weblogic & use in EJB" Watch "java.net.URL binding to JNDI in weblogic & use in EJB" New topic
Author

java.net.URL binding to JNDI in weblogic & use in EJB

Tarun Tyagi
Greenhorn

Joined: Jun 01, 2004
Posts: 9
I am facing problems in looking up a URL object from JNDI , in an EJB , deployed in Weblogic 8.1 .
According to the Weblogic Docs , at
(http://edocs.beasys.com/wls/docs91/ejb/implementing.html)
"Configuring EJBs to Send Requests to a URL"

I have provided an entry for Resource Ref in ejb-jar.xml as

<resource-ref>
<res-ref-name>url/FileURL</res-ref-name>
<res-type>java.net.URL</res-type>
<res-auth>Container</res-auth>
</resource-ref>

and an entry for resource-description in weblogic-ejb-jar.xml as

<resource-description>
<res-ref-name>
url/FileURL
</res-ref-name>
<jndi-name>
http://www.rediff.com/
</jndi-name>
</resource-description>

In the business method in ejb the code to do the lookup is as follows

Properties h = new Properties();
h.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
h.put(Context.PROVIDER_URL, "t3://localhost:7001");
h.put(Context.SECURITY_PRINCIPAL, "weblogic");
h.put(Context.SECURITY_CREDENTIALS, "weblogic");
Context ctx = new InitialContext(h);
URL url = (URL) ctx.lookup("java:comp/env/url/FileURL");
URLConnection connection = url.openConnection();

When executing this method, a Naming execption is thrown which states

javax.naming.LinkException: . Root exception is javax.naming.NameNotFoundException: While trying to lookup 'http:./www.redif
f.com/' didn't find subcontext 'http:' Resolved ; remaining name 'http://www/rediff/com/'

I have tried the above using a file url (file:///c:/a.txt)
as well and got the same error.

If anyone has succeffully used java.net.URL as a resource from EJB in Weblogic , do let me know .

Else , pls suggest , what could be going wrong in the above scenerio .

Thanks in Advance
Tarun
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
I wonder if the oblique character is being escaped. Try setting your jndi-name to http:///www.rediff.com/.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Reid M. Pinchback
Ranch Hand

Joined: Jan 25, 2002
Posts: 775
This may sound silly, but if you have line breaks in your weblogic-ejb-jar.xml as shown, maybe that is confusing WLS about the name you are trying to use for the binding? Normally I'd just assume that whitespace was trimmed away, but I've seen whacky things happen with WLS JNDI bindings before so I don't take anything for granted. The DTD definition for the jndi-name element is pcdata, not tokens, so no parser-level guarantee that whitespace will be eliminated.

Also, you may want to use the 8.1 documentation instead of the 9.0 documentation; there are differences. I didn't spot a difference for this particular feature, but unfortunately both docs contain the same mistakes (telling people to set the jndi-name element in ejb-jar.xml obviously isn't possible).


Reid - SCJP2 (April 2002)
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
Right, so try both of these:

<jndi-name>http://www.rediff.com/</jndi-name>
<jndi-name>http:///www.rediff.com/</jndi-name>
Tarun Tyagi
Greenhorn

Joined: Jun 01, 2004
Posts: 9
Thanks . I will try both the suggestions and write back .
Although , it is quite unfortunate that docs for both 8.1 and 9.0 are wrong , <jndi-name> element in ejb-jar.xml.
Xavier Dury
Greenhorn

Joined: Mar 20, 2006
Posts: 1
Did anyone find a way to resolve this problem? I'm facing it too
Thomas Taeger
Ranch Hand

Joined: Dec 16, 2002
Posts: 309
Originally posted by Tarun Tyagi:
... Root exception is javax.naming.NameNotFoundException ...


Does that not point to the missing of a library / jar file at runtime? Just a thought ...

Is there anything in the WebLogic installation directory tree (maybe in a .../client directory) what you need to copy over to the lib/ of your client machine and include it as a VM parameter (-D...) or within the IDE project properties?

Thomas
[ March 20, 2006: Message edited by: Thomas Taeger ]

www.classic-and-class.com - www.evalulearn.com
Interfaces are the glue of OO.
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
Here is a silly question... Why go through all this trouble to tie yourself to an application server specific feature?

Just use Jakarta Commons-HttpClient and open the http connection yourself. In practice I have found Commons-HttpClient to be extremely robust and scalable.

More information on Commons-HttpClient can be found here:
http://jakarta.apache.org/commons/httpclient/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.net.URL binding to JNDI in weblogic & use in EJB