@Test public void testThatWeCanRetrieveAllMessagesUsingHeader() throws Exception { Action.ActionResult result = Action.action(new Invocation() { @Override public Result invoke() throws Throwable { return controller.getMessages(null, null); } }) .header(HeaderNames.ACCEPT_LANGUAGE, "en") .invoke(); assertThat(toString(result)).contains("hello"); assertThat(result).hasHeader(HeaderNames.ETAG); final String etagEn = result.getResult().getHeaders().get(HeaderNames.ETAG); result = Action.action(new Invocation() { @Override public Result invoke() throws Throwable { return controller.getMessages(null, null); } }) .header(HeaderNames.ACCEPT_LANGUAGE, "fr") .invoke(); assertThat(toString(result)).contains("bonjour"); assertThat(result).hasHeader(HeaderNames.ETAG); final String etagFr = result.getResult().getHeaders().get(HeaderNames.ETAG); result = Action.action(new Invocation() { @Override public Result invoke() throws Throwable { return controller.getMessages(null, null); } }) .header(HeaderNames.ACCEPT_LANGUAGE, "fr-FR") .invoke(); assertThat(toString(result)).contains("hello"); assertThat(result).hasHeader(HeaderNames.ETAG); final String etagFrFr = result.getResult().getHeaders().get(HeaderNames.ETAG); result = Action.action(new Invocation() { @Override public Result invoke() throws Throwable { return controller.getMessages(null, null); } }) .header(HeaderNames.ACCEPT_LANGUAGE, "fr_FR") .invoke(); assertThat(toString(result)).contains("hello"); assertThat(result).hasHeader(HeaderNames.ETAG); result = Action.action(new Invocation() { @Override public Result invoke() throws Throwable { return controller.getMessages(null, etagEn); } }) .header(HeaderNames.ACCEPT_LANGUAGE, "en") .header(HeaderNames.IF_NONE_MATCH,etagEn) .invoke(); assertThat(result).hasStatus(Status.NOT_MODIFIED); result = Action.action(new Invocation() { @Override public Result invoke() throws Throwable { return controller.getMessages(null, etagFr); } }) .header(HeaderNames.ACCEPT_LANGUAGE, "fr") .header(HeaderNames.IF_NONE_MATCH,etagEn) .invoke(); assertThat(result).hasStatus(Status.NOT_MODIFIED); result = Action.action(new Invocation() { @Override public Result invoke() throws Throwable { return controller.getMessages(null, etagFrFr); } }) .header(HeaderNames.ACCEPT_LANGUAGE, "fr-FR") .header(HeaderNames.IF_NONE_MATCH,etagEn) .invoke(); assertThat(result).hasStatus(Status.NOT_MODIFIED); }
@Route(method = HttpMethod.GET, uri = "i18n") public Result getMessages(@QueryParameter("locales") List<Locale> locales, @HttpParameter(HeaderNames.IF_NONE_MATCH) String ifNoneMatch) { Map<String, String> messages; String etag; StringBuilder builder = new StringBuilder(); if (locales != null && !locales.isEmpty()) { for (Locale locale : locales) { builder.append(service.etag(locale)); } } else { for (Locale locale : context().request().languages()) { builder.append(service.etag(locale)); } } etag = builder.toString(); if (ifNoneMatch != null && ifNoneMatch.equals(etag)) { return new Result(Status.NOT_MODIFIED); } if (locales != null && !locales.isEmpty()) { messages = service.getAllMessages(locales.toArray(new Locale[locales.size()])); } else { messages = service.getAllMessages(context().request().languages()); } if (messages != null) { return ok(messages).with(HeaderNames.ETAG, etag).json(); } else { return notFound().json(); } }
I18nController extends DefaultController { @Route(method = HttpMethod.GET, uri = "i18n") public Result getMessages(@QueryParameter("locales") List<Locale> locales, @HttpParameter(HeaderNames.IF_NONE_MATCH) String ifNoneMatch) { Map<String, String> messages; String etag; StringBuilder builder = new StringBuilder(); if (locales != null && !locales.isEmpty()) { for (Locale locale : locales) { builder.append(service.etag(locale)); } } else { for (Locale locale : context().request().languages()) { builder.append(service.etag(locale)); } } etag = builder.toString(); if (ifNoneMatch != null && ifNoneMatch.equals(etag)) { return new Result(Status.NOT_MODIFIED); } if (locales != null && !locales.isEmpty()) { messages = service.getAllMessages(locales.toArray(new Locale[locales.size()])); } else { messages = service.getAllMessages(context().request().languages()); } if (messages != null) { return ok(messages).with(HeaderNames.ETAG, etag).json(); } else { return notFound().json(); } } }
I18nController extends DefaultController { @Route(method = HttpMethod.GET, uri = "i18n") public Result getMessages(@QueryParameter("locales") List<Locale> locales, @HttpParameter(HeaderNames.IF_NONE_MATCH) String ifNoneMatch) { Map<String, String> messages; String etag; StringBuilder builder = new StringBuilder(); if (locales != null && !locales.isEmpty()) { for (Locale locale : locales) { builder.append(service.etag(locale)); } } else { for (Locale locale : context().request().languages()) { builder.append(service.etag(locale)); } } etag = builder.toString(); if (ifNoneMatch != null && ifNoneMatch.equals(etag)) { return new Result(Status.NOT_MODIFIED); } if (locales != null && !locales.isEmpty()) { messages = service.getAllMessages(locales.toArray(new Locale[locales.size()])); } else { messages = service.getAllMessages(context().request().languages()); } if (messages != null) { return ok(messages).with(HeaderNames.ETAG, etag).json(); } else { return notFound().json(); } }  }
I18nController extends DefaultController { @Route(method = HttpMethod.GET, uri = "i18n") public Result getMessages(@QueryParameter("locales") List<Locale> locales, @HttpParameter(HeaderNames.IF_NONE_MATCH) String ifNoneMatch) { Map<String, String> messages; String etag; StringBuilder builder = new StringBuilder(); if (locales != null && !locales.isEmpty()) { for (Locale locale : locales) { builder.append(service.etag(locale)); } } else { for (Locale locale : context().request().languages()) { builder.append(service.etag(locale)); } } etag = builder.toString(); if (ifNoneMatch != null && ifNoneMatch.equals(etag)) { return new Result(Status.NOT_MODIFIED); } if (locales != null && !locales.isEmpty()) { messages = service.getAllMessages(locales.toArray(new Locale[locales.size()])); } else { messages = service.getAllMessages(context().request().languages()); } if (messages != null) { return ok(messages).with(HeaderNames.ETAG, etag).json(); } else { return notFound().json(); } }  @Route(method = HttpMethod.GET, uri = "i18n/bundles/{file<.+>}.properties") Result getBundleResource(@PathParameter("file") String file,
                                    @HttpParameter(HeaderNames.IF_NONE_MATCH) String ifNoneMatch); @Route(method = HttpMethod.GET, uri = "i18n/bundles/{file<.+>}.json") Result getBundleResourceForI18Next(@QueryParameter("locales") String listOfLocales,
                                              @HttpParameter(HeaderNames.IF_NONE_MATCH) String ifNoneMatch); @Route(method = HttpMethod.GET, uri = "i18n/{key}") Result getMessage(@Parameter("key") String key, @QueryParameter("locale") Locale locale); @Route(method = HttpMethod.GET, uri = "i18n") Result getMessages(@QueryParameter("locales") List<Locale> locales,
                              @HttpParameter(HeaderNames.IF_NONE_MATCH) String ifNoneMatch); }
I18nController extends DefaultController { @Route(method = HttpMethod.GET, uri = "i18n") public Result getMessages(@QueryParameter("locales") List<Locale> locales, @HttpParameter(HeaderNames.IF_NONE_MATCH) String ifNoneMatch) { Map<String, String> messages; String etag; StringBuilder builder = new StringBuilder(); if (locales != null && !locales.isEmpty()) { for (Locale locale : locales) { builder.append(service.etag(locale)); } } else { for (Locale locale : context().request().languages()) { builder.append(service.etag(locale)); } } etag = builder.toString(); if (ifNoneMatch != null && ifNoneMatch.equals(etag)) { return new Result(Status.NOT_MODIFIED); } if (locales != null && !locales.isEmpty()) { messages = service.getAllMessages(locales.toArray(new Locale[locales.size()])); } else { messages = service.getAllMessages(context().request().languages()); } if (messages != null) { return ok(messages).with(HeaderNames.ETAG, etag).json(); } else { return notFound().json(); } }  @Route(method = HttpMethod.GET, uri = "i18n/bundles/{file<.+>}.properties") Result getBundleResource(@PathParameter("file") String file,
                                    @HttpParameter(HeaderNames.IF_NONE_MATCH) String ifNoneMatch); @Route(method = HttpMethod.GET, uri = "i18n/bundles/{file<.+>}.json") Result getBundleResourceForI18Next(@QueryParameter("locales") String listOfLocales,
                                              @HttpParameter(HeaderNames.IF_NONE_MATCH) String ifNoneMatch); @Route(method = HttpMethod.GET, uri = "i18n/{key}") Result getMessage(@Parameter("key") String key, @QueryParameter("locale") Locale locale); @Route(method = HttpMethod.GET, uri = "i18n") Result getMessages(@QueryParameter("locales") List<Locale> locales,
                              @HttpParameter(HeaderNames.IF_NONE_MATCH) String ifNoneMatch);  }