📄 requestimpl.java
字号:
// when initially requested, but an invalidated session // must be rechecked // NOTE: The only way to check validity is to access // a property that returns IllegalStateException if not try { serverSession.getCreationTime(); } catch (IllegalStateException e) { serverSession = null; } if (serverSession != null) return serverSession; } if( ! create ) return null; // context.log("RequestImpl: created new session!"); contextM.doNewSessionRequest( this, response ); if ( serverSession == null ) { context.log("RequestImpl: no session created!"); return null; } reqSessionId = serverSession.getId(); response.setSessionId( reqSessionId ); return serverSession; } // -------------------- public int getCookieCount() { if( ! didCookies ) { didCookies=true; RequestUtil.processCookies( this, cookies ); } return cookies.size(); } public Cookie getCookie( int idx ) { if( ! didCookies ) { didCookies=true; RequestUtil.processCookies( this, cookies ); } return (Cookie)cookies.elementAt(idx); } public Cookie[] getCookies() { int count=getCookieCount(); Cookie[] cookieArray = new Cookie[ count ]; for (int i = 0; i < count; i ++) { cookieArray[i] = getCookie( i ); } return cookieArray; } // -------------------- LookupResult public ServletWrapper getWrapper() { return handler; } public void setWrapper(ServletWrapper handler) { this.handler=handler; } public Container getContainer() { return container; } public void setContainer(Container container) { this.container=container; } /** The file - result of mapping the request ( using aliases and other * mapping rules. Usefull only for static resources. */ public String getMappedPath() { return mappedPath; } public void setMappedPath( String m ) { mappedPath=m; } public void setRequestURI( String r ) { this.requestURI=r; } public void setParameters( Hashtable h ) { if(h!=null) this.parameters=h; // XXX Should we override query parameters ?? } public Hashtable getParameters() { return parameters; } public void setContentLength( int len ) { this.contentLength=len; } public void setContentType( String type ) { this.contentType=type; } public void setCharEncoding( String enc ) { this.charEncoding=enc; } public void setAuthType(String authType) { this.authType = authType; } public void setPathInfo(String pathInfo) { this.pathInfo = pathInfo; } /** Set query string - will be called by forward */ public void setQueryString(String queryString) { // the query will be processed when getParameter() will be called. // Or - if you alredy have it parsed, call setParameters() this.queryString = queryString; } public void setServletPath(String servletPath) { this.servletPath = servletPath; } // XXX // the server name should be pulled from a server object of some // sort, not just set and got. // -------------------- Attributes public Object getAttribute(String name) { Object value=attributes.get(name); if( value != null ) return value; // allow access to FacadeManager for servlets // ( this way you don't need to deal with init ). if( name.equals(FacadeManager.FACADE_ATTRIBUTE)) { return context.getAttribute( name ); } return null; } public void setAttribute(String name, Object value) { if(name!=null && value!=null) attributes.put(name, value); } public void removeAttribute(String name) { attributes.remove(name); } public Enumeration getAttributeNames() { return attributes.keys(); } // End Attributes // -------------------- Sub requests /** If this is a sub-request, return the parent */ public Request getParent() { return parent; } public void setParent( Request req ) { parent =req; } /** During include, a sub-request will be created. * This represents the current included request */ public Request getChild() { return child; } public void setChild( Request req ) { child=req; } /** This is the top request ( for a sub-request ) */ public Request getTop() { if( top == null ) { if( parent==null ) top=this; else { int i=MAX_INCLUDE; Request p=parent; while( i-- > 0 && p.getParent()!= null ) p=p.getParent(); if( i == 0 ) throw new IllegalStateException("Too deep includes"); top=p; } } return top; } // -------------------- Facade for MimeHeaders public Enumeration getHeaders(String name) { // Vector v = reqA.getMimeHeaders().getHeadersVector(name); Vector v = getMimeHeaders().getHeadersVector(name); return v.elements(); } // -------------------- Utils - facade for RequestUtil public BufferedReader getReader() throws IOException { return RequestUtil.getReader( this ); } private void handleParameters() { if(!didParameters) { String qString=getQueryString(); if(qString!=null) { didParameters=true; RequestUtil.processFormData( qString, parameters ); } } if (!didReadFormData) { didReadFormData = true; Hashtable postParameters=RequestUtil.readFormData( this ); if(postParameters!=null) parameters = RequestUtil.mergeParameters(parameters, postParameters); } } private void initRequest() { context = null; attributes.clear(); parameters.clear(); cookies.removeAllElements(); // requestURI = null; // queryString = null; contentLength = -1; contentType = null; charEncoding = null; authType = null; remoteUser = null; reqSessionId = null; serverSession = null; didParameters = false; didReadFormData = false; didCookies = false; container=null; handler=null; jvmRoute = null; scheme = "http";// no need to use Constants method = "GET"; requestURI="/"; queryString=null; protocol="HTTP/1.0"; headers.clear(); // XXX use recycle pattern serverName=null; serverPort=-1; pathTranslated=null; pathInfo=null; pathTranslatedIsSet=false; sessionIdSource = null; // XXX a request need to override those if it cares // about security remoteAddr="127.0.0.1"; remoteHost="localhost"; localHost="localhost"; if( bBuffer != null ) bBuffer.recycle(); for( int i=0; i<ACCOUNTS; i++ ) accTable[i]=0; for( int i=0; i<ContextManager.MAX_NOTES; i++ ) notes[i]=null; parent=null; child=null; top=null; notAuthenticated=true; userRoles=null; reqRoles=null; } // -------------------- End utils public void recycle() { if( requestFacade != null && context != null ) { context.getFacadeManager().recycle(this); } initRequest(); } public MimeHeaders getMimeHeaders() { return headers; } public String getHeader(String name) { return headers.getHeader(name); } public Enumeration getHeaderNames() { return headers.names(); } public ByteBuffer getInputBuffer() { return bBuffer; } public void setInputBuffer(ByteBuffer buf) { bBuffer=buf; } public ServletInputStream getInputStream() throws IOException { return in; } public int getServerPort() { return serverPort; } public String getRemoteAddr() { return remoteAddr; } public String getRemoteHost() { return remoteHost; } /** Fill in the buffer. This method is probably easier to implement than previous. This method should only be called from SerlvetInputStream implementations. No need to implement it if your adapter implements ServletInputStream. */ // you need to override this method if you want non-empty InputStream public int doRead( byte b[], int off, int len ) throws IOException { return -1; // not implemented - implement getInputStream } // XXX I hate this - but the only way to remove this method from the // inteface is to implement it on top of doRead(b[]). // Don't use this method if you can ( it is bad for performance !!) // you need to override this method if you want non-empty InputStream public int doRead() throws IOException { return -1; } // -------------------- "cooked" info -------------------- // Hints = return null if you don't know, // and Tom will find the value. You can also use the static // methods in RequestImpl // What's between context path and servlet name ( /servlet ) // A smart server may use arbitrary prefixes and rewriting public String getServletPrefix() { return null; } public void setScheme( String scheme ) { this.scheme=scheme; } public void setMethod( String method ) { this.method=method; } public void setProtocol( String protocol ) { this.protocol=protocol; } public void setMimeHeaders( MimeHeaders headers ) { this.headers=headers; } public void setBody( StringBuffer body ) { // ??? } public void setServerPort(int serverPort ) { this.serverPort=serverPort; } public void setRemoteAddr( String remoteAddr ) { this.remoteAddr=remoteAddr; } public void setRemoteHost(String remoteHost) { this.remoteHost=remoteHost; } public String getLocalHost() { return localHost; } public void setLocalHost(String host) { this.localHost = host; } public String toString() { StringBuffer sb=new StringBuffer(); sb.append( "R( "); if( context!=null) { sb.append( context.getPath() ); if( getServletPath() != null ) sb.append( " + " + getServletPath() + " + " + getPathInfo()); else sb.append( " + " + getLookupPath()); } else { sb.append(getRequestURI()); } sb.append(")"); return sb.toString(); } public String toStringDebug() { StringBuffer sb=new StringBuffer(); sb.append( "Request( " + context ).append("\n"); sb.append( " URI:" + getRequestURI() ).append("\n"); sb.append( " SP:" + getServletPath() ); sb.append( ",PI:" + getPathInfo() ); sb.append( ",LP:" + getLookupPath() ); sb.append( ",MP:" + getMappedPath() ); sb.append( "," + getWrapper() +") "); return sb.toString(); } // -------------------- Accounting -------------------- // XXX Will be implemented as a note ! public static final int ACC_PRE_CMAP=0; public static final int ACC_PRE_RMAP=1; public static final int ACC_POST_MAP=2; public static final int ACC_PRE_SERVICE=3; public static final int ACC_POST_SERVICE=4; public static final int ACC_IN_OUT=5; public static final int ACC_OUT_COUNT=6; public static final int ACCOUNTS=7; long accTable[]=new long[ACCOUNTS]; public void setAccount( int pos, long value ) { accTable[pos]=value; } public long getAccount( int pos ) { return accTable[pos]; } // -------------------- Per-Container "notes" Object notes[]=new Object[ContextManager.MAX_NOTES]; public void setNote( int pos, Object value ) { notes[pos]=value; } public Object getNote( int pos ) { return notes[pos]; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -