EJB2 - java.lang.IllegalArgumentException

4 respostas
Andre_Fonseca

Pessoal,

Estou começando a brincar com EJB 2.1 usando o Apache Geronimo 1.1 no Eclipse.
Um dos exemplos que eu fiz (Exam Study Kit - Manning) usa um stateless Session Bean que ta dando pau na hora do lookup
Eu to usando OpenEJB. Abaixo o código do client e tb o ejb-jar.xml alem da exception..

Se alguem puder me ajudar, acho que tem algo errado no .xml

[]´s

#FortuneClient.java ##
public static void main(String[] args) {
    try {
	Properties props = System.getProperties();
	props.put(Context.INITIAL_CONTEXT_FACTORY,
	"org.openejb.client.RemoteInitialContextFactory");
	props.put(Context.PROVIDER_URL, "localhost:4201");
	props.put(Context.SECURITY_PRINCIPAL, "system");
	props.put(Context.SECURITY_CREDENTIALS, "manager");
			
	Context ictx = new InitialContext(props);
	Object objref =
		ictx.lookup("java:comp/env/ejb/FortuneSelector");
	FortuneHome home =
		(FortuneHome)PortableRemoteObject.narrow(objref,
			FortuneHome.class);
	Fortune fortuner = home.create();
	System.out.println(fortuner.getNextFortune());
	System.exit(0);
    } catch (Exception ex) {
	System.err.println("Caught an exception!");
	ex.printStackTrace();
    }
}
## ejb-jar.xml ##
<display-name>FortuneBean</display-name>
	<enterprise-beans>
		<session>
			<display-name>FortuneBean</display-name>
			<ejb-name>FortuneCookieBean</ejb-name>
			<home>FortuneHome</home>
			<remote>Fortune</remote>
			<ejb-class>FortuneBean</ejb-class>
			<session-type>Stateless</session-type>
			<transaction-type>Bean</transaction-type>
			<ejb-ref>
				<ejb-ref-name>ejb/FortuneSelector</ejb-ref-name>
				<ejb-ref-type>Session</ejb-ref-type>
				<home>FortuneHome</home>
				<remote>Fortune</remote>
				<ejb-link>FortuneCookieBean</ejb-link>
			</ejb-ref>
			<security-identity>
				<description></description>
				<use-caller-identity></use-caller-identity>
			</security-identity>			
		</session>
	</enterprise-beans>
## Exception ##
Caught an exception!
java.lang.ClassCastException: java.lang.IllegalArgumentException
	at org.openejb.client.JNDIContext.lookup(JNDIContext.java:266)
	at javax.naming.InitialContext.lookup(InitialContext.java:351)
	at FortuneClient.main(FortuneClient.java:25)

4 Respostas

Andre_Fonseca

mais uma coisa, a exception que o Geronimo dá é a seguinte:

09:54:18,328 ERROR [JndiRequestHandler] JNDI request error java.lang.IllegalArgumentException: uri path must be in the form [groupId]/[artifactId]/[version]/[type] : /java:comp/env/ejb/FortuneSelector

Obrigado

abreumania

troque a linha

Object objref =

ictx.lookup(“java:comp/env/ejb/FortuneSelector”);

por

Object objref =

ictx.lookup(“FortuneSelector”);

abreumania

Desculpe,

troque então o

Object objref = ictx.lookup(“java:comp/env/ejb/FortuneSelector”);

por

Object objref = ictx.lookup(“FortuneCookieBean”);

Andre_Fonseca

Cara funcionou, só que eu tive que baixar um jar e colocar no classpath:

que eu encontrei aqui:

Valeu… :slight_smile:

Criado 5 de outubro de 2007
Ultima resposta 5 de out. de 2007
Respostas 4
Participantes 2