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 2014 ForgeRock AS. 015 */ 016 017package org.forgerock.openig.handler; 018 019import java.io.IOException; 020 021import org.forgerock.openig.heap.GenericHeaplet; 022import org.forgerock.openig.heap.HeapException; 023import org.forgerock.openig.http.Exchange; 024import org.forgerock.openig.http.Response; 025import org.forgerock.openig.io.BranchingStreamWrapper; 026 027/** 028 * Creates a static response containing a simple HTML welcome page. 029 */ 030public class WelcomeHandler extends GenericHandler { 031 032 /** 033 * Creates a new welcome page handler. 034 */ 035 public WelcomeHandler() { 036 // Nothing to do. 037 } 038 039 @Override 040 public void handle(Exchange exchange) throws HandlerException, IOException { 041 Response response = new Response(); 042 response.setStatus(200); 043 response.setReason("OK"); 044 response.getHeaders().add("Content-Type", "text/html"); 045 response.setEntity(new BranchingStreamWrapper(getClass().getResourceAsStream( 046 "welcome.html"), storage)); 047 exchange.response = response; 048 } 049 050 /** 051 * Creates and initializes a static response handler in a heap environment. 052 */ 053 public static class Heaplet extends GenericHeaplet { 054 @Override 055 public Object create() throws HeapException { 056 return new WelcomeHandler(); 057 } 058 } 059}