class LocalizationBundleJaxrsService {

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public Response getBundles(@QueryParam(RestConstants.QUERY_PARAM_EXPANDED) Boolean expanded,
                               @Context HttpHeaders headers, @Context Request request, @Context HttpServletRequest httpRequest) {
        if (httpRequest != null && expanded == null) {
            Map<String, String[]> forwardedParameters = (Map<String, String[]>)httpRequest
                    .getAttribute(FORWARDED_PARAMETERS);
            if (forwardedParameters != null && forwardedParameters.get(RestConstants.QUERY_PARAM_EXPANDED) != null) {
                expanded = Boolean.valueOf(forwardedParameters.get(RestConstants.QUERY_PARAM_EXPANDED)[0]);
            }
        }
        if (Boolean.TRUE.equals(expanded)) {
            Locale locale = headers.getAcceptableLanguages().get(0);

            ObjectNode json = JsonNodeFactory.instance.objectNode();
            for (String currentBundle : bundleNames) {
                final Map<String, String> messages = messageSource.getAllMessagesForBaseName(currentBundle, locale);
                ObjectNode currentMessages = JsonNodeFactory.instance.objectNode();
                for (String key : messages.keySet()) {
                    currentMessages.put(key, messages.get(key));
                }
                json.put(currentBundle, currentMessages);
            }

            EntityTag etag = generateETag(json);
            Response.ResponseBuilder response = request.evaluatePreconditions(etag);

            if (response == null) {
                response = Response.ok(json).tag(etag);
            }

            return response.build();
        } else {
            return Response.ok(bundleNames).build();
        }
    }

}