2010-12-08

Notable Principles of J2EE Specs

Session Bean's Business Interface of EJB 3.x

from Enterprise JavaBeans Version 3.1 EJB Core Contracts and Requirements

  • The interface msut not extend the javax.ejb.EJBObject or javax.ejb.EJBLocalObject interface.
  • If the business interface is a remote business interface, the argument and return value must be a valid type for RMI/IIOP. The remote business interface is not required or expected to be a java.rmi.Remote interface. The throw clause should not include the java.rmi.RemoteException. The method of the business interface may only throw the java.rmi.RemoteException if the interface extends java.rmi.Remote.
  • The interface is allowed to have superinterfaces.
  • If the interface is a remote business interface, its method must not expose local interface types, timers or timer handles, or the managed collection classes that are used for EJB 2.1 entity beans with container-managed persistence as arguments or results.
  • The bean class must implement the interface or the interfaces must be designated as a local or remote business interface of the bean by means of the Local and Remote annotation or in the deployment descriptor. The following rules apply:
    • If the bean does not expose any other client view (Local, Remote, Non-interface, 2.x Remote Home, 2.x Local Home, Web Service) and the bean class implements a single interface, that interface is assumed to be the business interface of the bean. This business interface will be a local interface unless the interface is designated as a remote business interface by use of Remote annotation on the bean class or interface or by means of the deployment descriptor.
    • A bean class is permitted to have more than one interface. If a bean class has more than one interface-excluding the interface listed below-any business interface of the bean class must be explicitly designated as a business interface of the bean by means of the Local or Remote annotation on the bean class or interface or in the deployment descriptor.
    • The following interfaces are excluded when determining whether the bean class has more than one interface: java.io.Serializable; java.io.Externalizable; any of the interfaces defined by javax.ejb package.
    • The same business interface cannot be both a local and a remote business interface of the bean. It is also an error if the Local and/or Remote annotations are specified both on the bean class and on the referenced interface and the values differ.
    • While it is expected that the bean class will typically implement its business interface(s), if the bean class uses annotations or the deployment descriptor to designate its business interface(s), it is not required that the bean class also be specified as implementing the interface(s).

Application Exception of EJB 3.x

from Enterprise JavaBeans Version 3.1 EJB Core Contracts and Requirements

  • Application exceptions that are checked exceptions may be defined as such by being listed in the throws clauses of the method of the bean's business interface, no-interface view, home interface, component interface, and web service endpoint. An application exception that is an unchecked exception is defined as an application exception by annotating it with the ApplicationException metadata annotation, or denoting it in the deployment descriptor with the application-exception element.
  • An application exception does not automatically result in marking the transaction for rollback unless the ApplicationException annotation is applied to the exception class and is specified with the rollback element value true or the application-exception deployment descriptor element for the exception specifies the rollback element as true. The rollback subelement of the the application-exception deployment descriptor element may be explicitly specified to override the rollback value specified or defaulted by the ApplicationException annotation.

Specification for Exception Handling with EJB

System Exception with EJB 2.x

from Chapter 18. Exception Handling of Enterprise JavaBeans Specification Version 2.1

When bean method runs in the context of the caller's transaction

This case may happen with Required, Mandatory, and Supports attributes.

Container's action
  1. Log the exception or error.
  2. Mark the transaction for rollback.
  3. Discard instance.
  4. Throw javax.transaction.TransactionRolledbackException to remote client or throw javax.ejb.TransactionRolledbackLocalException to local client.

Note that while TransactionRolledbackLocalException can nest cause exception, TransactionRolledbackException can't.

Client's view
Receives javax.transaction.TransactionRolledbackException or javax.ejb.TransactionRolledbackLocalException.
Continuing transaction is fruitless.
When bean method runs in the context of a transaction that the container started immediately before dispatching the business method.

This case may happen with Required and RequiresNew attributes.

Container's action
  1. Log the exception or error.
  2. Rollback the container started transaction.
  3. Discard instance.
  4. Throw RemoteException to remote or web service client or throw EJBException to local client.

Note that both RemoteException and EJBException can nest cause exception.

Client’s view
Receives RemoteException or EJBException. If the client executes in a transaction, the client’s transaction may or may not be marked for rollback.
When bean method runs with an unspecified transaction context.

This case may happen with the NotSupported, Never, and Supports attributes.

Container's action
  1. Log the exception or error.
  2. Discard instance.
  3. Throw RemoteException to remote or web service client or throw EJBException to local client.
Client’s view
Receives RemoteException or EJBException.
If the client executes in a transaction, the client’s transaction may or may not be marked for rollback.
System Exception with EJB 3.0

from Chapter 14. Exception Handling of Enterprise JavaBeans Specification Version 3.0

When bean method runs in the context of the caller's transaction

This case may happen with Required, Mandatory, and Supports attributes.

Container's action
  1. Log the exception or error.
  2. Mark the transaction for rollback.
  3. Discard instance.
  4. Throw javax.transaction.TransactionRolledbackException to remote client or throw javax.ejb.EJBTransactionRolledbackException to local client.

Note that EJBTransactionRolledbackException can nest cause exception.

Client's view
Receives javax.ejb.EJBTransactionRolledbackException.
Continuing transaction is fruitless.
When bean method runs in the context of a transaction that the container started immediately before dispatching the business method.

This case may happen with Required and RequiresNew attributes.

Container's action
  1. Log the exception or error.
  2. Rollback the container started transaction.
  3. Discard instance.
  4. Throw EJBException client.

Note that EJBException can nest cause exception.

Client’s view
Receives EJBException. If the client executes in a transaction, the client’s transaction may or may not be marked for rollback.
When bean method runs with an unspecified transaction context.

This case may happen with the NotSupported, Never, and Supports attributes.

Container's action
  1. Log the exception or error.
  2. Discard instance.
  3. Throw EJBException to local client.
Client’s view
Receives EJBException.
If the client executes in a transaction, the client’s transaction may or may not be marked for rollback.

Mapping Requests to Servlets

from SRV.11 of Java Servlet Specification Version 2.4

URL path mapping urles
  1. The container will try to find an exact match of the path of the request to the path of the servlet. A successful match selects the servlet.
  2. The container will recursively try to match the longest path-prefix. This is done by stepping down the path tree a directory at a time, using the ’/’ character as a path separator. The longest match determines the servlet selected.
  3. If the last segment in the URL path contains an extension (e.g. .jsp), the servlet container will try to match a servlet that handles requests for the extension. An extension is defined as the part of the last segment after the last ’.’ character.
  4. If neither of the previous three rules result in a servlet match, the container will attempt to serve content appropriate for the resource requested. If a "default" servlet is defined for the application, it will be used.
Syntax for mapping definition
  • A string beginning with a ‘/’ character and ending with a ‘/*’ suffix is used for path mapping.
  • A string beginning with a ‘*.’ prefix is used as an extension mapping.
  • A string containing only the ’/’ character indicates the "default" servlet of the application. In this case the servlet path is the request URI minus the context path and the path info is null.
  • All other strings are used for exact matches only.
Example mapping
Path Pattern (url-pattern) Servlet (servlet-name)
/foo/bar/* servlet1
/baz/* servlet2
/catalog servlet3
*.bop servlet4
Incoming Path Servlet Handling Request
/foo/bar/index.html servlet1
/foo/bar/index.bop servlet1
/baz servlet2
/baz/index.html servlet2
/catalog servlet3
/catalog/index.html "default" servlet
/catalog/racecar.bop servlet4
/index.bop servlet4

Note that in the case of /catalog/index.html and /catalog/racecar.bop, the servlet mapped to “/catalog” is not used because the match is not exact.

0 comments:

Post a Comment