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.PasswordFormServlet;
00036 import org.openmobileis.services.security.SessionLoginManager;
00037
00038 import java.io.IOException;
00039
00040 import javax.servlet.ServletException;
00041 import javax.servlet.http.HttpServletRequest;
00042 import javax.servlet.http.HttpServletResponse;
00043
00052 public abstract class Service {
00053
00054
00055 private boolean isNavigationService = false;
00056 protected PasswordFormServlet passServlet;
00057
00058 public Service() {
00059 if (this instanceof NavigationBarService) {
00060 isNavigationService = true;
00061 }
00062 passServlet = new PasswordFormServlet();
00063 }
00064
00065
00066
00067
00068
00069
00070 public void runService(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
00071
00072
00073
00074
00075 if (SessionLoginManager.getManager().isInitializedPass()) {
00076
00077 if ((SessionLoginManager.getManager().getMaxTimeout()!=0) && SessionLoginManager.getManager().isInitializedPass()) {
00078 if (SessionLoginManager.getManager().isServiceCallElapseTime()) {
00079
00080 req.getSession(true).setAttribute("passservletreturnservice", this);
00081 req.getSession(true).setAttribute("passservletreturnservicerequri", req.getRequestURI());
00082 req.getSession(true).setAttribute("passservletreturnservicereqparam", req.getParameterMap());
00083 passServlet.service(req, res);
00084 return;
00085 }
00086 }
00087 SessionLoginManager.getManager().setServiceCall();
00088 }
00089
00090
00091 if (isNavigationService) {
00092 NavigationBarManager.getManager().setCurrentService((NavigationBarService)this, req);
00093 }
00094
00095
00096
00097 if (this.useWebCache()) {
00098 byte[] cachedResp = WebPageCacheManager.getManager().getCachedPage(req, this);
00099 if (cachedResp != null) {
00100 res.getWriter().print(cachedResp);
00101
00102 return;
00103 }
00104 }
00105
00106
00107 this.run(req, res);
00108
00109
00110
00111 if (this.useWebCache()) {
00112 WebPageCacheManager.getManager().setCachedPage(req, res.getOutputStream().toString().getBytes(), this);
00113
00114 }
00115 }
00116
00117
00118
00119
00120
00121
00122 public abstract void run( HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException;
00123
00124
00125
00126
00127
00128
00133 public boolean useWebCache() {
00134 return false;
00135 }
00136
00143 public String getNavigationBarLastServiceURI() {
00144 return null;
00145 }
00146
00150 public boolean isNavigationService() {
00151 return isNavigationService;
00152 }
00153
00154 public abstract String getServiceUri();
00155
00156
00157
00158
00159
00160 public boolean equals(Object obj) {
00161 if( obj instanceof Service){
00162 Service in = (Service) obj;
00163 if (in.getServiceUri().equals(this.getServiceUri())) {
00164 return true;
00165 }
00166 }
00167 return false;
00168 }
00169
00170 public int hashCode() {
00171 return this.getServiceUri().hashCode();
00172 }
00173
00174 }