class ErrorResponses {

    static Map<String, Object> buildHttpRequestContext(HttpServletRequest req) {
        Map<String, Object> result = new TreeMap<>();

        StringBuilder uriBuilder = new StringBuilder(req.getServletPath());
        if (req.getPathInfo() != null) {
            uriBuilder.append(req.getPathInfo());
        }
        if (req.getQueryString() != null) {
            uriBuilder.append('?').append(req.getQueryString());
        }
        result.put("relativeURI", uriBuilder.toString());
        result.put("method", req.getMethod());

        Enumeration<String> headerIt = req.getHeaderNames();
        while (headerIt.hasMoreElements()) {
            String header = headerIt.nextElement();
            result.put(header, req.getHeader(header));
        }

        return result;
    }

    private  ErrorResponses();

}