Skip to content

Commit

Permalink
re-add status code and header getters for backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronforest-wf committed Jul 3, 2024
1 parent 4dbf174 commit 3f85c2a
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
protected String tempFolderPath = null;

private Map<String, Authentication> authentications;

private Map<Long, Integer> lastStatusCodeByThread = new ConcurrentHashMap<>();
private Map<Long, Map<String, List<String>>> lastResponseHeadersByThread = new ConcurrentHashMap<>();

private DateFormat dateFormat;

Expand Down Expand Up @@ -270,6 +273,25 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
this.serverVariables = serverVariables;
return this;
}

/**
* Gets the status code of the previous request
*
* @return Status code
*/
@Deprecated
public int getStatusCode() {
return lastStatusCodeByThread.get(Thread.currentThread().threadId());
}

/**
* Gets the response headers of the previous request
* @return Response headers
*/
@Deprecated
public Map<String, List<String>> getResponseHeaders() {
return lastResponseHeadersByThread.get(Thread.currentThread().threadId());
}

/**
* Get authentications (key: authentication name, value: authentication).
Expand Down Expand Up @@ -990,15 +1012,18 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {

protected <T> T processResponse(CloseableHttpResponse response, TypeReference<T> returnType) throws ApiException, IOException, ParseException {
int statusCode = response.getCode();
lastStatusCodeByThread.put(Thread.currentThread().threadId(), statusCode);
if (statusCode == HttpStatus.SC_NO_CONTENT) {
return null;
}

Map<String, List<String>> responseHeaders = transformResponseHeaders(response.getHeaders());
lastResponseHeadersByThread.put(Thread.currentThread().threadId(), responseHeaders);

if (isSuccessfulStatus(statusCode)) {
return this.deserialize(response, returnType);
} else {
String message = EntityUtils.toString(response.getEntity());
Map<String, List<String>> responseHeaders = transformResponseHeaders(response.getHeaders());
throw new ApiException(message, statusCode, responseHeaders, message);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ public class ApiClient extends JavaTimeFormatter {
protected String tempFolderPath = null;

private Map<String, Authentication> authentications;

private Map<Long, Integer> lastStatusCodeByThread = new ConcurrentHashMap<>();
private Map<Long, Map<String, List<String>>> lastResponseHeadersByThread = new ConcurrentHashMap<>();

private DateFormat dateFormat;

Expand Down Expand Up @@ -241,6 +244,25 @@ public ApiClient setServerVariables(Map<String, String> serverVariables) {
this.serverVariables = serverVariables;
return this;
}

/**
* Gets the status code of the previous request
*
* @return Status code
*/
@Deprecated
public int getStatusCode() {
return lastStatusCodeByThread.get(Thread.currentThread().threadId());
}

/**
* Gets the response headers of the previous request
* @return Response headers
*/
@Deprecated
public Map<String, List<String>> getResponseHeaders() {
return lastResponseHeadersByThread.get(Thread.currentThread().threadId());
}

/**
* Get authentications (key: authentication name, value: authentication).
Expand Down Expand Up @@ -908,15 +930,18 @@ protected Cookie buildCookie(String key, String value, URI uri) {

protected <T> T processResponse(CloseableHttpResponse response, TypeReference<T> returnType) throws ApiException, IOException, ParseException {
int statusCode = response.getCode();
lastStatusCodeByThread.put(Thread.currentThread().threadId(), statusCode);
if (statusCode == HttpStatus.SC_NO_CONTENT) {
return null;
}

Map<String, List<String>> responseHeaders = transformResponseHeaders(response.getHeaders());
lastResponseHeadersByThread.put(Thread.currentThread().threadId(), responseHeaders);

if (isSuccessfulStatus(statusCode)) {
return this.deserialize(response, returnType);
} else {
String message = EntityUtils.toString(response.getEntity());
Map<String, List<String>> responseHeaders = transformResponseHeaders(response.getHeaders());
throw new ApiException(message, statusCode, responseHeaders, message);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ public class ApiClient extends JavaTimeFormatter {
protected String tempFolderPath = null;

private Map<String, Authentication> authentications;

private Map<Long, Integer> lastStatusCodeByThread = new ConcurrentHashMap<>();
private Map<Long, Map<String, List<String>>> lastResponseHeadersByThread = new ConcurrentHashMap<>();

private DateFormat dateFormat;

Expand Down Expand Up @@ -289,6 +292,25 @@ public ApiClient setServerVariables(Map<String, String> serverVariables) {
this.serverVariables = serverVariables;
return this;
}

/**
* Gets the status code of the previous request
*
* @return Status code
*/
@Deprecated
public int getStatusCode() {
return lastStatusCodeByThread.get(Thread.currentThread().threadId());
}

/**
* Gets the response headers of the previous request
* @return Response headers
*/
@Deprecated
public Map<String, List<String>> getResponseHeaders() {
return lastResponseHeadersByThread.get(Thread.currentThread().threadId());
}

/**
* Get authentications (key: authentication name, value: authentication).
Expand Down Expand Up @@ -1001,15 +1023,18 @@ protected Cookie buildCookie(String key, String value, URI uri) {

protected <T> T processResponse(CloseableHttpResponse response, TypeReference<T> returnType) throws ApiException, IOException, ParseException {
int statusCode = response.getCode();
lastStatusCodeByThread.put(Thread.currentThread().threadId(), statusCode);
if (statusCode == HttpStatus.SC_NO_CONTENT) {
return null;
}

Map<String, List<String>> responseHeaders = transformResponseHeaders(response.getHeaders());
lastResponseHeadersByThread.put(Thread.currentThread().threadId(), responseHeaders);

if (isSuccessfulStatus(statusCode)) {
return this.deserialize(response, returnType);
} else {
String message = EntityUtils.toString(response.getEntity());
Map<String, List<String>> responseHeaders = transformResponseHeaders(response.getHeaders());
throw new ApiException(message, statusCode, responseHeaders, message);
}
}
Expand Down

0 comments on commit 3f85c2a

Please sign in to comment.