How do get EJB3 InitialContext working with GWT GXT - Websphere

This is a discussion on How do get EJB3 InitialContext working with GWT GXT - Websphere ; Hello I'm busy with GWT in a Dynamic Web App, and i want to use EJB3 and JPA with it How can I get it working I created a factory System.out.println("EJB3ProxyServlet"); businessDelegator = BusinessDelegatorFactory.getBusinessDelegator(); try{ ejbSession = businessDelegator.getLocalEJBBWService(); }catch(Exception e){ ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: How do get EJB3 InitialContext working with GWT GXT

  1. How do get EJB3 InitialContext working with GWT GXT

    Hello

    I'm busy with GWT in a Dynamic Web App, and i want to use EJB3 and JPA
    with it
    How can I get it working

    I created a factory
    System.out.println("EJB3ProxyServlet");
    businessDelegator = BusinessDelegatorFactory.getBusinessDelegator();
    try{
    ejbSession = businessDelegator.getLocalEJBBWService();
    }catch(Exception e){
    System.err.println("Error occured "+ e.toString());
    e.printStackTrace();
    }

    --------------------------
    piece of Factory

    private static ServiceLocator serviceLocator =
    ServiceLocatorWebSphere.getInstance();

    // return an instance of Business Delegator with serviceLocator
    constructor-injected
    public static BusinessDelegator getBusinessDelegator() {

    return new BusinessDelegator(serviceLocator);
    }

    ---------------------
    BusinessDelegator


    private static final String EJBBWSERVICELOCAL
    = "nl.betterwell.service.EJBBWServiceLocal";

    private static Logger log = Logger.getLogger
    (BusinessDelegator.class.getName());

    private ServiceLocator sl = null;

    public BusinessDelegator(ServiceLocator serviceLocator) {
    this.sl = serviceLocator;
    }

    public EJBBWServiceLocal getLocalEJBBWService() {
    //return null;
    return sl.lookupResource(EJBBWSERVICELOCAL,
    ServiceLocatorContext.LOCAL);
    }


    public class ServiceLocatorWebSphere extends ServiceLocator {

    static {

    try {
    setInstance(new ServiceLocatorWebSphere());
    cache = Collections.synchronizedMap(new HashMap());

    } catch (NamingException e) {

    log.log(Level.SEVERE, e.getMessage());
    e.printStackTrace(System.err);
    }

    };


    private static final String REMOTE_EJB_CONTAINER = "hostname:2812";

    public ServiceLocatorWebSphere() throws NamingException {

    initLocalServiceLocator();
    initRemoteServiceLocator
    (REMOTE_EJB_CONTAINER,"userid","password"); // TODO
    }

    private void initLocalServiceLocator() throws NamingException { //
    get Abstract!
    Properties properties = new Properties();
    properties.put(Context.INITIAL_CONTEXT_FACTORY,
    "com.ibm.websphere.naming.WsnInitialContextFactory");

    ctx = new InitialContext(properties);

    log.log(Level.INFO, "Local Initial Context ServiceLocator
    created.");
    }

    private void initRemoteServiceLocator(String url, String user, String
    password) throws NamingException {
    Properties properties = new Properties();
    properties.put(Context.INITIAL_CONTEXT_FACTORY,
    "com.ibm.websphere.naming.WsnInitialContextFactory");
    properties.put(Context.SECURITY_CREDENTIALS, user);
    properties.put(Context.SECURITY_PRINCIPAL, password);

    ctxRemote = new InitialContext(properties);

    log.log(Level.INFO, "Remote Initial Context ServiceLocator
    created.");
    }

    @SuppressWarnings("unchecked")
    public T lookupResource(String idResource, ServiceLocatorContext
    slc) {

    if (cache.containsKey(idResource)) // TODO check Local or Remote?
    return (T) cache.get(idResource);

    return (T) ((slc == ServiceLocatorContext.LOCAL) ?

    lookupLocalResource(idResource)
    :
    lookupRemoteResource(idResource));
    }

    @SuppressWarnings("unchecked")
    private T lookupLocalResource(String idResource) {

    try {
    log.log(Level.INFO, "OK... let's lookup Local (" + idResource +
    ") !");

    T ref = (T) ctx.lookup("ejblocal:"+ idResource );
    cache.put(idResource, ref);

    return ref;

    } catch (NamingException e) {

    log.log(Level.SEVERE, e.getMessage());
    e.printStackTrace();
    }

    return null;
    }

    @SuppressWarnings("unchecked")
    private T lookupRemoteResource(String idResource) {

    try {
    log.log(Level.INFO, "OK... let's lookup Remote (" + idResource +
    ") !");

    T ref = (T) ctxRemote.lookup(idResource);
    T ejb = (T)PortableRemoteObject.narrow(ref,Object.class);
    cache.put(idResource, ejb);

    return ref;

    } catch (NamingException e) {

    log.log(Level.SEVERE, e.getMessage());
    e.printStackTrace();
    }

    return null;
    }

    }


    Can anyone please help,
    If i can't get it working today i will be forced to do it the old way
    with DAOs and Beans


    regards TOINE

  2. Re: How do get EJB3 InitialContext working with GWT GXT

    On 7 okt, 14:36, "iamtoi...@gmail.com" wrote:
    > Hello
    >
    > I'm busy with GWT in a Dynamic Web App, and i want to use EJB3 and JPA
    > with it
    > How can I get it working
    >
    > I created a factory
    > * * * * System.out.println("EJB3ProxyServlet");
    > * * * * * * * * businessDelegator = BusinessDelegatorFactory.getBusinessDelegator();
    > * * * * * * * * try{
    > * * * * * * * * * * * * ejbSession = businessDelegator.getLocalEJBBWService();
    > * * * * * * * * }catch(Exception e){
    > * * * * * * * * * * * * System.err.println("Erroroccured "+ e.toString());
    > * * * * * * * * * * * * e.printStackTrace();
    > * * * * * * * * }
    >
    > --------------------------
    > piece of Factory
    >
    > * * * * private static ServiceLocator serviceLocator =
    > ServiceLocatorWebSphere.getInstance();
    >
    > * * * * // return an instance of Business Delegator with serviceLocator
    > constructor-injected
    > * * * * public static BusinessDelegator getBusinessDelegator() {
    >
    > * * * * * * * * return new BusinessDelegator(serviceLocator);
    > * * * * }
    >
    > ---------------------
    > BusinessDelegator
    >
    > * * * * private static final String EJBBWSERVICELOCAL
    > = * * * "nl.betterwell.service.EJBBWServiceLocal";
    >
    > * * * * private static Logger log = Logger.getLogger
    > (BusinessDelegator.class.getName());
    >
    > * * * * private ServiceLocator sl = null;
    >
    > * * * * public BusinessDelegator(ServiceLocator serviceLocator) {
    > * * * * * * * * this.sl = serviceLocator;
    > * * * * }
    >
    > * * * * public EJBBWServiceLocal getLocalEJBBWService() {
    > * * * * * * * * //return null;
    > * * * * * * * * return sl.lookupResource(EJBBWSERVICELOCAL,
    > ServiceLocatorContext.LOCAL);
    > * * * * }
    >
    > public class ServiceLocatorWebSphere extends ServiceLocator *{
    >
    > * * * * static {
    >
    > * * * * * * * * try {
    > * * * * * * * * * * * * setInstance(new ServiceLocatorWebSphere());
    > * * * * * * * * * * * * cache = Collections.synchronizedMap(new HashMap());
    >
    > * * * * * * * * } catch (NamingException e) {
    >
    > * * * * * * * * * * * * log.log(Level.SEVERE, e.getMessage());
    > * * * * * * * * * * * * e.printStackTrace(System.err);
    > * * * * * * * * }
    >
    > * * * * };
    >
    > * * * * private static final String REMOTE_EJB_CONTAINER = "hostname:2812";
    >
    > * * * * public ServiceLocatorWebSphere() throws NamingException {
    >
    > * * * * * * * * initLocalServiceLocator();
    > * * * * * * * * initRemoteServiceLocator
    > (REMOTE_EJB_CONTAINER,"userid","password"); // TODO
    > * * * * }
    >
    > * * * * private void initLocalServiceLocator() throws NamingException { //
    > get Abstract!
    > * * * * * * * * Properties properties = new Properties();
    > * * * * * * * * properties.put(Context.INITIAL_CONTEXT_FACTORY,
    > "com.ibm.websphere.naming.WsnInitialContextFactory");
    >
    > * * * * * * * * ctx = new InitialContext(properties);
    >
    > * * * * * * * * log.log(Level.INFO, "Local Initial Context ServiceLocator
    > created.");
    > * * * * }
    >
    > * * * * private void initRemoteServiceLocator(String url, String user, String
    > password) throws NamingException {
    > * * * * * * * * Properties properties = new Properties();
    > * * * * * * * * properties.put(Context.INITIAL_CONTEXT_FACTORY,
    > "com.ibm.websphere.naming.WsnInitialContextFactory");
    > * * * * * * * * properties.put(Context.SECURITY_CREDENTIALS, user);
    > * * * * * * * * properties.put(Context.SECURITY_PRINCIPAL, password);
    >
    > * * * * * * * * ctxRemote = new InitialContext(properties);
    >
    > * * * * * * * * log.log(Level.INFO, "Remote Initial Context ServiceLocator
    > created.");
    > * * * * }
    >
    > * * * * @SuppressWarnings("unchecked")
    > * * * * public T lookupResource(String idResource, ServiceLocatorContext
    > slc) {
    >
    > * * * * * * * * if (cache.containsKey(idResource)) // TODO check Local or Remote?
    > * * * * * * * * * * * * return (T) cache.get(idResource);
    >
    > * * * * * * * * return (T) ((slc == ServiceLocatorContext.LOCAL) ?
    >
    > * * * * * * * * * * * * * * * * lookupLocalResource(idResource)
    > * * * * * * * * * * * * :
    > * * * * * * * * * * * * * * * * lookupRemoteResource(idResource));
    > * * * * }
    >
    > * * * * @SuppressWarnings("unchecked")
    > * * * * private T lookupLocalResource(String idResource) {
    >
    > * * * * * * * * try {
    > * * * * * * * * * * * * log.log(Level.INFO, "OK.... let's lookup Local (" + idResource +
    > ") !");
    >
    > * * * * * * * * * * * * T ref = (T) ctx.lookup("ejblocal:"+ idResource );
    > * * * * * * * * * * * * cache.put(idResource, ref);
    >
    > * * * * * * * * * * * * return ref;
    >
    > * * * * * * * * } catch (NamingException e) {
    >
    > * * * * * * * * * * * * log.log(Level.SEVERE, e.getMessage());
    > * * * * * * * * * * * * e.printStackTrace();
    > * * * * * * * * }
    >
    > * * * * * * * * return null;
    > * * * * }
    >
    > * * * * @SuppressWarnings("unchecked")
    > * * * * private T lookupRemoteResource(String idResource) {
    >
    > * * * * * * * * try {
    > * * * * * * * * * * * * log.log(Level.INFO, "OK.... let's lookup Remote (" + idResource +
    > ") !");
    >
    > * * * * * * * * * * * * T ref = (T) ctxRemote.lookup(idResource);
    > * * * * * * * * * * * * T ejb = (T)PortableRemoteObject.narrow(ref,Object.class);
    > * * * * * * * * * * * * cache.put(idResource, ejb);
    >
    > * * * * * * * * * * * * return ref;
    >
    > * * * * * * * * } catch (NamingException e) {
    >
    > * * * * * * * * * * * * log.log(Level.SEVERE, e.getMessage());
    > * * * * * * * * * * * * e.printStackTrace();
    > * * * * * * * * }
    >
    > * * * * * * * * return null;
    > * * * * }
    >
    > }
    >
    > Can anyone please help,
    > If i can't get it working today i will be forced to do it the old way
    > with DAOs and Beans
    >
    > regards TOINE


    FIXED it Service Locator did not init the Context

  3. Re: How do get EJB3 InitialContext working with GWT GXT

    On 7 okt, 14:36, "iamtoi...@gmail.com" wrote:
    > Hello
    >
    > I'm busy with GWT in a Dynamic Web App, and i want to use EJB3 and JPA
    > with it
    > How can I get it working
    >
    > I created a factory
    > * * * * System.out.println("EJB3ProxyServlet");
    > * * * * * * * * businessDelegator = BusinessDelegatorFactory.getBusinessDelegator();
    > * * * * * * * * try{
    > * * * * * * * * * * * * ejbSession = businessDelegator.getLocalEJBBWService();
    > * * * * * * * * }catch(Exception e){
    > * * * * * * * * * * * * System.err.println("Erroroccured "+ e.toString());
    > * * * * * * * * * * * * e.printStackTrace();
    > * * * * * * * * }
    >
    > --------------------------
    > piece of Factory
    >
    > * * * * private static ServiceLocator serviceLocator =
    > ServiceLocatorWebSphere.getInstance();
    >
    > * * * * // return an instance of Business Delegator with serviceLocator
    > constructor-injected
    > * * * * public static BusinessDelegator getBusinessDelegator() {
    >
    > * * * * * * * * return new BusinessDelegator(serviceLocator);
    > * * * * }
    >
    > ---------------------
    > BusinessDelegator
    >
    > * * * * private static final String EJBBWSERVICELOCAL
    > = * * * "nl.betterwell.service.EJBBWServiceLocal";
    >
    > * * * * private static Logger log = Logger.getLogger
    > (BusinessDelegator.class.getName());
    >
    > * * * * private ServiceLocator sl = null;
    >
    > * * * * public BusinessDelegator(ServiceLocator serviceLocator) {
    > * * * * * * * * this.sl = serviceLocator;
    > * * * * }
    >
    > * * * * public EJBBWServiceLocal getLocalEJBBWService() {
    > * * * * * * * * //return null;
    > * * * * * * * * return sl.lookupResource(EJBBWSERVICELOCAL,
    > ServiceLocatorContext.LOCAL);
    > * * * * }
    >
    > public class ServiceLocatorWebSphere extends ServiceLocator *{
    >
    > * * * * static {
    >
    > * * * * * * * * try {
    > * * * * * * * * * * * * setInstance(new ServiceLocatorWebSphere());
    > * * * * * * * * * * * * cache = Collections.synchronizedMap(new HashMap());
    >
    > * * * * * * * * } catch (NamingException e) {
    >
    > * * * * * * * * * * * * log.log(Level.SEVERE, e.getMessage());
    > * * * * * * * * * * * * e.printStackTrace(System.err);
    > * * * * * * * * }
    >
    > * * * * };
    >
    > * * * * private static final String REMOTE_EJB_CONTAINER = "hostname:2812";
    >
    > * * * * public ServiceLocatorWebSphere() throws NamingException {
    >
    > * * * * * * * * initLocalServiceLocator();
    > * * * * * * * * initRemoteServiceLocator
    > (REMOTE_EJB_CONTAINER,"userid","password"); // TODO
    > * * * * }
    >
    > * * * * private void initLocalServiceLocator() throws NamingException { //
    > get Abstract!
    > * * * * * * * * Properties properties = new Properties();
    > * * * * * * * * properties.put(Context.INITIAL_CONTEXT_FACTORY,
    > "com.ibm.websphere.naming.WsnInitialContextFactory");
    >
    > * * * * * * * * ctx = new InitialContext(properties);
    >
    > * * * * * * * * log.log(Level.INFO, "Local Initial Context ServiceLocator
    > created.");
    > * * * * }
    >
    > * * * * private void initRemoteServiceLocator(String url, String user, String
    > password) throws NamingException {
    > * * * * * * * * Properties properties = new Properties();
    > * * * * * * * * properties.put(Context.INITIAL_CONTEXT_FACTORY,
    > "com.ibm.websphere.naming.WsnInitialContextFactory");
    > * * * * * * * * properties.put(Context.SECURITY_CREDENTIALS, user);
    > * * * * * * * * properties.put(Context.SECURITY_PRINCIPAL, password);
    >
    > * * * * * * * * ctxRemote = new InitialContext(properties);
    >
    > * * * * * * * * log.log(Level.INFO, "Remote Initial Context ServiceLocator
    > created.");
    > * * * * }
    >
    > * * * * @SuppressWarnings("unchecked")
    > * * * * public T lookupResource(String idResource, ServiceLocatorContext
    > slc) {
    >
    > * * * * * * * * if (cache.containsKey(idResource)) // TODO check Local or Remote?
    > * * * * * * * * * * * * return (T) cache.get(idResource);
    >
    > * * * * * * * * return (T) ((slc == ServiceLocatorContext.LOCAL) ?
    >
    > * * * * * * * * * * * * * * * * lookupLocalResource(idResource)
    > * * * * * * * * * * * * :
    > * * * * * * * * * * * * * * * * lookupRemoteResource(idResource));
    > * * * * }
    >
    > * * * * @SuppressWarnings("unchecked")
    > * * * * private T lookupLocalResource(String idResource) {
    >
    > * * * * * * * * try {
    > * * * * * * * * * * * * log.log(Level.INFO, "OK.... let's lookup Local (" + idResource +
    > ") !");
    >
    > * * * * * * * * * * * * T ref = (T) ctx.lookup("ejblocal:"+ idResource );
    > * * * * * * * * * * * * cache.put(idResource, ref);
    >
    > * * * * * * * * * * * * return ref;
    >
    > * * * * * * * * } catch (NamingException e) {
    >
    > * * * * * * * * * * * * log.log(Level.SEVERE, e.getMessage());
    > * * * * * * * * * * * * e.printStackTrace();
    > * * * * * * * * }
    >
    > * * * * * * * * return null;
    > * * * * }
    >
    > * * * * @SuppressWarnings("unchecked")
    > * * * * private T lookupRemoteResource(String idResource) {
    >
    > * * * * * * * * try {
    > * * * * * * * * * * * * log.log(Level.INFO, "OK.... let's lookup Remote (" + idResource +
    > ") !");
    >
    > * * * * * * * * * * * * T ref = (T) ctxRemote.lookup(idResource);
    > * * * * * * * * * * * * T ejb = (T)PortableRemoteObject.narrow(ref,Object.class);
    > * * * * * * * * * * * * cache.put(idResource, ejb);
    >
    > * * * * * * * * * * * * return ref;
    >
    > * * * * * * * * } catch (NamingException e) {
    >
    > * * * * * * * * * * * * log.log(Level.SEVERE, e.getMessage());
    > * * * * * * * * * * * * e.printStackTrace();
    > * * * * * * * * }
    >
    > * * * * * * * * return null;
    > * * * * }
    >
    > }
    >
    > Can anyone please help,
    > If i can't get it working today i will be forced to do it the old way
    > with DAOs and Beans
    >
    > regards TOINE


    FIXED

    Did NOT Init the Context

    regards toine

+ Reply to Thread