Skip to content

Commit

Permalink
changes to example app, error handling on PayloadDispatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
serhii-vydiuk-kevychsolutions committed Jan 2, 2025
1 parent 926d133 commit ae48f93
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -31,10 +31,21 @@ public Collection<String> 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<String> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}


Expand Down

0 comments on commit ae48f93

Please sign in to comment.