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
e096fd8e
Commit
e096fd8e
authored
Feb 25, 2015
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move RibbonInterceptor into commons
It didn't depend on Ribbon at all so it can live in the commons project.
parent
e6f30ebf
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
5 additions
and
96 deletions
+5
-96
RibbonAutoConfiguration.java
...amework/cloud/netflix/ribbon/RibbonAutoConfiguration.java
+3
-16
RibbonInterceptor.java
...ringframework/cloud/netflix/ribbon/RibbonInterceptor.java
+0
-79
RibbonInterceptorTests.java
...ramework/cloud/netflix/ribbon/RibbonInterceptorTests.java
+2
-1
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonAutoConfiguration.java
View file @
e096fd8e
...
...
@@ -21,13 +21,14 @@ import java.util.List;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
import
org.springframework.boot.autoconfigure.AutoConfigureBefore
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancerAutoConfiguration
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancerClient
;
import
org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.http.client.ClientHttpRequestInterceptor
;
import
org.springframework.web.client.RestTemplate
;
import
com.netflix.client.IClient
;
...
...
@@ -42,6 +43,7 @@ import com.netflix.client.IClient;
@ConditionalOnClass
({
IClient
.
class
,
RestTemplate
.
class
})
@RibbonClients
@AutoConfigureAfter
(
EurekaClientAutoConfiguration
.
class
)
@AutoConfigureBefore
(
LoadBalancerAutoConfiguration
.
class
)
public
class
RibbonAutoConfiguration
{
@Autowired
(
required
=
false
)
...
...
@@ -55,24 +57,9 @@ public class RibbonAutoConfiguration {
}
@Bean
@ConditionalOnMissingBean
(
RestTemplate
.
class
)
public
RestTemplate
restTemplate
(
RibbonInterceptor
ribbonInterceptor
)
{
RestTemplate
restTemplate
=
new
RestTemplate
();
List
<
ClientHttpRequestInterceptor
>
list
=
new
ArrayList
<>();
list
.
add
(
ribbonInterceptor
);
restTemplate
.
setInterceptors
(
list
);
return
restTemplate
;
}
@Bean
@ConditionalOnMissingBean
(
LoadBalancerClient
.
class
)
public
LoadBalancerClient
loadBalancerClient
()
{
return
new
RibbonLoadBalancerClient
(
springClientFactory
());
}
@Bean
public
RibbonInterceptor
ribbonInterceptor
(
LoadBalancerClient
loadBalancerClient
)
{
return
new
RibbonInterceptor
(
loadBalancerClient
);
}
}
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonInterceptor.java
deleted
100644 → 0
View file @
e6f30ebf
/*
* Copyright 2013-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
cloud
.
netflix
.
ribbon
;
import
java.io.IOException
;
import
java.net.URI
;
import
org.springframework.cloud.client.ServiceInstance
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancerClient
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancerRequest
;
import
org.springframework.http.HttpRequest
;
import
org.springframework.http.client.ClientHttpRequestExecution
;
import
org.springframework.http.client.ClientHttpRequestInterceptor
;
import
org.springframework.http.client.ClientHttpResponse
;
import
org.springframework.http.client.support.HttpRequestWrapper
;
/**
* @author Spencer Gibb
*/
public
class
RibbonInterceptor
implements
ClientHttpRequestInterceptor
{
private
LoadBalancerClient
loadBalancer
;
public
RibbonInterceptor
(
LoadBalancerClient
loadBalancer
)
{
this
.
loadBalancer
=
loadBalancer
;
}
@Override
public
ClientHttpResponse
intercept
(
final
HttpRequest
request
,
final
byte
[]
body
,
final
ClientHttpRequestExecution
execution
)
throws
IOException
{
final
URI
originalUri
=
request
.
getURI
();
String
serviceName
=
originalUri
.
getHost
();
return
this
.
loadBalancer
.
execute
(
serviceName
,
new
LoadBalancerRequest
<
ClientHttpResponse
>()
{
@Override
public
ClientHttpResponse
apply
(
final
ServiceInstance
instance
)
throws
Exception
{
HttpRequest
serviceRequest
=
new
ServiceRequestWrapper
(
request
,
instance
);
return
execution
.
execute
(
serviceRequest
,
body
);
}
});
}
private
class
ServiceRequestWrapper
extends
HttpRequestWrapper
{
private
final
ServiceInstance
instance
;
public
ServiceRequestWrapper
(
HttpRequest
request
,
ServiceInstance
instance
)
{
super
(
request
);
this
.
instance
=
instance
;
}
@Override
public
URI
getURI
()
{
URI
uri
=
RibbonInterceptor
.
this
.
loadBalancer
.
reconstructURI
(
this
.
instance
,
getRequest
().
getURI
());
return
uri
;
}
}
}
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/ribbon/RibbonInterceptorTests.java
View file @
e096fd8e
...
...
@@ -26,6 +26,7 @@ import org.mockito.Mock;
import
org.mockito.MockitoAnnotations
;
import
org.springframework.cloud.client.ServiceInstance
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancerClient
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancerInterceptor
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancerRequest
;
import
org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.RibbonServer
;
import
org.springframework.http.HttpRequest
;
...
...
@@ -65,7 +66,7 @@ public class RibbonInterceptorTests {
@Test
public
void
testIntercept
()
throws
Exception
{
RibbonServer
server
=
new
RibbonServer
(
"myservice"
,
new
Server
(
"myhost"
,
8080
));
RibbonInterceptor
interceptor
=
new
Ribbon
Interceptor
(
new
MyClient
(
server
));
LoadBalancerInterceptor
interceptor
=
new
LoadBalancer
Interceptor
(
new
MyClient
(
server
));
given
(
this
.
request
.
getURI
()).
willReturn
(
new
URL
(
"http://myservice"
).
toURI
());
given
(
this
.
execution
.
execute
(
isA
(
HttpRequest
.
class
),
isA
(
byte
[].
class
)))
.
willReturn
(
this
.
response
);
...
...
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