Hello
I'm trying to get gwt application to work with EJB3 and JPA.... via a servlet it works fine but when i use a factory with a servicelocator within my public class ProxyServiceImpl extends RemoteServiceServlet implements ProxyService, ServiceTemplateInterface { //@EJB EJBBWBean ejbSession; /** * */ EJBBWServiceLocal ejbSession =null; BusinessDelegator businessDelegator = null; private static final long serialVersionUID = -5280597539333461188L; public ProxyServiceImpl(){ System.out.println("EJB3ProxyServlet"); businessDelegator = BusinessDelegatorFactory.getBusinessDelegator(); try{ ejbSession = businessDelegator.getLocalEJBBWService(); }catch(Exception e){ System.err.println("Error occured "+ e.toString()); e.printStackTrace(); } } public boolean isAuthorizedPerson(String userId){ boolean isAuthorized = false; if ( DEBUG )System.out.println("HomeServiceServlet.isAuthorizedPerson (" + userId +" "); if("toine".equals(userId)){ isAuthorized = true; } return isAuthorized; } public String getUserName(){ return "toine eetgerink"; } @Override public boolean isAuthorized(String userId) { // TODO Auto-generated method stub return false; } @Override public List<Category> getCategorys() { // Thanks business delegate! ;-) return ejbSession.getCategorys(); } @Override public List<Subcategory> getSubCategorys(String catName) { // TODO Auto-generated method stub return null; } @Override public Users getUserByUserNameandPassword(String userName, String password){ return null; //return ejbSession.getUserByUserNamePassword(userName, password); } @Override public String getTest(){ if( ejbSession == null) { try{ ejbSession = businessDelegator.getLocalEJBBWService(); }catch(Exception e){ System.err.println("Error occured "+ e.toString()); e.printStackTrace(); } }else{ System.out.println(" getting session" +ejbSession.getClass().getName ()); } return ejbSession.getTest(); } } with factory ... package nl.betterwell.bwgxt01.server.services; import java.util.Hashtable; import java.util.Properties; import java.util.logging.Logger; import javax.naming.Context; import nl.betterwell.server.services.ServiceLocator; import nl.betterwell.server.services.ServiceLocatorOPENEJB; import nl.betterwell.server.services.ServiceLocatorWebSphere; public class BusinessDelegatorFactory { private static final Logger log = Logger.getLogger (BusinessDelegatorFactory.class.getName()); private static ServiceLocator serviceLocator = ServiceLocatorWebSphere.getInstance(); // return an instance of Business Delegator with serviceLocator constructor-injected public static BusinessDelegator getBusinessDelegator() { return new BusinessDelegator(serviceLocator); } /* */ } package nl.betterwell.bwgxt01.server.services; /** * Business Delegator * * @author toine eetgerink */ import java.util.logging.Logger; import nl.betterwell.server.services.ServiceLocator; import nl.betterwell.server.services.ServiceLocator.ServiceLocatorContext; import nl.betterwell.service.EJBBWServiceLocal; import nl.betterwell.service.EJBBWServiceRemote; public class BusinessDelegator { private static final String EJBBWSERVICEREMOTE = "nl.betterwell.service.EJBBWServiceRemote"; 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 EJBBWServiceRemote getRemoteEJBBWService() { //return null; return sl.lookupResource(EJBBWSERVICEREMOTE, ServiceLocatorContext.REMOTE); } } package nl.betterwell.server.services; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.rmi.PortableRemoteObject; /* * EJB3 Service Locator */ public class ServiceLocatorWebSphere extends ServiceLocator { static { try { setInstance(new ServiceLocatorWebSphere()); cache = Collections.synchronizedMap(new HashMap<String, Object>()); } catch (NamingException e) { log.log(Level.SEVERE, e.getMessage()); e.printStackTrace(System.err); } }; private static final String REMOTE_EJB_CONTAINER = "myhostname:2812"; public ServiceLocatorWebSphere() throws NamingException { initLocalServiceLocator(); initRemoteServiceLocator (REMOTE_EJB_CONTAINER,"username","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> 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> 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> 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to google-web-toolkit@googlegroups.com To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en -~----------~----~----~----~------~----~------~--~---