users@glassfish.java.net

Re: GlassFish v3, EJB 3.1 and Standalone Client

From: <glassfish_at_javadesktop.org>
Date: Mon, 14 Dec 2009 02:29:24 PST

hello Witold,
you're absolutely right,
there was my mistake with understanding, interface is not required if you don't want remote assess.

now here is working example:
1.Remote Interface:
[code]
/**
 *
 * @author paatal
 */
@Remote
public interface SessBeanInt {

    public String testMethod(String name) throws Exception;
    
}

[/code]
2. Implementation:
[code]
/**
 *
 * @author paatal
 */
@Stateless
@Remote(SessBeanInt.class)
public class MySessionBean implements SessBeanInt {

    public String testMethod(String name) throws Exception {
        System.out.println("testMethod initialized.");
        return "Hello : " + name;
    }
}
[/code]

3. remote test client :
[code]
/**
 *
 * @author paatal
 */
public class Main {

    public static void main(String[] args) {
        try {
            Properties jndiProps = new Properties();
            jndiProps.put("java.naming.factory.initial", "com.sun.enterprise.naming.impl.SerialInitContextFactory");
            jndiProps.put("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
            jndiProps.put("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
            jndiProps.setProperty("org.omg.CORBA.ORBInitialHost", "127.0.0.1");
            jndiProps.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
            Context ctx = new InitialContext(jndiProps);
            SessBeanInt mySessionBean = (SessBeanInt) ctx.lookup("java:global/MyEJBModule/MySessionBean");
            System.out.println(mySessionBean.testMethod("Paata"));

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
[/code]

server output : "INFO: testMethod initialized."
client output : "Hello : Paata"
[Message sent by forum member 'paata' ]

http://forums.java.net/jive/thread.jspa?messageID=376360