If you use the FFDCSupport aspect, you can ensure a consistent FFDC policy for
your application by adding
declare warning
or
error advice
to your aspects While this
capability is not explicitly provided by the FFDCSupport aspect, you can leverage
the use of AspectJ and follow a standard pattern of enforcing a policy
implemented using an aspect with compiler warnings or errors.
In Figure 6, aspect
Example_6
illustrates how to prevent direct use of the FFDC API
or undesired dumping of exception messages and stack traces to the console. The
declare warning statements on lines 51 and 57 instruct the AspectJ compiler to
issue warnings during weaving if join points are matched by the accompanying
pointcuts on lines 48 and 54 respectively.
The statements are only evaluated during compilation and have no impact on the
runtime.
import com.ibm.websphere.ffdc.FFDCSupport;
public aspect Example_3 extends FFDCSupport {
protected pointcut ffdcScope () :
within(com.foo.*)
&& !within(com.foo.Goo);
}
In Figure 3 aspect
Example_3
has the same effect as
Example_1
except it excludes FFDC for class com.foo.Goo by
using the
&&
and
!
operators to form a
pointcut expression
.
Figure 9. Add FFDC to all classes in the com.foo package excluding com.foo.Goo
import com.ibm.websphere.ffdc.FFDCSupport;
public aspect Example_3 extends FFDCSupport {
protected pointcut ffdcScope () :
within(com.foo.*)
&& !withincode(* com.foo.Goo.aMethod(..));
}
In Figure 4, aspect
Example_4
is also similar to
Example_1
, however FFDC is excluded from a particular method on
line 30 using the withincode() PCD.
Figure 10. Add FFDC to the com.foo package but exclude aMethod
import com.ibm.websphere.ffdc.FFDCSupport;
public aspect Example_4 extends FFDCSupport {
protected pointcut ffdcScope () :
within(com.foo.*)
&& !args(ClassNotFoundException);
}
In Figure 5 aspect
Example_5
illustrates how to account for a
programming by exception
, where certain exceptions are
not considered to be a failure and should not be reported. In the example, the handling of
ClassNotFoundException
will not be reported to FFDC. The
args()
PCD on line 39 selects a join points based on contextual information in this
case the exception passed to the handler join point.
Figure 11. Add FFDC to the com.foo package but exclude catch blocks for ClassNotFoundException handling
WebSphere Adapter development overview
191
Summary of Contents for WebSphere Adapter Toolkit
Page 2: ......
Page 6: ...iv WebSphere Adapters WebSphere Adapter Toolkit User Guide...
Page 220: ...214 WebSphere Adapters WebSphere Adapter Toolkit User Guide...
Page 224: ...218 WebSphere Adapters WebSphere Adapter Toolkit User Guide...
Page 225: ......
Page 226: ...Printed in USA...