|
public class FooClient { |
|
private static final String CLIENT_ID = BackendClients.FOO.id; |
|
|
|
static final String DOWORK_PATH = "/do-work"; // existing header versioning |
|
static final String DOWORK_V2_PATH = "/v2/do-work"; // new version of existing endpoint path versioning |
|
static final String DOOTHERWORK_V1_PATH = "/v1/do-other-work"; // new endpoint path versioning |
|
|
|
|
|
private final DynamicHoneycombClient client; |
|
// TO BE DEPRECATED |
|
private final FooApiVersion apiVersion; |
|
private final String host; |
|
|
|
// TO BE DEPRECATED: existing constructor with header versioning |
|
public FooClient(String host, |
|
DynamicHoneycombClient honeycombClient, |
|
FooApiVersion apiVersion) { |
|
this.host = host; |
|
this.client = honeycombClient; |
|
this.apiVersion = apiVersion; |
|
} |
|
|
|
// new constructor, version agnostic |
|
public FooClient(String host, |
|
DynamicHoneycombClient honeycombClient) { |
|
this.host = host; |
|
this.client = honeycombClient; |
|
this.apiVersion = apiVersion; |
|
} |
|
|
|
// TO BE DEPRECATED: existing endpoint with header versioning |
|
public void doWork(Object request) { |
|
String response = |
|
sendRequest(DOWORK_PATH, HttpVerb.POST, apiVersion.getValue(), request); |
|
} |
|
|
|
|
|
// new version of existing endpoint with path versioning |
|
public void doWorkV2(Object request) { |
|
String response = |
|
sendRequest(DOWORK_V2_PATH, HttpVerb.POST, request); |
|
} |
|
|
|
// new endpoint (v1) with path versioning |
|
public void doOtherWorkV1(Object request) { |
|
String response = |
|
sendRequest(DOOTHERWORK_V1_PATH, HttpVerb.POST, request); |
|
} |
|
|
|
} |
|
|
|
/* BarService consuming FooClient */ |
|
|
|
// TO BE DEPRECATED: existing client autowire |
|
@Bean |
|
public FooClient fooClient() { |
|
return new FooClient(fooHost, dynamicHoneycombClient, FooApiVersion.V1); |
|
} |
|
|
|
// new client autowire for path versioning |
|
@Bean |
|
public FooClient fooClientWithPathVersioning() { |
|
return new FooClient(fooHost, dynamicHoneycombClient); |
|
} |
|
|
|
// TO BE DEPRECATED: existing call to doWork v1 |
|
fooClient.doWork(request); |
|
|
|
// new call to doWork v2 |
|
fooClientWithPathVersioning.doWorkV2(request); |
|
|
|
// new call to doOtherWork v1 |
|
fooClientWithPathVersioning.doOtherWorkV1(request); |
|
|
|
|
|
|