EJB + WebLogic + Stand Alone Application

3 respostas
F

estou desenvolvedo um exemplo de chamada do EJB por uma aplicação Stand alone, mas esta dando uma exceção.
Estou utilizando o WebLogic 11gR1

A classe que faz o lookup

Context ctx = null;
        	Hashtable ht = new Hashtable();
        	ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
        	ht.put(Context.PROVIDER_URL,"t3://localhost:7001/");
        	ctx = new InitialContext(ht);
        	HelloBean helloBean =  (HelloBean) ctx.lookup ("HelloBean#br.com.teste.HelloBeanRemote");

O mapeamento no projeto EJB:

@Stateless (name = "HelloBean" , mappedName = "HelloBean")
public class HelloBean implements HelloBeanRemote{

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

    public String test() {
		return "Remote is Ready";
	}

}

Interface

@Remote
public interface HelloBeanRemote {

	public String test( );
}

ele retorna a seguinte exceção :

Exception in thread "main" java.lang.ClassCastException: $Proxy0 cannot be cast to br.com.teste.HelloBean
at br.com.tutorial.EjbCliente.connect(EjbCliente.java:37)
at br.com.tutorial.EjbCliente.main(EjbCliente.java:16)

No overview do JNDI tree fica

This page displays details about this bound object.
Binding Name:
HelloBean#br.com.teste.HelloBeanRemote

Class:
$Proxy109

Hash Code:
14629952

toString Results:
ClusterableRemoteRef(-1985301664966677648S::base_domain:AdminServer [-1985301664966677648S::base_domain:AdminServer/346])/346

Alguem sabe pq dessa exceção?

3 Respostas

felipeguerra
Troca sua interface por essa:
@Remote  
public interface HelloBeanRemote {  
   //JNDI name
   static final String JNDI_NAME = "HelloBeanRemote#seu.pacote.HelloBeanRemote";
  
    public String test( );  
}
HelloBeanRemote helloBean = (HelloBeanRemote) ctx.lookup (HelloBeanRemote.JNDI_NAME);
trabalhe com interface e não implementação.
F

troquei, mesmo assim deu a mesma exceção o.o qual o motivo de colocar essa variavel final na interface?

quando eu olho no console do weblogic as outras classes todas mostram o nome certo la no class Name do overview mas o meu remote bean fica $Proxy. … isso é correto ?

F

Eu não tinha visto a ultima parte da resposta … agora deu certo…
mas apenas corrigindo o que vc tinha falado a itnerface tem que ser

@Remote    
public interface HelloBeanRemote {    
   //JNDI name  
   static final String JNDI_NAME = "HelloBean#br.com.teste.HelloBeanRemote";  
    
    public String test( );    
}

static final String JNDI_NAME = “$NomeJNDI#pacote.HelloBeanRemote”;

$NomeJNDI = mappedName = “HelloBean” …

obrigado RESOLVIDO

Criado 16 de janeiro de 2012
Ultima resposta 16 de jan. de 2012
Respostas 3
Participantes 2