[JBoss Seam] - Reloading ResourceBundle without restarting the server
by mustaghattack
I see few solutions to achieve this :
(1) extend seam's ResourceBundle component to use bundle in database (there is a post in the forum on this)
(2) extend seam's ResourceBundle component and manage resource bundles manually (I mean writing the cache and the load method)
(3) extend seam's ResourceBundle and use the clearCache method of java util's ResourceBundle (since JDK 6)
So far I tried to use the clearCache method but it doesnt work :
| public void updateBundles() {
| java.util.ResourceBundle.clearCache()
| }
|
This method is called from the view. The cache is cleared : when I trace the loadBundle I get different instances of ResourceBundle, but the content doesnt change (of course I change the bundle file between two sessions).
I've done a simple test in a Java Application it works well :
| ResourceBundle rb = ResourceBundle.getBundle("test.bundle.messages");
| System.out.println("rb = " + rb);
| System.out.println("toto = " + rb.getString("toto"));
|
| // get the same instance
| rb = ResourceBundle.getBundle("test.bundle.messages");
| System.out.println("rb without clearing cache = " + rb);
|
| java.util.ResourceBundle.clearCache();
| readLineOnConsole(); // change the bundle content
|
| // get another instance
| rb = ResourceBundle.getBundle("test.bundle.messages");
| System.out.println("rb after clearing cache = " + rb);
| System.out.println("toto = " + rb.getString("toto")); // display the changes
|
Any idea ?
Maybe someone has implemented the 2nd solution ?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4066719#4066719
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4066719
18Â years, 9Â months
[JBoss Seam] - Re: weblets similar fuctionality in seam?
by jbuechel
Thanks for the hint, Norman!
It's quite simple and pretty much that what i was looking for.
Here is some code for interested ones:
| @Startup
| @Scope(ScopeType.APPLICATION)
| @Name("fwcResource")
| @Install(precedence = Install.BUILT_IN)
| @BypassInterceptors
| public class FwcResource extends AbstractResource {
|
| //Has to start with the url-pattern of Seam Resource Servlet mapping in web.xml
| public static final String WEB_RESOURCE_PATH = "/seam/resource/fwc";
| private static final String RESOURCE_PATH = "/fwc";
|
| @Override
| public String getResourcePath() {
|
| return RESOURCE_PATH;
| }
|
| @Override
| public void getResource(HttpServletRequest request,
| HttpServletResponse response) throws ServletException, IOException {
|
| String pathInfo = request.getPathInfo().substring(
| getResourcePath().length());
|
| InputStream in = Resources.getResourceAsStream(
| "/com/test" + pathInfo,
| getServletContext());
|
| if (in != null) {
| byte[] buffer = new byte[1024];
| int read = in.read(buffer);
| while (read != -1) {
| response.getOutputStream().write(buffer, 0, read);
| read = in.read(buffer);
| }
| response.getOutputStream().flush();
| } else {
| response.sendError(HttpServletResponse.SC_NOT_FOUND);
| }
|
| }
|
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4066704#4066704
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4066704
18Â years, 9Â months