Skip to content

Commit

Permalink
improved logging
Browse files Browse the repository at this point in the history
Issue #642
  • Loading branch information
rsoika committed Feb 18, 2020
1 parent d103ba9 commit 93a2db4
Showing 1 changed file with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,15 @@ public String post(String uri, String dataString, final String _contentType, Str
iLastHTTPResult = urlConnection.getResponseCode();
logger.finest("......Sending 'POST' request to URL : " + serviceEndpoint);
logger.finest("......Response Code : " + iLastHTTPResult);

String content = readResponse(urlConnection);
return content;

// read response if response was successful
if (iLastHTTPResult >= 200 && iLastHTTPResult <= 299) {
return readResponse(urlConnection);
} else {
String error = "Error " + iLastHTTPResult + " - failed POST request: '" + uri + "'";
logger.warning(error);
throw new RestAPIException(iLastHTTPResult, error);
}

} catch (IOException ioe) {
String error = "Error POST request '" + uri + " - " + ioe.getMessage();
Expand Down Expand Up @@ -323,14 +329,20 @@ public String post(String uri, byte[] data, final String _contentType, String ac
// Close the streams
outputStreamToRequestBody.close();
httpRequestBodyWriter.close();

iLastHTTPResult = urlConnection.getResponseCode();
logger.finest("......Sending 'POST' request to URL : " + serviceEndpoint);
logger.finest("......Response Code : " + iLastHTTPResult);


String content = readResponse(urlConnection);
return content;
// read response if response was successful
if (iLastHTTPResult >= 200 && iLastHTTPResult <= 299) {
return readResponse(urlConnection);
} else {
String error = "Error " + iLastHTTPResult + " - failed POST request: '" + uri + "'";
logger.warning(error);
throw new RestAPIException(iLastHTTPResult, error);
}

} catch (IOException ioe) {
String error = "Error POST request '" + uri + " - " + ioe.getMessage();
logger.warning(error);
Expand Down

0 comments on commit 93a2db4

Please sign in to comment.