• 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

JNDI_NAME lookup

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
i am fairly new to Websphere - although i have done EJB development using the WTE before. My problem arises when trying to get my session bean to locate my entity bean using JNDI lookupname. I havent used the InitialContext.lookup before (thanks to the co i used to work in having a wrapper class on all this stuff!) and this is what i have so far:
java.lang.Object homeObject = vjInitContext.lookup(GraphicalAssistantHome.JNDI_LOOKUP_NAME);
GraphicalAssistantHome gaHome = (GraphicalAssistantHome)PortableRemoteObject.narrow((org.omg.CORBA.Object)homeObject, GraphicalAssistantHome.class);
however i am getting the following error :
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
com.ibm.ejs.container.UncheckedException: ; nested exception is: java.lang.ClassCastException
I think it may have to do with my InitialContext and perhaps i should initialise the INITIAL_CONTEXT_FACTORY and PROVIDERURL properties in a Resource Bundle - however i am not certain what these properties should be set to or where (should i just extend ResourceBundle class and make my own class of it?)
This is probably quite a basic question - but as a fundamental, it means i cant ensure the rest of my code works. Any help would be appreciated
Thanx
nm
 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this:
java.lang.Object homeObject = vjInitContext.lookup(GraphicalAssistantHome.JNDI_LOOKUP_NAME);
GraphicalAssistantHome gaHome = (GraphicalAssistantHome)PortableRemoteObject.narrow(homeObject, GraphicalAssistantHome.class);
 
Noreen Masterson
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
nope- that didnt work -- but thanx for the suggestion!
still geting the same exception :
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: com.ibm.ejs.container.UncheckedException: ; nested exception is: java.lang.ClassCastException
although this is what is output in the console for the PNS :
[02.05.02 10:31:10:217 BST] 1962 NamingContext E resolve: name = sterling.ebiz.retrieveallcomponents cname = /
[02.05.02 10:31:37:385 BST] c47 BootstrapRequ E operation: get
[02.05.02 10:31:37:666 BST] 1962 NamingContext E resolve: name = sterling.ebiz.graphicalassistant cname = /
nm
 
Noreen Masterson
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi again --
well i made a few changes to my entity and session beans as i reckon the output from the PNS on the Console def indicates it is retrieving the entity bean....
my aim was that the method i was calling on the entity would return an Enumeration --> but i changed this all to just return a single instance of the object - and it seems to be working correctly.
However i dont understand why it wont return an Enumeration? I have tested my entity using the Test Client and the finder method i have written def returns an enumeration as it adds each instance of the object that matches the query....
in my session bean i call one of the methods in the entity on each obj in the enumeration and add the results to a vector. When i run this in my test client on the WTE, i get the classcast exception and am informed the vector is empty.
AS said above, when i changed this to retrieve just one instance, it is successful... am i missing something?
sorry it has turned a bit more comvaluted!
nm
 
Noreen Masterson
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hullo again
well through some perseverance (and the help of the debugger)i have found out where my problem is -- the casting exception is coming from when i try to retrieve an object from the Enumeration and cast it as the remote object
Anyhoo... here is what i am trying to do :
Enumeration graphicalAssistantEnum = this.getComponentByProductId(productId);
if (graphicalAssistantEnum.hasMoreElements()){
GraphicalAssistant ga = (GraphicalAssistant)graphicalAssistantEnum.nextElement();
componentDetailsVector.add(ga.getComponentDetails());
}
and my casting exception is coming from the .nextElement call on the enum.... but i have retested my entity adn it is surely getting each instance of the remote object (GraphicalAssistant) and storing them in an enumeration without problem.... it just doesnt seem to work when i try to get it back out....
my head is baffled!
any help appreciated!
nm
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bingo! You can't just do a cast after you take an EJB reference out of an Enumeration -- you have to do a PortableRemoteObject.narrow() on the Object returned from the Enumeration and then cast that.
Kyle
 
Noreen Masterson
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kyle - u are a godsent angel! =)
thanx muchly
just a quick Q --> is this a websphere issue-- as i have been able to just get an object from an enumeration before (i am unsure if it was something that was taken care of in the framework i was working in then..)
Anyway. many thanx.
nm
 
Kyle Brown
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's actually an issue of where the spec is vague. If you do it the WebSphere way it will work in any application server, but some application servers don't require you to do so.
Kyle
 
It's a tiny ad only because the water is so cold.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic