Fix: detection of network exceptions, merge duplicate HTTPRequest functions
This commit is contained in:
@@ -434,11 +434,14 @@ public class ServerRequest extends Thread {
|
|||||||
catch (SheepItException e) {
|
catch (SheepItException e) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
catch (NoRouteToHostException e) {
|
catch (IOException e) {
|
||||||
|
if (e.getCause() instanceof NoRouteToHostException || e.getCause() instanceof UnknownHostException) {
|
||||||
throw new SheepItServerDown();
|
throw new SheepItServerDown();
|
||||||
}
|
}
|
||||||
catch (UnknownHostException e) {
|
StringWriter sw = new StringWriter();
|
||||||
throw new SheepItServerDown();
|
PrintWriter pw = new PrintWriter(sw);
|
||||||
|
e.printStackTrace(pw);
|
||||||
|
throw new SheepItException("error requestJob: unknown IO exception " + e + " stacktrace: " + sw.toString());
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
@@ -458,30 +461,7 @@ public class ServerRequest extends Thread {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Response HTTPRequest(HttpUrl.Builder httpUrlBuilder, RequestBody data_) throws IOException {
|
public Response HTTPRequest(HttpUrl.Builder httpUrlBuilder, RequestBody data_) throws IOException {
|
||||||
String url = httpUrlBuilder.build().toString();
|
return HTTPRequest(httpUrlBuilder, data_, false);
|
||||||
Request.Builder builder = new Request.Builder().addHeader("User-Agent", HTTP_USER_AGENT).url(url);
|
|
||||||
|
|
||||||
this.log.debug("Server::HTTPRequest url(" + url + ")");
|
|
||||||
|
|
||||||
if (data_ != null) {
|
|
||||||
builder.post(data_);
|
|
||||||
}
|
|
||||||
|
|
||||||
Request request = builder.build();
|
|
||||||
|
|
||||||
try {
|
|
||||||
Response response = httpClient.newCall(request).execute();
|
|
||||||
|
|
||||||
if (response.isSuccessful() == false) {
|
|
||||||
this.log.error("Received unsuccessful HTTP response " + response);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.lastRequestTime = new Date().getTime();
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
throw new IOException("Unexpected response from HTTP Stack" + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response HTTPRequest(HttpUrl.Builder httpUrlBuilder, RequestBody data_, boolean checkIsSuccessful) throws IOException {
|
public Response HTTPRequest(HttpUrl.Builder httpUrlBuilder, RequestBody data_, boolean checkIsSuccessful) throws IOException {
|
||||||
@@ -507,10 +487,10 @@ public class ServerRequest extends Thread {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
catch (ConnectException e) {
|
catch (ConnectException e) {
|
||||||
throw new ConnectException("Unexpected response from HTTP Stack" + e.getMessage());
|
throw new ConnectException("Unexpected response from HTTP Stack " + e.getMessage());
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
throw new IOException("Unexpected response from HTTP Stack" + e.getMessage());
|
throw new IOException("Unexpected response from HTTP Stack " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user