Manueller EJB Lookup im JBoss AS 7.0.1

  • Themenstarter Themenstarter Sym
  • Beginndatum Beginndatum
S

Sym

Gast
Hallo,

leider ist der AS 7.0.1 im EE-Bereich noch nicht ganz optimal. Ich nutze ein EAR mit einer EJB-Einheit. Diese EJBs kann ich im WAR leider nicht injecten, weil dies derzeit anscheinend nicht richtig unterstützt wird.

Nun möchte ich einen manuellen Lookup auf meine Bean machen.

Code:
package de.larmic.ts.ejb.user.api;

public interface Authentication {
	String authenticate(final String email, final String password);
}

Code:
@Stateless(mappedName = "ejb/AuthenticationLocal")
@Local(Authentication.class)
public class AuthenticationLocal implements Authentication {

	@Override
	public String authenticate(final String email, final String password) {
		return "test@tsas-segen.de".equals(email) && "test".equals(password) ? "todo:securitytoken" : null;
	}
}

Beim Deployment des EARs bekomme ich folgende Meldung:

Code:
INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-7) JNDI bindings for session bean named AuthenticationLocal in deployment unit subdeployment "larmic-ts-ejb-1.0-SNAPSHOT.jar" of deployment "larmic-ts-ear-1.0-SNAPSHOT.ear" are as follows:

	java:global/larmic-ts-ear-1.0-SNAPSHOT/larmic-ts-ejb-1.0-SNAPSHOT/AuthenticationLocal!de.larmic.ts.ejb.user.api.Authentication
	java:app/larmic-ts-ejb-1.0-SNAPSHOT/AuthenticationLocal!de.larmic.ts.ejb.user.api.Authentication
	java:module/AuthenticationLocal!de.larmic.ts.ejb.user.api.Authentication
	java:global/larmic-ts-ear-1.0-SNAPSHOT/larmic-ts-ejb-1.0-SNAPSHOT/AuthenticationLocal
	java:app/larmic-ts-ejb-1.0-SNAPSHOT/AuthenticationLocal
	java:module/AuthenticationLocal

Das sieht soweit gut aus.

Mein manueller Lookup:

Code:
try {
	final Context ctx = new InitialContext();
	final Object obj = ctx.lookup("java:app/larmic-ts-ejb-1.0-SNAPSHOT/AuthenticationLocal!de.larmic.ts.ejb.user.api.Authentication");
	this.authentication = (Authentication) obj;
} catch (final NamingException e) {
	throw new EJBException(e);
}

Allerdings bekomme ich eine ClassCastException, weil der Proxy sich nicht casten lässt.

Code:
class de.larmic.ts.ejb.user.api.Authentication$$$view3

Mache ich einen anderen Lookup nach java:module/AuthenticationLocal bekomme ich eine NamingException.

Was könnte das Problem sein. Wie könnte ich das umgehen?

Danke fürs Lesen 🙂
 
Ja,

eingebunden als

Code:
<dependency>
	<groupId>de.larmic.ts</groupId>
	<artifactId>larmic-ts-ejb</artifactId>
	<type>ejb-client</type>
	<version>${larmic.ts.version}</version>
</dependency>

Sonst gäbe es ja auch Compiler-Fehler oder ist das bei ejb-client anders?
 
Sorry aber hier kann ich echt nur Kopfschütteln.

Du merkst also, dass das essentielle Feature Depenedcy Injection nicht funktioniert und deine Lösung sind manulle lookups? Ernsthaft?

Ich bin mir ziemlich sicher, dass in Jboss 7 Annotationen, die schon in JBoss 5und teilweise Jboss 4 funktioniert haben immer noch funktionieren.

Schreib mal bitte deine Klassen wie folgt um:

EJB
Java:
@Stateless
public class AuthenticationLocal implements Authentication {
	@Override
	public String authenticate(final String email, final String password) {
		return "test@tsas-segen.de".equals(email) && "test".equals(password) ? "todo:securitytoken" : null;
	}
}

@Local
public interface Authentication {
	String authenticate(final String email, final String password);
}

WAR
Java:
@ApplicationScoped
public class Test implements Serialiseable{

@EJB
private Authentication authenticator;

@PostConstruct
void init(){
System.out.println(authenticator.authenticate("test@tsas-segen.de","test");
}
}

EJB Dependencies sehen bei mir übrigens so aus:

[XML]
<dependency>
<groupId>de.larmic.ts</groupId>
<artifactId>larmic-ts-ejb</artifactId>
<scope>provided</scope>
<type>ejb</type>
<version>${larmic.ts.version}</version>
</dependency>
[/XML]
 
Zuletzt bearbeitet:
Hallo Deadalus,

Dir ist aber klar, dass der aktuelle JBoss 7 nur im Web Profile Only als Java EE6 Certified vorliegt und dies bei dem kompletten JBoss noch nicht der Fall ist, oder? Das dies ohne EAR in einem Projekt klappt, ist mir klar.

Oder hast Du ein laufendes EAR, welches im JB AS 7 lauffähig ist?

Also nicht gleich kopfschütteln!

edit: Vielleicht sollte ich noch einmal erwähnen, dass es im Glassfish 3.1 keine Probleme damit gibt, weil ein manueller Lookup nicht notwendig ist.
 
Zuletzt bearbeitet von einem Moderator:
Ja, das habe ich schon gelesen. Gestern kam die Beta von JBoss 7.1 raus, ich weiß allerdings noch nicht, ob das da bereits behoben ist.
 
Ah ok, dann schaue ich mal Montag. Ich sehe gerade, in der Roadmap wurde der Termin auch angepasst.

Dann mal kommende Woche schauen... 😀

Edit: Für Local-EJBs wurde das Problem allerdings bereits behoben. Der manuelle Lookup funktioniert dort zwar nicht, wie in der Spec angegeben, allerdings ist das auch nicht mehr notwendig, da ein Inject nun funktioniert.

Ich setze das hier mal auf erledigt (ist ja auch alt genug und eigentlich ging es hier um eine Möglichkeit, auf EJBs in einer sehr frühen JBoss 7 AS Full zuzugreifen, was mittlerweile geht)
 
Zuletzt bearbeitet von einem Moderator:

Neue Themen


Zurück
Oben