Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
a30cd39c
Commit
a30cd39c
authored
May 12, 2019
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
异常处理显示
parent
37cb42d3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
8 deletions
+10
-8
CookiesHelper.java
...main/java/com/yanzuoguang/cloud/helper/CookiesHelper.java
+10
-8
No files found.
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/helper/CookiesHelper.java
View file @
a30cd39c
...
@@ -3,13 +3,15 @@ package com.yanzuoguang.cloud.helper;
...
@@ -3,13 +3,15 @@ package com.yanzuoguang.cloud.helper;
import
com.yanzuoguang.token.TokenHelper
;
import
com.yanzuoguang.token.TokenHelper
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.helper.UrlHelper
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
javax.servlet.http.Cookie
;
import
javax.servlet.http.Cookie
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLDecoder
;
import
java.net.URLEncoder
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -44,7 +46,7 @@ public class CookiesHelper {
...
@@ -44,7 +46,7 @@ public class CookiesHelper {
* @param key 键值
* @param key 键值
* @return 缓存的键值
* @return 缓存的键值
*/
*/
public
static
String
get
(
String
key
)
{
public
static
String
get
(
String
key
)
throws
UnsupportedEncodingException
{
HttpServletRequest
request
=
getRequest
();
HttpServletRequest
request
=
getRequest
();
Map
<
String
,
String
>
map
=
new
HashMap
<>();
Map
<
String
,
String
>
map
=
new
HashMap
<>();
int
keyLength
=
0
;
int
keyLength
=
0
;
...
@@ -56,7 +58,7 @@ public class CookiesHelper {
...
@@ -56,7 +58,7 @@ public class CookiesHelper {
keyLength
=
StringHelper
.
toInt
(
item
.
getValue
());
keyLength
=
StringHelper
.
toInt
(
item
.
getValue
());
continue
;
continue
;
}
else
{
}
else
{
return
U
rlHelper
.
decoding
(
item
.
getValue
(),
CHARSET
);
return
U
RLDecoder
.
decode
(
item
.
getValue
(),
CHARSET
);
}
}
}
else
if
(
item
.
getName
().
startsWith
(
key
))
{
}
else
if
(
item
.
getName
().
startsWith
(
key
))
{
map
.
put
(
key
,
item
.
getValue
());
map
.
put
(
key
,
item
.
getValue
());
...
@@ -72,7 +74,7 @@ public class CookiesHelper {
...
@@ -72,7 +74,7 @@ public class CookiesHelper {
}
}
sb
.
append
(
map
.
get
(
itemKey
));
sb
.
append
(
map
.
get
(
itemKey
));
}
}
return
U
rlHelper
.
decoding
(
sb
.
toString
(),
CHARSET
);
return
U
RLDecoder
.
decode
(
sb
.
toString
(),
CHARSET
);
}
}
/**
/**
...
@@ -81,9 +83,9 @@ public class CookiesHelper {
...
@@ -81,9 +83,9 @@ public class CookiesHelper {
* @param key 键
* @param key 键
* @param value 值
* @param value 值
*/
*/
public
static
void
set
(
String
key
,
String
value
)
{
public
static
void
set
(
String
key
,
String
value
)
throws
UnsupportedEncodingException
{
HttpServletResponse
response
=
getResposne
();
HttpServletResponse
response
=
getResposne
();
String
toValue
=
U
rlHelper
.
encoding
(
value
,
CHARSET
);
String
toValue
=
U
RLEncoder
.
encode
(
value
,
CHARSET
);
if
(
toValue
.
length
()
<
ITEM_MAX_SIZE
)
{
if
(
toValue
.
length
()
<
ITEM_MAX_SIZE
)
{
// 创建cookie对象
// 创建cookie对象
Cookie
cookie
=
new
Cookie
(
key
,
value
);
Cookie
cookie
=
new
Cookie
(
key
,
value
);
...
@@ -135,7 +137,7 @@ public class CookiesHelper {
...
@@ -135,7 +137,7 @@ public class CookiesHelper {
/**
/**
* 登录结束处理
* 登录结束处理
*/
*/
public
static
void
tokenFinish
()
{
public
static
void
tokenFinish
()
throws
UnsupportedEncodingException
{
String
tokenResponse
=
TokenHelper
.
getTokenString
();
String
tokenResponse
=
TokenHelper
.
getTokenString
();
if
(!
StringHelper
.
isEmpty
(
tokenResponse
))
{
if
(!
StringHelper
.
isEmpty
(
tokenResponse
))
{
set
(
TOKEN_STRING_KEY
,
tokenResponse
);
set
(
TOKEN_STRING_KEY
,
tokenResponse
);
...
@@ -146,7 +148,7 @@ public class CookiesHelper {
...
@@ -146,7 +148,7 @@ public class CookiesHelper {
/**
/**
* 登录初始化
* 登录初始化
*/
*/
public
static
void
tokenInit
()
{
public
static
void
tokenInit
()
throws
UnsupportedEncodingException
{
String
tokenRequest
=
get
(
CookiesHelper
.
TOKEN_STRING_KEY
);
String
tokenRequest
=
get
(
CookiesHelper
.
TOKEN_STRING_KEY
);
if
(!
StringHelper
.
isEmpty
(
tokenRequest
))
{
if
(!
StringHelper
.
isEmpty
(
tokenRequest
))
{
TokenHelper
.
setTokenString
(
tokenRequest
);
TokenHelper
.
setTokenString
(
tokenRequest
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment