File tree Expand file tree Collapse file tree
src/main/java/io/github/devopsws/demo/service Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,3 +17,10 @@ items:
1717 api : /lower?text=Hello
1818 expect :
1919 body : hello
20+
21+ # # Cookies
22+ - name : no-cookie
23+ request :
24+ api : /cookies/echo
25+ expect :
26+ body : cookies are empty
Original file line number Diff line number Diff line change 1+ package io .github .devopsws .demo .service ;
2+
3+ import org .springframework .web .bind .annotation .GetMapping ;
4+ import org .springframework .web .bind .annotation .RequestMapping ;
5+ import org .springframework .web .bind .annotation .RestController ;
6+ import jakarta .servlet .http .Cookie ;
7+ import jakarta .servlet .http .HttpServletRequest ;
8+
9+ @ RestController
10+ @ RequestMapping ("/cookies" )
11+ public class CookieService {
12+ @ GetMapping ("/echo" )
13+ public String cookie (HttpServletRequest request , String name ) {
14+ Cookie [] cookies = request .getCookies ();
15+ if (cookies == null ) {
16+ return "cookies are empty" ;
17+ }
18+
19+ for (int i = 0 ; i < cookies .length ; i ++) {
20+ if (cookies [i ].getName ().equals (name )) {
21+ return cookies [i ].getValue ();
22+ }
23+ }
24+
25+ return "not found" ;
26+ }
27+ }
Original file line number Diff line number Diff line change 44import org .springframework .web .bind .annotation .RestController ;
55
66@ RestController
7- public class Health {
7+ public class HealthService {
88 @ GetMapping ("/health" )
99 public String health () {
1010 return "OK" ;
You can’t perform that action at this time.
0 commit comments