JBoss Seam: Coming to an App Server Near You
With the GA release of Seam 1.1 today, Seam application developers now have a variety of deployment options available on JBoss AS, Glassfish, WebLogic, and Tomcat servers :
EJB3-based Seam Applications
If you would like to take advantage the full power of the EJB3 container and develop Seam applications using EJB3 session and entit beans (POJO-like components), your Seam application will be able to deploy in the following application servers.
- JBoss AS 4.0.5 with EJB3: You must install the EJB3 profile of JBoss from the JEMS installer. All examples in the distribution deploys in JBoss AS with EJB3 support.
- Sun Glassfish v1 UR1: The
"examples/glassfish"project in the distrbution shows the Glassfish configuration for the Seam Hotel Booking example app. You can read more about it here. - Tomcat 5.5.17+: In this scenario, the application itself bundles and bootstraps a embedded JBoss EJB3 container. The “ant tomcat” build target in other examples (e.g. in
"examples/booking"project) shows how to build Seam applications with JBoss Embeddedable EJB3 container for deployment on Tomcat.
We will test Seam on the Java EE 5.0 certified versions of WebLogic and Oracle when they come out.
POJO-based Seam Applications
If you just want to develop database-driven web applications, without needing EJB3 container services such as messaging, JMX etc., you can write your application in Seam and Hibernate POJOs. You can choose to use the Hibernate session API or the JPA EntityManager for data access. The Seam POJO example apps in the distribution re-implement the Seam Hotel Booking demo. They are in the "examples/hibernate2" (Hibernate Session) and "examples/jpa" (JPA EntityManager) projects respectively. For those applications, you can deploy on:
- JBoss AS 4.0.5 with default J2EE profile: The Seam POJO applications deploy on JBoss AS with or without EJB3 support. Just run
"ant jboss"to build the JBoss AS deployable WAR files. - Sun Glassfish v1 UR1: Glassfish has an TM bug with its embedded Derby database. So, we have to provide a workaround in a special Hibernate dialect in this scenario. See the
readme.txtfile inhibernate2andjpaexamples for more details. Run"ant glassfish"to build Glassfish deployable WAR files. - WebLogic 9.2: Run
"ant weblogic"to build WebLogic deployable WAR files. You can deploy the example Seam POJO applications in the WebLogic “examples” server. - Tomcat 5.5.17+: For the Seam POJO apps, the app no longer needs to bootstrap the embedded EJB3 conatiner. But it does need to bootstrap a JTA datasource from the embedded HSQL database. Run
"ant tomcat"to build the Tomcat deployable WAR files.
May 20th, 2008 at 7:57 am
Hello Michael,
first of all… i love seam! i have a problem, sadly, i got some troubles.
i have created a project (ear) with the seam eclipse plugin. I got 4 projects test, ejb, war and the aer containing references to the ejb and war modules. everything ok… after that i created an ejb project where i want to hoard the model/entities, added a reference to this project in the ear application.xml and referenced this project from the ejb project.
The problem is, that seam does not recognize the managed entity beans so i must use things like that:
@Name("authenticator")
public @Stateless class AuthenticatorBean implements Authenticator {
@Logger Log log;
@In Identity identity;
@EJB UserFacade userFacade;
public boolean authenticate() {
log.info("authenticating #0", identity.getUsername());
//write your authentication logic here,
//return true if the authentication was
//successful, false otherwise
//TODO: Login Module entwickeln (Factory-Pattern) damit man unterschiedliche Login Arten unterstützen kann
User user = userFacade.findUserByCredentials(identity.getUsername(), identity.getPassword());
if(user == null) {
return false;
}
// (needed but don't want to use this) //Contexts.getSessionContext().set("user", user);
for(Membership m: user.getMemberships()) {
identity.addRole(m.getRole().getRolename());
}
return true;
}
}
The Entity:
@Entity
@Table(name="USER")
@Name("user")
public class User extends AbstractOrganizationUnit {
/**
*
*/
private static final long serialVersionUID = 1L;
@NotNull
@Column(name="USR_NAME")
@Min(8)
private String username;
@NotNull
@Column(name="USR_PWD")
@Min(8)
private String password;
@CollectionOfElements
@JoinTable(name="USER_MEMBERSHIP",
joinColumns=@JoinColumn(name="USR_ID")
)
private Set memberships;
/**
*
*/
public User() {}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Set getMemberships() {
return memberships;
}
public void setMemberships(Set memberships) {
this.memberships = memberships;
}
/**
* @param membership
* @return
*/
public boolean addMembership(Membership membership) {
return this.getMemberships().add(membership);
}
/**
* @param membership
* @return
*/
public boolean removeMembership(Membership membership) {
return this.getMemberships().remove(membership);
}
}
The Facede/Action Bean:
@Name("userFacade")
public @Stateless class UserFacadeBean implements UserFacade {
@PersistenceContext
private EntityManager em;
@Logger
private Log log;
public User findUserByCredentials(String username, String password) {
log.debug("findUserByCredentials() called!");
try {
return (User)em.createQuery("from User where username=:username and password=:password")
.setParameter("username", username)
.setParameter("password", password)
.getSingleResult();
} catch (RuntimeException e) {
log.error("#0 ocurred.", e.getClass().getSimpleName());
return null;
}
}
}
The other beans in the projects created by the plugin are recognized and also showed in the “Seam Components View”.
Could you help me?
Thanx in advance,
nadenka