Move RestClientRibbonCommand back to original place.
Made it public and undid other refactorings.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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 com.netflix.client.http.HttpResponse;
|
||||
import com.netflix.niws.client.http.RestClient;
|
||||
import org.springframework.cloud.netflix.zuul.filters.route.support.AbstractRibbonCommand;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 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 class RestClientRibbonCommand extends AbstractRibbonCommand<RestClient, HttpRequest, HttpResponse> {
|
||||
|
||||
public RestClientRibbonCommand(String commandKey, RestClient client, RibbonCommandContext context) {
|
||||
super(commandKey, client, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HttpRequest createRequest() throws Exception {
|
||||
HttpRequest.Builder builder = HttpRequest.newBuilder()
|
||||
.verb(RestClientRibbonCommandFactory.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.getParams().keySet()) {
|
||||
List<String> values = this.context.getParams().get(name);
|
||||
for (String value : values) {
|
||||
builder.queryParams(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<HttpClientRibbonCommandFactory.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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<OkHttpRibbonCommandFactory.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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,102 +0,0 @@
|
||||
/*
|
||||
* 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.restclient;
|
||||
|
||||
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
|
||||
*/
|
||||
public class RestClientRibbonCommandFactory implements RibbonCommandFactory<RestClientRibbonCommandFactory.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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
@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.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 RestClientRibbonCommandFactory.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 RestClientRibbonCommandFactory.RestClientRibbonCommand {
|
||||
static class MyCommand extends RestClientRibbonCommand {
|
||||
|
||||
private int errorCode;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user