Invoking Method reflection

Discussions

EJB programming & troubleshooting: Invoking Method reflection

  1. Invoking Method reflection (9 messages)

    Hi,

    I am trying to invoke a method on my remote EJB SB using reflection.

    This method takes a serilizable object as its parameter,
    when trying to access this method with reflection code throws "java.lang.IllegalArgumentException: argument type mismatch"

    I cross checked the paramter type its matching with the method in ejb

    any help is appreciated

    Regards
    Shoj

    Threaded Messages (9)

  2. Invoking Method reflection[ Go to top ]

    Hi,
      Just check whether the first argument is the stub object which is used to call the method on it .Hope this helps.

    Cheers
    Deb
  3. Invoking Method reflection[ Go to top ]

    Hi,

    Its a value object not a Stub of any sort

    Regards
    Shoj
  4. Invoking Method reflection[ Go to top ]

    Try to make it work first without using reflection. This eliminates the class version mismatches etc. These errors dont come out as simple errors when we use reflection. Once it works normally, u can try reflection.
  5. Invoking Method reflection[ Go to top ]

    Hi

    Its working without reflection !!!!
  6. code snippet plzzzzz[ Go to top ]

    hi,

    can you dump your code snippet here ? i think that would give us better idea since the exception stack is hardly enough.

    shrini
  7. code snippet plzzzzz[ Go to top ]

    public void myMethod(ValueObject vo)
    {
    Method[] methods = ejbObject.getClass().getMethods();
    Method method;

    int count = methods.length;
    try {
    Object[] args = new Object[1];
    args[0] = vo;

    for(int i=0; i<count;i++)
    {
    method = methods[i];
    if(method.getName().equals("myMethod")){
    method.invoke(ejbObject,args);
    break;
    }
    }
    } catch (IllegalArgumentException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IllegalAccessException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (InvocationTargetException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    }
  8. code snippet plzzzzz[ Go to top ]

    Is myMethod overloaded? Rather than getting all the methods on ejbObject and then looking for a matching name you might be better off getting the specific one that you want, specifying the parameter types:

    Class[] types = { vo.getClass() };
    method = ejbObject.getClass().getMethod("myMethod", types);
    Object[] args = { vo };
    method.invoke(ejbObject, args);
  9. code snippet plzzzzz[ Go to top ]

    I agree with DS.
    Can you try it and let us know ?

    Also what is ejbObject ?
    I mean is that a remote interface got from home ? Then check what is the ejbObject.getClass() ? I doubt that this may not be a remote interface ?

    pls post ur findings.

    shrini
  10. EJBObject is the stub[ Go to top ]

    EJBObject is the stub I mentioned above . It represents the client side stub to communicate ..

    Thanks
    Deb