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
a3ab3259
Unverified
Commit
a3ab3259
authored
Apr 07, 2016
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make RibbonClientHttpRequestFactory disabled by default.
fixes gh-961
parent
e87d9432
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
22 deletions
+29
-22
RibbonAutoConfiguration.java
...amework/cloud/netflix/ribbon/RibbonAutoConfiguration.java
+4
-3
RibbonLoadBalancerClient.java
...mework/cloud/netflix/ribbon/RibbonLoadBalancerClient.java
+3
-0
MetricsRestTemplateTests.java
...ework/cloud/netflix/metrics/MetricsRestTemplateTests.java
+5
-3
RibbonClientHttpRequestFactoryTests.java
...d/netflix/ribbon/RibbonClientHttpRequestFactoryTests.java
+17
-16
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonAutoConfiguration.java
View file @
a3ab3259
...
...
@@ -73,7 +73,7 @@ public class RibbonAutoConfiguration {
@Configuration
@ConditionalOnClass
(
HttpRequest
.
class
)
@ConditionalOnProperty
(
value
=
"ribbon.http.client.enabled"
,
matchIfMissing
=
tru
e
)
@ConditionalOnProperty
(
value
=
"ribbon.http.client.enabled"
,
matchIfMissing
=
fals
e
)
protected
static
class
RibbonClientConfig
{
@Autowired
...
...
@@ -83,11 +83,12 @@ public class RibbonAutoConfiguration {
private
LoadBalancerClient
loadBalancerClient
;
@Bean
public
RestTemplateCustomizer
restTemplateCustomizer
()
{
public
RestTemplateCustomizer
restTemplateCustomizer
(
final
RibbonClientHttpRequestFactory
ribbonClientHttpRequestFactory
)
{
return
new
RestTemplateCustomizer
()
{
@Override
public
void
customize
(
RestTemplate
restTemplate
)
{
restTemplate
.
setRequestFactory
(
ribbonClientHttpRequestFactory
()
);
restTemplate
.
setRequestFactory
(
ribbonClientHttpRequestFactory
);
}
};
}
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonLoadBalancerClient.java
View file @
a3ab3259
...
...
@@ -74,6 +74,9 @@ public class RibbonLoadBalancerClient implements LoadBalancerClient {
public
<
T
>
T
execute
(
String
serviceId
,
LoadBalancerRequest
<
T
>
request
)
{
ILoadBalancer
loadBalancer
=
getLoadBalancer
(
serviceId
);
Server
server
=
getServer
(
loadBalancer
);
if
(
server
==
null
)
{
throw
new
IllegalStateException
(
"No instances available for "
+
serviceId
);
}
RibbonServer
ribbonServer
=
new
RibbonServer
(
serviceId
,
server
,
isSecure
(
server
,
serviceId
),
serverIntrospector
(
serviceId
).
getMetadata
(
server
));
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/metrics/MetricsRestTemplateTests.java
View file @
a3ab3259
...
...
@@ -42,7 +42,7 @@ import static org.junit.Assert.assertThat;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
classes
=
MetricsRestTemplateTests
.
App
.
class
)
@WebIntegrationTest
(
value
=
{
"spring.application.name=ribbonclienttest"
,
"spring.jmx.enabled=true"
},
randomPort
=
true
)
"spring.jmx.enabled=true"
,
"ribbon.http.client.enabled=true"
},
randomPort
=
true
)
@DirtiesContext
public
class
MetricsRestTemplateTests
extends
RibbonClientHttpRequestFactoryTests
{
...
...
@@ -51,12 +51,14 @@ public class MetricsRestTemplateTests extends RibbonClientHttpRequestFactoryTest
public
void
requestFactoryIsRibbon
()
{
ClientHttpRequestFactory
requestFactory
=
this
.
restTemplate
.
getRequestFactory
();
assertThat
(
"wrong RequestFactory type: "
+
requestFactory
.
getClass
(),
requestFactory
,
is
(
instanceOf
(
InterceptingClientHttpRequestFactory
.
class
)));
requestFactory
,
is
(
instanceOf
(
InterceptingClientHttpRequestFactory
.
class
)));
InterceptingClientHttpRequestFactory
intercepting
=
(
InterceptingClientHttpRequestFactory
)
requestFactory
;
Object
interceptorsField
=
ReflectionTestUtils
.
getField
(
intercepting
,
"interceptors"
);
assertThat
(
"wrong interceptors type: "
+
interceptorsField
.
getClass
(),
interceptorsField
,
is
(
instanceOf
(
List
.
class
)));
assertThat
(
"wrong interceptors type: "
+
interceptorsField
.
getClass
(),
interceptorsField
,
is
(
instanceOf
(
List
.
class
)));
@SuppressWarnings
(
"unchecked"
)
List
<
ClientHttpRequestInterceptor
>
interceptors
=
(
List
<
ClientHttpRequestInterceptor
>)
interceptorsField
;
assertThat
(
"interceptors is wrong size"
,
interceptors
,
hasSize
(
1
));
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/ribbon/RibbonClientHttpRequestFactoryTests.java
View file @
a3ab3259
...
...
@@ -49,18 +49,19 @@ import org.springframework.web.client.RestTemplate;
import
com.netflix.loadbalancer.Server
;
import
com.netflix.loadbalancer.ServerList
;
import
lombok.SneakyThrows
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
lombok.SneakyThrows
;
/**
* @author Spencer Gibb
*/
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
classes
=
RibbonClientHttpRequestFactoryTests
.
App
.
class
)
@WebIntegrationTest
(
value
=
{
"spring.application.name=ribbonclienttest"
,
"spring.jmx.enabled=true"
,
"spring.cloud.netflix.metrics.enabled=false"
},
randomPort
=
true
)
"spring.jmx.enabled=true"
,
"spring.cloud.netflix.metrics.enabled=false"
,
"ribbon.http.client.enabled=true"
},
randomPort
=
true
)
@DirtiesContext
public
class
RibbonClientHttpRequestFactoryTests
{
...
...
@@ -73,23 +74,23 @@ public class RibbonClientHttpRequestFactoryTests {
@Test
public
void
requestFactoryIsRibbon
()
{
ClientHttpRequestFactory
requestFactory
=
this
.
restTemplate
.
getRequestFactory
();
assertTrue
(
"wrong RequestFactory type: "
+
requestFactory
.
getClass
(),
requestFactory
instanceof
RibbonClientHttpRequestFactory
);
ClientHttpRequestFactory
requestFactory
=
this
.
restTemplate
.
getRequestFactory
();
assertTrue
(
"wrong RequestFactory type: "
+
requestFactory
.
getClass
(),
requestFactory
instanceof
RibbonClientHttpRequestFactory
);
}
@Test
public
void
vanillaRequestWorks
()
{
ResponseEntity
<
String
>
response
=
this
.
restTemplate
.
getForEntity
(
"http://simple/"
,
String
.
class
);
ResponseEntity
<
String
>
response
=
this
.
restTemplate
.
getForEntity
(
"http://simple/"
,
String
.
class
);
assertEquals
(
"wrong response code"
,
HttpStatus
.
OK
,
response
.
getStatusCode
());
assertEquals
(
"wrong response body"
,
"hello"
,
response
.
getBody
());
}
@Test
public
void
requestWithPathParamWorks
()
{
ResponseEntity
<
String
>
response
=
this
.
restTemplate
.
getForEntity
(
"http://simple/path/{param}"
,
String
.
class
,
"world"
);
ResponseEntity
<
String
>
response
=
this
.
restTemplate
.
getForEntity
(
"http://simple/path/{param}"
,
String
.
class
,
"world"
);
assertEquals
(
"wrong response code"
,
HttpStatus
.
OK
,
response
.
getStatusCode
());
assertEquals
(
"wrong response body"
,
"hello world"
,
response
.
getBody
());
}
...
...
@@ -113,16 +114,16 @@ public class RibbonClientHttpRequestFactoryTests {
@Test
public
void
requestWithPostWorks
()
{
ResponseEntity
<
String
>
response
=
this
.
restTemplate
.
postForEntity
(
"http://simple/post"
,
"world"
,
String
.
class
);
ResponseEntity
<
String
>
response
=
this
.
restTemplate
.
postForEntity
(
"http://simple/post"
,
"world"
,
String
.
class
);
assertEquals
(
"wrong response code"
,
HttpStatus
.
OK
,
response
.
getStatusCode
());
assertEquals
(
"wrong response body"
,
"hello world"
,
response
.
getBody
());
}
@Test
public
void
requestWithEmptyPostWorks
()
{
ResponseEntity
<
String
>
response
=
this
.
restTemplate
.
postForEntity
(
"http://simple/emptypost"
,
""
,
String
.
class
);
ResponseEntity
<
String
>
response
=
this
.
restTemplate
.
postForEntity
(
"http://simple/emptypost"
,
""
,
String
.
class
);
assertEquals
(
"wrong response code"
,
HttpStatus
.
OK
,
response
.
getStatusCode
());
assertEquals
(
"wrong response body"
,
"hello empty"
,
response
.
getBody
());
}
...
...
@@ -132,8 +133,8 @@ public class RibbonClientHttpRequestFactoryTests {
public
void
requestWithHeaderWorks
()
{
RequestEntity
<
Void
>
entity
=
RequestEntity
.
get
(
new
URI
(
"http://simple/header"
))
.
header
(
"X-Param"
,
"world"
).
build
();
ResponseEntity
<
String
>
response
=
this
.
restTemplate
.
exchange
(
entity
,
String
.
class
);
ResponseEntity
<
String
>
response
=
this
.
restTemplate
.
exchange
(
entity
,
String
.
class
);
assertEquals
(
"wrong response code"
,
HttpStatus
.
OK
,
response
.
getStatusCode
());
assertEquals
(
"wrong response body"
,
"hello world"
,
response
.
getBody
());
}
...
...
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