001 /*
002 *
003 * $Revision: 14775 $ $Date: 2009-02-23 16:25:39 +0100 (Mon, 23 Feb 2009) $
004 *
005 * This file is part of *** M y C o R e ***
006 * See http://www.mycore.de/ for details.
007 *
008 * This program is free software; you can use it, redistribute it
009 * and / or modify it under the terms of the GNU General Public License
010 * (GPL) as published by the Free Software Foundation; either version 2
011 * of the License or (at your option) any later version.
012 *
013 * This program is distributed in the hope that it will be useful, but
014 * WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016 * GNU General Public License for more details.
017 *
018 * You should have received a copy of the GNU General Public License
019 * along with this program, in a file called gpl.txt or license.txt.
020 * If not, write to the Free Software Foundation Inc.,
021 * 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA
022 */
023
024 package org.mycore.frontend.servlets;
025
026 import java.net.InetAddress;
027
028 import javax.servlet.http.HttpServletRequest;
029 import javax.servlet.http.HttpServletResponse;
030
031 import org.hibernate.Transaction;
032
033 import org.mycore.backend.hibernate.MCRHIBConnection;
034 import org.mycore.common.MCRConfiguration;
035 import org.mycore.common.MCRConfigurationException;
036
037 /**
038 * This class simply is a container for objects needed during a Servlet session
039 * like the HttpServletRequest and HttpServeltResponse. The class provids only
040 * get-methods to return the objects set while constructing the job object.
041 *
042 * @author Detlev Degenhardt
043 * @version $Revision: 14775 $ $Date: 2009-02-23 16:25:39 +0100 (Mon, 23 Feb 2009) $
044 */
045 public class MCRServletJob {
046 /** The HttpServletRequest object */
047 private HttpServletRequest theRequest = null;
048
049 /** The HttpServletResponse object */
050 private HttpServletResponse theResponse = null;
051
052 private Transaction transaction = null;
053
054 /**
055 * The constructor takes the given objects and stores them in private
056 * objects.
057 *
058 * @param theRequest
059 * the HttpServletRequest object for this servlet job
060 * @param theResponse
061 * the HttpServletResponse object for this servlet job
062 */
063 public MCRServletJob(HttpServletRequest theRequest, HttpServletResponse theResponse) {
064 this.theRequest = theRequest;
065 this.theResponse = theResponse;
066 }
067
068 /** returns the HttpServletRequest object */
069 public HttpServletRequest getRequest() {
070 return theRequest;
071 }
072
073 /** returns the HttpServletResponse object */
074 public HttpServletResponse getResponse() {
075 return theResponse;
076 }
077
078 /** returns true if the current http request was issued from the local host * */
079 public boolean isLocal() {
080 try {
081 String serverName = theRequest.getServerName();
082 String serverIP = InetAddress.getByName(serverName).getHostAddress();
083 String remoteIP = MCRServlet.getRemoteAddr(theRequest);
084
085 return (remoteIP.equals(serverIP) || remoteIP.equals("127.0.0.1"));
086 } catch (Exception ex) {
087 String msg = "Exception while testing if http request was from local host";
088 throw new MCRConfigurationException(msg, ex);
089 }
090 }
091 }