@Test public void testBuildOfServerContext() { Map<String, Object> serverContext = ErrorResponses.buildServerContext(); assertThat(serverContext.isEmpty(), is(false)); }
static Map<String, Object> buildServerContext() { Map<String, Object> result = new TreeMap<>(); Optional<String> hostName = NetworkExt.getHostName(); if (hostName.isPresent()) { result.put("hostName", hostName.get()); } Optional<List<String>> localIPs = NetworkExt.getLocalIPs(); if (localIPs.isPresent()) { List<String> nonLoopbackIPs = localIPs.get().stream().filter(ip -> !NetworkExt.isLoopbackIP(ip)).collect(Collectors.toList()); result.put("ipV4", nonLoopbackIPs.stream().filter(ip -> !NetworkExt.isIPv6(ip)).collect(Collectors.toList())); result.put("ipV6", nonLoopbackIPs.stream().filter(NetworkExt::isIPv6).collect(Collectors.toList())); } return result; }
ErrorResponses { static Map<String, Object> buildServerContext() { Map<String, Object> result = new TreeMap<>(); Optional<String> hostName = NetworkExt.getHostName(); if (hostName.isPresent()) { result.put("hostName", hostName.get()); } Optional<List<String>> localIPs = NetworkExt.getLocalIPs(); if (localIPs.isPresent()) { List<String> nonLoopbackIPs = localIPs.get().stream().filter(ip -> !NetworkExt.isLoopbackIP(ip)).collect(Collectors.toList()); result.put("ipV4", nonLoopbackIPs.stream().filter(ip -> !NetworkExt.isIPv6(ip)).collect(Collectors.toList())); result.put("ipV6", nonLoopbackIPs.stream().filter(NetworkExt::isIPv6).collect(Collectors.toList())); } return result; } }
ErrorResponses { static Map<String, Object> buildServerContext() { Map<String, Object> result = new TreeMap<>(); Optional<String> hostName = NetworkExt.getHostName(); if (hostName.isPresent()) { result.put("hostName", hostName.get()); } Optional<List<String>> localIPs = NetworkExt.getLocalIPs(); if (localIPs.isPresent()) { List<String> nonLoopbackIPs = localIPs.get().stream().filter(ip -> !NetworkExt.isLoopbackIP(ip)).collect(Collectors.toList()); result.put("ipV4", nonLoopbackIPs.stream().filter(ip -> !NetworkExt.isIPv6(ip)).collect(Collectors.toList())); result.put("ipV6", nonLoopbackIPs.stream().filter(NetworkExt::isIPv6).collect(Collectors.toList())); } return result; } private  ErrorResponses(); }
ErrorResponses { static Map<String, Object> buildServerContext() { Map<String, Object> result = new TreeMap<>(); Optional<String> hostName = NetworkExt.getHostName(); if (hostName.isPresent()) { result.put("hostName", hostName.get()); } Optional<List<String>> localIPs = NetworkExt.getLocalIPs(); if (localIPs.isPresent()) { List<String> nonLoopbackIPs = localIPs.get().stream().filter(ip -> !NetworkExt.isLoopbackIP(ip)).collect(Collectors.toList()); result.put("ipV4", nonLoopbackIPs.stream().filter(ip -> !NetworkExt.isIPv6(ip)).collect(Collectors.toList())); result.put("ipV6", nonLoopbackIPs.stream().filter(NetworkExt::isIPv6).collect(Collectors.toList())); } return result; } private  ErrorResponses(); static ErrorResponse noRequestBody(HttpServletRequest httpServletRequest); static ErrorResponse badRequest(HttpServletRequest httpServletRequest, String message); static ErrorResponse badRequest(HttpServletRequest httpServletRequest, String message, Exception cause); static ErrorResponse badRequest(HttpServletRequest httpServletRequest, Exception cause); static ErrorResponse internalServerError(HttpServletRequest httpServletRequest, Exception cause); static void sendError(HttpServletResponse httpServletResponse, ErrorResponse.ErrorResponseBuilder errorResponseBuilder); static void sendError(HttpServletResponse httpServletResponse, ErrorResponse errorResponse); static Map<String, Object> buildWebRequestContext(WebRequest webRequest); }
ErrorResponses { static Map<String, Object> buildServerContext() { Map<String, Object> result = new TreeMap<>(); Optional<String> hostName = NetworkExt.getHostName(); if (hostName.isPresent()) { result.put("hostName", hostName.get()); } Optional<List<String>> localIPs = NetworkExt.getLocalIPs(); if (localIPs.isPresent()) { List<String> nonLoopbackIPs = localIPs.get().stream().filter(ip -> !NetworkExt.isLoopbackIP(ip)).collect(Collectors.toList()); result.put("ipV4", nonLoopbackIPs.stream().filter(ip -> !NetworkExt.isIPv6(ip)).collect(Collectors.toList())); result.put("ipV6", nonLoopbackIPs.stream().filter(NetworkExt::isIPv6).collect(Collectors.toList())); } return result; } private  ErrorResponses(); static ErrorResponse noRequestBody(HttpServletRequest httpServletRequest); static ErrorResponse badRequest(HttpServletRequest httpServletRequest, String message); static ErrorResponse badRequest(HttpServletRequest httpServletRequest, String message, Exception cause); static ErrorResponse badRequest(HttpServletRequest httpServletRequest, Exception cause); static ErrorResponse internalServerError(HttpServletRequest httpServletRequest, Exception cause); static void sendError(HttpServletResponse httpServletResponse, ErrorResponse.ErrorResponseBuilder errorResponseBuilder); static void sendError(HttpServletResponse httpServletResponse, ErrorResponse errorResponse); static Map<String, Object> buildWebRequestContext(WebRequest webRequest);  }