Created
September 29, 2018 12:48
-
-
Save Charlynux/5d845f966e33bbfef212c2a1db669b3c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Package definition and imports | |
@Controller | |
public class LoggingController { | |
@GetMapping("/") | |
public String readValues(Request request) { | |
String cookieValue = readCookieValue(request); | |
String headerValue = readHeaderValue(request); | |
// Do something with values | |
} | |
private String readCookieValue(Request request) { | |
Cookie[] cookies = request.getCookies(); | |
if (cookies != null) { | |
for (Cookie cookie : cookies) { | |
if (cookie.getName().equals("cookieName")) { | |
return cookie.getValue(); | |
} | |
} | |
} | |
return ""; | |
} | |
private String readHeaderValue(Request request) { | |
String headerValue = request.getHeader("headerName"); | |
if (headerValue == null) { | |
return ""; | |
} else { | |
return headerValue; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Package definition and imports | |
@Controller | |
public class LoggingController { | |
@GetMapping("/") | |
public String readValues( | |
@CookieValue(value = "cookieName", defaultValue = "") cookieName, | |
@RequestHeader(value = "headerName", defaultValue = "") headerName | |
) { | |
// Do something with values | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment