Skip to content

Commit

Permalink
[SDCISA-13736, SDCISA-10974] Enhance error reporting in HttpResourceS…
Browse files Browse the repository at this point in the history
…torage and EventBusResourceStorage.
  • Loading branch information
hiddenalpha committed Jan 5, 2024
1 parent 23b8cfc commit 70bd61b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
public class EventBusResourceStorage implements ResourceStorage {

private static final Logger log = LoggerFactory.getLogger(EventBusResourceStorage.class);
private EventBus eventBus;
private String address;
private final EventBus eventBus;
private final String address;

public EventBusResourceStorage(EventBus eventBus, String address) {
this.eventBus = eventBus;
Expand All @@ -34,14 +34,16 @@ public void get(String uri, final Handler<Buffer> bodyHandler) {

eventBus.request(address, request, (Handler<AsyncResult<Message<Buffer>>>) message -> {
if (message.failed()) {
log.warn("Got failed msg from event bus while GET. Lets run into NPE now.", message.cause());
log.warn("Got failed msg from event bus while GET. Lets run into NPE now.", new Exception("stacktrace", message.cause()));

Check warning on line 37 in gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/EventBusResourceStorage.java

View check run for this annotation

Codecov / codecov/patch

gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/EventBusResourceStorage.java#L37

Added line #L37 was not covered by tests
// Would be best to stop processing now. But we don't to keep backward
// compatibility (Will run into NPE anyway).
}
Buffer buffer = message.result().body();
int headerLength = buffer.getInt(0);
JsonObject header1 = new JsonObject(buffer.getString(4, headerLength + 4));
if (header1.getInteger("statusCode") == 200) {
Integer statusCode = header1.getInteger("statusCode");

Check warning on line 44 in gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/EventBusResourceStorage.java

View check run for this annotation

Codecov / codecov/patch

gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/EventBusResourceStorage.java#L44

Added line #L44 was not covered by tests
if( statusCode == null ) log.debug("getInteger(\"statusCode\") -> null");
if( statusCode != null && statusCode == 200 ){
bodyHandler.handle(buffer.getBuffer(4 + headerLength, buffer.length()));
} else {
bodyHandler.handle(null);
Expand All @@ -56,7 +58,8 @@ public void put(String uri, MultiMap headers, Buffer buffer, final Handler<Integ
request.setInt(0, header.length()).appendBuffer(header).appendBuffer(buffer);
eventBus.request(address, request, (Handler<AsyncResult<Message<Buffer>>>) message -> {
if (message.failed()) {
log.warn("Got failed msg from event bus while PUT. Lets run into NPE now.", message.cause());
log.warn("Got failed msg from event bus while PUT. Lets run into NPE now.",
new Exception("stacktrace", message.cause()));

Check warning on line 62 in gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/EventBusResourceStorage.java

View check run for this annotation

Codecov / codecov/patch

gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/EventBusResourceStorage.java#L61-L62

Added lines #L61 - L62 were not covered by tests
// Would be best to stop processing now. But we don't to keep backward
// compatibility (Will run into NPE anyway).
}
Expand All @@ -79,7 +82,8 @@ public void delete(String uri, final Handler<Integer> doneHandler) {
request.setInt(0, header.length()).appendBuffer(header);
eventBus.request(address, request, (Handler<AsyncResult<Message<Buffer>>>) message -> {
if (message.failed()) {
log.warn("Got failed msg from event bus while DELETE. Lets run into NPE now.", message.cause());
log.warn("Got failed msg from event bus while DELETE. Lets run into NPE now.",
new Exception("stacktrace", message.cause()));

Check warning on line 86 in gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/EventBusResourceStorage.java

View check run for this annotation

Codecov / codecov/patch

gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/EventBusResourceStorage.java#L85-L86

Added lines #L85 - L86 were not covered by tests
// Would be best to stop processing now. But we don't to keep backward
// compatibility (Will run into NPE anyway).
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,28 @@ public void get(final String path, final Handler<Buffer> bodyHandler) {
log.debug("Reading {}", path);
client.request(HttpMethod.GET, path).onComplete(asyncResult -> {
if (asyncResult.failed()) {
log.warn("Failed request to {}: {}", path, asyncResult.cause());
log.warn("Failed request to {} (HINT: Happy timeout on caller side)",
path, new Exception("stacktrace", asyncResult.cause()));

Check warning on line 50 in gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/HttpResourceStorage.java

View check run for this annotation

Codecov / codecov/patch

gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/HttpResourceStorage.java#L49-L50

Added lines #L49 - L50 were not covered by tests
return;
}
HttpClientRequest request = asyncResult.result();

request.exceptionHandler(e -> {
log.error("Storage request error", e);
log.error("Storage request error", new Exception("stacktrace", e));

Check warning on line 56 in gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/HttpResourceStorage.java

View check run for this annotation

Codecov / codecov/patch

gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/HttpResourceStorage.java#L56

Added line #L56 was not covered by tests
bodyHandler.handle(null);
});
request.setTimeout(TIMEOUT);
request.send(event -> {
HttpClientResponse response = event.result();
response.exceptionHandler(exception -> {
log.error("Reading {} failed: {}", path, exception.getMessage());
log.error("Reading {} failed", path, new Exception("stacktrace", exception));

Check warning on line 63 in gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/HttpResourceStorage.java

View check run for this annotation

Codecov / codecov/patch

gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/HttpResourceStorage.java#L63

Added line #L63 was not covered by tests
bodyHandler.handle(null);
});
if (response.statusCode() == StatusCode.OK.getStatusCode()) {
response.bodyHandler(bodyHandler);
} else {
log.debug("Got status code other than 200. Status code = {}, status message is '{}'.",
(response == null ? "<null>" : response.statusCode()),
((response == null || response.statusMessage() == null) ? "<null>" : response.statusMessage()));
response.statusCode(), response.statusMessage());

Check warning on line 70 in gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/HttpResourceStorage.java

View check run for this annotation

Codecov / codecov/patch

gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/HttpResourceStorage.java#L70

Added line #L70 was not covered by tests
bodyHandler.handle(null);
}
});
Expand All @@ -86,12 +86,12 @@ public int getPort() {
public void put(final String uri, MultiMap headers, Buffer buffer, final Handler<Integer> doneHandler) {
client.request(HttpMethod.PUT, uri).onComplete(asyncResult -> {
if (asyncResult.failed()) {
log.warn("Failed request to {}: {}", uri, asyncResult.cause());
log.warn("Failed request to {} (HINT: Happy timout on caller side)",
uri, new Exception("stacktrace", asyncResult.cause()));

Check warning on line 90 in gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/HttpResourceStorage.java

View check run for this annotation

Codecov / codecov/patch

gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/HttpResourceStorage.java#L89-L90

Added lines #L89 - L90 were not covered by tests
return;
}
HttpClientRequest request = asyncResult.result();


request.exceptionHandler(exception -> {
log.error("Putting {} failed: {}", uri, exception.getMessage());
doneHandler.handle(StatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
Expand All @@ -106,12 +106,16 @@ public void put(final String uri, MultiMap headers, Buffer buffer, final Handler
request.putHeader("Content-Length", "" + buffer.length());
request.write(buffer);
request.send(asyncRespnose -> {
if( asyncRespnose.failed() ){
log.error("TODO error handling", new Exception("stacktrace", asyncRespnose.cause()));
return;

Check warning on line 111 in gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/HttpResourceStorage.java

View check run for this annotation

Codecov / codecov/patch

gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/HttpResourceStorage.java#L110-L111

Added lines #L110 - L111 were not covered by tests
}
HttpClientResponse response = asyncRespnose.result();
response.exceptionHandler(exception -> {
log.error("Exception on response to PUT from {}: {}", uri, exception.getMessage());
response.exceptionHandler( ex -> {
log.error("Exception on response to PUT {}", uri, new Exception("stacktrace", ex));

Check warning on line 115 in gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/HttpResourceStorage.java

View check run for this annotation

Codecov / codecov/patch

gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/HttpResourceStorage.java#L114-L115

Added lines #L114 - L115 were not covered by tests
doneHandler.handle(StatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
});
response.endHandler(event -> doneHandler.handle(response.statusCode()));
response.endHandler(nothing -> doneHandler.handle(response.statusCode()));

Check warning on line 118 in gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/HttpResourceStorage.java

View check run for this annotation

Codecov / codecov/patch

gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/HttpResourceStorage.java#L118

Added line #L118 was not covered by tests
});
});
}
Expand All @@ -125,20 +129,24 @@ public void put(final String uri, final Buffer buffer, final Handler<Integer> do
public void delete(final String uri, final Handler<Integer> doneHandler) {
client.request(HttpMethod.DELETE, uri).onComplete(asyncResult -> {
if (asyncResult.failed()) {
log.warn("Failed request to {}: {}", uri, asyncResult.cause());
log.warn("Failed request to {}", uri, new Exception("stacktrace", asyncResult.cause()));

Check warning on line 132 in gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/HttpResourceStorage.java

View check run for this annotation

Codecov / codecov/patch

gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/HttpResourceStorage.java#L132

Added line #L132 was not covered by tests
return;
}
HttpClientRequest request = asyncResult.result();

request.exceptionHandler(exception -> {
log.error("Deleting {} failed: {}", uri, exception.getMessage());
request.exceptionHandler( ex -> {
log.warn("Deleting {} failed", uri, new Exception("stacktrace", ex));

Check warning on line 138 in gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/HttpResourceStorage.java

View check run for this annotation

Codecov / codecov/patch

gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/HttpResourceStorage.java#L137-L138

Added lines #L137 - L138 were not covered by tests
doneHandler.handle(StatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
});
request.setTimeout(TIMEOUT);
request.send(asyncRespnose -> {
if( asyncRespnose.failed() ){
log.warn("TODO error handling", new Exception("stacktrace", asyncRespnose.cause()));
return;

Check warning on line 145 in gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/HttpResourceStorage.java

View check run for this annotation

Codecov / codecov/patch

gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/HttpResourceStorage.java#L144-L145

Added lines #L144 - L145 were not covered by tests
}
HttpClientResponse response = asyncRespnose.result();
response.exceptionHandler(exception -> {
log.error("Exception on response to DELETE from {}: {}", uri, exception.getMessage());
log.error("Exception on response to DELETE from {}", uri, new Exception("stacktrace", exception));

Check warning on line 149 in gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/HttpResourceStorage.java

View check run for this annotation

Codecov / codecov/patch

gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/HttpResourceStorage.java#L149

Added line #L149 was not covered by tests
doneHandler.handle(StatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
});
response.endHandler(event -> doneHandler.handle(response.statusCode()));
Expand Down

0 comments on commit 70bd61b

Please sign in to comment.