Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
discovery
Overview
Overview
Details
Activity
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
谢捷峰
discovery
Commits
5939a3d5
Commit
5939a3d5
authored
Aug 18, 2018
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
重构类结构
parent
fb5f4557
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
5 additions
and
72 deletions
+5
-72
discovery-console/src/main/java/com/nepxion/discovery/console/handler/ConsoleErrorHandler.java
+3
-1
discovery-plugin-config-center/src/main/java/com/nepxion/discovery/plugin/configcenter/parser/json/JsonConfigParser.java
+2
-2
discovery-plugin-config-center/src/main/java/com/nepxion/discovery/plugin/configcenter/parser/json/jackson/JacksonSerializer.java
+0
-69
No files found.
discovery-console/src/main/java/com/nepxion/discovery/console/handler/ConsoleErrorHandler.java
View file @
5939a3d5
...
@@ -16,6 +16,8 @@ import org.apache.commons.io.IOUtils;
...
@@ -16,6 +16,8 @@ import org.apache.commons.io.IOUtils;
import
org.springframework.http.client.ClientHttpResponse
;
import
org.springframework.http.client.ClientHttpResponse
;
import
org.springframework.web.client.DefaultResponseErrorHandler
;
import
org.springframework.web.client.DefaultResponseErrorHandler
;
import
com.nepxion.discovery.common.constant.DiscoveryConstant
;
public
class
ConsoleErrorHandler
extends
DefaultResponseErrorHandler
{
public
class
ConsoleErrorHandler
extends
DefaultResponseErrorHandler
{
private
String
cause
;
private
String
cause
;
...
@@ -23,7 +25,7 @@ public class ConsoleErrorHandler extends DefaultResponseErrorHandler {
...
@@ -23,7 +25,7 @@ public class ConsoleErrorHandler extends DefaultResponseErrorHandler {
public
void
handleError
(
ClientHttpResponse
response
)
throws
IOException
{
public
void
handleError
(
ClientHttpResponse
response
)
throws
IOException
{
// 这里绝对不能关闭InputStream
// 这里绝对不能关闭InputStream
InputStream
inputStream
=
response
.
getBody
();
InputStream
inputStream
=
response
.
getBody
();
cause
=
IOUtils
.
toString
(
inputStream
,
"UTF-8"
);
cause
=
IOUtils
.
toString
(
inputStream
,
DiscoveryConstant
.
ENCODING_UTF_8
);
}
}
public
String
getCause
()
{
public
String
getCause
()
{
...
...
discovery-plugin-config-center/src/main/java/com/nepxion/discovery/plugin/configcenter/parser/json/JsonConfigParser.java
View file @
5939a3d5
...
@@ -15,7 +15,7 @@ import org.slf4j.LoggerFactory;
...
@@ -15,7 +15,7 @@ import org.slf4j.LoggerFactory;
import
com.nepxion.discovery.common.entity.RuleEntity
;
import
com.nepxion.discovery.common.entity.RuleEntity
;
import
com.nepxion.discovery.common.exception.DiscoveryException
;
import
com.nepxion.discovery.common.exception.DiscoveryException
;
import
com.nepxion.discovery.
plugin.configcenter.parser.json.jackson.JacksonSerializer
;
import
com.nepxion.discovery.
common.util.JsonUtil
;
import
com.nepxion.discovery.plugin.framework.config.PluginConfigParser
;
import
com.nepxion.discovery.plugin.framework.config.PluginConfigParser
;
public
class
JsonConfigParser
implements
PluginConfigParser
{
public
class
JsonConfigParser
implements
PluginConfigParser
{
...
@@ -28,7 +28,7 @@ public class JsonConfigParser implements PluginConfigParser {
...
@@ -28,7 +28,7 @@ public class JsonConfigParser implements PluginConfigParser {
}
}
try
{
try
{
RuleEntity
ruleEntity
=
J
acksonSerializer
.
fromJson
(
config
,
RuleEntity
.
class
);
RuleEntity
ruleEntity
=
J
sonUtil
.
fromJson
(
config
,
RuleEntity
.
class
);
ruleEntity
.
setContent
(
config
);
ruleEntity
.
setContent
(
config
);
LOG
.
info
(
"Rule entity=\n{}"
,
ruleEntity
);
LOG
.
info
(
"Rule entity=\n{}"
,
ruleEntity
);
...
...
discovery-plugin-config-center/src/main/java/com/nepxion/discovery/plugin/configcenter/parser/json/jackson/JacksonSerializer.java
deleted
100644 → 0
View file @
fb5f4557
package
com
.
nepxion
.
discovery
.
plugin
.
configcenter
.
parser
.
json
.
jackson
;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import
java.text.SimpleDateFormat
;
import
org.apache.commons.lang3.StringUtils
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.nepxion.discovery.common.constant.DiscoveryConstant
;
public
class
JacksonSerializer
{
private
static
ObjectMapper
objectMapper
;
static
{
objectMapper
=
new
ObjectMapper
();
objectMapper
.
setDateFormat
(
new
SimpleDateFormat
(
DiscoveryConstant
.
DATE_FORMAT
));
}
public
static
<
T
>
String
toJson
(
T
object
)
{
if
(
object
==
null
)
{
throw
new
IllegalArgumentException
(
"Object is null"
);
}
try
{
return
objectMapper
.
writeValueAsString
(
object
);
}
catch
(
JsonProcessingException
e
)
{
throw
new
IllegalArgumentException
(
e
.
getMessage
(),
e
);
}
}
public
static
<
T
>
T
fromJson
(
String
json
,
Class
<
T
>
clazz
)
{
if
(
StringUtils
.
isEmpty
(
json
))
{
throw
new
IllegalArgumentException
(
"Json is null or empty"
);
}
try
{
return
objectMapper
.
readValue
(
json
,
clazz
);
}
catch
(
Exception
e
)
{
throw
new
IllegalArgumentException
(
e
.
getMessage
(),
e
);
}
}
public
static
<
T
>
T
fromJson
(
String
json
,
TypeReference
<
T
>
typeReference
)
{
if
(
StringUtils
.
isEmpty
(
json
))
{
throw
new
IllegalArgumentException
(
"Json is null or empty"
);
}
try
{
return
objectMapper
.
readValue
(
json
,
typeReference
);
}
catch
(
Exception
e
)
{
throw
new
IllegalArgumentException
(
e
.
getMessage
(),
e
);
}
}
public
static
ObjectMapper
getObjectMapper
()
{
return
objectMapper
;
}
}
\ No newline at end of file
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