This filter accesses the Dynamo request and response objects and retrieves the Profile object attached to the request. Next, the filter finds the Profile ID on the Profile object and saves as an attribute of the request. Finally, the filter passes control to the filter chain so it determines the next resource to call.

Keep in mind that this code sample might not provide the most efficient means for obtaining the Profile object, but rather it is an easy-to-follow code sample that illustrates how a filter operates in the context of a filter chain.

import atg.servlet.ServletUtil;
import atg.servlet.DynamoHttpServletRequest;
import atg.servlet.DynamoHttpServletResponse;
import atg.userprofiling.Profile;

import javax.servlet.*;
import javax.servlet.http.*;

 * An example filter that demonstrates how
 * to get the DynamoHttpServletRequest
 * in a Filter.
public class MyFilter
  implements Filter {

   * Called when MyFilter is started
   * by the application server.
  public void init(FilterConfig pConfig) {
   // Initialize MyFilter here.

   * Called when MyFilter is about to
   * be destroyed by the application server.
  public void destroy() {
   // Cleanup MyFilter here
   * Called by the application server
   * when this filter is involved in a request.
   * Resolves the Profile nucleus component
   * and adds the Profile id as a request
   * attribute.
   public void doFilter(ServletRequest request,
                       ServletResponse response,
                       FilterChain chain)
    throws IOException, ServletException
    // Get the Dynamo Request/Response Pair
   DynamoHttpServletRequest dRequest =
   DynamoHttpServletResponse = dRequest.getResponse();

   // Resolve the Profile object
   Profile profile =

   // Add the Profile id as a request attribute

   // Pass control on to the next filter

The example described here accesses the request and response in this manner. It also resolves a component in Nucleus, which is another common operation that can be handled by a filter. Any resource that makes calls to a Nucleus component must also provide a means for discerning that component’s Nucleus address. For instructions on how to do this, see the Basic Nucleus Operation section in the Nucleus: Organizing JavaBean Components chapter.