001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/portal/standard/PortalRequestDispatcher.java $ 002 /*---------------- FILE HEADER ------------------------------------------ 003 004 This file is part of deegree. 005 Copyright (C) 2001-2008 by: 006 EXSE, Department of Geography, University of Bonn 007 http://www.giub.uni-bonn.de/deegree/ 008 lat/lon GmbH 009 http://www.lat-lon.de 010 011 This library is free software; you can redistribute it and/or 012 modify it under the terms of the GNU Lesser General Public 013 License as published by the Free Software Foundation; either 014 version 2.1 of the License, or (at your option) any later version. 015 016 This library is distributed in the hope that it will be useful, 017 but WITHOUT ANY WARRANTY; without even the implied warranty of 018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 019 Lesser General Public License for more details. 020 021 You should have received a copy of the GNU Lesser General Public 022 License along with this library; if not, write to the Free Software 023 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 024 025 Contact: 026 027 Andreas Poth 028 lat/lon GmbH 029 Aennchenstr. 19 030 53177 Bonn 031 Germany 032 E-Mail: poth@lat-lon.de 033 034 Prof. Dr. Klaus Greve 035 Department of Geography 036 University of Bonn 037 Meckenheimer Allee 166 038 53115 Bonn 039 Germany 040 E-Mail: greve@giub.uni-bonn.de 041 042 ---------------------------------------------------------------------------*/ 043 044 package org.deegree.portal.standard; 045 046 import java.io.File; 047 import java.io.IOException; 048 import java.net.MalformedURLException; 049 import java.net.URL; 050 import java.util.Map; 051 import java.util.Set; 052 053 import javax.servlet.ServletConfig; 054 import javax.servlet.ServletException; 055 import javax.servlet.http.HttpServletRequest; 056 import javax.servlet.http.HttpServletResponse; 057 import javax.servlet.http.HttpSession; 058 059 import org.deegree.enterprise.control.RequestDispatcher; 060 import org.deegree.framework.log.ILogger; 061 import org.deegree.framework.log.LoggerFactory; 062 import org.deegree.framework.version.Version; 063 import org.deegree.portal.Constants; 064 import org.deegree.portal.context.ViewContext; 065 import org.deegree.portal.context.WebMapContextFactory; 066 067 068 069 /** 070 * This is a <code>RequestDispatcher</code> which creates a event out of 071 * a GET or POST requests.<P> 072 * 073 * Furthermore this class implements 074 * 075 * <HR> 076 * <B>Design Patterns:</B>:<BR> 077 * 078 * The following Design Patterns are used: 079 * <UL> 080 * <LI> Proxy 081 * </UL> 082 * 083 * @author <a href="mailto:friebe@gmx.net">Torsten Friebe</a> 084 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a> 085 * 086 * @version $Revision: 9346 $ $Date: 2007-12-27 17:39:07 +0100 (Do, 27 Dez 2007) $ 087 * 088 */ 089 public class PortalRequestDispatcher extends RequestDispatcher { 090 091 private static final ILogger LOG = 092 LoggerFactory.getLogger( PortalRequestDispatcher.class ); 093 094 protected ViewContext vc = null; 095 096 /** 097 * This method initializes the servlet. 098 * 099 * @param cfg the servlet configuration 100 * 101 * @throws ServletException an exception 102 */ 103 public void init( ServletConfig cfg ) throws ServletException { 104 super.init( cfg ); 105 106 String clientContext = this.getInitParameter( "MapContext.configFile" ); 107 if ( ! ( new File( clientContext ).exists() ) ) { 108 clientContext = getServletContext().getRealPath( clientContext ); 109 } 110 try { 111 File file = new File( clientContext ); 112 vc = WebMapContextFactory.createViewContext( file.toURL(), null, null ); 113 } catch(Exception e) { 114 e.printStackTrace(); 115 } 116 117 try { 118 if ( this.getInitParameter( "UserRepository" ) != null ) { 119 URL userRepository = new URL( this.getInitParameter( "UserRepository" ) ); 120 getServletContext().setAttribute( Constants.USERREPOSITORY, userRepository ); 121 } 122 } catch (MalformedURLException e1) { 123 e1.printStackTrace(); 124 } 125 126 LOG.logInfo( "Starting deegree version " 127 + Version.getVersion() + " on server: " + this.getServletContext().getServerInfo() 128 + " / Java version: " + System.getProperty( "java.version" ) ); 129 } 130 131 /** 132 * 133 * 134 * @param request 135 * @param response 136 * 137 * @throws ServletException 138 * @throws IOException 139 */ 140 protected void service( HttpServletRequest request, HttpServletResponse response ) 141 throws ServletException, IOException { 142 Map<String, String[]> params = request.getParameterMap(); 143 Set<String> keys = params.keySet(); 144 for ( String key : keys ) { 145 String[] array = params.get( key ); 146 for ( String k : array ) { 147 LOG.logDebug( "found parameter for key: " + key + " param: " + k ); 148 } 149 } 150 String[] rpcCalls = request.getParameterValues( "rpc" ); 151 152 if ( rpcCalls != null ) { 153 if ( rpcCalls.length > 1 ) { 154 LOG.logDebug( "found multiple rpc parameters" ); 155 156 } 157 for ( String tmp : rpcCalls ) { 158 LOG.logDebug( "Found parameter: " + tmp ); 159 } 160 } 161 HttpSession session = request.getSession( true ); 162 session.setAttribute( Constants.DEFAULTMAPCONTEXT , vc ); 163 if ( session.getAttribute( Constants.CURRENTMAPCONTEXT ) == null ) { 164 session.setAttribute( Constants.CURRENTMAPCONTEXT , vc ); 165 } 166 super.service( request, response ); 167 } 168 169 }