0

I have problem with calling remote ejb. I have successfully deployed remote EJB:

public interface IHelloWordlHome extends EJBHome {
    mybeans.IHelloWordl create() throws RemoteException, javax.ejb.CreateException;
}

public interface IHelloWordl extends javax.ejb.EJBObject {
    public String hello(String name) throws RemoteException;
}

@javax.ejb.Stateless(name = "HelloWordlEJB")
public class HelloWordlBean implements Serializable {
    public HelloWordlBean() {
    }

    public String hello(String name) {
        return "asd" + name;
    }

    public void ejbCreate() throws CreateException {
    }
}

ejb-jar.xml:

<enterprise-beans>
    <session>
        <ejb-name>HelloWordlEJB</ejb-name>
        <home>mybeans.IHelloWordlHome</home>
        <remote>mybeans.IHelloWordl</remote>
        <ejb-class>mybeans.HelloWordlBean</ejb-class>
        <session-type>Stateless</session-type>
        <transaction-type>Container</transaction-type>
    </session>
</enterprise-beans>

and now I am trying to run standalone client. That means it's totaly different application which now runs on same machine as server (localhost) but later it will run on different machine. As the glassfish description (dont have the link atm) says I used InitialContext without parameters, in server log I found the JNDI name of my bean ("java:global/ear_ear_exploded/ejb/HelloWordlEJB!mybeans.HelloWordlBean") and trying to look it up. I use gl-client.jar lib and I have it on my classpath. Note that I didnt copy that .jar, I am using the .jar in glassfish installation folder (I know that could be problem becouse it links other .jars) I copied (ctrl+c & ctrl+v) the bean interface (IHelloWordl) from server to client.

client code:

public static void main(String[] args) throws NamingException, RemoteException {
        IHelloWordl foo = (IHelloWordl) new InitialContext().lookup("java:global/ear_ear_exploded/ejb/HelloWordlEJB!mybeans.HelloWordlBean");
        foo.hello("Martin");
}

This is what my IDE runs:

P:\Java\jdk1.8.0\bin\java -Didea.launcher.port=7534 "-Didea.launcher.bin.path=P:\IntelliJ IDEA 13.1.1\bin" -Dfile.encoding=UTF-8 -classpath "P:\Java\jdk1.8.0\jre\lib\charsets.jar;P:\Java\jdk1.8.0\jre\lib\deploy.jar;P:\Java\jdk1.8.0\jre\lib\javaws.jar;P:\Java\jdk1.8.0\jre\lib\jce.jar;P:\Java\jdk1.8.0\jre\lib\jfr.jar;P:\Java\jdk1.8.0\jre\lib\jfxswt.jar;P:\Java\jdk1.8.0\jre\lib\jsse.jar;P:\Java\jdk1.8.0\jre\lib\management-agent.jar;P:\Java\jdk1.8.0\jre\lib\plugin.jar;P:\Java\jdk1.8.0\jre\lib\resources.jar;P:\Java\jdk1.8.0\jre\lib\rt.jar;P:\Java\jdk1.8.0\jre\lib\ext\access-bridge.jar;P:\Java\jdk1.8.0\jre\lib\ext\cldrdata.jar;P:\Java\jdk1.8.0\jre\lib\ext\dnsns.jar;P:\Java\jdk1.8.0\jre\lib\ext\jaccess.jar;P:\Java\jdk1.8.0\jre\lib\ext\jfxrt.jar;P:\Java\jdk1.8.0\jre\lib\ext\localedata.jar;P:\Java\jdk1.8.0\jre\lib\ext\nashorn.jar;P:\Java\jdk1.8.0\jre\lib\ext\sunec.jar;P:\Java\jdk1.8.0\jre\lib\ext\sunjce_provider.jar;P:\Java\jdk1.8.0\jre\lib\ext\sunmscapi.jar;P:\Java\jdk1.8.0\jre\lib\ext\sunpkcs11.jar;P:\Java\jdk1.8.0\jre\lib\ext\zipfs.jar;D:\projects\self\dt-reservation-system-for-doctors\project-ejbclient\out\production\project-ejbclient;D:\projects\self\dt-reservation-system-for-doctors\project-ejbclient\lib\javax.annotation.jar;D:\projects\self\dt-reservation-system-for-doctors\project-ejbclient\lib\javax.ejb.jar;D:\projects\self\dt-reservation-system-for-doctors\project-ejbclient\lib\javax.jms.jar;D:\projects\self\dt-reservation-system-for-doctors\project-ejbclient\lib\javax.transaction.jar;D:\projects\self\dt-reservation-system-for-doctors\project-ejbclient\lib\javax.persistence.jar;D:\projects\self\dt-reservation-system-for-doctors\project-ejbclient\lib\javax.servlet.jar;D:\projects\self\dt-reservation-system-for-doctors\project-ejbclient\lib\javax.resource.jar;D:\projects\self\dt-reservation-system-for-doctors\project-ejbclient\lib\javax.servlet.jsp.jar;D:\projects\self\dt-reservation-system-for-doctors\project-ejbclient\lib\javax.servlet.jsp.jstl.jar;P:\glassfish4\glassfish\lib\gf-client.jar;P:\glassfish4\glassfish\lib\appserv-rt.jar;P:\IntelliJ IDEA 13.1.1\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain mybeans.Main

When I run the client I am getting exception which I can't realy understand and found no help online:

Exception in thread "main" javax.naming.CommunicationException: Communication exception for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is java.rmi.MarshalException: CORBA BAD_PARAM 1398079494 Maybe; nested exception is: 
    java.io.NotSerializableException: ----------BEGIN server-side stack trace----------
org.omg.CORBA.BAD_PARAM: WARNING: 00100006: Class mybeans.__EJB31_Generated__HelloWordlBean__Intf____Bean__ is not Serializable  vmcid: SUN  minor code: 6 completed: Maybe
    at com.sun.proxy.$Proxy153.notSerializable(Unknown Source)
    at com.sun.corba.ee.impl.misc.ORBUtility.throwNotSerializableForCorba(ORBUtility.java:783)
    at com.sun.corba.ee.impl.javax.rmi.CORBA.Util.writeAny(Util.java:360)
    at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl$10.write(DynamicMethodMarshallerImpl.java:306)
    at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl.writeResult(DynamicMethodMarshallerImpl.java:488)
    at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:177)
    at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatchToServant(ServerRequestDispatcherImpl.java:528)
    at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatch(ServerRequestDispatcherImpl.java:199)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequestRequest(MessageMediatorImpl.java:1549)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:1425)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleInput(MessageMediatorImpl.java:930)
    at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:213)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:694)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.dispatch(MessageMediatorImpl.java:496)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.doWork(MessageMediatorImpl.java:2222)
    at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:497)
    at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:540)

----------END server-side stack trace----------]
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:513)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:438)
    at javax.naming.InitialContext.lookup(InitialContext.java:417)
    at mybeans.Main.main(Main.java:10)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.rmi.MarshalException: CORBA BAD_PARAM 1398079494 Maybe; nested exception is: 
    java.io.NotSerializableException: ----------BEGIN server-side stack trace----------
org.omg.CORBA.BAD_PARAM: WARNING: 00100006: Class mybeans.__EJB31_Generated__HelloWordlBean__Intf____Bean__ is not Serializable  vmcid: SUN  minor code: 6 completed: Maybe
    at com.sun.proxy.$Proxy153.notSerializable(Unknown Source)
    at com.sun.corba.ee.impl.misc.ORBUtility.throwNotSerializableForCorba(ORBUtility.java:783)
    at com.sun.corba.ee.impl.javax.rmi.CORBA.Util.writeAny(Util.java:360)
    at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl$10.write(DynamicMethodMarshallerImpl.java:306)
    at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl.writeResult(DynamicMethodMarshallerImpl.java:488)
    at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:177)
    at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatchToServant(ServerRequestDispatcherImpl.java:528)
    at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatch(ServerRequestDispatcherImpl.java:199)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequestRequest(MessageMediatorImpl.java:1549)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:1425)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleInput(MessageMediatorImpl.java:930)
    at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:213)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:694)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.dispatch(MessageMediatorImpl.java:496)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.doWork(MessageMediatorImpl.java:2222)
    at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:497)
    at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:540)

----------END server-side stack trace----------
    at com.sun.corba.ee.impl.javax.rmi.CORBA.Util.mapSystemException(Util.java:300)
    at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.privateInvoke(StubInvocationHandlerImpl.java:211)
    at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.invoke(StubInvocationHandlerImpl.java:150)
    at com.sun.corba.ee.impl.presentation.rmi.codegen.CodegenStubBase.invoke(CodegenStubBase.java:226)
    at com.sun.enterprise.naming.impl._SerialContextProvider_DynamicStub.lookup(com/sun/enterprise/naming/impl/_SerialContextProvider_DynamicStub.java)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:478)
    ... 8 more
Caused by: java.io.NotSerializableException: ----------BEGIN server-side stack trace----------
org.omg.CORBA.BAD_PARAM: WARNING: 00100006: Class mybeans.__EJB31_Generated__HelloWordlBean__Intf____Bean__ is not Serializable  vmcid: SUN  minor code: 6 completed: Maybe
    at com.sun.proxy.$Proxy153.notSerializable(Unknown Source)
    at com.sun.corba.ee.impl.misc.ORBUtility.throwNotSerializableForCorba(ORBUtility.java:783)
    at com.sun.corba.ee.impl.javax.rmi.CORBA.Util.writeAny(Util.java:360)
    at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl$10.write(DynamicMethodMarshallerImpl.java:306)
    at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl.writeResult(DynamicMethodMarshallerImpl.java:488)
    at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:177)
    at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatchToServant(ServerRequestDispatcherImpl.java:528)
    at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatch(ServerRequestDispatcherImpl.java:199)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequestRequest(MessageMediatorImpl.java:1549)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:1425)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleInput(MessageMediatorImpl.java:930)
    at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:213)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:694)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.dispatch(MessageMediatorImpl.java:496)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.doWork(MessageMediatorImpl.java:2222)
    at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:497)
    at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:540)

----------END server-side stack trace----------
    at com.sun.corba.ee.impl.javax.rmi.CORBA.Util.mapSystemException(Util.java:292)
    ... 13 more
Caused by: org.omg.CORBA.BAD_PARAM: ----------BEGIN server-side stack trace----------
org.omg.CORBA.BAD_PARAM: WARNING: 00100006: Class mybeans.__EJB31_Generated__HelloWordlBean__Intf____Bean__ is not Serializable  vmcid: SUN  minor code: 6 completed: Maybe
    at com.sun.proxy.$Proxy153.notSerializable(Unknown Source)
    at com.sun.corba.ee.impl.misc.ORBUtility.throwNotSerializableForCorba(ORBUtility.java:783)
    at com.sun.corba.ee.impl.javax.rmi.CORBA.Util.writeAny(Util.java:360)
    at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl$10.write(DynamicMethodMarshallerImpl.java:306)
    at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl.writeResult(DynamicMethodMarshallerImpl.java:488)
    at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:177)
    at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatchToServant(ServerRequestDispatcherImpl.java:528)
    at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatch(ServerRequestDispatcherImpl.java:199)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequestRequest(MessageMediatorImpl.java:1549)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:1425)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleInput(MessageMediatorImpl.java:930)
    at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:213)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:694)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.dispatch(MessageMediatorImpl.java:496)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.doWork(MessageMediatorImpl.java:2222)
    at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:497)
    at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:540)

----------END server-side stack trace----------  vmcid: SUN  minor code: 6 completed: Maybe
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
    at com.sun.corba.ee.impl.protocol.giopmsgheaders.MessageBase.getSystemException(MessageBase.java:813)
    at com.sun.corba.ee.impl.protocol.giopmsgheaders.ReplyMessage_1_2.getSystemException(ReplyMessage_1_2.java:131)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.getSystemExceptionReply(MessageMediatorImpl.java:594)
    at com.sun.corba.ee.impl.protocol.ClientRequestDispatcherImpl.processResponse(ClientRequestDispatcherImpl.java:519)
    at com.sun.corba.ee.impl.protocol.ClientRequestDispatcherImpl.marshalingComplete(ClientRequestDispatcherImpl.java:393)
    at com.sun.corba.ee.impl.protocol.ClientDelegateImpl.invoke(ClientDelegateImpl.java:272)
    at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.privateInvoke(StubInvocationHandlerImpl.java:198)
    ... 12 more

I am despread :/ Can anyone help?

Srneczek
  • 2,143
  • 1
  • 22
  • 26

2 Answers2

0

I'm not sure where you got this from but it looks like you mixed something up. In EJB 3 you don't have to extend EJBHome or EJBObject. You don't need the HomeInterface.

You should do it in this way:

import javax.ejb.Remote;

@Remote
public interface HelloWorldRemote {
    public String hello(String name);
}

and:

@javax.ejb.Stateless(name = "HelloWorldEJB")
public class HelloWorldBean implements HelloWorldRemote {

    public String hello(String name) {
        return "asd" + name;
    }
}

PS: There was a typo in your HelloWorld (HelloWordl).

You don't need any declaration in the ejb-jar.xml.

The client-code should look similar to this:

InitialContext con = new InitialContext();
HelloWorldBean foo = (HelloWorldBean) con.lookup("java:global/ear_ear_exploded/HelloWorldEJB");

See also:

Community
  • 1
  • 1
unwichtich
  • 13,712
  • 4
  • 53
  • 66
0

Your class must be serializable, meaning your EJB needs implements Serializable

mrossini
  • 378
  • 3
  • 10