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
5d6590da
Unverified
Commit
5d6590da
authored
May 23, 2016
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Angel eureka clients can use brixton eureka servers.
Updates so CloudJacksonJson extension is properly recognized by Eureka Server as LegacyJacksonJson. see gh-978 fixes gh-1111
parent
9e479481
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
14 deletions
+34
-14
CloudJacksonJson.java
...amework/cloud/netflix/eureka/server/CloudJacksonJson.java
+26
-12
EurekaServerConfiguration.java
...loud/netflix/eureka/server/EurekaServerConfiguration.java
+8
-2
No files found.
spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/CloudJacksonJson.java
View file @
5d6590da
...
@@ -11,7 +11,9 @@ import org.springframework.util.StringUtils;
...
@@ -11,7 +11,9 @@ import org.springframework.util.StringUtils;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
com.fasterxml.jackson.core.JsonGenerator
;
import
com.fasterxml.jackson.core.JsonGenerator
;
import
com.fasterxml.jackson.core.JsonParser
;
import
com.fasterxml.jackson.core.Version
;
import
com.fasterxml.jackson.core.Version
;
import
com.fasterxml.jackson.databind.DeserializationContext
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.ObjectReader
;
import
com.fasterxml.jackson.databind.ObjectReader
;
import
com.fasterxml.jackson.databind.ObjectWriter
;
import
com.fasterxml.jackson.databind.ObjectWriter
;
...
@@ -36,9 +38,13 @@ public class CloudJacksonJson extends LegacyJacksonJson {
...
@@ -36,9 +38,13 @@ public class CloudJacksonJson extends LegacyJacksonJson {
protected
final
CloudJacksonCodec
codec
=
new
CloudJacksonCodec
();
protected
final
CloudJacksonCodec
codec
=
new
CloudJacksonCodec
();
public
CloudJacksonCodec
getCodec
()
{
return
codec
;
}
@Override
@Override
public
String
codecName
()
{
public
String
codecName
()
{
return
getCodecName
(
this
.
getClass
()
);
return
getCodecName
(
LegacyJacksonJson
.
class
);
}
}
@Override
@Override
...
@@ -120,31 +126,39 @@ public class CloudJacksonJson extends LegacyJacksonJson {
...
@@ -120,31 +126,39 @@ public class CloudJacksonJson extends LegacyJacksonJson {
static
class
CloudInstanceInfoSerializer
extends
InstanceInfoSerializer
{
static
class
CloudInstanceInfoSerializer
extends
InstanceInfoSerializer
{
@Override
@Override
public
void
serialize
(
InstanceInfo
info
,
JsonGenerator
jgen
,
public
void
serialize
(
final
InstanceInfo
info
,
JsonGenerator
jgen
,
SerializerProvider
provider
)
throws
IOException
{
SerializerProvider
provider
)
throws
IOException
{
if
(
info
.
getInstanceId
()
==
null
&&
info
.
getMetadata
()
!=
null
)
{
InstanceInfo
updated
=
updateIfNeeded
(
info
);
String
instanceId
=
calculateInstanceId
(
info
);
super
.
serialize
(
updated
,
jgen
,
provider
);
info
=
new
InstanceInfo
.
Builder
(
info
).
setInstanceId
(
instanceId
).
build
();
}
}
super
.
serialize
(
info
,
jgen
,
provider
);
}
}
private
String
calculateInstanceId
(
InstanceInfo
info
)
{
static
InstanceInfo
updateIfNeeded
(
final
InstanceInfo
info
)
{
if
(
info
.
getInstanceId
()
==
null
&&
info
.
getMetadata
()
!=
null
)
{
String
instanceId
=
info
.
getMetadata
().
get
(
"instanceId"
);
String
instanceId
=
info
.
getMetadata
().
get
(
"instanceId"
);
String
hostName
=
info
.
getHostName
();
if
(
StringUtils
.
hasText
(
instanceId
))
{
if
(
instanceId
!=
null
&&
StringUtils
.
hasText
(
hostName
)
&&
!
instanceId
.
startsWith
(
hostName
))
{
// backwards compatibility for Angel
instanceId
=
hostName
+
":"
+
instanceId
;
if
(
StringUtils
.
hasText
(
info
.
getHostName
())
&&
!
instanceId
.
startsWith
(
info
.
getHostName
()))
{
instanceId
=
info
.
getHostName
()+
":"
+
instanceId
;
}
}
return
instanceId
==
null
?
hostName
:
instanceId
;
return
new
InstanceInfo
.
Builder
(
info
).
setInstanceId
(
instanceId
).
build
()
;
}
}
}
}
return
info
;
}
static
class
CloudInstanceInfoDeserializer
extends
InstanceInfoDeserializer
{
static
class
CloudInstanceInfoDeserializer
extends
InstanceInfoDeserializer
{
protected
CloudInstanceInfoDeserializer
(
ObjectMapper
mapper
)
{
protected
CloudInstanceInfoDeserializer
(
ObjectMapper
mapper
)
{
super
(
mapper
);
super
(
mapper
);
}
}
@Override
public
InstanceInfo
deserialize
(
JsonParser
jp
,
DeserializationContext
context
)
throws
IOException
{
InstanceInfo
info
=
super
.
deserialize
(
jp
,
context
);
InstanceInfo
updated
=
updateIfNeeded
(
info
);
return
updated
;
}
}
}
}
}
spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaServerConfiguration.java
View file @
5d6590da
...
@@ -52,6 +52,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
...
@@ -52,6 +52,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
import
com.netflix.appinfo.ApplicationInfoManager
;
import
com.netflix.appinfo.ApplicationInfoManager
;
import
com.netflix.discovery.EurekaClient
;
import
com.netflix.discovery.EurekaClient
;
import
com.netflix.discovery.EurekaClientConfig
;
import
com.netflix.discovery.EurekaClientConfig
;
import
com.netflix.discovery.converters.EurekaJacksonCodec
;
import
com.netflix.discovery.converters.wrappers.CodecWrapper
;
import
com.netflix.discovery.converters.wrappers.CodecWrapper
;
import
com.netflix.discovery.converters.wrappers.CodecWrappers
;
import
com.netflix.discovery.converters.wrappers.CodecWrappers
;
import
com.netflix.eureka.DefaultEurekaServerContext
;
import
com.netflix.eureka.DefaultEurekaServerContext
;
...
@@ -102,6 +103,7 @@ public class EurekaServerConfiguration extends WebMvcConfigurerAdapter {
...
@@ -102,6 +103,7 @@ public class EurekaServerConfiguration extends WebMvcConfigurerAdapter {
@Value
(
"${eureka.server.defaultOpenForTrafficCount:1}"
)
@Value
(
"${eureka.server.defaultOpenForTrafficCount:1}"
)
private
int
defaultOpenForTrafficCount
;
private
int
defaultOpenForTrafficCount
;
public
static
final
CloudJacksonJson
JACKSON_JSON
=
new
CloudJacksonJson
();
@Bean
@Bean
public
HasFeatures
eurekaServerFeature
()
{
public
HasFeatures
eurekaServerFeature
()
{
...
@@ -128,15 +130,19 @@ public class EurekaServerConfiguration extends WebMvcConfigurerAdapter {
...
@@ -128,15 +130,19 @@ public class EurekaServerConfiguration extends WebMvcConfigurerAdapter {
return
new
EurekaController
(
this
.
applicationInfoManager
);
return
new
EurekaController
(
this
.
applicationInfoManager
);
}
}
static
{
CodecWrappers
.
registerWrapper
(
JACKSON_JSON
);
EurekaJacksonCodec
.
setInstance
(
JACKSON_JSON
.
getCodec
());
}
@Bean
@Bean
public
ServerCodecs
serverCodecs
()
{
public
ServerCodecs
serverCodecs
()
{
CodecWrappers
.
registerWrapper
(
new
CloudJacksonJson
());
return
new
CloudServerCodecs
(
this
.
eurekaServerConfig
);
return
new
CloudServerCodecs
(
this
.
eurekaServerConfig
);
}
}
private
static
CodecWrapper
getFullJson
(
EurekaServerConfig
serverConfig
)
{
private
static
CodecWrapper
getFullJson
(
EurekaServerConfig
serverConfig
)
{
CodecWrapper
codec
=
CodecWrappers
.
getCodec
(
serverConfig
.
getJsonCodecName
());
CodecWrapper
codec
=
CodecWrappers
.
getCodec
(
serverConfig
.
getJsonCodecName
());
return
codec
==
null
?
CodecWrappers
.
getCodec
(
CloudJacksonJson
.
class
)
:
codec
;
return
codec
==
null
?
CodecWrappers
.
getCodec
(
JACKSON_JSON
.
codecName
()
)
:
codec
;
}
}
private
static
CodecWrapper
getFullXml
(
EurekaServerConfig
serverConfig
)
{
private
static
CodecWrapper
getFullXml
(
EurekaServerConfig
serverConfig
)
{
...
...
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