1 17 18 package org.objectweb.jac.aspects.gui.web; 19 20 import java.util.Enumeration ; 21 import java.util.Hashtable ; 22 import java.util.Map ; 23 import javax.servlet.http.HttpServletRequest ; 24 import org.apache.log4j.Logger; 25 import org.objectweb.jac.util.Semaphore; 26 27 30 public abstract class AbstractJacRequest implements JacRequest { 31 static Logger logger = Logger.getLogger("web.session"); 32 33 Map headers = new Hashtable (); 34 public AbstractJacRequest(HttpServletRequest servletRequest) { 35 Enumeration headerNames = servletRequest.getHeaderNames(); 36 while (headerNames.hasMoreElements()) { 37 String name = (String )headerNames.nextElement(); 38 headers.put(name,servletRequest.getHeader(name)); 39 } 40 } 41 public abstract Object getParameter(String name); 42 public boolean isIEUserAgent() { 43 String userAgent = getUserAgent(); 44 if (userAgent!=null && userAgent.indexOf("MSIE")!=-1) { 45 return true; 46 } else { 47 return false; 48 } 49 } 50 public String getUserAgent() { 51 return getHeader("User-Agent"); 52 } 53 public boolean userAgentMatch(String s) { 54 String userAgent = getHeader("User-Agent"); 55 if (userAgent!=null && userAgent.indexOf(s)!=-1) { 56 return true; 57 } else { 58 return false; 59 } 60 } 61 public String getHeader(String name) { 62 return (String )headers.get(name); 63 } 64 65 JacRequest parent; 66 public void setParent(JacRequest parent) { 67 this.parent = parent; 68 } 69 70 72 transient protected Semaphore semaphore = new Semaphore(); 73 74 protected static final long DEFAULT_REQUEST_TIMEOUT = 1000*60*30; 76 public boolean waitForResponse() { 77 logger.debug("wait for response " + this + " (" + semaphore.getCount()+")"); 78 boolean result = semaphore.acquire(DEFAULT_REQUEST_TIMEOUT); 79 if (result) { 80 logger.debug("got response " + this + " (" + semaphore.getCount()+")"); 81 if (semaphore.getCount()>0) { 82 logger.warn("Session "+this+": semaphore > 0 ("+semaphore.getCount()+")"); 83 } 84 } else { 85 logger.debug("timeout "+this); 86 } 87 return result; 88 } 89 90 public void setResponse() { 91 logger.debug("set response " + this + " (" + semaphore.getCount()+")"); 92 semaphore.release(); 93 } 94 95 } 96 | Popular Tags |