Red Hat Training

A Red Hat training course is available for Red Hat JBoss Enterprise Application Platform

Appendix A. Reference Material

A.1. EJB JNDI Naming Reference

The JNDI lookup name for a session bean uses the following syntax:

ejb:<appName>/<moduleName>/<distinctName>/<beanName>!<viewClassName>?stateful
  • <appName>: If the session bean’s JAR file has been deployed within an enterprise archive (EAR) then the appName is the name of the respective EAR. By default, the name of an EAR is its filename without the .ear suffix. The application name can be overridden in its application.xml file. If the session bean is not deployed in an EAR, then leave the appName blank.
  • <moduleName>: The moduleName is the name of the JAR file in which the session bean is deployed. The default name of the JAR file is its filename without the .jar suffix. The module name can be overridden in the JAR’s ejb-jar.xml file.
  • <distinctName>: JBoss EAP allows each deployment to specify an optional distinct name. If the deployment does not have a distinct name, then leave the distinctName blank.
  • <beanName>: The beanName is the simple class name of the session bean to be invoked.
  • <viewClassName>: The viewClassName is the fully qualified class name of the remote interface. This includes the package name of the interface.
  • ?stateful: The ?stateful suffix is required when the JNDI name refers to a stateful session bean. It is not included for other bean types.

For example, if we deployed hello.jar having a stateful bean org.jboss.example.HelloBean that exposed a remote interface org.jboss.example.Hello, then the JNDI lookup name would be:

ejb:/hello/HelloBean!org.jboss.example.Hello?stateful"

A.2. EJB Reference Resolution

This section covers how JBoss EAP implements @EJB and @Resource. Please note that XML always overrides annotations but the same rules apply.

Rules for the @EJB annotation
  • The @EJB annotation also has a mappedName() attribute. The specification leaves this as vendor specific metadata, but JBoss EAP recognizes mappedName() as the global JNDI name of the EJB you are referencing. If you have specified a mappedName(), then all other attributes are ignored and this global JNDI name is used for binding.
  • If you specify @EJB with no attributes defined:

    @EJB
    ProcessPayment myEjbref;

    Then the following rules apply:

    • The EJB jar of the referencing bean is searched for an EJB with the interface used in the @EJB injection. If there are more than one EJB that publishes same business interface, then an exception is thrown. If there is only one bean with that interface then that one is used.
    • Search the EAR for EJBs that publish that interface. If there are duplicates, then an exception is thrown. Otherwise the matching bean is returned.
    • Search globally in JBoss EAP runtime for an EJB of that interface. Again, if duplicates are found, an exception is thrown.
  • @EJB.beanName() corresponds to <ejb-link>. If the beanName() is defined, then use the same algorithm as @EJB with no attributes defined except use the beanName() as a key in the search. An exception to this rule is if you use the ejb-link # syntax: it allows you to put a relative path to a jar in the EAR where the EJB you are referencing is located. Refer to the EJB 3.2 specification for more details.

A.3. Project Dependencies for Remote EJB Clients

Maven projects that include the invocation of session beans from remote clients require the following dependencies from the JBoss EAP Maven repository.

Note

The artifactId versions are subject to change. Refer to the JBoss EAP Maven Repository for the latest versions.

Table A.1. Maven Dependencies for Remote EJB Clients

GroupIDArtifactID

org.jboss.bom

jboss-eap-javaee7

org.jboss.spec.javax.transaction

jboss-transaction-api_1.2_spec

org.jboss.spec.javax.ejb

jboss-ejb-api_3.2_spec

org.jboss.eap

wildfly-ejb-client-bom

The jboss-eap-javaee7 "Bill of Materials" (BOM) packages the correct version of many of the artifacts commonly required by a JBoss EAP application. The BOM dependency is specified in the <dependencyManagement> section of the pom.xml with the scope of import.

Example POM File <dependencyManagement> Section

<dependencyManagement>
   <dependencies>
      <dependency>
      <groupId>org.jboss.bom</groupId>
        <artifactId>jboss-eap-javaee7</artifactId>
        <version>${version.jboss.bom.eap}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
   </dependencies>
</dependencyManagement>

The remaining dependencies are specified in the <dependencies> section of the pom.xml file with a scope of runtime.

Example POM File <dependencies> Section

<dependencies>
    <!-- Include the EJB client JARs -->
    <dependency>
        <groupId>org.jboss.eap</groupId>
        <artifactId>wildfly-ejb-client-bom</artifactId>
        <type>pom</type>
        <scope>compile</scope>
    </dependency>

    <!-- Include any additional dependencies required by the application
        ...
    -->

</dependencies>

The ejb-remote quickstart that ships with JBoss EAP provides a complete working example of remote EJB client application. See the client/pom.xml file located in root directory of that quickstart for a complete example of dependency configuration for remote session bean invocation.

A.4. jboss-ejb3.xml Deployment Descriptor Reference

jboss-ejb3.xml is a custom deployment descriptor that can be used in either EJB JAR or WAR archives. In an EJB JAR archive it must be located in the META-INF/ directory. In a WAR archive it must be located in the WEB-INF/ directory.

The format is similar to ejb-jar.xml, using some of the same namespaces and providing some other additional namespaces. The contents of jboss-ejb3.xml are merged with the contents of ejb-jar.xml, with the jboss-ejb3.xml items taking precedence.

This document only covers the additional non-standard namespaces used by jboss-ejb3.xml. Refer to http://java.sun.com/xml/ns/javaee/ for documentation on the standard namespaces.

The root namespace is http://www.jboss.com/xml/ns/javaee.

Assembly descriptor namespaces
The following namespaces can all be used in the <assembly-descriptor> element. They can be used to apply their configuration to a single bean, or to all beans in the deployment by using * as the ejb-name.
The clustering namespace: urn:clustering:1.0
xmlns:c="urn:clustering:1.0"

This allows you to mark EJB’s as clustered. It is the deployment descriptor equivalent to @org.jboss.ejb3.annotation.Clustered.

<c:clustering>
   <ejb-name>DDBasedClusteredSFSB</ejb-name>
   <c:clustered>true</c:clustered>
</c:clustering>
The security namespace (urn:security)
xmlns:s="urn:security"

This allows you to set the security-domain and the run-as-principal for an EJB.

<s:security>
  <ejb-name>*</ejb-name>
  <s:security-domain>myDomain</s:security-domain>
  <s:run-as-principal>myPrincipal</s:run-as-principal>
</s:security>
The resource adapter namespace: urn:resource-adapter-binding
xmlns:r="urn:resource-adapter-binding"

This allows you to set the resource adapter for a Message-Driven Bean.

<r:resource-adapter-binding>
  <ejb-name>*</ejb-name>
  <r:resource-adapter-name>myResourceAdapter</r:resource-adapter-name>
</r:resource-adapter-binding>
The IIOP namespace: urn:iiop
xmlns:u="urn:iiop"

The IIOP namespace is where IIOP settings are configured.

The pool namespace: urn:ejb-pool:1.0
xmlns:p="urn:ejb-pool:1.0"

This allows you to select the pool that is used by the included stateless session beans or Message-Driven Beans. Pools are defined in the server configuration.

<p:pool>
   <ejb-name>*</ejb-name>
   <p:bean-instance-pool-ref>my-pool</p:bean-instance-pool-ref>
</p:pool>
The cache namespace: urn:ejb-cache:1.0
xmlns:c="urn:ejb-cache:1.0"

This allows you to select the cache that is used by the included stateful session beans. Caches are defined in the server configuration.

<c:cache>
   <ejb-name>*</ejb-name>
   <c:cache-ref>my-cache</c:cache-ref>
</c:cache>
<?xml version="1.1" encoding="UTF-8"?>
<jboss:ejb-jar xmlns:jboss="http://www.jboss.com/xml/ns/javaee"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:c="urn:clustering:1.0"
    xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-ejb3-2_0.xsd"
    version="3.1"
    impl-version="2.0">
  <enterprise-beans>
     <message-driven>
        <ejb-name>ReplyingMDB</ejb-name>
        <ejb-class>org.jboss.as.test.integration.ejb.mdb.messagedestination.ReplyingMDB</ejb-class>
        <activation-config>
           <activation-config-property>
              <activation-config-property-name>destination</activation-config-property-name>
              <activation-config-property-value>java:jboss/mdbtest/messageDestinationQueue
              </activation-config-property-value>
           </activation-config-property>
        </activation-config>
     </message-driven>
  </enterprise-beans>
  <assembly-descriptor>
     <c:clustering>
        <ejb-name>DDBasedClusteredSFSB</ejb-name>
        <c:clustered>true</c:clustered>
     </c:clustering>
  </assembly-descriptor>
</jboss:ejb-jar>
Note

There are known issues with the jboss-ejb3-spec-2_0.xsd file that may result in schema validation errors. You can ignore these errors. For more information, see https://bugzilla.redhat.com/show_bug.cgi?id=1192591.

A.5. Configure an EJB Thread Pool

You can create an EJB Thread pool using the management console or the management CLI.

Configure an EJB Thread Pool Using the Management Console

  1. Log in to the management console.
  2. Click on the Configuration tab. Expand the Subsystems menu.
  3. Select EJB 3 and then click View.
  4. Select the Container tab and then click Thread Pools.
  5. Click Add. The Create THREAD-POOL dialog appears.
  6. Specify the required details, Name and Max threads value.
  7. Click Save.

Configure an EJB Thread Pool Using the Management CLI

Use the add operation with the following syntax:

/subsystem=ejb3/thread-pool=THREADPOOLNAME:add(max-threads=MAXSIZE)
  • Replace THREADPOOLNAME with the required name for the thread pool.
  • Replace MAXSIZE with the maximum size of the thread pool.

Use the read-resource operation to confirm the creation of the bean pool:

/subsystem=ejb3/thread-pool=THREADPOOLNAME:read-resource

To reconfigure all the services in the ejb3 subsystem to use a new thread pool, use the following commands:

/subsystem=ejb3/thread-pool=bigger:add(max-threads=100)
/subsystem=ejb3/service=async:write-attribute(name=thread-pool-name, value="bigger")
/subsystem=ejb3/service=remote:write-attribute(name=thread-pool-name, value="bigger")
/subsystem=ejb3/service=timer-service:write-attribute(name=thread-pool-name, value="bigger")
reload

XML Configuration Sample:

<subsystem xmlns="urn:jboss:domain:ejb3:4.0">
    ...
    <async thread-pool-name="bigger"/>
    ...
    <timer-service thread-pool-name="bigger" default-data-store="default-file-store">
    ...
    <remote connector-ref="http-remoting-connector" thread-pool-name="bigger"/>
    ...
    <thread-pools>
        <thread-pool name="default">
            <max-threads count="10"/>
            <keepalive-time time="100" unit="milliseconds"/>
        </thread-pool>
        <thread-pool name="bigger">
            <max-threads count="100"/>
        </thread-pool>
    </thread-pools>
    ...
Note

keepalive-time should not be used as it is not effective.





Revised on 2018-02-08 10:17:17 EST