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 2009 Sun Microsystems Inc.
015 * Portions Copyright 2010–2011 ApexIdentity Inc.
016 * Portions Copyright 2011-2014 ForgeRock AS.
017 */
018
019package org.forgerock.openig.handler;
020
021import java.io.IOException;
022
023import org.forgerock.openig.http.Exchange;
024
025/**
026 * Handles an HTTP exchange request by producing an associated response.
027 */
028public interface Handler {
029
030    /**
031     * Called to request the handler respond to the request.
032     * <p>
033     * A handler that doesn't hand-off an exchange to another handler downstream is
034     * responsible for creating the response in the exchange object.
035     * <p>
036     * <strong>Important note:</strong> If an existing response exists in the exchange object
037     * and the handler intends to replace it with its own, it must first check to see if the
038     * existing response has an entity, and if it does, must call its {@code close} method in
039     * order to signal that the processing of the response from a remote server is complete.
040     *
041     * @param exchange the exchange containing the request to handle.
042     * @throws HandlerException if an exception occurs that prevents handling of the request.
043     * @throws IOException if an I/O exception occurs.
044     */
045    void handle(Exchange exchange) throws HandlerException, IOException;
046}