Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members

RedirectToFromCallingService.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2005 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: openmobileis@e-care.fr
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00020  * USA
00021  *
00022  *  Author : Philippe Delrieu
00023  *  
00024  *  Modifications :
00025  *  2004 Creation P.Delrieu
00026  *  2004 Modified by Romain Beaugrand
00027  * 
00028  */
00029 
00030 package org.openmobileis.services;
00031 
00032 import java.io.IOException;
00033 import java.util.Hashtable;
00034 
00035 import javax.servlet.ServletException;
00036 import javax.servlet.http.HttpServletRequest;
00037 import javax.servlet.http.HttpServletResponse;
00038 import javax.servlet.http.HttpSession;
00039 
00040 import org.openmobileis.services.navigation.NavigationBarManager;
00041 import org.openmobileis.services.servlet.OpenmisHttpServletRequest;
00042 import org.openmobileis.common.util.log.*;
00043 
00048 public class RedirectToFromCallingService extends Service {
00049 
00053         public RedirectToFromCallingService() {
00054                 super();
00055         }
00056 
00060         public void run(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
00061                 
00062             OpenmisHttpServletRequest openmisReq = (OpenmisHttpServletRequest)req;
00063             
00064                 // begin search
00065                 String to = req.getParameter("to");
00066                 if (to != null) { // start redirect
00067                         //remove to parameter
00068                     openmisReq.removeParameter("to");
00069                         //res.getCallingServiceManager().pushCallingService(this.getServiceUri(), req);
00070                     HttpSession session = req.getSession();
00071                         CallingServiceManager callServManager = (CallingServiceManager)session.getAttribute("openMIS.CallingServiceManager");
00072                         callServManager.pushCallingService(this.getServiceUri(), req);
00073                         //update navigation bar
00074                         String uri = (String)req.getParameter("from");
00075                         if (uri != null)        {
00076                                 NavigationBarManager.getManager().updateRequestParametersForRedirectService(uri, req);
00077                         }
00078                   res.sendRedirect(to);
00079                 } else  { //manage redirect return
00080                         String from = (String)req.getParameter("from");
00081                         if (from == null)       {
00082                             HttpSession session = req.getSession();
00083                                 CallingServiceManager callServManager = (CallingServiceManager)session.getAttribute("openMIS.CallingServiceManager");
00084                                 callServManager.peekToTheSpecifiedCallingService(this.getServiceUri());
00085                                 //res.getCallingServiceManager().peekToTheSpecifiedCallingService(this.getServiceUri());
00086                                 //Hashtable oldParameterList = res.getCallingServiceManager().getCallingServiceParameters();
00087                                 Hashtable oldParameterList = callServManager.getCallingServiceParameters();
00088                                 //res.getCallingServiceManager().popCallingService();
00089                                 callServManager.popCallingService();
00090                                 if (oldParameterList != null)   {
00091                                         //manage old request in new one
00092                                     openmisReq.addParameters(oldParameterList);
00093                                         from = (String)req.getParameter("from");
00094                                 }
00095                         }
00096                         if (from!=null) {
00097                                 res.sendRedirect(from);                         
00098                         } else {
00099                         LogManager.traceError(LogServices.WEBSERVICE, "RedirectToFromCallingService can't find to service");
00100                         ServletTools.sendErrorPage("Internal Error" , "No service specified to return", "/index", res);
00101                         }       
00102                 }
00103         }
00104 
00105   
00106   public String getName() {
00107     return "calendar.RedirectToFromCallingService";
00108   }
00109   
00113   public String getServiceUri() {
00114     return ServiceManager.getManager().getServiceBaseURI()+"/admin/redirectService";
00115   }
00116 
00117 }

Generated on Thu Oct 6 10:06:33 2005 for OpenMobileIS by  doxygen 1.4.3