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
8d259b9d
Commit
8d259b9d
authored
Dec 18, 2015
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #669 from zanella/invalid_hostname
* invalid_hostname: Added check for invalid hostname
parents
4ffeff20
7c7513ee
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
5 deletions
+21
-5
RibbonClientHttpRequestFactory.java
.../cloud/netflix/ribbon/RibbonClientHttpRequestFactory.java
+3
-0
RibbonClientHttpRequestFactoryTests.java
...d/netflix/ribbon/RibbonClientHttpRequestFactoryTests.java
+18
-5
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonClientHttpRequestFactory.java
View file @
8d259b9d
...
...
@@ -48,6 +48,9 @@ public class RibbonClientHttpRequestFactory implements ClientHttpRequestFactory
public
ClientHttpRequest
createRequest
(
URI
originalUri
,
HttpMethod
httpMethod
)
throws
IOException
{
String
serviceId
=
originalUri
.
getHost
();
if
(
serviceId
==
null
)
{
throw
new
IOException
(
"Invalid hostname in the URI ["
+
originalUri
.
toASCIIString
()
+
"]"
);
}
ServiceInstance
instance
=
loadBalancer
.
choose
(
serviceId
);
if
(
instance
==
null
)
{
throw
new
IllegalStateException
(
"No instances available for "
+
serviceId
);
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/ribbon/RibbonClientHttpRequestFactoryTests.java
View file @
8d259b9d
...
...
@@ -16,14 +16,11 @@
package
org
.
springframework
.
cloud
.
netflix
.
ribbon
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
java.net.URI
;
import
lombok.SneakyThrows
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.rules.ExpectedException
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
...
...
@@ -44,11 +41,17 @@ import org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.client.ResourceAccessException
;
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
;
/**
* @author Spencer Gibb
*/
...
...
@@ -59,6 +62,9 @@ import com.netflix.loadbalancer.ServerList;
@DirtiesContext
public
class
RibbonClientHttpRequestFactoryTests
{
@Rule
public
final
ExpectedException
exceptionRule
=
ExpectedException
.
none
();
@Autowired
private
RestTemplate
restTemplate
;
...
...
@@ -123,6 +129,13 @@ public class RibbonClientHttpRequestFactoryTests {
assertEquals
(
"wrong response body"
,
"hello world"
,
response
.
getBody
());
}
@Test
public
void
invalidHostNameError
()
{
exceptionRule
.
expect
(
ResourceAccessException
.
class
);
exceptionRule
.
expectMessage
(
"Invalid hostname"
);
restTemplate
.
getForEntity
(
"http://simple_bad"
,
String
.
class
);
}
@Configuration
@EnableAutoConfiguration
@RestController
...
...
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