JBoss Application Configuration Breakdown
The open source project JBoss has been a great boon to enterprise development for Java. It has allowed developers to work with, experiment with, and ultimately master Enterprise Java Beans (EJB) development using a full-fledged application server. This is in addition to the obvious practical uses for a low-cost application server; without such a server, many development shops would have barred the use of Java technology.
However, even this wonderful application server is not without its faults. Many developers find the documentation difficult to consume and/or completely lacking. To help fill in some of these gaps, this first article will break down the jboss.xml file so that those who choose not to use XDoclet to develop their EJBs can easily understand jboss.xml. This breakdown covers the upcoming 4.0 release of JBoss, and most of the information contained herein should apply to the earlier 3.x versions.
Understanding the Tag Levels
While there are quite a few tags that can be used in the jboss.xml file, it should be noted that none of them are required per se. A JBoss application can function perfectly without a jboss.xml file; these tags simply allow greater flexibility and configuration of an application.
NOTE
None of the tags are required, nor do they have to be in a specific order. The order used here is just the order in which the tags are spelled out in the Document Type Definition (DTD).
enforce-ejb-restrictions
This tag tells the container to enforce EJB 1.1 restrictions. This element can accept a value of true or false.
security-domain
This tag indicates the global security manager for the application. This element specifies the JNDI name of the object that implements the EJBSecurityManager and RealmMapping for the domain. (See the resource-manager section for an example.) This setting can be overridden at the container level, using the security-domain element.
unauthenticated-principal
This tag defines the name of the user returned by the EJBContext.getCallerPrincipal() method if no authenticated user is available.
enterprise-beans
Contained within this top-level tag are tags that define the three types of enterprise beans (Entity Java Beans, Session Java Beans, and Message Java Beans):
entity. Defines all of the Entity Java Beans that are used within the application.
session. Defines all of the Session Java Beans that are used within the application. The session tags are identical to those of the entity tag, with the exception of the read-only tag, which doesn't apply to Session Java Beans. The tags also serve the same purposes, and the Session Java Beans don't have any unique tags.
message. Defines all of the Message Java Beans that are used within the application. Some of the message tags are identical to those of the entity and session tags and serve the same purpose. Other tags are specific to the message tag.
The following table describes the tags that are specific to each type of bean.
entity |
session |
message |
Tag |
Description |
X |
X |
X |
ejb-name |
Used to connect beans defined in the jboss.xml file with beans defined in the ejb-jar.xml file. This element must exist in both files for JBoss to match up the settings. |
X |
X |
|
jndi-name |
Name used in the Context.lookup() call to return a reference to this EJB's remote home. This element must be unique within the application. |
X |
X |
|
local-jndi-name |
Name used in the Context.lookup() call to return a reference to this EJB's local home. This element must be unique within the application. |
X |
X |
|
call-by-value |
Instructs JBoss to pass results back as object streams rather than references to the objects themselves. The result is that a method caller will receive an object constructed by its own class loadernot the class loader used by the called EJB. The primary use is class version conflicts. If a method caller contains a different version of the object being returned, it will load its own version of that object instead of throwing an exception. |
X |
|
|
read-only |
Specifies whether this entity is read-only. This element accepts only the values true and false. |
X |
X |
X |
configuration-name |
Links this entity to a container configuration defined elsewhere in the jboss.xml file. This name must match a container-name element in the container-configurations section, or one of the existing container configurations defined in the standard XML files included with JBoss. This element is optional; if it doesn't exist, JBoss will select one of the standard configurations. |
X |
X |
X |
security-proxy |
Defines the class to be used as the security proxy for this bean. |
X |
X |
X |
ejb-ref |
Gives the JNDI name of an external EJB reference. If this element is used, you don't provide an ejb-link but instead define the jndi-name in jboss.xml. |
X |
X |
|
ejb-local-ref |
Alternative to the ejb-link normally defined in the ejb-jar.xml file. |
X |
X |
X |
service-ref |
Provides specific deployment values to the web service reference in the ejb-jar.xml file. |
X |
X |
X |
security-identity |
Indicates whether a specific run-as identity will be used by this bean. If a run-as role is defined for the bean, a run-as-principal can also be defined here. Otherwise, the principal will be defined as anonymous. |
X |
X |
X |
resource-ref |
Defines the mapping between the names of resources in the code and the names of resources in the XML configuration files. If this element is not provided, JBoss assumes that the names in the code and the XML documents are the same. |
X |
X |
X |
resource-env-ref |
Defines a mapping between the names of environmental resources used in the code and those resources' JNDI names. If this element is not provided, JBoss assumes that the JNDI names match the names used in the code. |
X |
X |
|
clustered |
Indicates whether this bean will be used in a clustered environment. The only values accepted by this element are true and false. If this element is not present, JBoss assumes false. |
X |
X |
|
cluster-config |
Used for configurations specific to the cluster (outside the scope of this article). |
|
|
X |
destination-jndi-name |
Defines the name of the topic or queue used by this message bean. |
|
|
X |
mdb-user |
Defines the username to be used for connecting to the topic or queue for this bean. |
|
|
X |
mdb-passwd |
Defines the password to be used for connecting to the topic or queue for this bean. |
|
|
X |
mdb-client-id |
Defines the client ID for durable message beans. This allows the messaging subsystem to determine who a client is when a reconnection occurs. |
|
|
X |
mdb-subscription-id |
Defines the subscription ID for durable message beans. This allows the messaging subsystem to be able to determine who a client is when a reconnection occurs. |
|
|
X |
resource-adapter-name |
Name of the adapter used for messages. This is the name of the "rar" defined in the JCA. This element would be used in a situation where your application needs to be able to connect to other enterprise systems such as SAP, PeopleSoft, or Siebel. |
assembly-descriptor
This element defines application assembly information. The definition of security roles allows you to map assembly roles to principals, as in the following example:
<security-role> <role-name>Administrator</role-name> <principal-name>admin</principal-name> <principal-name>root</principal-name> </security-role>
This mapping specifies that both admin and root are part of the Administrator role.
resource-manager
This is the element that manages resources. A resource has three different names:
The first name is defined in the resource-ref section of the ejb-jar.xml file. The developer of the bean supplies this name.
The second name is defined by the application assembler and is referenced using the resource-ref section of the appropriate bean.
The final name of the resource is the actual JNDI name or URL for the resource. This final name is mapped in resource-managers. If a resource is not mapped here, JBoss will look for it as if it were a datasource. Here's an example of this mapping:
<resource-manager res-class="org.jboss.ejb.deployment.JDBCResource"> <res-name>jdbc/someName</res-name> <res-jndi-name>java:/jdbc/someName</res-jndi-name> </resource-manager>
container-configurations
This element defines the different possible configurations for the container of the beans. If no configurations are defined, the standard configurations will be used automatically. The standardjboss.xml file contains 15 configurations, predefined with the following names:
Standard CMP 2.x EntityBean
Standard CMP EntityBean
Clustered CMP 2.x EntityBean
Clustered CMP EntityBean
IIOP CMP 2.x EntityBean
IIOP CMP EntityBean
Standard Stateless SessionBean
Clustered Stateless SessionBean
IIOP Stateless SessionBean
Standard Stateful SessionBean
Clustered Stateful SessionBean
IIOP Stateful SessionBean
Standard BMP EntityBean
Clustered BMP EntityBean
IIOP BMP EntityBean
Standard MessageDrivenBean
NOTE
The names are correct; in a J2EE context, EntityBean and SessionBean are considered single words.