📄 httprequest.java
字号:
protected Cookie createSessionCookie()
{
String s = "NEWJSDKCOOKIE";
Cookie cookie = new Cookie(sessionCookieName, s);
cookie.setComment("Session ID");
cookie.setPath("/");
return cookie;
}
public String getRequestedSessionId()
{
if(requestedSessionID != null)
return requestedSessionID;
Cookie cookie = getCookie(sessionCookieName);
if(cookie != null)
requestedSessionID = cookie.getValue();
return requestedSessionID;
}
protected Cookie getCookie(String s)
{
Cookie acookie[] = getCookies();
Cookie cookie = null;
if(acookie == null)
return null;
for(int i = 0; i < acookie.length; i++)
{
if(!acookie[i].getName().equals(s))
continue;
cookie = (Cookie)acookie[i].clone();
break;
}
return cookie;
}
public boolean isRequestedSessionIdFromCookie()
{
String s = getRequestedSessionId();
return s != null;
}
public boolean isRequestedSessionIdFromUrl()
{
return false;
}
public boolean isRequestedSessionIdValid()
{
if(isRequestedSessionIdFromCookie())
{
session = (HttpSessionImpl)sessionContext.getSession(requestedSessionID);
if(session != null)
{
session.setNew(false);
session.setCookieSupported(true);
session.setLastAccessedTime();
response.setHttpSession(session);
return true;
}
}
return false;
}
public String getMethod()
{
MessageBytes messagebytes = line.getMethod();
if(messagebytes.equals("GET"))
return "GET";
if(messagebytes.equals("POST"))
return "POST";
else
return messagebytes.toString();
}
public String getRequestURI()
{
if(isRequestURIAssigned)
return assignedRequestURI;
else
return line.getURI().toString();
}
public void setRequestURI(String s)
{
isRequestURIAssigned = true;
assignedRequestURI = s;
}
public String getServletPath()
{
return servletPath.toString();
}
public String getPathInfo()
{
return decode(pathInfo.toString());
}
public String getPathTranslated()
{
String s = getPathInfo();
if(s != null)
return con.getRealPath(s);
else
return null;
}
public String getRealPath(String s)
{
return con.getRealPath(s);
}
public String getQueryString()
{
return line.getQueryString().toString();
}
public void setRemoteUser(String s)
{
remoteUser.setString(s);
}
public void setRemoteUser(byte abyte0[], int i, int j)
{
remoteUser.setBytes(abyte0, i, j);
}
public String getRemoteUser()
{
return remoteUser.toString();
}
public void setAuthType(String s)
{
authType.setString(s);
}
public void setAuthType(byte abyte0[], int i, int j)
{
authType.setBytes(abyte0, i, j);
}
public String getAuthType()
{
return authType.toString();
}
public String getHeader(String s)
{
return headers.getHeader(s);
}
public void setHeader(String s, String s1)
{
headers.putHeader(s, s1);
}
public int getIntHeader(String s)
{
return headers.getIntHeader(s);
}
public long getDateHeader(String s)
{
return headers.getDateHeader(s);
}
public Enumeration getHeaderNames()
{
return headers.names();
}
public Object getAttribute(String s)
{
for(int i = 0; i < attributeDictionaries.size(); i++)
{
Dictionary dictionary = (Dictionary)attributeDictionaries.elementAt(i);
Object obj = dictionary.get(s);
if(obj != null)
return obj;
}
return null;
}
public void addAttributeDictionary(Dictionary dictionary)
{
attributeDictionaries.addElement(dictionary);
}
public void dump(PrintStream printstream)
{
printstream.println(">> REQUEST LINE INFO");
line.dump(printstream);
printstream.println(">> HEADERS");
headers.dump(printstream);
printstream.println();
}
public Object clone()
{
try
{
return super.clone();
}
catch(CloneNotSupportedException ex)
{
throw new RuntimeException("Clone not supported on Cloneable");
}
}
public void setParametersDictionary(Dictionary dictionary)
{
params = dictionary;
}
public void setRawInputStream(InputStream inputstream)
throws IOException
{
in.init(inputstream);
}
public ServletConnection getConnection()
{
return con;
}
public boolean isFilterRequest()
{
return isFilterRequest;
}
public void setFilterRequest(boolean flag)
{
isFilterRequest = flag;
}
private String decode(String s)
{
if(s == null)
return null;
if(s.indexOf(37) == -1)
return s;
byte abyte0[] = new byte[s.length()];
int i = 0;
for(int j = 0; j < s.length(); j++)
if(s.charAt(j) == '%')
{
abyte0[i++] = (byte)Integer.parseInt(s.substring(j + 1, j + 3), 16);
if(j + 2 >= s.length())
j = s.length();
else
j += 2;
}
else
{
abyte0[i++] = (byte)s.charAt(j);
}
return new String(abyte0, 0, 0, i);
}
private Hashtable getParametersFromRequest()
{
Hashtable hashtable = null;
if(line.getMethod().equals("GET"))
{
String s = line.getQueryString().toString();
if(s != null)
try
{
hashtable = HttpUtils.parseQueryString(s);
}
catch(IllegalArgumentException ex)
{
hashtable = null;
}
}
else
if(line.getMethod().equals("POST"))
if(getContentType() != null && getContentType().equals("application/x-www-form-urlencoded"))
try
{
hashtable = HttpUtils.parsePostData(getContentLength(), getInputStream());
}
catch(Exception ex)
{
hashtable = null;
}
else
try
{
String s1 = line.getQueryString().toString();
if(s1 != null)
hashtable = HttpUtils.parseQueryString(s1);
}
catch(Exception ex)
{
hashtable = null;
}
if(hashtable == null)
hashtable = nullHashtable;
return hashtable;
}
protected void setRequest(HttpRequest httprequest)
{
line = httprequest.line;
}
/// mod by Ligou
public String getCharacterEncoding()
{
if(charEncoding == null)
if(mimeType == null)
setContentType("text/plain");
else
charEncoding = HttpResponse.getContentCharset(mimeType);
if(charEncoding == null)
{
StringBuffer stringbuffer = new StringBuffer(mimeType);
charEncoding = chooseCharacterEncoding();
stringbuffer.append(";charset=\"");
stringbuffer.append(charEncoding);
stringbuffer.append("\"");
mimeType = stringbuffer.toString();
setHeader("Content-Type", mimeType);
}
return charEncoding;
}
protected String chooseCharacterEncoding()
{
return "8859_1";
}
public void setContentType(String s)
{
if(s.equalsIgnoreCase(mimeType))
return;
if(mimeType != null)
{
throw new IllegalStateException("MIME type was already set");
}
else
{
mimeType = s;
setHeader("Content-Type", s);
return;
}
}
public boolean isUserInRole(java.lang.String role) {
return true;
}
/// end of Mod.
private String scheme;
private String sessionCookieName;
protected HttpRequestLine line;
protected final MessageString servletPath = new MessageString();
protected final MessageString pathInfo = new MessageString();
protected String assignedRequestURI;
protected boolean isRequestURIAssigned;
protected MessageBytes requestPath;
protected final MessageString remoteUser = new MessageString();
protected final MessageString authType = new MessageString();
protected MimeHeaders headers;
protected HttpInputStream in;
protected ServletConnection con;
protected int length;
private boolean keepAlive;
protected Dictionary params;
protected HttpSessionImpl session;
protected String requestedSessionID;
protected SessionContextImpl sessionContext;
protected HttpResponse response;
private Vector attributeDictionaries;
private static final String METHOD_STRING_GET = "GET";
private static final String METHOD_STRING_POST = "POST";
private Hashtable nullHashtable;
private String mimeType;
private BufferedReader reader;
private boolean gotReader;
private boolean gotInputStream;
private boolean isFilterRequest;
private String charEncoding;
//add by lightning
public java.util.Enumeration getHeaders(java.lang.String name)
{
return null;
}
public java.lang.String getContextPath()
{
return null;
}
public java.security.Principal getUserPrincipal()
{
return null;
}
public java.lang.StringBuffer getRequestURL()
{
return null;
}
public HttpSession getSession()
{
return null;
}
public java.util.Enumeration getAttributeNames(){
return null;
}
public void setCharacterEncoding(java.lang.String env)
throws java.io.UnsupportedEncodingException
{
;
}
public java.util.Map getParameterMap(){
return null;
}
public void setAttribute(java.lang.String name,
java.lang.Object o){
}
public void removeAttribute(java.lang.String name){
}
public java.util.Locale getLocale(){
return null;
}
public java.util.Enumeration getLocales(){
return null;
}
public boolean isSecure(){
return true;
}
public javax.servlet.RequestDispatcher getRequestDispatcher(java.lang.String path){
return null;
}
public boolean isRequestedSessionIdFromURL(){
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -