Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
71dbd7bc
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
71dbd7bc
编写于
8月 14, 2013
作者:
R
Rossen Stoyanchev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove qetQueryParams from ServerHttpRequest
上级
4c0490a0
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
32 addition
and
67 deletion
+32
-67
spring-web/src/main/java/org/springframework/http/server/ServerHttpRequest.java
...va/org/springframework/http/server/ServerHttpRequest.java
+0
-6
spring-web/src/main/java/org/springframework/http/server/ServletServerHttpRequest.java
...springframework/http/server/ServletServerHttpRequest.java
+0
-29
spring-web/src/test/java/org/springframework/http/server/ServletServerHttpRequestTests.java
...gframework/http/server/ServletServerHttpRequestTests.java
+0
-18
spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/AbstractHttpSendingTransportHandler.java
...ransport/handler/AbstractHttpSendingTransportHandler.java
+18
-0
spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/HtmlFileTransportHandler.java
...et/sockjs/transport/handler/HtmlFileTransportHandler.java
+12
-12
spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/JsonpPollingTransportHandler.java
...ockjs/transport/handler/JsonpPollingTransportHandler.java
+2
-2
未找到文件。
spring-web/src/main/java/org/springframework/http/server/ServerHttpRequest.java
浏览文件 @
71dbd7bc
...
...
@@ -21,7 +21,6 @@ import java.security.Principal;
import
org.springframework.http.HttpInputMessage
;
import
org.springframework.http.HttpRequest
;
import
org.springframework.util.MultiValueMap
;
/**
* Represents a server-side HTTP request.
...
...
@@ -32,11 +31,6 @@ import org.springframework.util.MultiValueMap;
*/
public
interface
ServerHttpRequest
extends
HttpRequest
,
HttpInputMessage
{
/**
* Returns the map of query parameters. Empty if no query has been set.
*/
MultiValueMap
<
String
,
String
>
getQueryParams
();
/**
* Return a {@link java.security.Principal} instance containing the name of the
* authenticated user. If the user has not been authenticated, the method returns
...
...
spring-web/src/main/java/org/springframework/http/server/ServletServerHttpRequest.java
浏览文件 @
71dbd7bc
...
...
@@ -34,8 +34,6 @@ import java.util.HashMap;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
javax.servlet.http.HttpServletRequest
;
...
...
@@ -43,9 +41,6 @@ import org.springframework.http.HttpHeaders;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.MediaType
;
import
org.springframework.util.Assert
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.MultiValueMap
;
/**
* {@link ServerHttpRequest} implementation that is based on a {@link HttpServletRequest}.
...
...
@@ -61,14 +56,10 @@ public class ServletServerHttpRequest implements ServerHttpRequest {
private
static
final
String
METHOD_POST
=
"POST"
;
private
static
final
Pattern
QUERY_PARAM_PATTERN
=
Pattern
.
compile
(
"([^&=]+)(=?)([^&]+)?"
);
private
final
HttpServletRequest
servletRequest
;
private
HttpHeaders
headers
;
private
MultiValueMap
<
String
,
String
>
queryParams
;
private
ServerHttpAsyncRequestControl
asyncRequestControl
;
...
...
@@ -154,26 +145,6 @@ public class ServletServerHttpRequest implements ServerHttpRequest {
return
new
InetSocketAddress
(
this
.
servletRequest
.
getRemoteHost
(),
this
.
servletRequest
.
getRemotePort
());
}
@Override
public
MultiValueMap
<
String
,
String
>
getQueryParams
()
{
if
(
this
.
queryParams
==
null
)
{
MultiValueMap
<
String
,
String
>
result
=
new
LinkedMultiValueMap
<
String
,
String
>();
String
queryString
=
this
.
servletRequest
.
getQueryString
();
if
(
queryString
!=
null
)
{
Matcher
m
=
QUERY_PARAM_PATTERN
.
matcher
(
queryString
);
while
(
m
.
find
())
{
String
name
=
m
.
group
(
1
);
String
[]
values
=
this
.
servletRequest
.
getParameterValues
(
name
);
if
(
values
!=
null
)
{
result
.
put
(
name
,
Arrays
.
asList
(
values
));
}
}
}
this
.
queryParams
=
CollectionUtils
.
unmodifiableMultiValueMap
(
result
);
}
return
this
.
queryParams
;
}
@Override
public
InputStream
getBody
()
throws
IOException
{
if
(
isFormPost
(
this
.
servletRequest
))
{
...
...
spring-web/src/test/java/org/springframework/http/server/ServletServerHttpRequestTests.java
浏览文件 @
71dbd7bc
...
...
@@ -18,7 +18,6 @@ package org.springframework.http.server;
import
java.net.URI
;
import
java.nio.charset.Charset
;
import
java.util.Arrays
;
import
java.util.List
;
import
org.junit.Before
;
...
...
@@ -106,21 +105,4 @@ public class ServletServerHttpRequestTests {
assertArrayEquals
(
"Invalid content returned"
,
content
,
result
);
}
@Test
public
void
getQueryParams
()
throws
Exception
{
mockRequest
.
setQueryString
(
"foo=bar"
);
mockRequest
.
addParameter
(
"foo"
,
"bar"
);
mockRequest
.
addParameter
(
"a"
,
"b"
);
assertEquals
(
Arrays
.
asList
(
"bar"
),
request
.
getQueryParams
().
get
(
"foo"
));
assertNull
(
request
.
getQueryParams
().
get
(
"a"
));
}
@Test
public
void
getQueryParamsTwoValues
()
throws
Exception
{
mockRequest
.
setQueryString
(
"baz=qux&baz=42"
);
mockRequest
.
addParameter
(
"baz"
,
"qux"
);
mockRequest
.
addParameter
(
"baz"
,
"42"
);
assertEquals
(
Arrays
.
asList
(
"qux"
,
"42"
),
request
.
getQueryParams
().
get
(
"baz"
));
}
}
\ No newline at end of file
spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/AbstractHttpSendingTransportHandler.java
浏览文件 @
71dbd7bc
...
...
@@ -17,10 +17,13 @@
package
org.springframework.web.socket.sockjs.transport.handler
;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.server.ServerHttpRequest
;
import
org.springframework.http.server.ServerHttpResponse
;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.socket.WebSocketHandler
;
import
org.springframework.web.socket.WebSocketSession
;
import
org.springframework.web.socket.sockjs.SockJsException
;
...
...
@@ -28,6 +31,8 @@ import org.springframework.web.socket.sockjs.support.frame.SockJsFrame;
import
org.springframework.web.socket.sockjs.support.frame.SockJsFrame.FrameFormat
;
import
org.springframework.web.socket.sockjs.transport.TransportHandler
;
import
org.springframework.web.socket.sockjs.transport.session.AbstractHttpSockJsSession
;
import
org.springframework.web.util.UriComponentsBuilder
;
import
org.springframework.web.util.UriUtils
;
/**
* Base class for HTTP transport handlers that push messages to connected clients.
...
...
@@ -81,4 +86,17 @@ public abstract class AbstractHttpSendingTransportHandler extends TransportHandl
protected
abstract
FrameFormat
getFrameFormat
(
ServerHttpRequest
request
);
protected
final
String
getCallbackParam
(
ServerHttpRequest
request
)
{
String
query
=
request
.
getURI
().
getQuery
();
MultiValueMap
<
String
,
String
>
params
=
UriComponentsBuilder
.
newInstance
().
query
(
query
).
build
().
getQueryParams
();
String
value
=
params
.
getFirst
(
"c"
);
try
{
return
StringUtils
.
isEmpty
(
value
)
?
null
:
UriUtils
.
decode
(
value
,
"UTF-8"
);
}
catch
(
UnsupportedEncodingException
e
)
{
// should never happen
throw
new
SockJsException
(
"Unable to decode callback query parameter"
,
null
,
e
);
}
}
}
spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/HtmlFileTransportHandler.java
浏览文件 @
71dbd7bc
...
...
@@ -98,18 +98,18 @@ public class HtmlFileTransportHandler extends AbstractHttpSendingTransportHandle
public
void
handleRequestInternal
(
ServerHttpRequest
request
,
ServerHttpResponse
response
,
AbstractHttpSockJsSession
sockJsSession
)
{
String
callback
=
request
.
getQueryParams
().
getFirst
(
"c"
);
if
(!
StringUtils
.
hasText
(
callback
))
{
response
.
setStatusCode
(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
try
{
response
.
getBody
().
write
(
"\"callback\" parameter required"
.
getBytes
(
"UTF-8"
));
}
catch
(
IOException
t
)
{
sockJsSession
.
tryCloseWithSockJsTransportError
(
t
,
CloseStatus
.
SERVER_ERROR
);
throw
new
SockJsTransportFailureException
(
"Failed to write to response"
,
sockJsSession
.
getId
(),
t
);
}
return
;
String
callback
=
getCallbackParam
(
request
);
if
(!
StringUtils
.
hasText
(
callback
))
{
response
.
setStatusCode
(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
try
{
response
.
getBody
().
write
(
"\"callback\" parameter required"
.
getBytes
(
"UTF-8"
));
}
catch
(
IOException
t
)
{
sockJsSession
.
tryCloseWithSockJsTransportError
(
t
,
CloseStatus
.
SERVER_ERROR
);
throw
new
SockJsTransportFailureException
(
"Failed to write to response"
,
sockJsSession
.
getId
(),
t
);
}
return
;
}
super
.
handleRequestInternal
(
request
,
response
,
sockJsSession
);
}
...
...
@@ -137,7 +137,7 @@ public class HtmlFileTransportHandler extends AbstractHttpSendingTransportHandle
protected
void
writePrelude
()
throws
IOException
{
// we already validated the parameter above..
String
callback
=
get
Request
().
getQueryParams
().
getFirst
(
"c"
);
String
callback
=
get
CallbackParam
(
getRequest
()
);
String
html
=
String
.
format
(
PARTIAL_HTML_CONTENT
,
callback
);
getResponse
().
getBody
().
write
(
html
.
getBytes
(
"UTF-8"
));
...
...
spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/JsonpPollingTransportHandler.java
浏览文件 @
71dbd7bc
...
...
@@ -65,7 +65,7 @@ public class JsonpPollingTransportHandler extends AbstractHttpSendingTransportHa
AbstractHttpSockJsSession
sockJsSession
)
throws
SockJsException
{
try
{
String
callback
=
request
.
getQueryParams
().
getFirst
(
"c"
);
String
callback
=
getCallbackParam
(
request
);
if
(!
StringUtils
.
hasText
(
callback
))
{
response
.
setStatusCode
(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
response
.
getBody
().
write
(
"\"callback\" parameter required"
.
getBytes
(
"UTF-8"
));
...
...
@@ -84,7 +84,7 @@ public class JsonpPollingTransportHandler extends AbstractHttpSendingTransportHa
protected
FrameFormat
getFrameFormat
(
ServerHttpRequest
request
)
{
// we already validated the parameter above..
String
callback
=
request
.
getQueryParams
().
getFirst
(
"c"
);
String
callback
=
getCallbackParam
(
request
);
return
new
SockJsFrame
.
DefaultFrameFormat
(
callback
+
"(\"%s\");\r\n"
)
{
@Override
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录