Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
caopu16
whatsmars
提交
617603d6
W
whatsmars
项目概览
caopu16
/
whatsmars
与 Fork 源项目一致
Fork自
武汉红喜 / whatsmars
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
whatsmars
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
617603d6
编写于
4月 14, 2016
作者:
武汉红喜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
parseParameters
上级
4cf0ce05
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
116 addition
and
16 deletion
+116
-16
whatsmars-tomcat/src/main/java/com/whatsmars/tomcat/connector/HttpRequest.java
...main/java/com/whatsmars/tomcat/connector/HttpRequest.java
+116
-16
未找到文件。
whatsmars-tomcat/src/main/java/com/whatsmars/tomcat/connector/HttpRequest.java
浏览文件 @
617603d6
package
com.whatsmars.tomcat.connector
;
import
org.apache.catalina.util.Enumerator
;
import
org.apache.catalina.util.ParameterMap
;
import
org.apache.catalina.util.RequestUtil
;
import
javax.servlet.*
;
import
javax.servlet.http.*
;
import
java.io.BufferedReader
;
...
...
@@ -24,6 +28,25 @@ public class HttpRequest implements HttpServletRequest {
protected
SocketInputStream
input
;
/**
* The parsed parameters for this request. This is populated only if
* parameter information is requested via one of the
* <code>getParameter()</code> family of method calls. The key is the
* parameter name, while the value is a String array of values for this
* parameter.
* <p>
* <strong>IMPLEMENTATION NOTE</strong> - Once the parameters for a
* particular request are parsed and stored here, they are not modified.
* Therefore, application level access to the parameters need not be
* synchronized.
*/
protected
ParameterMap
parameters
=
null
;
// extends LinkedHashMap has a boolean var 'locked'
/**
* Have the parameters for this request been parsed yet?
*/
protected
boolean
parsed
=
false
;
public
HttpRequest
(
SocketInputStream
input
)
{
this
.
input
=
input
;
}
...
...
@@ -40,6 +63,99 @@ public class HttpRequest implements HttpServletRequest {
}
}
public
String
getParameter
(
String
name
)
{
parseParameters
();
String
values
[]
=
(
String
[])
parameters
.
get
(
name
);
if
(
values
!=
null
)
return
(
values
[
0
]);
else
return
(
null
);
}
public
Map
getParameterMap
()
{
parseParameters
();
return
(
this
.
parameters
);
}
public
Enumeration
getParameterNames
()
{
parseParameters
();
return
(
new
Enumerator
(
parameters
.
keySet
()));
}
public
String
[]
getParameterValues
(
String
name
)
{
parseParameters
();
String
values
[]
=
(
String
[])
parameters
.
get
(
name
);
if
(
values
!=
null
)
return
(
values
);
else
return
null
;
}
/**
* Parse the parameters of this request, if it has not already occurred.
* If parameters are present in both the query string and the request
* content, they are merged.
*/
protected
void
parseParameters
()
{
if
(
parsed
)
return
;
ParameterMap
results
=
parameters
;
if
(
results
==
null
)
results
=
new
ParameterMap
();
results
.
setLocked
(
false
);
String
encoding
=
getCharacterEncoding
();
if
(
encoding
==
null
)
encoding
=
"ISO-8859-1"
;
// Parse any parameters specified in the query string
String
queryString
=
getQueryString
();
try
{
RequestUtil
.
parseParameters
(
results
,
queryString
,
encoding
);
}
catch
(
Exception
e
)
{
;
}
// Parse any parameters specified in the input stream
String
contentType
=
getContentType
();
if
(
contentType
==
null
)
contentType
=
""
;
int
semicolon
=
contentType
.
indexOf
(
';'
);
if
(
semicolon
>=
0
)
{
contentType
=
contentType
.
substring
(
0
,
semicolon
).
trim
();
}
else
{
contentType
=
contentType
.
trim
();
}
if
(
"POST"
.
equals
(
getMethod
())
&&
(
getContentLength
()
>
0
)
&&
"application/x-www-form-urlencoded"
.
equals
(
contentType
))
{
try
{
int
max
=
getContentLength
();
int
len
=
0
;
byte
buf
[]
=
new
byte
[
getContentLength
()];
ServletInputStream
is
=
getInputStream
();
while
(
len
<
max
)
{
int
next
=
is
.
read
(
buf
,
len
,
max
-
len
);
if
(
next
<
0
)
{
break
;
}
len
+=
next
;
}
is
.
close
();
if
(
len
<
max
)
{
throw
new
RuntimeException
(
"Content length mismatch"
);
}
RequestUtil
.
parseParameters
(
results
,
buf
,
encoding
);
}
catch
(
UnsupportedEncodingException
ue
)
{
;
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
"Content read fail"
);
}
}
// Store the final results
results
.
setLocked
(
true
);
parsed
=
true
;
parameters
=
results
;
}
public
void
setRequestURI
(
String
requestURI
)
{
this
.
requestURI
=
requestURI
;
}
...
...
@@ -212,22 +328,6 @@ public class HttpRequest implements HttpServletRequest {
return
null
;
}
public
String
getParameter
(
String
name
)
{
return
null
;
}
public
Enumeration
<
String
>
getParameterNames
()
{
return
null
;
}
public
String
[]
getParameterValues
(
String
name
)
{
return
new
String
[
0
];
}
public
Map
<
String
,
String
[]>
getParameterMap
()
{
return
null
;
}
public
String
getProtocol
()
{
return
protocol
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录