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