package flex.messaging; import javax.servlet.ServletConfig; import java.io.File; import java.io.IOException; /** * @author Ivan Latysh * * @since 9-May-2008 1:59:23 PM */ public class MyMessageBrokerServlet extends MessageBrokerServlet{ protected String getFlexWritePath(ServletConfig servletConfig) throws IllegalArgumentException, IOException{ String DEFAULT_WRITE_PATH = "WEB-INF/flex"; File writePath = null; // sanity check if (servletConfig == null) throw new IllegalArgumentException("Given servlet config is null"); // get write path String flexWritePathString = servletConfig.getInitParameter("flex.write.path"); // use default value if (null==flexWritePathString) { // report servletConfig.getServletContext().log("`flex.write.path` has not been specified, will use {"+DEFAULT_WRITE_PATH+"}"); flexWritePathString = DEFAULT_WRITE_PATH; } // get application home File applicationHome = new File(servletConfig.getServletContext().getRealPath("/")); // consult with security manager if (null!=System.getSecurityManager()) { try { System.getSecurityManager().checkRead(applicationHome.getAbsolutePath()); } catch (Exception e) { // report servletConfig.getServletContext().log("Current security configuration deny READ access to {"+applicationHome.getAbsolutePath()+"}", e); // break here throw new IOException("READ access has been denied to application home directory {"+applicationHome.getAbsolutePath()+"}", e); } } // construct write path writePath = new File(applicationHome, flexWritePathString); // consult with security manager if (null!=System.getSecurityManager()) { try { System.getSecurityManager().checkWrite(writePath.getAbsolutePath()); } catch (Exception e) { // report servletConfig.getServletContext().log("Current security configuration deny WRITE access to {"+writePath.getAbsolutePath()+"}", e); // add stack trace e.printStackTrace(); // break here throw new IOException("WRITE access has been denied to {"+writePath.getAbsolutePath()+"}", e); } } // return write path return writePath.getAbsolutePath(); } }