- Refactor "FileUtils.getErrorMessageFromResponseBody(conn)" into "FileUtils.getMessageFromResponseBody(conn, isError)", in order to be able to either retrieve the "normal" or the "error" response.
- Add comments.
This commit is contained in:
parent
3e8f9c6074
commit
a22144bd51
|
@ -32,7 +32,6 @@ public class ImpalaController {
|
|||
|
||||
try {
|
||||
List<String> publications = jdbcTemplate.queryForList(query, String.class);
|
||||
|
||||
return new ResponseEntity<>(publications.toString(), HttpStatus.OK);
|
||||
} catch (Exception e) {
|
||||
String errorMsg = "Problem when executing \"getAssignmentsQuery\": " + query;
|
||||
|
|
|
@ -352,7 +352,7 @@ public class FileUtils {
|
|||
conn.connect();
|
||||
int statusCode = conn.getResponseCode();
|
||||
if ( statusCode != 200 ) {
|
||||
logger.warn("HTTP-" + statusCode + ": " + getErrorMessageFromResponseBody(conn) + "\nProblem when requesting the ZipFile of batch_" + batchNum + " from the Worker with ID \"" + workerId + "\" and requestUrl: " + requestUrl);
|
||||
logger.warn("HTTP-" + statusCode + ": " + getMessageFromResponseBody(conn, true) + "\nProblem when requesting the ZipFile of batch_" + batchNum + " from the Worker with ID \"" + workerId + "\" and requestUrl: " + requestUrl);
|
||||
return null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -368,21 +368,21 @@ public class FileUtils {
|
|||
}
|
||||
|
||||
|
||||
private String getErrorMessageFromResponseBody(HttpURLConnection conn) {
|
||||
StringBuilder errorMsgStrB = new StringBuilder(500);
|
||||
try ( BufferedReader br = new BufferedReader(new InputStreamReader(conn.getErrorStream())) ) { // Try-with-resources
|
||||
public static String getMessageFromResponseBody(HttpURLConnection conn, boolean isError) {
|
||||
StringBuilder msgStrB = new StringBuilder(500);
|
||||
try ( BufferedReader br = new BufferedReader(new InputStreamReader((isError ? conn.getErrorStream() : conn.getInputStream()))) ) { // Try-with-resources
|
||||
String inputLine;
|
||||
while ( (inputLine = br.readLine()) != null )
|
||||
{
|
||||
if ( !inputLine.isEmpty() )
|
||||
errorMsgStrB.append(inputLine);
|
||||
msgStrB.append(inputLine);
|
||||
}
|
||||
return (errorMsgStrB.length() != 0) ? errorMsgStrB.toString() : null; // Make sure we return a "null" on empty string, to better handle the case in the caller-function.
|
||||
return (msgStrB.length() != 0) ? msgStrB.toString() : null; // Make sure we return a "null" on empty string, to better handle the case in the caller-function.
|
||||
} catch ( IOException ioe ) {
|
||||
logger.error("IOException when retrieving the error-message: " + ioe.getMessage());
|
||||
logger.error("IOException when retrieving the response-body: " + ioe.getMessage());
|
||||
return null;
|
||||
} catch ( Exception e ) {
|
||||
logger.error("Could not extract the errorMessage!", e);
|
||||
} catch ( Exception e ) { // This includes the case, where the "conn.getErrorStream()" returns < null >.
|
||||
logger.error("Could not extract the response-body!", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -465,11 +465,12 @@ public class FileUtils {
|
|||
continue;
|
||||
}
|
||||
|
||||
// Mark this full-text as not-retrieved, since it will be deleted from local-storage. The retrieved link to the full-text will be kept.
|
||||
payload.setLocation(null);
|
||||
// Mark this full-text as not-retrieved, since it will be deleted from local-storage. The retrieved link to the full-text ("actual_url") will be kept, for now.
|
||||
payload.setLocation(null); // This will cause the payload to not be inserted into the "payload" table in the database. Only the "attempt" record will be inserted.
|
||||
payload.setHash(null);
|
||||
payload.setMime_type(null);
|
||||
payload.setSize(null);
|
||||
// The id-url record will be called as a new assignment in the future.
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue