diff --git a/packages/java/examples/OwlTestApp/src/main/java/com/readme/example/OwlController.java b/packages/java/examples/OwlTestApp/src/main/java/com/readme/example/OwlController.java index 61d448db7..88cc26d07 100644 --- a/packages/java/examples/OwlTestApp/src/main/java/com/readme/example/OwlController.java +++ b/packages/java/examples/OwlTestApp/src/main/java/com/readme/example/OwlController.java @@ -1,12 +1,12 @@ package com.readme.example; +import com.readme.datatransfer.har.HttpStatus; import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpHeaders; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; +import java.util.*; @RestController public class OwlController { @@ -31,10 +31,21 @@ public Collection getAllOwl() { } @PutMapping("/owl/{owlName}") - public String createOwl(@PathVariable String owlName, @RequestBody String body) { - UUID owlUuid = UUID.randomUUID(); - owlStorage.put(owlUuid.toString(), owlName); - return "Owl " + owlName + " is created with id: " + owlUuid + "\n" + - " Creation request body: \n" + body; + public ResponseEntity createOwl(@PathVariable String owlName, @RequestBody String body) { + UUID birdId = UUID.randomUUID(); + owlStorage.put(birdId.toString(), owlName); + + String responseBody = "Bird " + owlName + " created a bird with id: " + birdId + "\n" + + "Creation request body: \n" + body; + + HttpHeaders headers = new HttpHeaders(); + headers.add("bird-id", birdId.toString()); + headers.add("bird-token", Base64.getEncoder() + .encodeToString(birdId.toString() + .getBytes())); + + return ResponseEntity.status(HttpStatus.CREATED.getCode()) + .headers(headers) + .body(responseBody); } } \ No newline at end of file diff --git a/packages/java/readme-metrics/src/main/java/com/readme/datatransfer/PayloadDataDispatcher.java b/packages/java/readme-metrics/src/main/java/com/readme/datatransfer/PayloadDataDispatcher.java index 26f4e9dda..a1efd6b1c 100644 --- a/packages/java/readme-metrics/src/main/java/com/readme/datatransfer/PayloadDataDispatcher.java +++ b/packages/java/readme-metrics/src/main/java/com/readme/datatransfer/PayloadDataDispatcher.java @@ -17,10 +17,14 @@ public class PayloadDataDispatcher { public void dispatch(PayloadData payloadData) { - LogOptions logOptions = new LogOptions(); //TODO implement LogOptions - - OutgoingLogBody outgoingLogBody = payloadConstructor.construct(payloadData, logOptions); - dataSender.send(Collections.singletonList(outgoingLogBody)); + try { + LogOptions logOptions = new LogOptions(); //TODO implement LogOptions + + OutgoingLogBody outgoingLogBody = payloadConstructor.construct(payloadData, logOptions); + dataSender.send(Collections.singletonList(outgoingLogBody)); + } catch (Exception e) { + log.error("Error occurred on data dispatch phase: {}", e.getMessage()); + } }