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.common.SecurityManager;
00034 import org.openmobileis.services.navigation.NavigationBarManager;
00035 import org.openmobileis.services.navigation.NavigationBarService;
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 private String name;
00054 private String uri;
00055 private boolean isNavigationService = false;
00056
00057 public Service() {
00058 if (this instanceof NavigationBarService) {
00059 isNavigationService = true;
00060 }
00061 }
00062
00063
00064
00065
00066
00067
00068 public void runService(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
00069
00070
00071
00072
00073 if (SecurityManager.getManager().isInitializedPass()) {
00074 String type = req.getParameter("type");
00075 if ((type !=null) && (type.equals("setPassword"))) {
00076 String pwd = req.getParameter("pwd");
00077 if (SecurityManager.getManager().validateServicePass(pwd)) {
00078 SecurityManager.getManager().setServiceCall();
00079 }
00080 }
00081
00082
00083 if ((SecurityManager.getManager().getMaxTimeout()!=0) && SecurityManager.getManager().isInitializedPass()) {
00084 if (SecurityManager.getManager().isServiceCallElapseTime()) {
00085 res.sendRedirect(res.encodeRedirectURL("/showpassform"));
00086 return;
00087 }
00088 }
00089 SecurityManager.getManager().setServiceCall();
00090 }
00091
00092
00093 if (isNavigationService) {
00094 NavigationBarManager.getManager().setCurrentService((NavigationBarService)this, req);
00095 }
00096
00097
00098
00099 if (this.useWebCache()) {
00100 byte[] cachedResp = WebPageCacheManager.getManager().getCachedPage(req, this);
00101 if (cachedResp != null) {
00102 res.getWriter().print(cachedResp);
00103
00104 return;
00105 }
00106 }
00107
00108
00109 this.run(req, res);
00110
00111
00112
00113 if (this.useWebCache()) {
00114 WebPageCacheManager.getManager().setCachedPage(req, res.getOutputStream().toString().getBytes(), this);
00115
00116 }
00117 }
00118
00119
00120
00121
00122
00123
00124 public abstract void run( HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException;
00125
00126
00127
00128
00129 public String getName() {
00130 return name;
00131 }
00132
00133
00134
00135
00136
00137
00138 public void init (String name) {
00139 this.name = name;
00140 }
00141
00146 public boolean useWebCache() {
00147 return false;
00148 }
00149
00156 public String getNavigationBarLastServiceURI() {
00157 return null;
00158 }
00159
00163 public boolean isNavigationService() {
00164 return isNavigationService;
00165 }
00166
00167 public String getServiceUri() {
00168 return this.uri;
00169 }
00170
00171 public void setServiceURI(String uri) {
00172 this.uri = uri;
00173 }
00174
00175 }