Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
3dbe38e4
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,发现更多精彩内容 >>
提交
3dbe38e4
编写于
4月 21, 2010
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added check for WebSphere's compliance mode (SPR-7064)
上级
c5f83686
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
56 addition
and
15 deletion
+56
-15
org.springframework.web/src/main/java/org/springframework/web/util/UrlPathHelper.java
...main/java/org/springframework/web/util/UrlPathHelper.java
+39
-4
org.springframework.web/src/test/java/org/springframework/web/util/UrlPathHelperTests.java
...java/org/springframework/web/util/UrlPathHelperTests.java
+17
-11
未找到文件。
org.springframework.web/src/main/java/org/springframework/web/util/UrlPathHelper.java
浏览文件 @
3dbe38e4
...
...
@@ -18,6 +18,7 @@ package org.springframework.web.util;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLDecoder
;
import
java.util.Properties
;
import
javax.servlet.http.HttpServletRequest
;
import
org.apache.commons.logging.Log
;
...
...
@@ -47,8 +48,10 @@ public class UrlPathHelper {
*/
private
static
final
String
WEBSPHERE_URI_ATTRIBUTE
=
"com.ibm.websphere.servlet.uri_non_decoded"
;
private
static
final
Log
logger
=
LogFactory
.
getLog
(
UrlPathHelper
.
class
);
static
volatile
Boolean
websphereComplianceFlag
;
private
final
Log
logger
=
LogFactory
.
getLog
(
getClass
());
private
boolean
alwaysUseFullPath
=
false
;
...
...
@@ -234,9 +237,10 @@ public class UrlPathHelper {
servletPath
=
request
.
getServletPath
();
}
if
(
servletPath
.
length
()
>
1
&&
servletPath
.
endsWith
(
"/"
)
&&
request
.
getAttribute
(
WEBSPHERE_URI_ATTRIBUTE
)
!=
null
)
{
// On WebSphere, for a "/foo/" case that would be "/foo" on all other servlet containers:
// removing trailing slash, proceeding with that slash as final path mapping...
shouldRemoveTrailingServletPathSlash
(
request
))
{
// On WebSphere, in non-compliant mode, for a "/foo/" case that would be "/foo"
// on all other servlet containers: removing trailing slash, proceeding with
// that remaining slash as final lookup path...
servletPath
=
servletPath
.
substring
(
0
,
servletPath
.
length
()
-
1
);
}
return
servletPath
;
...
...
@@ -347,4 +351,35 @@ public class UrlPathHelper {
return
enc
;
}
private
boolean
shouldRemoveTrailingServletPathSlash
(
HttpServletRequest
request
)
{
if
(
request
.
getAttribute
(
WEBSPHERE_URI_ATTRIBUTE
)
==
null
)
{
// Regular servlet container: behaves as expected in any case,
// so the trailing slash is the result of a "/" url-pattern mapping.
// Don't remove that slash.
return
false
;
}
if
(
websphereComplianceFlag
==
null
)
{
ClassLoader
classLoader
=
UrlPathHelper
.
class
.
getClassLoader
();
String
className
=
"com.ibm.ws.webcontainer.WebContainer"
;
String
methodName
=
"getWebContainerProperties"
;
String
propName
=
"com.ibm.ws.webcontainer.removetrailingservletpathslash"
;
boolean
flag
=
false
;
try
{
Class
<?>
cl
=
classLoader
.
loadClass
(
className
);
Properties
prop
=
(
Properties
)
cl
.
getMethod
(
methodName
).
invoke
(
null
);
flag
=
Boolean
.
parseBoolean
(
prop
.
getProperty
(
propName
));
}
catch
(
Throwable
ex
)
{
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"Could not introspect WebSphere web container properties: "
+
ex
);
}
}
websphereComplianceFlag
=
flag
;
}
// Don't bother if WebSphere is configured to be fully Servlet compliant.
// However, if it is not compliant, do remove the improper trailing slash!
return
!
websphereComplianceFlag
;
}
}
org.springframework.web/src/test/java/org/springframework/web/util/UrlPathHelperTests.java
浏览文件 @
3dbe38e4
...
...
@@ -16,10 +16,11 @@
package
org.springframework.web.util
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.*;
import
org.junit.Before
;
import
org.junit.Ignore
;
import
org.junit.Test
;
import
org.springframework.mock.web.MockHttpServletRequest
;
/**
...
...
@@ -146,12 +147,11 @@ public class UrlPathHelperTests {
}
@Test
public
void
tomcat
DefaultServletFileWithCompliantSetting
()
throws
Exception
{
public
void
was
DefaultServletFileWithCompliantSetting
()
throws
Exception
{
request
.
setAttribute
(
WEBSPHERE_URI_ATTRIBUTE
,
"/test/foo"
);
tomcatDefaultServletFile
();
}
@Test
public
void
wasDefaultServletFolder
()
throws
Exception
{
request
.
setContextPath
(
"/test"
);
...
...
@@ -163,10 +163,16 @@ public class UrlPathHelperTests {
assertEquals
(
"/foo/"
,
helper
.
getLookupPathForRequest
(
request
));
}
//
@Test
@Test
public
void
wasDefaultServletFolderWithCompliantSetting
()
throws
Exception
{
request
.
setAttribute
(
WEBSPHERE_URI_ATTRIBUTE
,
"/test/foo/"
);
tomcatDefaultServletFolder
();
UrlPathHelper
.
websphereComplianceFlag
=
true
;
try
{
request
.
setAttribute
(
WEBSPHERE_URI_ATTRIBUTE
,
"/test/foo/"
);
tomcatDefaultServletFolder
();
}
finally
{
UrlPathHelper
.
websphereComplianceFlag
=
false
;
}
}
...
...
@@ -185,7 +191,7 @@ public class UrlPathHelperTests {
}
// test the root mapping for /foo/* w/o a trailing slash - <host>/<context>/foo
// @Test
@Test
@Ignore
public
void
tomcatCasualServletRootWithMissingSlash
()
throws
Exception
{
request
.
setContextPath
(
"/test"
);
request
.
setPathInfo
(
null
);
...
...
@@ -226,14 +232,14 @@ public class UrlPathHelperTests {
assertEquals
(
"/"
,
helper
.
getLookupPathForRequest
(
request
));
}
//
@Test
@Test
public
void
wasCasualServletRootWithCompliantSetting
()
throws
Exception
{
request
.
setAttribute
(
WEBSPHERE_URI_ATTRIBUTE
,
"/test/foo/"
);
tomcatCasualServletRoot
();
}
// test the root mapping for /foo/* w/o a trailing slash - <host>/<context>/foo
// @Test
@Test
@Ignore
public
void
wasCasualServletRootWithMissingSlash
()
throws
Exception
{
request
.
setContextPath
(
"/test"
);
request
.
setPathInfo
(
null
);
...
...
@@ -244,7 +250,7 @@ public class UrlPathHelperTests {
assertEquals
(
"/"
,
helper
.
getLookupPathForRequest
(
request
));
}
// @Test
@Test
@Ignore
public
void
wasCasualServletRootWithMissingSlashWithCompliantSetting
()
throws
Exception
{
request
.
setAttribute
(
WEBSPHERE_URI_ATTRIBUTE
,
"/test/foo"
);
tomcatCasualServletRootWithMissingSlash
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录