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