-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1409 from dimagi/dv/api_versioning
Providing API version header from server to caller when available.
- Loading branch information
Showing
3 changed files
with
24 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ | |
* | ||
* @author Phillip Mates ([email protected]) | ||
*/ | ||
public class ModernHttpRequester implements ResponseStreamAccessor { | ||
public class ModernHttpRequester { | ||
/** | ||
* How long to wait when opening network connection in milliseconds | ||
*/ | ||
|
@@ -87,7 +87,23 @@ public void makeRequestAndProcess() { | |
} | ||
try { | ||
response = makeRequest(); | ||
processResponse(responseProcessor, response.code(), this); | ||
final ModernHttpRequester requester = this; | ||
processResponse(responseProcessor, response.code(), new ResponseStreamAccessor() { | ||
/** | ||
* Only gets called if response processor is supplied | ||
* @return Input Stream from cache | ||
* @throws IOException if an io error happens while reading or writing to cache | ||
*/ | ||
@Override | ||
public InputStream getResponseStream() throws IOException { | ||
return requester.getResponseStream(response); | ||
} | ||
|
||
@Override | ||
public String getApiVersion() { | ||
return requester.getApiVersion(); | ||
} | ||
}); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
responseProcessor.handleIOException(e); | ||
|
@@ -153,7 +169,8 @@ public static void processResponse(HttpResponseProcessor responseProcessor, | |
responseProcessor.handleIOException(e); | ||
return; | ||
} | ||
responseProcessor.processSuccess(responseCode, responseStream); | ||
String apiVersion = streamAccessor.getApiVersion(); | ||
responseProcessor.processSuccess(responseCode, responseStream, apiVersion); | ||
} finally { | ||
StreamsUtil.closeStream(responseStream); | ||
} | ||
|
@@ -181,14 +198,8 @@ public InputStream getResponseStream(Response<ResponseBody> response) throws IOE | |
return cache.retrieveCache(); | ||
} | ||
|
||
/** | ||
* Only gets called if response processor is supplied | ||
* @return Input Stream from cache | ||
* @throws IOException if an io error happens while reading or writing to cache | ||
*/ | ||
@Override | ||
public InputStream getResponseStream() throws IOException { | ||
return getResponseStream(response); | ||
public String getApiVersion() { | ||
return response != null ? response.headers().get("x-api-current-version") : null; | ||
} | ||
|
||
public static RequestBody getPostBody(Multimap<String, String> inputs) { | ||
|