Hi Wes,

I'm accessing the bean over a service locator. I have attached the class source at the end.

Regards,
Michael

Wes Wannemacher schrieb:
How are you getting a copy of your EJB in your action?

vwg.yyy.cancard.ui.action.Usermanagement.Usermanagement.list(Userman
agement.java:41)

That line in the stacktrace indicates that you are in the action when
you get the error, but the stacktrace dives down into a proxied object
after that. You do realize that you can't use the standard @Remote /
@Local on struts 2 action properties? Struts 2 creates it's own
objects so any JEE annotations are probably not going to work.

-Wes



package vwg.audi.cancard.ejb3connectors;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import javax.naming.InitialContext;
import javax.naming.NamingException;

import org.apache.log4j.Logger;

import vwg.audi.cancard.business.facade.CancardFacade;
import vwg.audi.cancard.business.facade.UserFacade;

/**
 * ServiceLocator
 * 
 * <p>The ServiceLocator handles the lookup of the EnterpriseJavaBeans.
 *
 *  @author Michael Obster
 */
public class ServiceLocator {

    private static Logger log = Logger.getLogger(ServiceLocator.class);
    private static ServiceLocator instance;
    private InitialContext context = null;
    private Map<String, Object> cache;

    private static final String USERSERVICE = "cancard/UserFacadeBean/local";
    private static final String CANCARDSERVICE = 
"cancard/CancardFacadeBean/local";
    
    /**
     * Create instance.
     * @param context initial context
     */
    private ServiceLocator(InitialContext context) {
        this.context = context;
        cache = Collections.synchronizedMap(new HashMap<String, Object>());
    }

    /**
     * Returns the instance of ServiceLocator class
     */
    public static ServiceLocator getInstance() throws ServiceLocatorException {
        if (instance == null) {
            try {
                instance = new ServiceLocator(new InitialContext());
            } catch (NamingException ne) {
                log.fatal("ServiceLocater could not be initialized!", ne);
                throw new ServiceLocatorException(ne);
            }
        }
        return instance;
    }

    public UserFacade getUserService() throws ServiceLocatorException {
        return (UserFacade) getRef(USERSERVICE);
    }
    
    public CancardFacade getCancardService() throws ServiceLocatorException {
        return (CancardFacade) getRef(CANCARDSERVICE);
    }
    
    private Object getRef(String refName) throws ServiceLocatorException {
        try {
            if (cache.containsKey(refName)) {
                return cache.get(refName);
            }
            Object ref = context.lookup(refName);
            cache.put(refName, ref);
            return ref;
        } catch (NamingException ne) {
            log.error("Service : " + refName + " could not be looked up!", ne);
            throw new ServiceLocatorException(ne);
        }
    }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to