1+ package com .owl .example ;
2+
3+ import com .readme .core .datatransfer .har .HttpStatus ;
4+ import org .springframework .http .HttpHeaders ;
5+ import org .springframework .http .MediaType ;
6+ import org .springframework .http .ResponseEntity ;
7+ import org .springframework .web .bind .annotation .*;
8+
9+ import java .util .*;
10+
11+ /**
12+ * OwlController is a sample REST controller intended for demonstration and testing purposes.
13+ * <p>
14+ * It simulates typical HTTP requests and responses to showcase how the ReadMe Metrics SDK
15+ * integrates into a Spring Boot application.
16+ * <p>
17+ * This controller is not intended for production use and serves only as an example endpoint
18+ * to test how the SDK logs and processes different request types.
19+ */
20+ @ RestController
21+ public class OwlController {
22+
23+ private final Map <String , String > owlStorage = new HashMap <>();
24+
25+ public OwlController () {
26+ owlStorage .put ("1" , "Default Owl" );
27+ }
28+
29+ @ GetMapping ("/owl/{id}" )
30+ public String getOwlById (@ PathVariable String id ) {
31+ return "Owl with id " + id ;
32+ }
33+
34+ @ GetMapping ("/owls" )
35+ public Collection <String > getAllOwl () {
36+ return owlStorage .values ();
37+ }
38+
39+ @ PutMapping ("/owl/{owlName}" )
40+ public ResponseEntity <String > createOwl (@ PathVariable String owlName , @ RequestBody String body ) {
41+ UUID birdId = UUID .randomUUID ();
42+ owlStorage .put (birdId .toString (), owlName );
43+
44+ String responseBody = "Bird " + owlName + " created a bird with id: " + birdId + "\n " +
45+ "Creation request body: \n " + body ;
46+
47+ HttpHeaders headers = new HttpHeaders ();
48+ headers .add ("bird-id" , birdId .toString ());
49+ headers .add ("bird-token" , Base64 .getEncoder ()
50+ .encodeToString (birdId .toString ()
51+ .getBytes ()));
52+
53+ return ResponseEntity .status (HttpStatus .CREATED .getCode ())
54+ .headers (headers )
55+ .body (responseBody );
56+ }
57+
58+ @ PutMapping (value = "/owl/urlencoded/{owlName}" , consumes = MediaType .APPLICATION_FORM_URLENCODED_VALUE )
59+ public ResponseEntity <String > createOwlUrlencoded (@ RequestParam Map <String , String > params ) {
60+ UUID birdId = UUID .randomUUID ();
61+
62+ String responseBody = "Created a bird with id: " + birdId + "\n " +
63+ "Creation request urlencoded body: \n " + params ;
64+
65+ HttpHeaders headers = new HttpHeaders ();
66+ headers .add ("bird-id" , birdId .toString ());
67+ headers .add ("bird-token" , Base64 .getEncoder ()
68+ .encodeToString (birdId .toString ()
69+ .getBytes ()));
70+
71+ return ResponseEntity .status (HttpStatus .CREATED .getCode ())
72+ .headers (headers )
73+ .body (responseBody );
74+ }
75+
76+ }
0 commit comments