001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions Copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2010–2011 ApexIdentity Inc. 015 * Portions Copyright 2011-2014 ForgeRock AS. 016 */ 017 018package org.forgerock.openig.filter; 019 020import java.io.IOException; 021 022import org.forgerock.openig.handler.Handler; 023import org.forgerock.openig.handler.HandlerException; 024import org.forgerock.openig.http.Exchange; 025 026/** 027 * Filters the request and/or response of an HTTP exchange. 028 * 029 * @see Chain 030 */ 031public interface Filter { 032 033 /** 034 * Filters the request and/or response of an exchange. Initially, {@code exchange.request} 035 * contains the request to be filtered. To pass the request to the next filter or handler 036 * in the chain, the filter calls {@code next.handle(exchange)}. After this call, 037 * {@code exchange.response} contains the response that can be filtered. 038 * <p> 039 * This method may elect not to pass the request to the next filter or handler, and instead 040 * handle the request itself. It can achieve this by merely avoiding a call to 041 * {@code next.handle(exchange)} and creating its own response object the exchange. The 042 * filter is also at liberty to replace a response with another of its own after the call 043 * to {@code next.handle(exchange)}. 044 * <p> 045 * <strong>Important note:</strong> If an existing response exists in the exchange object 046 * and the filter intends to replace it with its own, it must first check to see if the 047 * existing response has an entity, and if it does, must call its {@code close} method in 048 * order to signal that the processing of the response from a remote server is complete. 049 * 050 * @param exchange the exchange containing the request and response to filter. 051 * @param next the next filter or handler in the chain to handle the exchange. 052 * @throws HandlerException if an exception occurred handling the exchange. 053 * @throws IOException if an I/O exception occurred. 054 */ 055 void filter(Exchange exchange, Handler next) throws HandlerException, IOException; 056}