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
orjavax.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. Thethrow
clause should not include thejava.rmi.RemoteException
. The method of the business interface may only throw thejava.rmi.RemoteException
if the interface extendsjava.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
andRemote
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
orRemote
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 byjavax.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/orRemote
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).
- 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
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 theApplicationException
metadata annotation, or denoting it in the deployment descriptor with theapplication-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
-
- Log the exception or error.
- Mark the transaction for rollback.
- Discard instance.
- Throw
javax.transaction.TransactionRolledbackException
to remote client or throwjavax.ejb.TransactionRolledbackLocalException
to local client.
Note that while
TransactionRolledbackLocalException
can nest cause exception,TransactionRolledbackException
can't. - Client's view
-
Receives
javax.transaction.TransactionRolledbackException
orjavax.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
-
- Log the exception or error.
- Rollback the container started transaction.
- Discard instance.
- Throw
RemoteException
to remote or web service client or throwEJBException
to local client.
Note that both
RemoteException
andEJBException
can nest cause exception. - Client’s view
-
Receives
RemoteException
orEJBException
. 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
-
- Log the exception or error.
- Discard instance.
- Throw
RemoteException
to remote or web service client or throwEJBException
to local client.
- Client’s view
-
Receives
RemoteException
orEJBException
.
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
-
- Log the exception or error.
- Mark the transaction for rollback.
- Discard instance.
- Throw
javax.transaction.TransactionRolledbackException
to remote client or throwjavax.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
-
- Log the exception or error.
- Rollback the container started transaction.
- Discard instance.
- 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
-
- Log the exception or error.
- Discard instance.
- 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
- 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.
- 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.
- 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.
- 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