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
6877f089
Unverified
Commit
6877f089
authored
Jun 24, 2016
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move RestClientRibbonCommand back to original place.
Made it public and undid other refactorings.
parent
74ac6eae
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
170 additions
and
99 deletions
+170
-99
ZuulProxyConfiguration.java
...gframework/cloud/netflix/zuul/ZuulProxyConfiguration.java
+1
-1
RestClientRibbonCommand.java
...d/netflix/zuul/filters/route/RestClientRibbonCommand.java
+27
-62
RestClientRibbonCommandFactory.java
...ix/zuul/filters/route/RestClientRibbonCommandFactory.java
+54
-0
HttpClientRibbonCommand.java
...ix/zuul/filters/route/apache/HttpClientRibbonCommand.java
+41
-0
HttpClientRibbonCommandFactory.java
.../filters/route/apache/HttpClientRibbonCommandFactory.java
+1
-17
OkHttpRibbonCommand.java
...etflix/zuul/filters/route/okhttp/OkHttpRibbonCommand.java
+41
-0
OkHttpRibbonCommandFactory.java
...zuul/filters/route/okhttp/OkHttpRibbonCommandFactory.java
+1
-17
RestClientRibbonCommandIntegrationTests.java
...e/restclient/RestClientRibbonCommandIntegrationTests.java
+4
-2
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/ZuulProxyConfiguration.java
View file @
6877f089
...
...
@@ -37,7 +37,7 @@ import org.springframework.cloud.netflix.zuul.filters.discovery.ServiceRouteMapp
import
org.springframework.cloud.netflix.zuul.filters.discovery.SimpleServiceRouteMapper
;
import
org.springframework.cloud.netflix.zuul.filters.pre.PreDecorationFilter
;
import
org.springframework.cloud.netflix.zuul.filters.route.okhttp.OkHttpRibbonCommandFactory
;
import
org.springframework.cloud.netflix.zuul.filters.route.
restclient.
RestClientRibbonCommandFactory
;
import
org.springframework.cloud.netflix.zuul.filters.route.RestClientRibbonCommandFactory
;
import
org.springframework.cloud.netflix.zuul.filters.route.RibbonCommandFactory
;
import
org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter
;
import
org.springframework.cloud.netflix.zuul.filters.route.SimpleHostRoutingFilter
;
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/
restclient/RestClientRibbonCommandFactory
.java
→
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/
RestClientRibbonCommand
.java
View file @
6877f089
...
...
@@ -15,88 +15,53 @@
*
*/
package
org
.
springframework
.
cloud
.
netflix
.
zuul
.
filters
.
route
.
restclient
;
package
org
.
springframework
.
cloud
.
netflix
.
zuul
.
filters
.
route
;
import
com.netflix.client.http.HttpRequest
;
import
com.netflix.client.http.HttpResponse
;
import
org.springframework.cloud.netflix.ribbon.SpringClientFactory
;
import
com.netflix.niws.client.http.RestClient
;
import
org.springframework.cloud.netflix.zuul.filters.route.RibbonCommandContext
;
import
org.springframework.cloud.netflix.zuul.filters.route.RibbonCommandFactory
;
import
org.springframework.cloud.netflix.zuul.filters.route.support.AbstractRibbonCommand
;
import
java.util.List
;
/**
* @author Spencer Gibb
* Hystrix wrapper around Eureka Ribbon command
*
* see original
* https://github.com/Netflix/zuul/blob/master/zuul-netflix/src/main/java/com/
* netflix/zuul/dependency/ribbon/hystrix/RibbonCommand.java
*/
public
class
RestClientRibbonCommandFactory
implements
RibbonCommandFactory
<
RestClientRibbonCommandFactory
.
RestClientRibbonCommand
>
{
@SuppressWarnings
(
"deprecation"
)
public
class
RestClientRibbonCommand
extends
AbstractRibbonCommand
<
RestClient
,
HttpRequest
,
HttpResponse
>
{
private
final
SpringClientFactory
clientFactory
;
public
RestClientRibbonCommandFactory
(
SpringClientFactory
clientFactory
)
{
this
.
clientFactory
=
clientFactory
;
public
RestClientRibbonCommand
(
String
commandKey
,
RestClient
client
,
RibbonCommandContext
context
)
{
super
(
commandKey
,
client
,
context
);
}
@Override
@SuppressWarnings
(
"deprecation"
)
public
RestClientRibbonCommand
create
(
RibbonCommandContext
context
)
{
RestClient
restClient
=
this
.
clientFactory
.
getClient
(
context
.
getServiceId
(),
RestClient
.
class
);
return
new
RestClientRibbonCommand
(
context
.
getServiceId
(),
restClient
,
context
);
}
protected
HttpRequest
createRequest
()
throws
Exception
{
HttpRequest
.
Builder
builder
=
HttpRequest
.
newBuilder
()
.
verb
(
RestClientRibbonCommandFactory
.
getVerb
(
this
.
context
.
getMethod
()))
.
uri
(
this
.
context
.
uri
())
.
entity
(
this
.
context
.
getRequestEntity
());
/**
* Hystrix wrapper around Eureka Ribbon command
*
* see original
* https://github.com/Netflix/zuul/blob/master/zuul-netflix/src/main/java/com/
* netflix/zuul/dependency/ribbon/hystrix/RibbonCommand.java
*/
@SuppressWarnings
(
"deprecation"
)
public
static
class
RestClientRibbonCommand
extends
AbstractRibbonCommand
<
RestClient
,
HttpRequest
,
HttpResponse
>
{
public
RestClientRibbonCommand
(
String
commandKey
,
RestClient
client
,
RibbonCommandContext
context
)
{
super
(
commandKey
,
client
,
context
);
if
(
this
.
context
.
getRetryable
()
!=
null
)
{
builder
.
setRetriable
(
this
.
context
.
getRetryable
());
}
@Override
protected
HttpRequest
createRequest
()
throws
Exception
{
HttpRequest
.
Builder
builder
=
HttpRequest
.
newBuilder
()
.
verb
(
getVerb
(
this
.
context
.
getMethod
()))
.
uri
(
this
.
context
.
uri
())
.
entity
(
this
.
context
.
getRequestEntity
());
if
(
this
.
context
.
getRetryable
()
!=
null
)
{
builder
.
setRetriable
(
this
.
context
.
getRetryable
());
for
(
String
name
:
this
.
context
.
getHeaders
().
keySet
())
{
List
<
String
>
values
=
this
.
context
.
getHeaders
().
get
(
name
);
for
(
String
value
:
values
)
{
builder
.
header
(
name
,
value
);
}
for
(
String
name
:
this
.
context
.
getHeaders
().
keySet
())
{
List
<
String
>
values
=
this
.
context
.
getHeaders
().
get
(
name
);
for
(
String
value
:
values
)
{
builder
.
header
(
name
,
value
);
}
}
for
(
String
name
:
this
.
context
.
getParams
().
keySet
())
{
List
<
String
>
values
=
this
.
context
.
getParams
().
get
(
name
);
for
(
String
value
:
values
)
{
builder
.
queryParams
(
name
,
value
);
}
}
for
(
String
name
:
this
.
context
.
getParams
().
keySet
())
{
List
<
String
>
values
=
this
.
context
.
getParams
().
get
(
name
);
for
(
String
value
:
values
)
{
builder
.
queryParams
(
name
,
value
);
}
return
builder
.
build
();
}
}
static
HttpRequest
.
Verb
getVerb
(
String
method
)
{
if
(
method
==
null
)
return
HttpRequest
.
Verb
.
GET
;
try
{
return
HttpRequest
.
Verb
.
valueOf
(
method
.
toUpperCase
());
}
catch
(
IllegalArgumentException
e
)
{
return
HttpRequest
.
Verb
.
GET
;
}
return
builder
.
build
();
}
}
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/RestClientRibbonCommandFactory.java
0 → 100644
View file @
6877f089
/*
* Copyright 2013-2016 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
.
zuul
.
filters
.
route
;
import
com.netflix.client.http.HttpRequest
;
import
org.springframework.cloud.netflix.ribbon.SpringClientFactory
;
import
com.netflix.niws.client.http.RestClient
;
/**
* @author Spencer Gibb
*/
public
class
RestClientRibbonCommandFactory
implements
RibbonCommandFactory
<
RestClientRibbonCommand
>
{
private
final
SpringClientFactory
clientFactory
;
public
RestClientRibbonCommandFactory
(
SpringClientFactory
clientFactory
)
{
this
.
clientFactory
=
clientFactory
;
}
@Override
@SuppressWarnings
(
"deprecation"
)
public
RestClientRibbonCommand
create
(
RibbonCommandContext
context
)
{
RestClient
restClient
=
this
.
clientFactory
.
getClient
(
context
.
getServiceId
(),
RestClient
.
class
);
return
new
RestClientRibbonCommand
(
context
.
getServiceId
(),
restClient
,
context
);
}
static
HttpRequest
.
Verb
getVerb
(
String
method
)
{
if
(
method
==
null
)
return
HttpRequest
.
Verb
.
GET
;
try
{
return
HttpRequest
.
Verb
.
valueOf
(
method
.
toUpperCase
());
}
catch
(
IllegalArgumentException
e
)
{
return
HttpRequest
.
Verb
.
GET
;
}
}
}
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/apache/HttpClientRibbonCommand.java
0 → 100644
View file @
6877f089
/*
* Copyright 2013-2016 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
.
zuul
.
filters
.
route
.
apache
;
import
org.springframework.cloud.netflix.ribbon.apache.RibbonApacheHttpRequest
;
import
org.springframework.cloud.netflix.ribbon.apache.RibbonApacheHttpResponse
;
import
org.springframework.cloud.netflix.ribbon.apache.RibbonLoadBalancingHttpClient
;
import
org.springframework.cloud.netflix.zuul.filters.route.RibbonCommandContext
;
import
org.springframework.cloud.netflix.zuul.filters.route.support.AbstractRibbonCommand
;
/**
* @author Spencer Gibb
*/
public
class
HttpClientRibbonCommand
extends
AbstractRibbonCommand
<
RibbonLoadBalancingHttpClient
,
RibbonApacheHttpRequest
,
RibbonApacheHttpResponse
>
{
public
HttpClientRibbonCommand
(
final
String
commandKey
,
final
RibbonLoadBalancingHttpClient
client
,
RibbonCommandContext
context
)
{
super
(
commandKey
,
client
,
context
);
}
@Override
protected
RibbonApacheHttpRequest
createRequest
()
throws
Exception
{
return
new
RibbonApacheHttpRequest
(
this
.
context
);
}
}
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/apache/HttpClientRibbonCommandFactory.java
View file @
6877f089
...
...
@@ -17,12 +17,9 @@
package
org
.
springframework
.
cloud
.
netflix
.
zuul
.
filters
.
route
.
apache
;
import
org.springframework.cloud.netflix.ribbon.SpringClientFactory
;
import
org.springframework.cloud.netflix.ribbon.apache.RibbonApacheHttpRequest
;
import
org.springframework.cloud.netflix.ribbon.apache.RibbonApacheHttpResponse
;
import
org.springframework.cloud.netflix.ribbon.apache.RibbonLoadBalancingHttpClient
;
import
org.springframework.cloud.netflix.zuul.filters.route.RibbonCommandContext
;
import
org.springframework.cloud.netflix.zuul.filters.route.RibbonCommandFactory
;
import
org.springframework.cloud.netflix.zuul.filters.route.support.AbstractRibbonCommand
;
import
lombok.RequiredArgsConstructor
;
...
...
@@ -31,7 +28,7 @@ import lombok.RequiredArgsConstructor;
*/
@RequiredArgsConstructor
public
class
HttpClientRibbonCommandFactory
implements
RibbonCommandFactory
<
HttpClientRibbonCommand
Factory
.
HttpClientRibbonCommand
>
{
RibbonCommandFactory
<
HttpClientRibbonCommand
>
{
private
final
SpringClientFactory
clientFactory
;
...
...
@@ -45,17 +42,4 @@ public class HttpClientRibbonCommandFactory implements
return
new
HttpClientRibbonCommand
(
serviceId
,
client
,
context
);
}
class
HttpClientRibbonCommand
extends
AbstractRibbonCommand
<
RibbonLoadBalancingHttpClient
,
RibbonApacheHttpRequest
,
RibbonApacheHttpResponse
>
{
public
HttpClientRibbonCommand
(
final
String
commandKey
,
final
RibbonLoadBalancingHttpClient
client
,
RibbonCommandContext
context
)
{
super
(
commandKey
,
client
,
context
);
}
@Override
protected
RibbonApacheHttpRequest
createRequest
()
throws
Exception
{
return
new
RibbonApacheHttpRequest
(
this
.
context
);
}
}
}
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/okhttp/OkHttpRibbonCommand.java
0 → 100644
View file @
6877f089
/*
* Copyright 2013-2016 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
.
zuul
.
filters
.
route
.
okhttp
;
import
org.springframework.cloud.netflix.ribbon.okhttp.OkHttpLoadBalancingClient
;
import
org.springframework.cloud.netflix.ribbon.okhttp.OkHttpRibbonRequest
;
import
org.springframework.cloud.netflix.ribbon.okhttp.OkHttpRibbonResponse
;
import
org.springframework.cloud.netflix.zuul.filters.route.RibbonCommandContext
;
import
org.springframework.cloud.netflix.zuul.filters.route.support.AbstractRibbonCommand
;
/**
* @author Spencer Gibb
*/
public
class
OkHttpRibbonCommand
extends
AbstractRibbonCommand
<
OkHttpLoadBalancingClient
,
OkHttpRibbonRequest
,
OkHttpRibbonResponse
>
{
public
OkHttpRibbonCommand
(
final
String
commandKey
,
final
OkHttpLoadBalancingClient
client
,
RibbonCommandContext
context
)
{
super
(
commandKey
,
client
,
context
);
}
@Override
protected
OkHttpRibbonRequest
createRequest
()
throws
Exception
{
return
new
OkHttpRibbonRequest
(
this
.
context
);
}
}
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/okhttp/OkHttpRibbonCommandFactory.java
View file @
6877f089
...
...
@@ -18,11 +18,8 @@ package org.springframework.cloud.netflix.zuul.filters.route.okhttp;
import
org.springframework.cloud.netflix.ribbon.SpringClientFactory
;
import
org.springframework.cloud.netflix.ribbon.okhttp.OkHttpLoadBalancingClient
;
import
org.springframework.cloud.netflix.ribbon.okhttp.OkHttpRibbonRequest
;
import
org.springframework.cloud.netflix.ribbon.okhttp.OkHttpRibbonResponse
;
import
org.springframework.cloud.netflix.zuul.filters.route.RibbonCommandContext
;
import
org.springframework.cloud.netflix.zuul.filters.route.RibbonCommandFactory
;
import
org.springframework.cloud.netflix.zuul.filters.route.support.AbstractRibbonCommand
;
import
lombok.RequiredArgsConstructor
;
...
...
@@ -31,7 +28,7 @@ import lombok.RequiredArgsConstructor;
*/
@RequiredArgsConstructor
public
class
OkHttpRibbonCommandFactory
implements
RibbonCommandFactory
<
OkHttpRibbonCommand
Factory
.
OkHttpRibbonCommand
>
{
RibbonCommandFactory
<
OkHttpRibbonCommand
>
{
private
final
SpringClientFactory
clientFactory
;
...
...
@@ -45,17 +42,4 @@ public class OkHttpRibbonCommandFactory implements
return
new
OkHttpRibbonCommand
(
serviceId
,
client
,
context
);
}
class
OkHttpRibbonCommand
extends
AbstractRibbonCommand
<
OkHttpLoadBalancingClient
,
OkHttpRibbonRequest
,
OkHttpRibbonResponse
>
{
public
OkHttpRibbonCommand
(
final
String
commandKey
,
final
OkHttpLoadBalancingClient
client
,
RibbonCommandContext
context
)
{
super
(
commandKey
,
client
,
context
);
}
@Override
protected
OkHttpRibbonRequest
createRequest
()
throws
Exception
{
return
new
OkHttpRibbonRequest
(
this
.
context
);
}
}
}
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/route/restclient/RestClientRibbonCommandIntegrationTests.java
View file @
6877f089
...
...
@@ -43,6 +43,8 @@ import org.springframework.cloud.netflix.ribbon.RibbonClients;
import
org.springframework.cloud.netflix.ribbon.SpringClientFactory
;
import
org.springframework.cloud.netflix.ribbon.StaticServerList
;
import
org.springframework.cloud.netflix.zuul.EnableZuulProxy
;
import
org.springframework.cloud.netflix.zuul.filters.route.RestClientRibbonCommand
;
import
org.springframework.cloud.netflix.zuul.filters.route.RestClientRibbonCommandFactory
;
import
org.springframework.cloud.netflix.zuul.filters.route.RibbonCommandContext
;
import
org.springframework.cloud.netflix.zuul.filters.route.RibbonCommandFactory
;
import
org.springframework.cloud.netflix.zuul.filters.route.support.ZuulProxyTestBase
;
...
...
@@ -312,7 +314,7 @@ public class RestClientRibbonCommandIntegrationTests extends ZuulProxyTestBase {
@Override
@SuppressWarnings
(
"deprecation"
)
@SneakyThrows
public
RestClientRibbonCommand
Factory
.
RestClientRibbonCommand
create
(
RibbonCommandContext
context
)
{
public
RestClientRibbonCommand
create
(
RibbonCommandContext
context
)
{
String
uri
=
context
.
getUri
();
if
(
uri
.
startsWith
(
"/throwexception/"
))
{
String
code
=
uri
.
replace
(
"/throwexception/"
,
""
);
...
...
@@ -325,7 +327,7 @@ public class RestClientRibbonCommandIntegrationTests extends ZuulProxyTestBase {
}
}
static
class
MyCommand
extends
RestClientRibbonCommand
Factory
.
RestClientRibbonCommand
{
static
class
MyCommand
extends
RestClientRibbonCommand
{
private
int
errorCode
;
...
...
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