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
c9dc8f51
Commit
c9dc8f51
authored
Oct 14, 2014
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use boots HttpMessageConverters class rather than copied list of converters
parent
e52949e5
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
120 deletions
+39
-120
FeignBase.java
...va/org/springframework/cloud/netflix/feign/FeignBase.java
+0
-103
FeignUtils.java
...a/org/springframework/cloud/netflix/feign/FeignUtils.java
+20
-0
SpringDecoder.java
...rg/springframework/cloud/netflix/feign/SpringDecoder.java
+10
-10
SpringEncoder.java
...rg/springframework/cloud/netflix/feign/SpringEncoder.java
+9
-7
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/FeignBase.java
deleted
100644 → 0
View file @
e52949e5
package
org
.
springframework
.
cloud
.
netflix
.
feign
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Map
;
import
javax.xml.transform.Source
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.converter.ByteArrayHttpMessageConverter
;
import
org.springframework.http.converter.HttpMessageConverter
;
import
org.springframework.http.converter.ResourceHttpMessageConverter
;
import
org.springframework.http.converter.StringHttpMessageConverter
;
import
org.springframework.http.converter.feed.AtomFeedHttpMessageConverter
;
import
org.springframework.http.converter.feed.RssChannelHttpMessageConverter
;
import
org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
;
import
org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter
;
import
org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter
;
import
org.springframework.http.converter.xml.SourceHttpMessageConverter
;
import
org.springframework.util.Assert
;
import
org.springframework.util.ClassUtils
;
/**
* @author Spencer Gibb
*/
public
class
FeignBase
{
public
static
final
boolean
romePresent
=
ClassUtils
.
isPresent
(
"com.sun.syndication.feed.WireFeed"
,
FeignBase
.
class
.
getClassLoader
());
public
static
final
boolean
jaxb2Present
=
ClassUtils
.
isPresent
(
"javax.xml.bind.Binder"
,
FeignBase
.
class
.
getClassLoader
());
public
static
final
boolean
jackson2Present
=
ClassUtils
.
isPresent
(
"com.fasterxml.jackson.databind.ObjectMapper"
,
FeignBase
.
class
.
getClassLoader
())
&&
ClassUtils
.
isPresent
(
"com.fasterxml.jackson.core.JsonGenerator"
,
FeignBase
.
class
.
getClassLoader
());
public
static
final
boolean
jacksonPresent
=
ClassUtils
.
isPresent
(
"org.codehaus.jackson.map.ObjectMapper"
,
FeignBase
.
class
.
getClassLoader
())
&&
ClassUtils
.
isPresent
(
"org.codehaus.jackson.JsonGenerator"
,
FeignBase
.
class
.
getClassLoader
());
protected
final
List
<
HttpMessageConverter
<?>>
messageConverters
=
new
ArrayList
<
HttpMessageConverter
<?>>();
public
FeignBase
()
{
addDefaultConverters
(
messageConverters
);
}
/**
* Create a new instance of the {@link SpringDecoder} using the given list of
* {@link HttpMessageConverter} to use
* @param messageConverters the list of {@link HttpMessageConverter} to use
*/
public
FeignBase
(
List
<
HttpMessageConverter
<?>>
messageConverters
)
{
Assert
.
notEmpty
(
messageConverters
,
"'messageConverters' must not be empty"
);
this
.
messageConverters
.
addAll
(
messageConverters
);
}
@SuppressWarnings
(
"deprecation"
)
protected
void
addDefaultConverters
(
List
<
HttpMessageConverter
<?>>
messageConverters
)
{
messageConverters
.
add
(
new
ByteArrayHttpMessageConverter
());
messageConverters
.
add
(
new
StringHttpMessageConverter
());
messageConverters
.
add
(
new
ResourceHttpMessageConverter
());
messageConverters
.
add
(
new
SourceHttpMessageConverter
<
Source
>());
messageConverters
.
add
(
new
AllEncompassingFormHttpMessageConverter
());
if
(
romePresent
)
{
messageConverters
.
add
(
new
AtomFeedHttpMessageConverter
());
messageConverters
.
add
(
new
RssChannelHttpMessageConverter
());
}
if
(
jaxb2Present
)
{
messageConverters
.
add
(
new
Jaxb2RootElementHttpMessageConverter
());
}
if
(
jackson2Present
)
{
messageConverters
.
add
(
new
MappingJackson2HttpMessageConverter
());
}
else
if
(
jacksonPresent
)
{
messageConverters
.
add
(
new
org
.
springframework
.
http
.
converter
.
json
.
MappingJacksonHttpMessageConverter
());
}
}
/**
* Set the message body converters to use.
* <p>These converters are used to convert from and to HTTP requests and responses.
*/
public
void
setMessageConverters
(
List
<
HttpMessageConverter
<?>>
messageConverters
)
{
Assert
.
notEmpty
(
messageConverters
,
"'messageConverters' must not be empty"
);
this
.
messageConverters
.
clear
();
this
.
messageConverters
.
addAll
(
messageConverters
);
}
public
List
<
HttpMessageConverter
<?>>
getMessageConverters
()
{
return
messageConverters
;
}
protected
HttpHeaders
getHttpHeaders
(
Map
<
String
,
Collection
<
String
>>
headers
)
{
HttpHeaders
httpHeaders
=
new
HttpHeaders
();
for
(
Map
.
Entry
<
String
,
Collection
<
String
>>
entry
:
headers
.
entrySet
())
{
httpHeaders
.
put
(
entry
.
getKey
(),
new
ArrayList
<>(
entry
.
getValue
()));
}
return
httpHeaders
;
}
}
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/FeignUtils.java
0 → 100644
View file @
c9dc8f51
package
org
.
springframework
.
cloud
.
netflix
.
feign
;
import
org.springframework.http.HttpHeaders
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Map
;
/**
* @author Spencer Gibb
*/
public
class
FeignUtils
{
static
HttpHeaders
getHttpHeaders
(
Map
<
String
,
Collection
<
String
>>
headers
)
{
HttpHeaders
httpHeaders
=
new
HttpHeaders
();
for
(
Map
.
Entry
<
String
,
Collection
<
String
>>
entry
:
headers
.
entrySet
())
{
httpHeaders
.
put
(
entry
.
getKey
(),
new
ArrayList
<>(
entry
.
getValue
()));
}
return
httpHeaders
;
}
}
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/SpringDecoder.java
View file @
c9dc8f51
...
...
@@ -3,12 +3,12 @@ package org.springframework.cloud.netflix.feign;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.lang.reflect.Type
;
import
java.util.List
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.web.HttpMessageConverters
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.client.ClientHttpResponse
;
import
org.springframework.http.converter.HttpMessageConverter
;
import
org.springframework.web.client.HttpMessageConverterExtractor
;
import
feign.FeignException
;
...
...
@@ -16,25 +16,25 @@ import feign.Response;
import
feign.codec.DecodeException
;
import
feign.codec.Decoder
;
import
static
org
.
springframework
.
cloud
.
netflix
.
feign
.
FeignUtils
.
getHttpHeaders
;
/**
* @author Spencer Gibb
*/
public
class
SpringDecoder
extends
FeignBase
implements
Decoder
{
public
class
SpringDecoder
implements
Decoder
{
public
SpringDecoder
()
{
}
@Autowired
HttpMessageConverters
messageConverters
;
public
SpringDecoder
(
List
<
HttpMessageConverter
<?>>
messageConverters
)
{
super
(
messageConverters
);
public
SpringDecoder
()
{
}
@Override
public
Object
decode
(
final
Response
response
,
Type
type
)
throws
IOException
,
DecodeException
,
FeignException
{
public
Object
decode
(
final
Response
response
,
Type
type
)
throws
IOException
,
FeignException
{
if
(
type
instanceof
Class
)
{
@SuppressWarnings
({
"unchecked"
,
"rawtypes"
})
HttpMessageConverterExtractor
<?>
extractor
=
new
HttpMessageConverterExtractor
(
(
Class
<?>)
type
,
getMessage
Converters
());
(
Class
<?>)
type
,
messageConverters
.
get
Converters
());
Object
data
=
extractor
.
extractData
(
new
FeignResponseAdapter
(
response
));
return
data
;
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/SpringEncoder.java
View file @
c9dc8f51
...
...
@@ -8,6 +8,8 @@ import feign.codec.Encoder;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.web.HttpMessageConverters
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpOutputMessage
;
import
org.springframework.http.MediaType
;
...
...
@@ -17,19 +19,19 @@ import java.io.ByteArrayOutputStream;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.util.Collection
;
import
java.util.List
;
import
static
org
.
springframework
.
cloud
.
netflix
.
feign
.
FeignUtils
.
getHttpHeaders
;
/**
* @author Spencer Gibb
*/
public
class
SpringEncoder
extends
FeignBase
implements
Encoder
{
public
class
SpringEncoder
implements
Encoder
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
SpringEncoder
.
class
);
public
SpringEncoder
()
{
}
@Autowired
HttpMessageConverters
messageConverters
;
public
SpringEncoder
(
List
<
HttpMessageConverter
<?>>
messageConverters
)
{
super
(
messageConverters
);
public
SpringEncoder
()
{
}
@Override
...
...
@@ -46,7 +48,7 @@ public class SpringEncoder extends FeignBase implements Encoder {
requestContentType
=
MediaType
.
valueOf
(
type
);
}
for
(
HttpMessageConverter
<?>
messageConverter
:
getMessage
Converters
())
{
for
(
HttpMessageConverter
<?>
messageConverter
:
messageConverters
.
get
Converters
())
{
if
(
messageConverter
.
canWrite
(
requestType
,
requestContentType
))
{
if
(
logger
.
isDebugEnabled
())
{
if
(
requestContentType
!=
null
)
{
...
...
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