RedirectToFromCallingService.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2006 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: pdelrieu@openmobileis.org
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.common;
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 
00039 import org.openmobileis.services.Service;
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                         CallingServiceManager callServManager = CallingServiceManager.getManager();
00070                         callServManager.pushCallingService(this.getServiceUri(), req);
00071                         //update navigation bar
00072                         String uri = (String)req.getParameter("from");
00073                         if (uri != null)        {
00074                                 NavigationBarManager.getManager().updateRequestParametersForRedirectService(uri, req);
00075                         }
00076                   res.sendRedirect(to);
00077                 } else  { //manage redirect return
00078                         String from = (String)req.getParameter("from");
00079                         if (from == null)       {
00080                                 CallingServiceManager callServManager = CallingServiceManager.getManager();
00081                                 callServManager.peekToTheSpecifiedCallingService(this.getServiceUri());
00082                                 //res.getCallingServiceManager().peekToTheSpecifiedCallingService(this.getServiceUri());
00083                                 //Hashtable oldParameterList = res.getCallingServiceManager().getCallingServiceParameters();
00084                                 Hashtable oldParameterList = callServManager.getCallingServiceParameters();
00085                                 //res.getCallingServiceManager().popCallingService();
00086                                 callServManager.popCallingService();
00087                                 if (oldParameterList != null)   {
00088                                         //manage old request in new one
00089                                     openmisReq.addParameters(oldParameterList);
00090                                         from = (String)req.getParameter("from");
00091                                 }
00092                         }
00093                         if (from!=null) {
00094                                 res.sendRedirect(from);                         
00095                         } else {
00096                         LogManager.traceError(LogServices.WEBSERVICE, "RedirectToFromCallingService can't find to service");
00097                         ServletTools.sendErrorPage("Internal Error" , "No service specified to return", "/index", res);
00098                         }       
00099                 }
00100         }
00101 
00102   
00103   public String getName() {
00104     return "calendar.RedirectToFromCallingService";
00105   }
00106   
00110   public String getServiceUri() {
00111     return ServiceManager.getManager().getServiceBaseURI()+"/admin/redirectService";
00112   }
00113 
00114 }

Generated on Tue May 22 23:01:11 2007 for OpenMobileIS by  doxygen 1.5.1-p1