Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
1277889a
C
cat
项目概览
梦中观雨
/
cat
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
cat
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1277889a
编写于
7月 14, 2014
作者:
Y
youyong205
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #391 from youyong205/master
remove cookie filter
上级
fc6c0781
1d25deed
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
0 addition
and
175 deletion
+0
-175
cat-home/src/main/java/com/dianping/cat/CookieFilter.java
cat-home/src/main/java/com/dianping/cat/CookieFilter.java
+0
-166
cat-home/src/main/webapp/WEB-INF/web.xml
cat-home/src/main/webapp/WEB-INF/web.xml
+0
-9
未找到文件。
cat-home/src/main/java/com/dianping/cat/CookieFilter.java
已删除
100644 → 0
浏览文件 @
fc6c0781
package
com.dianping.cat
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
javax.servlet.Filter
;
import
javax.servlet.FilterChain
;
import
javax.servlet.FilterConfig
;
import
javax.servlet.ServletException
;
import
javax.servlet.ServletRequest
;
import
javax.servlet.ServletResponse
;
import
javax.servlet.http.Cookie
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.unidal.eunit.helper.Files
;
import
com.google.gson.JsonArray
;
import
com.google.gson.JsonElement
;
import
com.google.gson.JsonObject
;
import
com.google.gson.JsonParser
;
public
class
CookieFilter
implements
Filter
{
private
static
Map
<
String
,
Item
>
validateCookies
;
private
static
final
String
KEY
=
"neocortex-4j.cookies.whiteList"
;
public
static
void
main
(
String
args
[])
throws
Exception
{
String
value
=
Files
.
forIO
().
readFrom
(
new
File
(
"/data/appdatas/cat/cookies"
),
"utf-8"
);
JsonElement
element
=
new
JsonParser
().
parse
(
value
);
JsonArray
array
=
element
.
getAsJsonArray
();
List
<
Item
>
items
=
new
ArrayList
<
Item
>();
for
(
int
i
=
0
;
i
<
array
.
size
();
i
++)
{
JsonObject
str
=
array
.
get
(
i
).
getAsJsonObject
();
String
name
=
str
.
get
(
"name"
).
getAsString
();
String
domain
=
str
.
get
(
"domain"
).
getAsString
();
String
path
=
str
.
get
(
"path"
).
getAsString
();
items
.
add
(
new
Item
(
name
,
domain
,
path
));
}
validateCookies
=
new
HashMap
<
String
,
Item
>();
for
(
Item
item
:
items
)
{
validateCookies
.
put
(
item
.
getName
(),
item
);
System
.
out
.
println
(
item
.
toString
());
}
}
@Override
public
void
destroy
()
{
}
@Override
public
void
doFilter
(
ServletRequest
request
,
ServletResponse
response
,
FilterChain
chain
)
throws
IOException
,
ServletException
{
try
{
HttpServletRequest
httpServletRequest
=
(
HttpServletRequest
)
request
;
HttpServletResponse
httpServletResponse
=
(
HttpServletResponse
)
response
;
Cookie
[]
cookies
=
httpServletRequest
.
getCookies
();
String
domain
=
httpServletRequest
.
getServerName
();
String
path
=
httpServletRequest
.
getRequestURI
();
System
.
out
.
println
(
"domain:"
+
domain
+
" path:"
+
path
);
if
(
cookies
!=
null
)
{
for
(
Cookie
c
:
cookies
)
{
String
name
=
c
.
getName
();
if
(
validateCookies
!=
null
)
{
Item
item
=
validateCookies
.
get
(
name
);
if
(
item
==
null
||
!
item
.
getPath
().
equals
(
path
)
||
!
item
.
getDomain
().
equals
(
domain
))
{
Cookie
temp
=
new
Cookie
(
name
,
null
);
temp
.
setDomain
(
".dianping.com"
);
temp
.
setMaxAge
(
0
);
temp
.
setPath
(
"/"
);
httpServletResponse
.
addCookie
(
temp
);
System
.
err
.
println
(
"kill "
+
c
.
getName
()
+
" "
+
temp
.
getPath
()+
" "
+
temp
.
getDomain
());
}
else
{
System
.
err
.
println
(
"not kill 222 "
+
c
.
getName
());
}
}
else
{
System
.
out
.
println
(
"map is null"
);
}
}
}
}
catch
(
Exception
e
)
{
Cat
.
logError
(
e
);
}
chain
.
doFilter
(
request
,
response
);
}
@Override
public
void
init
(
FilterConfig
filterConfig
)
throws
ServletException
{
try
{
// ConfigCache config = ConfigCache.getInstance();
String
value
=
Files
.
forIO
().
readFrom
(
new
File
(
"/data/appdatas/cat/cookies"
),
"utf-8"
);
// String value = config.getProperty(KEY);
JsonElement
element
=
new
JsonParser
().
parse
(
value
);
JsonArray
array
=
element
.
getAsJsonArray
();
List
<
Item
>
items
=
new
ArrayList
<
Item
>();
for
(
int
i
=
0
;
i
<
array
.
size
();
i
++)
{
JsonObject
str
=
array
.
get
(
i
).
getAsJsonObject
();
String
name
=
str
.
get
(
"name"
).
getAsString
();
String
domain
=
str
.
get
(
"domain"
).
getAsString
();
String
path
=
str
.
get
(
"path"
).
getAsString
();
items
.
add
(
new
Item
(
name
,
domain
,
path
));
}
validateCookies
=
new
HashMap
<
String
,
Item
>();
for
(
Item
item
:
items
)
{
validateCookies
.
put
(
item
.
getName
(),
item
);
System
.
out
.
println
(
"put:"
+
item
.
toString
());
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
Cat
.
logError
(
e
);
}
}
public
static
class
Item
{
private
String
name
;
private
String
domain
;
private
String
path
;
public
Item
(
String
name
,
String
domain
,
String
path
)
{
this
.
name
=
name
;
this
.
domain
=
domain
;
this
.
path
=
path
;
}
public
String
getDomain
()
{
return
domain
;
}
public
String
getName
()
{
return
name
;
}
public
String
getPath
()
{
return
path
;
}
@Override
public
String
toString
()
{
return
"Item [name="
+
name
+
", domain="
+
domain
+
", path="
+
path
+
"]"
;
}
}
}
cat-home/src/main/webapp/WEB-INF/web.xml
浏览文件 @
1277889a
...
...
@@ -6,10 +6,6 @@
<filter-name>
cat-filter
</filter-name>
<filter-class>
com.dianping.cat.servlet.CatFilter
</filter-class>
</filter>
<filter>
<filter-name>
cookie-filter
</filter-name>
<filter-class>
com.dianping.cat.CookieFilter
</filter-class>
</filter>
<filter>
<filter-name>
domain-filter
</filter-name>
<filter-class>
com.dianping.cat.servlet.DomainFilter
</filter-class>
...
...
@@ -42,11 +38,6 @@
<url-pattern>
/r/*
</url-pattern>
<dispatcher>
REQUEST
</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>
cookie-filter
</filter-name>
<url-pattern>
/r/*
</url-pattern>
<dispatcher>
REQUEST
</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>
cat-filter
</filter-name>
<url-pattern>
/s/*
</url-pattern>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录