Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-cloud-netflix
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
spring-cloud-netflix
Commits
7cff8ddb
Unverified
Commit
7cff8ddb
authored
Oct 16, 2017
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add missing jackson serialization for instanceinfo.
Port information was missing from data sent to eureka. fixes gh-2372
parent
6b6889b8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
0 deletions
+48
-0
RestTemplateTransportClientFactory.java
...tflix/eureka/http/RestTemplateTransportClientFactory.java
+39
-0
EurekaServerMockApplication.java
...loud/netflix/eureka/http/EurekaServerMockApplication.java
+8
-0
RestTemplateEurekaHttpClientTest.java
...netflix/eureka/http/RestTemplateEurekaHttpClientTest.java
+1
-0
No files found.
spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/RestTemplateTransportClientFactory.java
View file @
7cff8ddb
...
...
@@ -23,10 +23,21 @@ import org.springframework.http.client.support.BasicAuthorizationInterceptor;
import
org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
;
import
org.springframework.web.client.RestTemplate
;
import
com.fasterxml.jackson.databind.BeanDescription
;
import
com.fasterxml.jackson.databind.DeserializationFeature
;
import
com.fasterxml.jackson.databind.JsonSerializer
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.PropertyNamingStrategy
;
import
com.fasterxml.jackson.databind.SerializationConfig
;
import
com.fasterxml.jackson.databind.SerializationFeature
;
import
com.fasterxml.jackson.databind.module.SimpleModule
;
import
com.fasterxml.jackson.databind.ser.BeanSerializerModifier
;
import
com.fasterxml.jackson.databind.ser.std.BeanSerializerBase
;
import
com.netflix.appinfo.InstanceInfo
;
import
com.netflix.discovery.converters.jackson.mixin.ApplicationsJsonMixIn
;
import
com.netflix.discovery.converters.jackson.mixin.InstanceInfoJsonMixIn
;
import
com.netflix.discovery.converters.jackson.serializer.InstanceInfoJsonBeanSerializer
;
import
com.netflix.discovery.shared.Applications
;
import
com.netflix.discovery.shared.resolver.EurekaEndpoint
;
import
com.netflix.discovery.shared.transport.EurekaHttpClient
;
import
com.netflix.discovery.shared.transport.TransportClientFactory
;
...
...
@@ -84,13 +95,41 @@ public class RestTemplateTransportClientFactory implements TransportClientFactor
converter
.
setObjectMapper
(
new
ObjectMapper
()
.
setPropertyNamingStrategy
(
PropertyNamingStrategy
.
SNAKE_CASE
));
SimpleModule
jsonModule
=
new
SimpleModule
();
jsonModule
.
setSerializerModifier
(
createJsonSerializerModifier
());
//keyFormatter, compact));
converter
.
getObjectMapper
().
registerModule
(
jsonModule
);
converter
.
getObjectMapper
().
configure
(
SerializationFeature
.
WRAP_ROOT_VALUE
,
true
);
converter
.
getObjectMapper
().
configure
(
DeserializationFeature
.
UNWRAP_ROOT_VALUE
,
true
);
converter
.
getObjectMapper
().
addMixIn
(
Applications
.
class
,
ApplicationsJsonMixIn
.
class
);
converter
.
getObjectMapper
().
addMixIn
(
InstanceInfo
.
class
,
InstanceInfoJsonMixIn
.
class
);
// converter.getObjectMapper().addMixIn(DataCenterInfo.class, DataCenterInfoXmlMixIn.class);
// converter.getObjectMapper().addMixIn(InstanceInfo.PortWrapper.class, PortWrapperXmlMixIn.class);
// converter.getObjectMapper().addMixIn(Application.class, ApplicationXmlMixIn.class);
// converter.getObjectMapper().addMixIn(Applications.class, ApplicationsXmlMixIn.class);
return
converter
;
}
public
static
BeanSerializerModifier
createJsonSerializerModifier
()
{
//final KeyFormatter keyFormatter, final boolean compactMode) {
return
new
BeanSerializerModifier
()
{
@Override
public
JsonSerializer
<?>
modifySerializer
(
SerializationConfig
config
,
BeanDescription
beanDesc
,
JsonSerializer
<?>
serializer
)
{
/*if (beanDesc.getBeanClass().isAssignableFrom(Applications.class)) {
return new ApplicationsJsonBeanSerializer((BeanSerializerBase) serializer, keyFormatter);
}*/
if
(
beanDesc
.
getBeanClass
().
isAssignableFrom
(
InstanceInfo
.
class
))
{
return
new
InstanceInfoJsonBeanSerializer
((
BeanSerializerBase
)
serializer
,
false
);
}
return
serializer
;
}
};
}
@Override
public
void
shutdown
()
{
}
...
...
spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/EurekaServerMockApplication.java
View file @
7cff8ddb
...
...
@@ -35,6 +35,10 @@ import com.netflix.appinfo.InstanceInfo;
import
com.netflix.discovery.shared.Application
;
import
com.netflix.discovery.shared.Applications
;
import
static
com
.
netflix
.
appinfo
.
InstanceInfo
.
DEFAULT_PORT
;
import
static
com
.
netflix
.
appinfo
.
InstanceInfo
.
DEFAULT_SECURE_PORT
;
import
static
org
.
springframework
.
util
.
Assert
.
isTrue
;
/**
* Mocked Eureka Server
*
...
...
@@ -62,6 +66,10 @@ public class EurekaServerMockApplication {
@PostMapping
(
"/apps/{appName}"
)
public
void
register
(
@PathVariable
String
appName
,
@RequestBody
InstanceInfo
instanceInfo
)
{
isTrue
(
instanceInfo
.
getPort
()
!=
DEFAULT_PORT
&&
instanceInfo
.
getPort
()
!=
0
,
"Port not received from client"
);
isTrue
(
instanceInfo
.
getSecurePort
()
!=
DEFAULT_SECURE_PORT
&&
instanceInfo
.
getSecurePort
()
!=
0
,
"Secure Port not received from client"
);
// Nothing to do
}
...
...
spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/RestTemplateEurekaHttpClientTest.java
View file @
7cff8ddb
...
...
@@ -67,6 +67,7 @@ public class RestTemplateEurekaHttpClientTest {
config
.
setVirtualHostName
(
appname
);
config
.
setSecureVirtualHostName
(
appname
);
config
.
setNonSecurePort
(
4444
);
config
.
setSecurePort
(
8443
);
config
.
setInstanceId
(
"127.0.0.1:customapp:4444"
);
info
=
new
EurekaConfigBasedInstanceInfoProvider
(
config
).
get
();
...
...
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