The character restrictions will vary depending on the final store, different files systems have different restrictions. So encoding the message id to a safe file name should be left up to the servlet managing that file system.
I would keep the RestServlet as a generic file storage tool. Filename rewriting could be done with a servlet filter or extending RestServlet?
