Jboss 7, lookup remoto

2 respostas
D

Pessoal, estou desenvolvendo meu primeiro ejb 3 client no jboss 7.1. Mas, não consigo fazer lookup.
Faço deploy dos ejbs e o console mostra o seguinte:

[b]11:48:33,718 INFO [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-8) JNDI bindings for session bean named CalculatorBean in deployment unit subdeployment “EJB3_Chap02.jar” of deployment “TesteEar.ear” are as follows:

java:global/TesteEar/EJB3_Chap02/CalculatorBean!calc.CalculatorRemote
java:app/EJB3_Chap02/CalculatorBean!calc.CalculatorRemote
java:module/CalculatorBean!calc.CalculatorRemote
java:jboss/exported/TesteEar/EJB3_Chap02/CalculatorBean!calc.CalculatorRemote
java:global/TesteEar/EJB3_Chap02/CalculatorBean
java:app/EJB3_Chap02/CalculatorBean
java:module/CalculatorBean[/b]

Faço lookup da seguinte maneira, mas nada funciona:

[b]package calc.client;

import java.util.Hashtable;

import javax.naming.Context;

import javax.naming.InitialContext;

import javax.naming.NamingEnumeration;

import javax.naming.NamingException;

import calc.CalculatorRemote;

public class CalculatorClient {

private static CalculatorRemote remote;

public static void main(String[] args) {

try{

remote = lookupRemoteStatelessCalculator();

<a href="//context.lookup">//context.lookup</a>(“EJB3_Chap02/” + CalculatorBean.class.getSimpleName() + “/remote”);

System.out.println(remote.add(1, 1));

}catch (Exception e) {

e.printStackTrace();

}

}
private static CalculatorRemote lookupRemoteStatelessCalculator() throws NamingException {
    final Hashtable jndiProperties = new Hashtable();
    //jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
    jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
    jndiProperties.put(Context.PROVIDER_URL, "remote://127.0.0.1:4447");
    
    //jndiProperties.put("remote.connection.default.username","dayserivera");
    //jndiProperties.put("remote.connection.default.password", "dayse");
    jndiProperties.put(Context.SECURITY_PRINCIPAL, "dayserivera");
    jndiProperties.put(Context.SECURITY_CREDENTIALS, "dayse");
    /*
    jndiProperties.put("endpoint.name", "client-endpoint");
    jndiProperties.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");
    jndiProperties.put("remote.connections", "default");
    jndiProperties.put("remote.connection.default.port", "4447");
    jndiProperties.put("remote.connection.default.host", "localhost");
    */
    jndiProperties.put("remote.connection.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS", "JBOSS-LOCAL-USER");
    jndiProperties.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "false");
    jndiProperties.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false");
    
    //jndiProperties.put("jboss.naming.client.ejb.context", true);
    
    final Context context = new InitialContext(jndiProperties);
    NamingEnumeration<?> namingEnum = context.list("java");
    while(namingEnum.hasMoreElements()){
    	Object obj = namingEnum.nextElement();
    	System.out.println(obj);
    }
    
    System.out.println(context.lookup("ejb:TesteEar/EJB3_Chap02//CalculatorBean!calc.CalculatorRemote"));
    
    // The app name is the application name of the deployed EJBs. This is typically the ear name
    // without the .ear suffix. However, the application name could be overridden in the application.xml of the
    // EJB deployment on the server.
    // Since we haven't deployed the application as a .ear, the app name for us will be an empty string
    final String appName = "";
    // This is the module name of the deployed EJBs on the server. This is typically the jar name of the
    // EJB deployment, without the .jar suffix, but can be overridden via the ejb-jar.xml
    // In this example, we have deployed the EJBs in a jboss-as-ejb-remote-app.jar, so the module name is
    // jboss-as-ejb-remote-app
    final String moduleName = "EJB3_Chap02";
    // AS7 allows each deployment to have an (optional) distinct name. We haven't specified a distinct name for
    // our EJB deployment, so this is an empty string
    final String distinctName = "";
    // The EJB name which by default is the simple class name of the bean implementation class
    //final String beanName = CalculatorBean.class.getSimpleName();
    // the remote view fully qualified class name
    final String viewClassName = CalculatorRemote.class.getName();
    // let's do the lookup
    //return (CalculatorRemote) context.lookup("ejb:" + appName + "/" + beanName);
    //return (CalculatorRemote) context.lookup("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName);
    return (CalculatorRemote) context.lookup("ejb:TesteEar/EJB3_Chap02//CalculatorBean!calc.CalculatorRemote");
}

}

[/b]

2 Respostas

tveronezi

Qual é o output de…

final Context context = new InitialContext(jndiProperties); 
NamingEnumeration<?> namingEnum = context.list("java"); 
while(namingEnum.hasMoreElements()){ 
  Object obj = namingEnum.nextElement(); 
  System.out.println(obj); 
}

?

tveronezi

Mais uma coisa… qual é o output de…

final Context context = new InitialContext(jndiProperties); 
NamingEnumeration<?> namingEnum = context.list(""); 
while(namingEnum.hasMoreElements()){ 
  Object obj = namingEnum.nextElement(); 
  System.out.println(obj); 
}

?

Note -> context.list("")

Criado 27 de agosto de 2012
Ultima resposta 27 de ago. de 2012
Respostas 2
Participantes 2