Skip to content

Commit

Permalink
[SDCISA-13736, SDCISA-10974] Fix bad habits in CopyResourceHandler.
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddenalpha committed Jan 5, 2024
1 parent 23b8cfc commit d34c6a2
Showing 1 changed file with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ public boolean handle(final HttpServerRequest request) {
if (task != null && validTask(request, task)) {
performGETRequest(request, task);
} else {
request.response().setStatusCode(StatusCode.BAD_REQUEST.getStatusCode());
request.response().setStatusMessage(StatusCode.BAD_REQUEST.getStatusMessage());
request.response().end();
HttpServerResponse rsp = request.response();
rsp.setStatusCode(StatusCode.BAD_REQUEST.getStatusCode());
rsp.setStatusMessage(StatusCode.BAD_REQUEST.getStatusMessage());
rsp.end();

Check warning on line 57 in gateleen-core/src/main/java/org/swisspush/gateleen/core/resource/CopyResourceHandler.java

View check run for this annotation

Codecov / codecov/patch

gateleen-core/src/main/java/org/swisspush/gateleen/core/resource/CopyResourceHandler.java#L54-L57

Added lines #L54 - L57 were not covered by tests
}
});

Expand Down Expand Up @@ -93,7 +94,7 @@ protected void performGETRequest(final HttpServerRequest request, final CopyTask

selfClient.request(HttpMethod.GET, task.getSourceUri()).onComplete(event -> {
if (event.failed()) {
log.warn("Failed request to {}: {}", request.uri(), event.cause());
log.warn("Failed request to {}", request.uri(), new Exception("stacktrace", event.cause()));

Check warning on line 97 in gateleen-core/src/main/java/org/swisspush/gateleen/core/resource/CopyResourceHandler.java

View check run for this annotation

Codecov / codecov/patch

gateleen-core/src/main/java/org/swisspush/gateleen/core/resource/CopyResourceHandler.java#L97

Added line #L97 was not covered by tests
return;
}
HttpClientRequest selfRequest = event.result();
Expand All @@ -104,10 +105,16 @@ protected void performGETRequest(final HttpServerRequest request, final CopyTask
selfRequest.setTimeout(DEFAULT_TIMEOUT);

// add exception handler
selfRequest.exceptionHandler(exception -> log.warn("CopyResourceHandler: GET request failed: " + request.uri() + ": " + exception.getMessage()));
selfRequest.exceptionHandler( ex -> {
log.warn("CopyResourceHandler: GET request failed: {}", request.uri(), new Exception("stacktrace", ex));
});

Check warning on line 110 in gateleen-core/src/main/java/org/swisspush/gateleen/core/resource/CopyResourceHandler.java

View check run for this annotation

Codecov / codecov/patch

gateleen-core/src/main/java/org/swisspush/gateleen/core/resource/CopyResourceHandler.java#L108-L110

Added lines #L108 - L110 were not covered by tests

// fire
selfRequest.send(asyncResult -> {
if( asyncResult.failed() ){
log.warn("stacktrace", new Exception("stacktrace", asyncResult.cause()));
return;

Check warning on line 116 in gateleen-core/src/main/java/org/swisspush/gateleen/core/resource/CopyResourceHandler.java

View check run for this annotation

Codecov / codecov/patch

gateleen-core/src/main/java/org/swisspush/gateleen/core/resource/CopyResourceHandler.java#L115-L116

Added lines #L115 - L116 were not covered by tests
}
HttpClientResponse response = asyncResult.result();
// POST response is OK
if (response.statusCode() == StatusCode.OK.getStatusCode()) {
Expand All @@ -133,7 +140,7 @@ protected void performPUTRequest(final HttpServerRequest request, final HttpClie

selfClient.request(HttpMethod.PUT, task.getDestinationUri()).onComplete(event -> {
if (event.failed()) {
log.warn("Failed request to {}: {}", request.uri(), event.cause());
log.warn("Failed request to {}", request.uri(), new Exception("stacktrace", event.cause()));

Check warning on line 143 in gateleen-core/src/main/java/org/swisspush/gateleen/core/resource/CopyResourceHandler.java

View check run for this annotation

Codecov / codecov/patch

gateleen-core/src/main/java/org/swisspush/gateleen/core/resource/CopyResourceHandler.java#L143

Added line #L143 was not covered by tests
return;
}
HttpClientRequest selfRequest = event.result();
Expand All @@ -149,6 +156,10 @@ protected void performPUTRequest(final HttpServerRequest request, final HttpClie

// fire
selfRequest.send(asyncResult -> {
if( asyncResult.failed() ){
log.warn("stacktrace", new Exception("stacktrace", asyncResult.cause()));
return;

Check warning on line 161 in gateleen-core/src/main/java/org/swisspush/gateleen/core/resource/CopyResourceHandler.java

View check run for this annotation

Codecov / codecov/patch

gateleen-core/src/main/java/org/swisspush/gateleen/core/resource/CopyResourceHandler.java#L160-L161

Added lines #L160 - L161 were not covered by tests
}
HttpClientResponse response = asyncResult.result();
createResponse(request, response, task);
});
Expand Down Expand Up @@ -176,8 +187,9 @@ private void createResponse(final HttpServerRequest request, final HttpClientRes
request.response().setStatusCode(StatusCodeTranslator.translateStatusCode(response.statusCode(), request.headers()));
request.response().setStatusMessage(response.statusMessage());
response.bodyHandler(buffer -> {
request.response().putHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(buffer.length()));
request.response().end(buffer);
var rsp = request.response();
rsp.putHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(buffer.length()));
rsp.end(buffer);

Check warning on line 192 in gateleen-core/src/main/java/org/swisspush/gateleen/core/resource/CopyResourceHandler.java

View check run for this annotation

Codecov / codecov/patch

gateleen-core/src/main/java/org/swisspush/gateleen/core/resource/CopyResourceHandler.java#L190-L192

Added lines #L190 - L192 were not covered by tests
});
}

Expand Down

0 comments on commit d34c6a2

Please sign in to comment.