Win a copy of Functional Design and Architecture this week in the Functional programming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

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

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wonder if the oblique character is being escaped. Try setting your jndi-name to http:///www.rediff.com/.
 
Ranch Hand
Posts: 775
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did anyone find a way to resolve this problem? I'm facing it too
 
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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/
reply
    Bookmark Topic Watch Topic
  • New Topic