Java Reference
In-Depth Information
The
HelloInterceptor
class defines an
@AroundInvoke
interceptor method,
modifyGreeting
, that converts the string passed to
HelloBean.setName
to
lowercase.
@AroundInvoke
public Object modifyGreeting(InvocationContext ctx) throws Exception
{
Object[] parameters = ctx.getParameters();
String param = (String) parameters[0];
param = param.toLowerCase();
parameters[0] = param;
ctx.setParameters(parameters);
try {
return ctx.proceed();
} catch (Exception e) {
logger.warning("Error calling ctx.proceed in modifyGreet-
ing()");
return null;
}
}
The parameters to
HelloBean.setName
are retrieved and stored in an
Object
array
by calling the
InvocationContext.getParameters
method. Because
setName
has only one parameter, it is the first and only element in the array. The string is set
to lowercase and stored in the
parameters
array, then passed to
InvocationCon-
text.setParameters
. To return control to the session bean,
InvocationCon-
text.proceed
is called.
The user interface of
interceptor
is a JavaServer Faces web application that consists
of two Facelets views:
index.xhtml
, which contains a form for entering the name, and
response.xhtml
, which displays the final name.
Running the
interceptor
Example
You can use either NetBeans IDE or Ant to build, package, deploy, and run the
inter-
ceptor
example.
To Run the
interceptor
Example Using NetBeans IDE
1. From the File menu, choose Open Project.
2. In the Open Project dialog, navigate to
tut-install
/examples/ejb/
.
3. Select the
interceptor
folder and click Open Project.