1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package bin;
import ejb.BookManagerRemote;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import jpa.Book;
/**
*
* @author lolveley
*/
public class Reservoir {
static Context ctx;
public void init() throws NamingException {
//ctx = new InitialContext();
Properties jndiProps = new Properties();
jndiProps.put("java.naming.factory.initial", "com.sun.enterprise.naming.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");
ctx = new InitialContext(jndiProps);
}
public Long create_book() throws NamingException {
Book book = new Book("Holmes & Watson");
book.setId(1L);
Object a = ctx.lookup(BookManagerRemote.class.getName());
BookManagerRemote bookEJB = (BookManagerRemote) a;
book = bookEJB.create(book);
return book.getId();
}
} |
Partager