00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 package org.openmobileis.services;
00031
00032 import org.openmobileis.services.cache.WebPageCacheManager;
00033 import org.openmobileis.services.navigation.NavigationBarManager;
00034 import org.openmobileis.services.navigation.NavigationBarService;
00035 import org.openmobileis.services.security.SecurityManager;
00036
00037 import java.io.IOException;
00038
00039 import javax.servlet.ServletException;
00040 import javax.servlet.http.HttpServletRequest;
00041 import javax.servlet.http.HttpServletResponse;
00042
00051 public abstract class Service {
00052
00053
00054 private boolean isNavigationService = false;
00055
00056 public Service() {
00057 if (this instanceof NavigationBarService) {
00058 isNavigationService = true;
00059 }
00060 }
00061
00062
00063
00064
00065
00066
00067 public void runService(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
00068
00069
00070
00071
00072 if (SecurityManager.getManager().isInitializedPass()) {
00073 String type = req.getParameter("type");
00074 if ((type !=null) && (type.equals("setPassword"))) {
00075 String pwd = req.getParameter("pwd");
00076 if (SecurityManager.getManager().validateServicePass(pwd)) {
00077 SecurityManager.getManager().setServiceCall();
00078 }
00079 }
00080
00081
00082 if ((SecurityManager.getManager().getMaxTimeout()!=0) && SecurityManager.getManager().isInitializedPass()) {
00083 if (SecurityManager.getManager().isServiceCallElapseTime()) {
00084 res.sendRedirect(res.encodeRedirectURL("/showpassform"));
00085 return;
00086 }
00087 }
00088 SecurityManager.getManager().setServiceCall();
00089 }
00090
00091
00092 if (isNavigationService) {
00093 NavigationBarManager.getManager().setCurrentService((NavigationBarService)this, req);
00094 }
00095
00096
00097
00098 if (this.useWebCache()) {
00099 byte[] cachedResp = WebPageCacheManager.getManager().getCachedPage(req, this);
00100 if (cachedResp != null) {
00101 res.getWriter().print(cachedResp);
00102
00103 return;
00104 }
00105 }
00106
00107
00108 this.run(req, res);
00109
00110
00111
00112 if (this.useWebCache()) {
00113 WebPageCacheManager.getManager().setCachedPage(req, res.getOutputStream().toString().getBytes(), this);
00114
00115 }
00116 }
00117
00118
00119
00120
00121
00122
00123 public abstract void run( HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException;
00124
00125
00126
00127
00128
00129
00134 public boolean useWebCache() {
00135 return false;
00136 }
00137
00144 public String getNavigationBarLastServiceURI() {
00145 return null;
00146 }
00147
00151 public boolean isNavigationService() {
00152 return isNavigationService;
00153 }
00154
00155 public abstract String getServiceUri();
00156
00157
00158
00159
00160
00161 public boolean equals(Object obj) {
00162 if( obj instanceof Service){
00163 Service in = (Service) obj;
00164 if (in.getServiceUri().equals(this.getServiceUri())) {
00165 return true;
00166 }
00167 }
00168 return false;
00169 }
00170
00171 public int hashCode() {
00172 return this.getServiceUri().hashCode();
00173 }
00174
00175 }