Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cloud-platform
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
youjj
cloud-platform
Commits
dbb78bde
Commit
dbb78bde
authored
Nov 13, 2019
by
jiaorz
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master-bacground-im' into dev
parents
002c9d6d
fccb3684
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
80 additions
and
1 deletion
+80
-1
pom.xml
ace-common/pom.xml
+5
-1
GlobalExceptionHandler.java
...iaoqi/security/common/handler/GlobalExceptionHandler.java
+3
-0
HttpRequestUtil.java
.../github/wxiaoqi/security/common/util/HttpRequestUtil.java
+72
-0
No files found.
ace-common/pom.xml
View file @
dbb78bde
...
@@ -112,7 +112,11 @@
...
@@ -112,7 +112,11 @@
<artifactId>
hutool-all
</artifactId>
<artifactId>
hutool-all
</artifactId>
<version>
4.5.10
</version>
<version>
4.5.10
</version>
</dependency>
</dependency>
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpclient
</artifactId>
<version>
4.5
</version>
</dependency>
<!-- swagger注解 -->
<!-- swagger注解 -->
<dependency>
<dependency>
<groupId>
io.swagger
</groupId>
<groupId>
io.swagger
</groupId>
...
...
ace-common/src/main/java/com/github/wxiaoqi/security/common/handler/GlobalExceptionHandler.java
View file @
dbb78bde
...
@@ -6,6 +6,7 @@ import com.github.wxiaoqi.security.common.exception.auth.ClientTokenException;
...
@@ -6,6 +6,7 @@ import com.github.wxiaoqi.security.common.exception.auth.ClientTokenException;
import
com.github.wxiaoqi.security.common.exception.auth.UserInvalidException
;
import
com.github.wxiaoqi.security.common.exception.auth.UserInvalidException
;
import
com.github.wxiaoqi.security.common.exception.auth.UserTokenException
;
import
com.github.wxiaoqi.security.common.exception.auth.UserTokenException
;
import
com.github.wxiaoqi.security.common.msg.BaseResponse
;
import
com.github.wxiaoqi.security.common.msg.BaseResponse
;
import
com.github.wxiaoqi.security.common.util.HttpRequestUtil
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpHeaders
;
...
@@ -66,6 +67,7 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
...
@@ -66,6 +67,7 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
if
(
0
==
ex
.
getStatus
())
{
if
(
0
==
ex
.
getStatus
())
{
response
.
setStatus
(
500
);
response
.
setStatus
(
500
);
}
}
HttpRequestUtil
.
httpGet
(
"http://10.5.52.3:8765/api/universal/mail/app/unauth/send?toUser=jiaoruizhen@126.com&subject=服务器异常&content="
+
ex
.
getMessage
()
+
":"
+
ex
);
return
new
BaseResponse
(
ex
.
getStatus
(),
ex
.
getMessage
());
return
new
BaseResponse
(
ex
.
getStatus
(),
ex
.
getMessage
());
}
}
...
@@ -73,6 +75,7 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
...
@@ -73,6 +75,7 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
public
BaseResponse
otherExceptionHandler
(
HttpServletResponse
response
,
Exception
ex
)
{
public
BaseResponse
otherExceptionHandler
(
HttpServletResponse
response
,
Exception
ex
)
{
response
.
setStatus
(
500
);
response
.
setStatus
(
500
);
logger
.
error
(
ex
.
getMessage
(),
ex
);
logger
.
error
(
ex
.
getMessage
(),
ex
);
HttpRequestUtil
.
httpGet
(
"http://10.5.52.3:8765/api/universal/mail/app/unauth/send?toUser=jiaoruizhen@126.com&subject=服务器异常&content="
+
ex
.
getMessage
()
+
":"
+
ex
);
return
new
BaseResponse
(
CommonConstants
.
EX_OTHER_CODE
,
ex
.
getMessage
());
return
new
BaseResponse
(
CommonConstants
.
EX_OTHER_CODE
,
ex
.
getMessage
());
}
}
}
}
ace-common/src/main/java/com/github/wxiaoqi/security/common/util/HttpRequestUtil.java
0 → 100644
View file @
dbb78bde
package
com
.
github
.
wxiaoqi
.
security
.
common
.
util
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.client.methods.HttpGet
;
import
org.apache.http.client.methods.HttpPost
;
import
org.apache.http.impl.client.DefaultHttpClient
;
import
java.io.IOException
;
import
java.net.URLDecoder
;
@Slf4j
public
class
HttpRequestUtil
{
/**
* post请求
* @param url url地址
* @return
*/
public
static
String
httpPost
(
String
url
){
//post请求返回结果
DefaultHttpClient
httpClient
=
new
DefaultHttpClient
();
HttpPost
method
=
new
HttpPost
(
url
);
String
str
=
""
;
try
{
HttpResponse
result
=
httpClient
.
execute
(
method
);
url
=
URLDecoder
.
decode
(
url
,
"UTF-8"
);
/**请求发送成功,并得到响应**/
if
(
result
.
getStatusLine
().
getStatusCode
()
==
200
)
{
try
{
/**读取服务器返回过来的json字符串数据**/
str
=
EntityUtils
.
toString
(
result
.
getEntity
(),
"UTF-8"
);
}
catch
(
Exception
e
)
{
log
.
error
(
"post请求提交失败:"
+
url
,
e
);
}
}
}
catch
(
IOException
e
)
{
log
.
error
(
"post请求提交失败:"
+
url
,
e
);
}
return
str
;
}
/**
* 发送get请求
* @param url 路径
* @return
*/
public
static
String
httpGet
(
String
url
){
//get请求返回结果
String
strResult
=
null
;
try
{
DefaultHttpClient
client
=
new
DefaultHttpClient
();
//发送get请求
HttpGet
request
=
new
HttpGet
(
url
);
HttpResponse
response
=
client
.
execute
(
request
);
/**请求发送成功,并得到响应**/
if
(
response
.
getStatusLine
().
getStatusCode
()
==
org
.
apache
.
http
.
HttpStatus
.
SC_OK
)
{
/**读取服务器返回过来的json字符串数据**/
strResult
=
EntityUtils
.
toString
(
response
.
getEntity
(),
"UTF-8"
);
}
else
{
log
.
error
(
"get请求提交失败:"
+
url
);
}
}
catch
(
IOException
e
)
{
log
.
error
(
"get请求提交失败:"
+
url
,
e
);
}
return
strResult
;
}
}
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