Skip to content

Commit

Permalink
Merge pull request #540 from SDCISA-13736-FixBadHabits-EventBusResour…
Browse files Browse the repository at this point in the history
…ceStorage
  • Loading branch information
hiddenalpha authored Jan 5, 2024
2 parents 23b8cfc + 4c5dd5f commit 85005c2
Showing 1 changed file with 10 additions and 6 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()));
// 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");
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()));
// 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()));
// Would be best to stop processing now. But we don't to keep backward
// compatibility (Will run into NPE anyway).
}
Expand Down

0 comments on commit 85005c2

Please sign in to comment.