EJB P.R.O.narrow method returns a null reference though object is valid

All,
I'm trying to deploy a simple stateless session bean to SUN server. The client code keeps failing because PortableRemoteObject.narrow returns null, even though the reference is located in JNDI tree.
I read somewhere that turning on RMI stub generation might help, but it didn't do it in my case.
This is a local server (SUN App Server, as downloaded from java.sun site).
JNDI tree contains the following entries:
UserTransaction
test.Dummy
jdbc
ejb
test.Server
Neither test.Dummy nor test.Server (the beans I deployed) want to load.
Any help would be appreciated.
Thanks!
Mark

Never mind. For some reason changing initial context creation from:
Properties p=new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,"whatever factory");
p.put(Context.PROVIDER_URL,"whatever url");
InitialContext context=new InitialContext(p);
to:
InitialContext context=new InitialContext();
fixed the problem. Which is strange, since JNDI tree was listing both objects, and they both could be resolved when using the first code snippet. Only the actual object creation was failing.
If anyone knows why this is so, please explain.
Cheers,
Mark

Similar Messages

  • Why are static methods called with null references,valid ?

    This is my code :
    package inheritance;
    public class inh6{
         public static void method(){
         System.out.println("Called");
         public static void main(String[] args){
              inh6 t4 = null;
         t4.method();
    O/P :
    CalledHere t4 is a null reference and yet we are able to call a method on it,why is null pointerexception not thrown.Why are we able to call static methods using null references ?
    t4 is null means it doesnot refer to any memeory address,hence how is method() called correctly.
    I hope i am clear. :)
    Thank you for your consideration.

    punter wrote:
    jverd wrote:
    Memory addresses have nothing to do with it. I doubt memory addresses are even mentioned once in the JLS.
    By memory address i mean the memory location the reference is pointing to.I know what you mean. But if you think it's relevant, can you show me where in the JLS it says anything about memory locations?
    >
    You can do that because a) t4's type is "reference to inh6" and b) method() is declared static, which means that you don't need an object to call it, just the class. That class comes from the compile time type of t4. The fact that t4 is null at runtime is irrelevant.
    So at compile time the type of t4 is inh6 and hence the method is called.Is it ? Had method() not been static a NullPointerException would have been thrown.Correct.
    With non-static, non-private, non-final methods, which implementation of the method gets called is determined at runtime, buy the class of the object on which it's being called. If any one of those "non"s goes away, then the method is entirely determined at compile time, and in the case of static methods, there's no instance necessary to call the method in the first place.

  • Methods returning String

    Do Methods returning String create a String object in memeory and pass back the reference to the calling Method?
    Thanks

    hmm, i'll take a shot at answering your query - hope this meets your requirement ... Java does manipulate objects by reference, and all object variables are references. So when a method returns a String object (this object would be created within the scope of the method) the object reference is returned to the caller.
    Now the point of confusion usually happens since, Java doesn't pass method arguments by reference; it passes them by value. Java passes object references by value as well. What this means is the references passed to the method are actually copies of the original references.Java copies and passes the reference by value, not the object. Thus, method manipulations on the object reference will alter the objects, since the references point to the original objects. But since the references are copies, swaps will fail.
    Hope the above helps.
    John Morrison

  • What is returned by narrow method?

    Hi,
    Following java code is part of the idlj-generated HelloHelper class. What is returned, When we called narrow() method in the client application code? It is stub or HelloApp.Hello object?
    ************** HelloHelper class *************************
    public static HelloApp.Hello narrow (org.omg.CORBA.Object obj){
    if (obj == null)
    return null;
    else if (obj instanceof HelloApp.Hello)
    return (HelloApp.Hello)obj;
    else if (!obj._is_a (id ()))
    throw new org.omg.CORBA.BAD_PARAM ();
    else{
    org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate ();
    HelloApp._HelloStub stub = new HelloApp._HelloStub ();
    stub._set_delegate(delegate);
    return stub;
    *********in the server application code****************
    HelloImpl helloImpl = new HelloImpl();
    org.omg.CORBA.Object ref = rootpoa.servant_to_reference(helloImpl);Hello href = HelloHelper.narrow(ref);
    String name = "Hello";NameComponent[] path = ncRef.to_name(name);ncRef.rebind(path, href);
    *********in the client application code****************
    static Hello hello;
    hello = HelloHelper.narrow(ncRef.resolve_str(name));
    Sincerely...

    Both. If the object is already a stub it returns it, otherwise it forms a stub from the object (presumably an IOR or the remote object itself) and returns it. In either case the stub is an instance of HelloApp.Hello which I would guess is a remote interface.

  • EJB method returns 2D String array

    Hi,
    one of EJB method returns a 2 dimensional array of String. Is it okay? Is this a good EJB programming practice?
    Thanks
    Sabir

    Its ok. but not consdered as best practice now.
    Check out the DTO pattern(previously called value obects from sun's site.
    --Ashwani                                                                                                                                                                                                                                                                       

  • Confusion in PortableRemoteObject.narrow() method

    In EJB 1.0 reference of home object is obtained through external casting as HelloHome home = (HelloHome)ctx.lookup("HelloHome")
    My question is that since IIOP has not been designed for Java, but for generic languages, and this means that there are some limitations. Some languages, in fact, do not have the concept of casting.
    Still why we have to cast the Object if we use PortableRemoteObject.narrow method for obtaining the home interface reference in EJB2.0.
    HelloHome home = (HelloHome)javax.rmi.PortableRemoteObject.narrow(object, HelloHome.class)

    If the client is built using Java, you can not explicitly cast from the Naming.lookup() function. Instead, you must use lookup() to return a generic java.lang.Object, and then cast to the specific object type with the PortableRemoteObject.Narrow(objectReference, interfaceName) method.

  • PortableRemoteObject.narrow() method

    Hi,
    I usually use this method in case of looking for some remote home interface. But recently I found some EJB examples, where an author ommited the PortableRemoteObject.narrow method. Actually the source code was generated by Lomboz.
    This unusual procedure made me to prepare some tests. I made some EJB bean and its interfaces, after that I made a little change inside on one cpy of home interface, that this one was out of date. In the end I generated appropriate client in two ways:
    - using PortableRemoteObject.narrow method
    - unusing PortableRemoteObject.narrow method
    The results, when I used PortableRemoteObject.narrow method and when I unused it is similar, both resposed by java.lang.ClassCastException
    The small difference was, in order to use PortableRemoteObject.narrow method I got:
    at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(Unknown Source)
         at javax.rmi.PortableRemoteObject.narrow(Unknown Source)
    Ommiting this method I got only;
    java.lang.ClassCastException: $Proxy0
    Well, in both ways I observed the same final exception:
    java.lang.ClassCastException, which good explains what happend wrong. What really is better to use PortableRemoteObject.narrow method based on my above experiences?
    Thank for some suggestions
    Krzysztof

    You need to do the .narrow() method on anything that comes across RMI. The reason is that you have no guarantee that the thing coming across RMI is a Java object. It's possible to send something other than a Java object.
    If your client is using a local interface instead of a remote interface, the narrow() is not required.

  • Find(String pkey) method returns multiple object of the same row

    I'm not quite sure what i've done or havent done, but I've implemented updating a row using the em.persist(Object) method.....works great, but after i did that a few times the find(String pkey) method returns multiple copies of 1 row in the db
    here are two rows in the db
    personid(PK) firstName lastName
    1234 joe jones
    2345 rachel jones
    when i execute any query looking for people with the last name jones, ie
    select object(p) from Person p where p.lastName='jones'
    it returns multiple objects of each row ie
    1234 joe jones
    1234 joe jones
    1234 joe jones
    1234 joe jones
    2345 rachel jones
    2345 rachel jones
    2345 rachel jones
    2345 rachel jones
    There is only one row for both rachel and joe in the db, but why is the entity manager returning multiple objects of each, and how do i prevent that without using DISTINCT?
    Thanks for the help in advance

    Sorry, i forgot to mention i'm using ejb 3 and jboss

  • Java.nio select() method return 0 in my client application

    Hello,
    I'm developing a simple chat application who echo messages
    But my client application loop because the select() method return 0
    This is my code
    // SERVER
    package test;
    import java.io.IOException;
    import java.net.InetSocketAddress;
    import java.nio.channels.SelectionKey;
    import java.nio.channels.Selector;
    import java.nio.channels.ServerSocketChannel;
    import java.nio.channels.SocketChannel;
    import java.util.Iterator;
    import java.util.Set;
    public class Server {
         private int port = 5001;
         public void work() {               
              try {
                   ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
                   serverSocketChannel.configureBlocking(false);
                   InetSocketAddress isa = new InetSocketAddress(port);               
                   serverSocketChannel.socket().bind(isa);
                   Selector selector = Selector.open();
                   serverSocketChannel.register(selector, SelectionKey.OP_ACCEPT);
                   System.out.println("Listing on "+port);
                   while(selector.select()>0) {
                        Set keys = selector.selectedKeys();
                        for(Iterator i = keys.iterator(); i.hasNext();) {
                             SelectionKey key = (SelectionKey) i.next();
                             i.remove();
                             if (key.isAcceptable()) {
                                  ServerSocketChannel keyChannel = (ServerSocketChannel)key.channel();                              
                                  SocketChannel channel = keyChannel.accept();
                                  channel.configureBlocking(false);                              
                                  channel.register(selector, SelectionKey.OP_READ );
                             } else if (key.isReadable()) {
                                  SocketChannel keyChannel = (SocketChannel) key.channel();
                                  String m = Help.read(keyChannel );
                                  Help.write(m.toUpperCase(), keyChannel );
              } catch (IOException e) {                                             
                   e.printStackTrace();                         
         public static void main(String[] args) {
              Server s = new Server();
              s.work();
    // CLIENT
    package test;
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.io.IOException;
    import java.net.InetSocketAddress;
    import java.nio.channels.SelectionKey;
    import java.nio.channels.Selector;
    import java.nio.channels.SocketChannel;
    import java.util.Iterator;
    import java.util.Set;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
    import javax.swing.SwingUtilities;
    public class Client extends JFrame  {
         private String host = "localhost";
         private int port = 5001;
         private SocketChannel socketChannel;
         private Selector selector;
         public void work() {               
              try {
                   socketChannel = SocketChannel.open();
                   socketChannel.configureBlocking(false);
                   InetSocketAddress isa = new InetSocketAddress(host, port);               
                   socketChannel.connect(isa);
                   selector = Selector.open();
                   socketChannel.register(selector, SelectionKey.OP_CONNECT | SelectionKey.OP_READ );
                   while(true) {
                        selector.select();
                        Set keys = selector.selectedKeys();
                        for(Iterator i = keys.iterator(); i.hasNext();) {
                             SelectionKey key = (SelectionKey) i.next();
                             i.remove();
                             if (key.isConnectable()) {
                                  SocketChannel keyChannel = (SocketChannel) key.channel();
                                  if (keyChannel.isConnectionPending()) {
                                       System.out.println("Connected "+keyChannel.finishConnect());                                                                           
                             } else if (key.isReadable()) {                                                                                                                                                           
                                  SocketChannel keyChannel = (SocketChannel) key.channel();                                             
                                  String m = Help.read(keyChannel);
                                  display(m);                                                                                                                                                                                                                   
              } catch (IOException e) {                                             
                   e.printStackTrace();                         
         private void display(final String m) {
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        area.append(m+"\n");
                        textFieed.setText("");
         private void sendMessage(final String m) {
              Thread t = new Thread(new Runnable() {               
                   public void run() {                                                                                
                        try {                         
                             Help.write(m, socketChannel);
                        } catch (IOException e) {               
                             e.printStackTrace();
              t.start();                    
         public Client() {
              addWindowListener(new WindowAdapter() {
                   public void windowClosing(WindowEvent e) {
                        System.exit(1);
              textFieed.addKeyListener(new KeyAdapter() {
                   public void keyPressed(KeyEvent e) {
                        if (e.getKeyCode()== KeyEvent.VK_ENTER) {
                             String m = textFieed.getText();
                             sendMessage(m);     
              area.setEditable(false);
              getContentPane().add(textFieed, "North");
              getContentPane().add(new JScrollPane(area));
              setBounds(200, 200, 400, 300);
              show();
         private String messageToSend;
         private JTextArea area = new JTextArea();
         JTextField textFieed = new JTextField();
         public static void main(String[] args) {
              Client s = new Client();
              s.work();
    // HELPER CLASS
    package test;
    import java.io.IOException;
    import java.nio.ByteBuffer;
    import java.nio.CharBuffer;
    import java.nio.channels.SocketChannel;
    import java.nio.charset.Charset;
    import java.nio.charset.CharsetDecoder;
    import java.nio.charset.CharsetEncoder;
    public class Help {
         private static Charset charset = Charset.forName("us-ascii");
         private static CharsetEncoder enc = charset.newEncoder();
         private static CharsetDecoder dec = charset.newDecoder();
         private static void log(String m) {
              System.out.println(m);
         public static String read(SocketChannel channel) throws IOException {
              log("*** start READ");                              
              int n;
              ByteBuffer buffer = ByteBuffer.allocate(1024);
              while((n = channel.read(buffer)) > 0) {
                   System.out.println("     adding "+n+" bytes");
              log("  BUFFER REMPLI : "+buffer);
              buffer.flip();               
              CharBuffer cb = dec.decode(buffer);          
              log("  CHARBUFFER : "+cb);
              String m = cb.toString();
              log("  MESSAGE : "+m);          
              log("*** end READ");
              //buffer.clear();
              return m;                    
         public static void write(String m, SocketChannel channel) throws IOException {          
              log("xxx start WRITE");          
              CharBuffer cb = CharBuffer.wrap(m);
              log("  CHARBUFFER : "+cb);          
              ByteBuffer  buffer = enc.encode(cb);
              log("  BUFFER ALLOUE REMPLI : "+buffer);
              int n;
              while(buffer.hasRemaining()) {
                   n = channel.write(buffer);                         
              System.out.println("  REMAINING : "+buffer.hasRemaining());
              log("xxx end WRITE");

    Here's the fix for that old problem. Change the work method to do the following
    - don't register interest in things that can't happen
    - when you connect register based on whether the connection is complete or pending.
    - add the OP_READ interest once the connection is complete.
    This doesn't fix all the other problems this code will have,
    eg.
    - what happens if a write is incomplete?
    - why does my code loop if I add OP_WRITE interest?
    - why does my interestOps or register method block?
    For code that answers all those questions see my obese post Taming the NIO Circus
    Here's the fixed up Client code
    // CLIENT
    package test
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.io.IOException;
    import java.net.InetSocketAddress;
    import java.nio.channels.SelectionKey;
    import java.nio.channels.Selector;
    import java.nio.channels.SocketChannel;
    import java.util.Iterator;
    import java.util.Set;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
    import javax.swing.SwingUtilities;
    public class Client extends JFrame  {
         private String host = "localhost";
         private int port = 5001;
         private SocketChannel socketChannel;
         private Selector selector;
         public void work() {
              try {
                   socketChannel = SocketChannel.open();
                   socketChannel.configureBlocking(false);
                   InetSocketAddress isa = new InetSocketAddress(host, port);
                   socketChannel.connect(isa);
                   selector = Selector.open();
                   int interest = 0;
                   if(socketChannel.isConnected())interest = SelectionKey.OP_READ;
                   else if(socketChannel.isConnectionPending())interest = SelectionKey.OP_CONNECT;
                   socketChannel.register(selector, interest);
                   while(true)
                        int nn = selector.select();
                        System.out.println("nn="+nn);
                        Set keys = selector.selectedKeys();
                        for(Iterator i = keys.iterator(); i.hasNext();)
                             SelectionKey key = (SelectionKey) i.next();
                             i.remove();
                             if (key.isConnectable())
                                  SocketChannel keyChannel = (SocketChannel) key.channel();
                                  System.out.println("Connected "+keyChannel.finishConnect());
                                  key.interestOps(SelectionKey.OP_READ);
                             if (key.isReadable())
                                  SocketChannel keyChannel = (SocketChannel) key.channel();
                                  String m = Help.read(keyChannel);
                                  display(m);
              } catch (IOException e) {
                   e.printStackTrace();
         private void display(final String m) {
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        area.append(m+"\n");
                        textFieed.setText("");
         private void sendMessage(final String m) {
              Thread t = new Thread(new Runnable() {
                   public void run() {
                        try {
                             Help.write(m, socketChannel);
                        } catch (IOException e) {
                             e.printStackTrace();
              t.start();
         public Client() {
              addWindowListener(new WindowAdapter() {
                   public void windowClosing(WindowEvent e) {
                        System.exit(1);
              textFieed.addKeyListener(new KeyAdapter() {
                   public void keyPressed(KeyEvent e) {
                        if (e.getKeyCode()== KeyEvent.VK_ENTER) {
                             String m = textFieed.getText();
                             sendMessage(m);
              area.setEditable(false);
              getContentPane().add(textFieed, "North");
              getContentPane().add(new JScrollPane(area));
              setBounds(200, 200, 400, 300);
              show();
         private String messageToSend;
         private JTextArea area = new JTextArea();
         JTextField textFieed = new JTextField();
         public static void main(String[] args) {
              Client s = new Client();
              s.work();

  • When a Method Returns an Object, does it return a copy or a pointer?

    When you have a method that returns an Object, is the Object returning a copy of the Object returned inside
    of the Method or is it an Actual pointer to the Object inside of the method's coresponding Object?
    so say you have an object ...
    Class Something {
    JLabel myLabel = new JLable("myLabel");
    public JLabel getLabel() {
    return myLabel;;
    Something something = new Something();
    JLable theLabel = something.getLabel()
    theLable.setString("theLable");
    so when I setString on the Object theLabel , am I going to change the value of myLabel inside of the Object something?

    Yes, it returns a pointer.

  • How to map AM method return values in the bean

    Hello -
    I have this requirement to map AM method return values in the bean as explained below. Please suggest a solution.
    Scenario: I am calling an AM method, which returns a String object on page load.
    AMImpl Method-
    public String getProfileName (){
    return "Profile";
    I wish to catch this retun value in the Bean Variable on page Load. I have created a methodAction biding on page and invokeAction to call this method on Page Load, but I don't know how to catch this value in the bean. Please suggest how to achieve this. Also, I need to achieve this in jsp page. I can't use TaskFlow for this.
    I am using ADF 11g.
    Regards -
    Rohit
    Edited by: Rohit Makkad on Apr 21, 2010 12:23 AM

    Hi, I think there are two ways, from the data control drag n drop the methods return value to the page. This way a binding for that will be created at the page definition eg retVal.
    and in the backing bean you can access it by calling resolveExpression("#{bindings.retVal.inputValue}")
    You can also call your method directly from the backbean
    ((YourAppModuleImpl) getBindings().getDataControl().getApplicationModule()).yourMethod();
    public DCBindingContainer getBindings() {
    return (DCBindingContainer) resolveExpression("#{bindings}");
    I dont know if the second method suits you
    Tilemahos

  • The class of the deferred-methods return type "{0}" can not be found.

    I am developing a multilingual portal application.
    I have the method that changes the locale based on user's choice in the bean and the method is being referred to as below.
    <af:selectOneChoice label="Select Language" autoSubmit="true"
    value="#{localeBean.locale}"
    valueChangeListener="localeBean.changeLocale">
    <af:selectItem label="English" value="en" id="si1"/>
    <af:selectItem label="French" value="fr" id="si2"/>
    <af:selectItem label="Dutch" value="nl" id="si3"/>
    </af:selectOneChoice>
    when i try to run the application, i am getting compile time errors as below,
    The class of the deferred-methods return type "{0}" can not be found.
    No property editor found for the bean "javax.el.MethodExpression".
    After going through the discussion forums i learned that the compilation errors can be resolved by setting the <jsp:directive.page deferredSyntaxAllowedAsLiteral="false> at the starting of the page.
    Even after that i am getting the compilation error.
    Any solutions, suggestions or possible approaches would be helpful as i am new to Webcenter Portal development.
    Thanks,

    The error you get points to a problem on the page (somewhere). Switch to source mode and check the right margin if you see orange or red marks. These are pointing to problems (not all are show stoppers, but they give you hints that something is not according to the standard for jsf, jsff, jsp or jspx pages.
    Have you checked that the bean is correctly defined and that it's reachable?
    Start a fresh page and isolate the problem, e.g. build a selectOneChoiuce on the new page (don't copy it as you might copy the error too) and make it work on the new page. Once you have it running you can compare the solution to your not running page.
    Timo

  • Can a method return a class ?

    hi,
    i have a simple question.
    can a method return class value ?
    in the below script i did'nt understand the commented line.
    package com.google.gwt.sample.stockwatcher.client;
    import com.google.gwt.user.client.rpc.RemoteService;
    import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
    @RemoteServiceRelativePath("login")
    public interface LoginService extends RemoteService {
      public LoginInfo login(String requestUri);  //What is this ? is this a sample of what i asked ?
    }

    The answer to your question is yes.
    The idea is that an object calls a function of another object (passing in objects to the function as arguments) in which that object returns an object (note the arguments or returned value of the function may alternately be primitive types). Each object typically encapsulates data and provides a rich set of functions to the calling object so that calling object doesn't have to deal with the raw data directly. Therefore, not only does the calling object get the data it wants, but also a rich set of functions that can manipulate that data.
    Example:
    Book book = new Book();
    int characterCount = book.getChapter(3).getParagraph(4).getSentence(12).getWord(8).getCharacterCount();
    In the above, each object (Book, Chapter,Paragraph,Sentence,Word) has a rich set of functions it provides to its caller.
    Example: the Sentence Object has a collection of word objects (raw data). Functions it provides to Paragraph object are:
    Word getWord(int index), Words getWords(), int getWordCount().
    If you haven't already done so, I suggest reading a book on Java from cover to cover to pick up such Object Oriented concepts.

  • Custom Login Module - Commit Method return TRUE always?

    Hi,
    I am creating a custom login module for my portal authentication.
    For the login module, should the commit() method always return TRUE?
    The example code on help.sap.com indicates yes to this question.
    However, the JAVA Sun standard indicates that commit should return FALSE if the preceding login method returned FALSE.
    Does the SAP example stray from the SUN standard?  How should I code the commit() method such that it works (Always TRUE, or follow lead of login() method)?
    Regards,
    Kevin

    Hi Kevin,
    I'm actually working with this document: <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/events/webinars/jaas%20login%20module%20development%20on%20webas%20java%20640.pdf#search=%22classloader%20sda%20jar%20reference%22">JAAS Login Modules</a>.
    There is also example code. If it should be ignored they return false, otherwise true (page 32).
    Regards,
    Marcus
    Message was edited by: Marcus Freiheit

  • Abstract class method returning unknown class

    Hi
    I have created an abstract class having one of the method returning an object of a class which is not present at the compiletime. surprisingly the compiler didn't check the availability of the returning class at compilation time. it gave exception of classnotfound when I tried to rum it.
    is there any explanation of it??

    Thanks for the replay. I got the reason.
    actually evenif I did not compile to class file, but I have kept my java file in the same directory. while compiling the abstract class the compiler automatically compiled the reffered class and generated the required class file.
    I got the error when I moved the java file to another dir
    the code is like
    <code>
    abstract class AbstractTest{
         CompleteClass method1(){
              System.out.println("inside method1 of abstract class");
              return new CompleteClass();
         ExtraClass method2(){
                   System.out.println("inside method2 of abstract class");
                   return new ExtraClass(); // this class was not compiled before
         } // only java file is there in the dir
         abstract void demoMethod();
    </code>

Maybe you are looking for