From 0737c7d3a79e2c27459deb19974117d8f73e2e6e Mon Sep 17 00:00:00 2001 From: Cleverson Sacramento Date: Mon, 15 Sep 2014 14:43:13 -0300 Subject: [PATCH] Atualização do arquétipo html-rest com cache e gzip --- archetype/html-rest/src/main/resources/archetype-resources/src/main/resources/messages.properties | 1 + archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/beans.xml | 1 + archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml | 30 ++++++++++++++++++++++++++++++ archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/bookmark-edit.html | 39 ++++++++++++++++++++++----------------- archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/bookmark-list.html | 26 ++++++++++++++++---------- archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/fonts/glyphicons-halflings-regular.woff | Bin 41721 -> 0 bytes archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/home.html | 26 ++++++++++++++++---------- archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/index.html | 8 ++++---- archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/controller/bookmark-edit.js | 22 ++++++++++++---------- archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/controller/bookmark-list.js | 19 ++++++++++++------- archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/controller/home.js | 4 +++- archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/controller/login.js | 8 ++++++-- archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/controller/menu.js | 6 +----- archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/lib/app.js | 5 ++--- archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/proxy/auth.js | 5 ++--- archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/proxy/bookmark.js | 17 ++++++++--------- archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/proxy/metadata.js | 25 +++++++++++++++++++++++++ archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/login.html | 26 ++++++++++++++++---------- archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/menu.html | 50 +++++++++++++++++++++++--------------------------- impl/core/src/main/java/br/gov/frameworkdemoiselle/util/Metadata.java | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ impl/core/src/main/resources/demoiselle-core-bundle.properties | 1 + impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/MetadataREST.java | 46 ++++++++++++++++++++++++++++++++++++++++++++++ impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/util/Cache.java | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/util/CacheInterceptor.java | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/util/ValidatePayloadInterceptor.java | 2 +- 25 files changed, 420 insertions(+), 119 deletions(-) create mode 100644 archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/proxy/metadata.js create mode 100644 impl/core/src/main/java/br/gov/frameworkdemoiselle/util/Metadata.java create mode 100644 impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/MetadataREST.java create mode 100644 impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/util/Cache.java create mode 100644 impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/util/CacheInterceptor.java diff --git a/archetype/html-rest/src/main/resources/archetype-resources/src/main/resources/messages.properties b/archetype/html-rest/src/main/resources/archetype-resources/src/main/resources/messages.properties index e69de29..71dfb33 100644 --- a/archetype/html-rest/src/main/resources/archetype-resources/src/main/resources/messages.properties +++ b/archetype/html-rest/src/main/resources/archetype-resources/src/main/resources/messages.properties @@ -0,0 +1 @@ +application.version=${project.version} diff --git a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/beans.xml b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/beans.xml index 23ff258..bac8fa5 100644 --- a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/beans.xml +++ b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/beans.xml @@ -8,6 +8,7 @@ br.gov.frameworkdemoiselle.util.ValidatePayloadInterceptor br.gov.frameworkdemoiselle.transaction.TransactionalInterceptor br.gov.frameworkdemoiselle.exception.ExceptionHandlerInterceptor + br.gov.frameworkdemoiselle.util.CacheInterceptor diff --git a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml index a9a4c49..aeb7006 100644 --- a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml +++ b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml @@ -25,4 +25,34 @@ --> + + Cache Filter + br.gov.frameworkdemoiselle.util.CacheFilter + + value + max-age=9223372036854775807,public + + + + Cache Filter + *.js + *.html + *.html?* + *.css + *.png + *.svg + *.ttf + *.woff + /api/metadata/* + + + + GZip Filter + org.tuckey.web.filters.urlrewrite.gzip.GzipFilter + + + GZip Filter + /* + + diff --git a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/bookmark-edit.html b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/bookmark-edit.html index f4294a0..d3b8134 100644 --- a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/bookmark-edit.html +++ b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/bookmark-edit.html @@ -1,13 +1,15 @@ + - - - - Bookmark Edit - - + + + +Bookmark Edit + + +
@@ -33,14 +35,17 @@
-

Aplicação de exemplo do Demoiselle 2.5.0

- - - - - - - - - - \ No newline at end of file +

+ Aplicação de exemplo do Demoiselle + + + + + + + + + + + + diff --git a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/bookmark-list.html b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/bookmark-list.html index 83179de..5e34a65 100644 --- a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/bookmark-list.html +++ b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/bookmark-list.html @@ -1,14 +1,16 @@ + - - - - Bookmark List - - - + + + +Bookmark List + + + +

@@ -16,7 +18,7 @@

- +
@@ -26,16 +28,20 @@
-

Aplicação de exemplo do Demoiselle 2.5.0

+

+ Aplicação de exemplo do Demoiselle +

+ + - \ No newline at end of file + diff --git a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/fonts/glyphicons-halflings-regular.woff b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/fonts/glyphicons-halflings-regular.woff index f7daa01..1a1e03c 100644 Binary files a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/fonts/glyphicons-halflings-regular.woff and b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/fonts/glyphicons-halflings-regular.woff differ diff --git a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/home.html b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/home.html index ae1f73c..acd18bc 100644 --- a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/home.html +++ b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/home.html @@ -1,30 +1,36 @@ + - - - - Bookmark - - + + + +Bookmark + + +

- Bem-vindo à aplicação de exemplo Bookmark usando arquétipo html-rest.
- Este é o seu ponto de partida, portanto sinta-se à vontade para modificar esta aplicação. + Bem-vindo à aplicação de exemplo Bookmark usando arquétipo html-rest.
Este é o seu ponto de partida, portanto sinta-se à vontade para + modificar esta aplicação.

-

Aplicação de exemplo do Demoiselle 2.5.0

+

+ Aplicação de exemplo do Demoiselle +

+ + - \ No newline at end of file + diff --git a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/index.html b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/index.html index ae29ef0..e30dfa5 100644 --- a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/index.html +++ b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/index.html @@ -1,5 +1,5 @@ - - - - \ No newline at end of file + + + + diff --git a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/controller/bookmark-edit.js b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/controller/bookmark-edit.js index 3db9695..a47ac58 100644 --- a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/controller/bookmark-edit.js +++ b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/controller/bookmark-edit.js @@ -1,9 +1,11 @@ $(function() { - $("#delete").hide(); - $("#description").focus(); + MetadataProxy.getDemoiselleVersion().done(function(data) { + $("#demoiselle-version").html(data); + }); + $(document).ready(function() { if (id = $.url().param('id')) { BookmarkProxy.load(id).done(loadOk).fail(loadFailed); @@ -15,24 +17,24 @@ $(function() { }); $("#save").click(function() { - var form = { + var data = { description : $("#description").val(), link : $("#link").val() }; if (id = $("#id").val()) { - BookmarkProxy.update(id, form).done(saveOk).fail(saveFailed); + BookmarkProxy.update(id, data).done(saveOk).fail(saveFailed); } else { - BookmarkProxy.insert(form).done(saveOk).fail(saveFailed); + BookmarkProxy.insert(data).done(saveOk).fail(saveFailed); } }); $("#delete").click(function() { bootbox.confirm("Tem certeza que deseja apagar?", function(result) { - if(result) { - BookmarkProxy.remove([$("#id").val()]).done(removeOk); + if (result) { + BookmarkProxy.remove([ $("#id").val() ]).done(removeOk); } - }); + }); }); $("#back").click(function() { @@ -52,7 +54,7 @@ function loadOk(data) { function loadFailed(request) { switch (request.status) { case 404: - bootbox.alert("Você está tentando acessar um registro inexistente!", function(){ + bootbox.alert("Você está tentando acessar um registro inexistente!", function() { location.href = "bookmark-list.html"; }); break; @@ -96,4 +98,4 @@ function saveFailed(request) { function removeOk(data) { location.href = 'bookmark-list.html'; -} \ No newline at end of file +} diff --git a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/controller/bookmark-list.js b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/controller/bookmark-list.js index 211437b..2fd5b61 100644 --- a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/controller/bookmark-list.js +++ b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/controller/bookmark-list.js @@ -1,7 +1,10 @@ $(function() { - $("#new").focus(); + MetadataProxy.getDemoiselleVersion().done(function(data) { + $("#demoiselle-version").html(data); + }); + $(document).ready(function() { BookmarkProxy.findAll().done(findAllOk); }); @@ -22,19 +25,21 @@ $(function() { }); if (ids.length == 0) { - bootbox.alert({message: "Nenhum registro selecionado"}); + bootbox.alert({ + message : "Nenhum registro selecionado" + }); } else { bootbox.confirm("Tem certeza que deseja apagar?", function(result) { - if(result) { + if (result) { BookmarkProxy.remove(ids).done(removeOk); } - }); + }); } }); }); function findAllOk(data) { - var oTable = $('#resultList').dataTable({ + $('#resultList').dataTable({ "aoColumns" : [ { "aTargets" : [ 0 ], "mDataProp" : "id", @@ -70,10 +75,10 @@ function findAllOk(data) { "bDestroy" : true, "sPaginationType" : "bs_full", "aaData" : data, - "bSort" : false + "bSort" : true }); } function removeOk() { BookmarkProxy.findAll().done(findAllOk); -} \ No newline at end of file +} diff --git a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/controller/home.js b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/controller/home.js index eae289a..fc24a5d 100644 --- a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/controller/home.js +++ b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/controller/home.js @@ -1,3 +1,5 @@ $(function() { - + MetadataProxy.getDemoiselleVersion().done(function(data) { + $("#demoiselle-version").html(data); + }); }); diff --git a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/controller/login.js b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/controller/login.js index a3bdbc6..48ffd40 100644 --- a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/controller/login.js +++ b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/controller/login.js @@ -1,17 +1,21 @@ $(function() { $("#username").focus(); + MetadataProxy.getDemoiselleVersion().done(function(data) { + $("#demoiselle-version").html(data); + }); + $("form").submit(function(event) { event.preventDefault(); $("[id$='-message']").hide(); - var form = { + var data = { 'username' : $("#username").val().trim(), 'password' : $("#password").val().trim() }; - AuthProxy.login(form).done(loginOk).fail(loginFail); + AuthProxy.login(data).done(loginOk).fail(loginFail); }); }); diff --git a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/controller/menu.js b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/controller/menu.js index 04f3e8e..c607049 100644 --- a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/controller/menu.js +++ b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/controller/menu.js @@ -1,18 +1,14 @@ $(function() { - $("#menu").load("menu.html", function() { - AuthProxy.getUser().done(getUserOk); $("#logout").on("click", function() { App.removeToken(); location.href = "login.html"; }); - }); - }); function getUserOk(data) { $("#username").html(data.username); -} \ No newline at end of file +} diff --git a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/lib/app.js b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/lib/app.js index 66a9760..d32e07f 100644 --- a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/lib/app.js +++ b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/lib/app.js @@ -2,7 +2,7 @@ $.ajaxSetup({ error : function(request) { switch (request.status) { case 401: - bootbox.alert("Você não está autenticado!", function(){ + bootbox.alert("Você não está autenticado!", function() { location.href = "login.html"; }); break; @@ -25,5 +25,4 @@ var App = { removeToken : function() { sessionStorage.removeItem(this.tokenKey); } - -} +}; diff --git a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/proxy/auth.js b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/proxy/auth.js index fc94e1c..59f3f57 100644 --- a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/proxy/auth.js +++ b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/proxy/auth.js @@ -8,7 +8,7 @@ var AuthProxy = { type : "POST", data : JSON.stringify($credentials), contentType : "application/json", - error: function(){ } + error : function() {} }); }, @@ -31,5 +31,4 @@ var AuthProxy = { } }); } - -} \ No newline at end of file +}; diff --git a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/proxy/bookmark.js b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/proxy/bookmark.js index 32d0068..87c5b5b 100644 --- a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/proxy/bookmark.js +++ b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/proxy/bookmark.js @@ -1,7 +1,7 @@ var BookmarkProxy = { - + url : "api/bookmark", - + findAll : function() { return $.ajax({ type : "GET", @@ -11,7 +11,7 @@ var BookmarkProxy = { } }); }, - + load : function($id) { return $.ajax({ type : "GET", @@ -21,12 +21,12 @@ var BookmarkProxy = { } }); }, - - insert : function($form) { + + insert : function($data) { return $.ajax({ type : "POST", url : this.url, - data : JSON.stringify($form), + data : JSON.stringify($data), contentType : "application/json", beforeSend : function(request) { request.setRequestHeader("Authorization", App.getToken()); @@ -45,7 +45,7 @@ var BookmarkProxy = { } }); }, - + remove : function($ids) { return $.ajax({ type : "DELETE", @@ -57,5 +57,4 @@ var BookmarkProxy = { } }); } - -} \ No newline at end of file +}; diff --git a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/proxy/metadata.js b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/proxy/metadata.js new file mode 100644 index 0000000..eb3d61b --- /dev/null +++ b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/proxy/metadata.js @@ -0,0 +1,25 @@ +var MetadataProxy = { + + url : "api/metadata", + + getVersion : function() { + return $.ajax({ + type : "GET", + url : this.url + "/version" + }); + }, + + getMessage : function($key) { + return $.ajax({ + type : "GET", + url : this.url + "/message/" + $key + }); + }, + + getDemoiselleVersion : function() { + return $.ajax({ + type : "GET", + url : this.url + "/demoiselle/version" + }); + } +}; diff --git a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/login.html b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/login.html index d0c64be..c43416e 100644 --- a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/login.html +++ b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/login.html @@ -1,16 +1,18 @@ - - - - - Bookmark - - + + + + + +Bookmark + + +
-
+

Bookmark | Login

@@ -38,12 +40,16 @@
-

Aplicação de exemplo do Demoiselle 2.5.0

+

+ Aplicação de exemplo do Demoiselle +

+ + - \ No newline at end of file + diff --git a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/menu.html b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/menu.html index b681804..93a168a 100644 --- a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/menu.html +++ b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/menu.html @@ -1,28 +1,24 @@ \ No newline at end of file +
+ + +
+ diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/util/Metadata.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/util/Metadata.java new file mode 100644 index 0000000..f5bfad5 --- /dev/null +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/util/Metadata.java @@ -0,0 +1,48 @@ +/* + * Demoiselle Framework + * Copyright (C) 2010 SERPRO + * ---------------------------------------------------------------------------- + * This file is part of Demoiselle Framework. + * + * Demoiselle Framework is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License version 3 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 + * along with this program; if not, see + * or write to the Free Software Foundation, Inc., 51 Franklin Street, + * Fifth Floor, Boston, MA 02110-1301, USA. + * ---------------------------------------------------------------------------- + * Este arquivo é parte do Framework Demoiselle. + * + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação + * do Software Livre (FSF). + * + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português + * para maiores detalhes. + * + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título + * "LICENCA.txt", junto com esse programa. Se não, acesse + * ou escreva para a Fundação do Software Livre (FSF) Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. + */ +package br.gov.frameworkdemoiselle.util; + +public final class Metadata { + + private Metadata() { + } + + public static String getVersion() { + ResourceBundle bundle = Beans.getReference(ResourceBundle.class, new NameQualifier("demoiselle-core-bundle")); + return bundle.getString("version"); + } +} diff --git a/impl/core/src/main/resources/demoiselle-core-bundle.properties b/impl/core/src/main/resources/demoiselle-core-bundle.properties index b8625ef..9f371a4 100644 --- a/impl/core/src/main/resources/demoiselle-core-bundle.properties +++ b/impl/core/src/main/resources/demoiselle-core-bundle.properties @@ -33,6 +33,7 @@ # ou escreva para a Fundação do Software Livre (FSF) Inc., # 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. +version=${project.version} engine-on=Iniciando o Demoiselle Framework ${project.version} resource-not-found=Arquivo {0} n\u00E3o foi encontrado key-not-found=A chave {0} n\u00E3o foi encontrada diff --git a/impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/MetadataREST.java b/impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/MetadataREST.java new file mode 100644 index 0000000..7201d13 --- /dev/null +++ b/impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/MetadataREST.java @@ -0,0 +1,46 @@ +package br.gov.frameworkdemoiselle.internal.implementation; + +import static javax.ws.rs.core.MediaType.TEXT_HTML; + +import java.util.ResourceBundle; + +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; + +import br.gov.frameworkdemoiselle.NotFoundException; +import br.gov.frameworkdemoiselle.util.Metadata; + +@Path("metadata") +public class MetadataREST { + + @Inject + private ResourceBundle bundle; + + @GET + @Path("demoiselle/version") + @Produces("text/plain") + public String getDemoiselleVersion() { + return Metadata.getVersion(); + } + + @GET + @Path("version") + @Produces("text/plain") + public String getAppVersion() { + return bundle.getString("application.version"); + } + + @GET + @Path("message/{key}") + @Produces(TEXT_HTML) + public String getMessage(@PathParam("key") String key) throws Exception { + if (!bundle.containsKey(key)) { + throw new NotFoundException(); + } + + return bundle.getString(key); + } +} diff --git a/impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/util/Cache.java b/impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/util/Cache.java new file mode 100644 index 0000000..0230b45 --- /dev/null +++ b/impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/util/Cache.java @@ -0,0 +1,58 @@ +/* + * Demoiselle Framework + * Copyright (C) 2010 SERPRO + * ---------------------------------------------------------------------------- + * This file is part of Demoiselle Framework. + * + * Demoiselle Framework is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License version 3 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 + * along with this program; if not, see + * or write to the Free Software Foundation, Inc., 51 Franklin Street, + * Fifth Floor, Boston, MA 02110-1301, USA. + * ---------------------------------------------------------------------------- + * Este arquivo é parte do Framework Demoiselle. + * + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação + * do Software Livre (FSF). + * + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português + * para maiores detalhes. + * + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título + * "LICENCA.txt", junto com esse programa. Se não, acesse + * ou escreva para a Fundação do Software Livre (FSF) Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. + */ +package br.gov.frameworkdemoiselle.util; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import javax.enterprise.util.Nonbinding; +import javax.interceptor.InterceptorBinding; + +@Inherited +@InterceptorBinding +@Target({ METHOD, TYPE }) +@Retention(RUNTIME) +public @interface Cache { + + @Nonbinding + String value(); +} diff --git a/impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/util/CacheInterceptor.java b/impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/util/CacheInterceptor.java new file mode 100644 index 0000000..8f4b7d5 --- /dev/null +++ b/impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/util/CacheInterceptor.java @@ -0,0 +1,66 @@ +/* + * Demoiselle Framework + * Copyright (C) 2010 SERPRO + * ---------------------------------------------------------------------------- + * This file is part of Demoiselle Framework. + * + * Demoiselle Framework is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License version 3 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 + * along with this program; if not, see + * or write to the Free Software Foundation, Inc., 51 Franklin Street, + * Fifth Floor, Boston, MA 02110-1301, USA. + * ---------------------------------------------------------------------------- + * Este arquivo é parte do Framework Demoiselle. + * + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação + * do Software Livre (FSF). + * + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português + * para maiores detalhes. + * + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título + * "LICENCA.txt", junto com esse programa. Se não, acesse + * ou escreva para a Fundação do Software Livre (FSF) Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. + */ +package br.gov.frameworkdemoiselle.util; + +import java.io.Serializable; + +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; +import javax.servlet.http.HttpServletResponse; + +/** + * Intercepts calls with {@code @ValidatePayload} annotations. + * + * @author SERPRO + */ +@Interceptor +@Cache(value = "") +public class CacheInterceptor implements Serializable { + + private static final long serialVersionUID = 1L; + + @AroundInvoke + public Object manage(final InvocationContext ic) throws Exception { + Object result = ic.proceed(); + + HttpServletResponse response = Beans.getReference(HttpServletResponse.class); + response.setHeader("Cache-Control", ic.getMethod().getAnnotation(Cache.class).value()); + + return result; + } +} diff --git a/impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/util/ValidatePayloadInterceptor.java b/impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/util/ValidatePayloadInterceptor.java index 9351b81..7652c0a 100644 --- a/impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/util/ValidatePayloadInterceptor.java +++ b/impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/util/ValidatePayloadInterceptor.java @@ -54,8 +54,8 @@ import javax.validation.ValidatorFactory; * * @author SERPRO */ -@ValidatePayload @Interceptor +@ValidatePayload public class ValidatePayloadInterceptor implements Serializable { private static final long serialVersionUID = 1L; -- libgit2 0.21.2