NullPointerException - ServiceLocator BEA WebLogic

Pessoal, estou usando ServiceLocator para pegar minha interface EJB, mas ta dando NullPointer alguem ajuda?

<07/02/2012 18h45min41s BRST> <Error> <HTTP> <BEA-101017> <[weblogic.servlet.internal.WebAppServletContext@19494f6 - appName: 'TesteEAR', name: 'Teste', context-path: '/Teste'] Root cause of ServletException. javax.faces.el.EvaluationException: java.lang.NullPointerException at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:98) at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:98) at javax.faces.component.UICommand.broadcast(UICommand.java:311) at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:781) at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1246) Truncated. see log file for complete stacktrace java.lang.NullPointerException at utils.ServiceLocator.jndiLookup(ServiceLocator.java:102) at utils.ServiceLocator.getLocalBean(ServiceLocator.java:83) at managedBeans.Teste.logar(Teste.java:28) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) Truncated. see log file for complete stacktrace

No meu servidor esta o projeto EAR que contem um WEB e um EJB

oq tem nessa linha?
utils.ServiceLocator.jndiLookup(ServiceLocator.java:102)

Isso aqui;

[code]private Object jndiLookup(String service){
try {
System.out.println(service);
return context.lookup(service);
} catch (NamingException e) {
System.out.println(e.getMessage());
throw null;
}

}[/code]

o e.getMessage ali gera esse erro: While trying to lookup 'LogarServiceBean.local' didn't find subcontext 'LogarServiceBean'. Resolved ''

Como você declarou esse cara? LogarServiceBean

Criei Session Bean EJB

[code]package session;

import javax.ejb.EJB;
import javax.ejb.Stateless;

import daos.DAOFactoryVivo;
import entity.Logar;

/**

  • Session Bean implementation class LogarServiceBean
    */
    @Stateless
    public class LogarServiceBean implements LogarService {

    @EJB
    DAOFactoryVivo dao;

    /**

    • Default constructor.
      */
      public LogarServiceBean() {
      // TODO Auto-generated constructor stub
      }

    public void insereLogar(Logar logar) {
    // TODO Auto-generated method stub
    dao.getVivoDAO().atualiza(logar);
    }

}
[/code]

Como que tá esse cara aqui? LogarService

Você ta fazendo look up na interface ou no bean direto?

LogarService ta assim:

[code]package session;
import javax.ejb.Local;

import entity.Logar;

@Local
public interface LogarService {

public void insereLogar(Logar logar);

}
[/code]

O look up ta na interface assim:

LogarService logarService = ServiceLocatorApp.getInstance().getLocalBean(LogarService.class);

Cara, nunca vi lookup sendo feito assim não: ServiceLocatorApp.getInstance().getLocalBean(LogarService.class);

Geralmente na hora do lookup é através de uma String que registra a classe no JNDI.

[quote=jakefrog]Cara, nunca vi lookup sendo feito assim não: ServiceLocatorApp.getInstance().getLocalBean(LogarService.class);

Geralmente na hora do lookup é através de uma String que registra a classe no JNDI.[/quote]

Tem algum exemplo que eu possa testar aqui?

Posso passar aqui pra ver se vc pode me ajudar?

ServiceLocatorApp

[code]package utils;

public class ServiceLocatorApp extends ServiceLocator {

private final String NOME_APLICACAO = "";
private final String SUFIXO_LOCAL = "Bean/local";
private final String SUFIXO_REMOTO = "Bean/remote";

private static ServiceLocatorApp instance = null;

private ServiceLocatorApp(){
	super.setup(NOME_APLICACAO, SUFIXO_LOCAL, SUFIXO_REMOTO);
}

public static ServiceLocatorApp getInstance(){
	if (instance == null){
	
		instance = new ServiceLocatorApp();
	}
	return instance;
}

}
[/code]

ServiceLocator

[code]package utils;

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

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;

public class ServiceLocator {

private String NOME_APLICACAO = "";
private String SUFIXO_LOCAL = "Bean/local";
private String SUFIXO_REMOTO = "Bean/remote";

InitialContext context = null;
Map<String,Object> cache = null;
	

/**
 * Inicializa service locator. 
 * Assume como sufixo dos beans: SUFIXO_LOCAL = "Bean/local" e SUFIXO_REMOTO = "Bean/remote".
 * 
 * @param nomeAplicacao nome da aplicação 
 */
public void setup(String nomeAplicacao){
	
	try {
		context = new InitialContext();
		cache = Collections.synchronizedMap(new HashMap<String,Object>());
	} catch  (NamingException e) {
		throw new RuntimeException(e);
	}
	
	if (!(nomeAplicacao == null || nomeAplicacao.trim().equals(""))){
		NOME_APLICACAO = nomeAplicacao + "/";
	}
}
	
/**
 * Inicializa service locator
 * 
 * @param nomeAplicacao nome da aplicação
 * @param sufixoLocal sufixo dos beans locais
 * @param sufixoRemoto sufixo dos beans remotos
 */
public void setup(String nomeAplicacao, String sufixoLocal, String sufixoRemoto){
	setup(nomeAplicacao);
	
	SUFIXO_LOCAL =  sufixoLocal;
	SUFIXO_REMOTO = sufixoRemoto;
}


/**
 * Obtem bean remoto 
 * @param interfaceRemota tipo do bean
 * @return
 */
@SuppressWarnings("unchecked")
public <T> T getRemoteBean(Class<T> interfaceRemota){
	String serviceName = getServiceName(interfaceRemota,false);
	T servico = (T)cache.get(serviceName);
	if (servico == null) {
		Object ref = jndiLookup(serviceName);
		servico = (T) PortableRemoteObject.narrow(ref, interfaceRemota);
		cache.put(serviceName, servico);
	}
	return servico;
}

/**
 * Obtem bean local
 * @param interfaceRemota tipo do bean
 * @return
 */
@SuppressWarnings("unchecked")
public <T> T getLocalBean(Class<T>interfaceLocal){
	String serviceName = getServiceName(interfaceLocal,true);
	T servico = (T)cache.get(serviceName);
	if (servico == null) {
		Object ref = jndiLookup(serviceName);
		servico = (T) PortableRemoteObject.narrow(ref, interfaceLocal);
		cache.put(serviceName, servico);
	}
	return servico;
}

private String getServiceName(Class<?> beanInterface, final boolean isLocal) {
	if (isLocal){
		return  NOME_APLICACAO + beanInterface.getSimpleName() + SUFIXO_LOCAL; 
	} else {
		return  NOME_APLICACAO + beanInterface.getSimpleName() + SUFIXO_REMOTO;
	}
}

private Object jndiLookup(String service){
	try {
		System.out.println(service);
		return context.lookup(service);
	} catch (NamingException e) {
		System.out.println(e.getMessage());
		throw null; 
   }

}

}
[/code]

Tem alguma coisa haver com meu EJB esta dentro do EAR?

Preciso criar algo no ejb-jar.xml?

Isso varia de servidor para servidor.

Achei esse post aqui que eu acho que irá te ajudar: http://www.guj.com.br/java/132452-lookup-de-ejb-local-no-weblogic-103

Consegui com esse post mesmo Jake hehe, valeu!!