001 //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.4_testing/src/org/deegree/enterprise/control/ajax/RequestDispatcher.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 53115 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
045 package org.deegree.enterprise.control.ajax;
046
047 import java.io.File;
048 import java.io.IOException;
049
050 import javax.servlet.ServletConfig;
051 import javax.servlet.ServletException;
052 import javax.servlet.http.HttpServlet;
053 import javax.servlet.http.HttpServletRequest;
054 import javax.servlet.http.HttpServletResponse;
055
056 import org.deegree.enterprise.servlet.ServletRequestWrapper;
057
058 /**
059 * This is a <code>RequestDispatcher</code> which creates an event out of a GET or POST request.
060 *
061 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth </a>
062 * @author last edited by: $Author: apoth $
063 *
064 * @version $Revision: 20969 $ $Date: 2009-11-23 16:51:29 +0100 (Mo, 23. Nov 2009) $
065 */
066 public class RequestDispatcher extends HttpServlet {
067
068 private static final long serialVersionUID = 1L;
069
070 private static String CONFIGURATION = "Handler.configFile";
071
072 protected transient ApplicationHandler appHandler = null;
073
074 /**
075 * This method initializes the servlet.
076 *
077 * @param cfg
078 * the servlet configuration
079 * @throws ServletException
080 * an exception
081 */
082 @Override
083 public void init( ServletConfig cfg )
084 throws ServletException {
085 super.init( cfg );
086
087 try {
088 String url = null;
089
090 String s = getInitParameter( CONFIGURATION );
091 if ( new File( s ).isAbsolute() ) {
092 url = s;
093 } else {
094 url = getServletContext().getRealPath( s );
095 }
096
097 this.appHandler = new ApplicationHandler( url );
098 } catch ( Exception e ) {
099 e.printStackTrace();
100 }
101 }
102
103 /**
104 *
105 * @param request
106 * @param response
107 * @throws ServletException
108 * @throws IOException
109 */
110 @Override
111 protected void service( HttpServletRequest request, HttpServletResponse response )
112 throws ServletException, IOException {
113
114 ResponseHandler responseHandler = new ResponseHandler( response );
115
116 // deliver event to application handler
117 deliverEvent( request, responseHandler );
118
119 }
120
121 /**
122 *
123 * @param request
124 * @param responseHandler
125 * @throws ServletException
126 */
127 protected void deliverEvent( HttpServletRequest request, ResponseHandler responseHandler ) throws ServletException {
128 if ( appHandler == null ) {
129 try {
130 String url = null;
131
132 String s = getInitParameter( CONFIGURATION );
133 if ( new File( s ).isAbsolute() ) {
134 url = s;
135 } else {
136 url = getServletContext().getRealPath( s );
137 }
138 System.out.println(url);
139 this.appHandler = new ApplicationHandler( url );
140 } catch ( Exception e ) {
141 e.printStackTrace();
142 }
143 }
144 this.appHandler.actionPerformed( getServletContext(), new ServletRequestWrapper( request ), responseHandler );
145 }
146 }