Search code examples
wildflywildfly-8

Where to save data in a Wildfly web application


So far I had saved files in the database. I want to go the other way and save media files in the filesystem.

What is the appropriate place to do so and not risking to lose the media file in case of new deployment/update of the application?

I'm using Wildfly 8.2.


Solution

  • I did so.

    0) I set a environment variable pointing to the media directory.

    1) I created a data handler bean that would easily allow to read/write data using the environment variable. This bean also composes the URI path for the resource, in case the front end (GUI) requires to display/deliver data.

    2) For http access and easier security handling I created a servlet pointing to the /media/ path. From there a backing bean invokes the data handler bean and returns it to the front end.

    This way everything is encapsulated and no variable or code is duplicated. Just make sure that you do not employ the media path on two or more servlets e.g. JSF and and the new media servlet.