6 Replies Latest reply on Jun 30, 2013 8:44 PM by Stephen Coy

    Unable to locate .xml file on /WEB-INF/ folder

    Bruno Lacerda Newbie

      Hi,

       

      I'm migrating an application from JBoss AS 4 to JBoss EAP 6 but i'm getting some probelms on load struts 1 configuration files located on /WEB-INF/ folder.

       

      There is a plugin configuration on struts-config.xml file that defines the location os these files as follow:

       

      <plug-in className="br.com.validatorcustomized.struts.plugins.formatter.FormatterPlugIn">

          <set-property property="pathnames" value="/WEB-INF/formatter-rules.xml, /WEB-INF/formatter.xml" />

      </plug-in>

       

      The exception on Startup is:

      javax.servlet.UnavailableException: Cannot load a formatter resource from '/WEB-INF/formatter-rules.xml, /WEB-INF/formatter.xml'.

       

      The files exists on /WEB-INF/ folder and if I change the name of the files to a name of a file that does not exist, the error is the same.

       

      Any help will be appreciated.

       

      Thanks in advance.

        • 1. Re: Unable to locate .xml file on /WEB-INF/ folder
          Stephen Coy Master

          Your FormatterPlugin is broken. It worked on JBoss AS 4 because that version of JBossAS had a very liberal view of what parts of the application should be made available on the classpath.

           

          You should update your plugin to use javax.servlet.ServletContext#getResourceAsStream(java.lang.String) to load it's configuration files.

          • 2. Re: Unable to locate .xml file on /WEB-INF/ folder
            Bruno Lacerda Newbie

            Hi Stephen, thanks for the reply.

             

            I was alocated in another client si it took me to respond.

             

            We use two struts plugins, the first

             

            1 -

             


            <plug-in className="org.apache.struts.validator.ValidatorPlugIn">

            <set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>

            </plug-in>

             

            2 -


            <plug-in className="br.com.validatorcustomized.struts.plugins.formatter.FormatterPlugIn">

            set-property property="pathnames" value="/WEB-INF/formatter-rules.xml, /WEB-INF/formatter.xml" />

            </plug-in>

             

            The first problem is that the br.com.validatorcustomized.struts.plugins.formatter.FormatterPlugIn cannot load the .xml files as I told before.

            If I put the org.apache.struts.validator.ValidatorPlugIn to read this same files it works, but rise another problem, the /WEB-INF/dtds/formatter_1_0.dtd files defined on the .xml files cannot be located.

             

            <?xml version="1.0" encoding="iso-8859-1"?>

            <!DOCTYPE form-formatter PUBLIC

                 "-//Validator - Formatter.//DTD Struts Plugins Formatter Rules Configuration 1.0//EN"

                       "/WEB-INF/dtds/formatter_1_0.dtd" >

             

            If I put the full path to the .dtd file (file:///C:/path/to/webapp/WEB-INF/dtds/formatter_1_0.dtd) the problem is solved but this solution is not portabble.

             

             

            This FormatterPlugin is a Thirdparty class and I don't have the source code.

            I decompile the FormatterPlugin.class and saw that the plugin is doing exactly what you told using the org.apache.struts.action.ActionServlet class as you can see below.

             

                public void init(ActionServlet servlet, ModuleConfig config)

                    throws ServletException

                {

                    moduleConfig = config;

                    this.servlet = servlet;

                    try

                    {

                        initResources();

                        servlet.getServletContext().setAttribute((new StringBuilder("br.com.validatorcustomized.struts.plugins.formatter.FORMATTER_RESOURCES")).append(config.getPrefix()).toString(), resources);

                    }

                    catch(Exception ex)

                    {

                        log.error(ex.getMessage(), ex);

                        throw new UnavailableException((new StringBuilder("Cannot load a formatter resource from '")).append(pathnames).append("'.").toString());

                    }

                }

             

               private void initResources()

                    throws IOException, ServletException

                {

                    StringTokenizer st;

                    List streamList;

                    st = new StringTokenizer(pathnames, ",");

                    streamList = new ArrayList();

                    try

                    {

                        while(st.hasMoreTokens())

                        {

                            String formatterRules = st.nextToken().trim();

                            if(log.isInfoEnabled())

                                log.info((new StringBuilder("Loading formatter rules file from '")).append(formatterRules).append("'.").toString());

             

                             // org.apache.struts.action.ActionServlet.getServletContext().getResourceAsStream(formatterRules);

                            InputStream input = servlet.getServletContext().getResourceAsStream(formatterRules);  // The error goes here.

             

                            if(input != null)

                                streamList.add(new BufferedInputStream(input));

                            else

                                throw new ServletException((new StringBuilder("Skipping formatter rules file from '")).append(formatterRules).append("'.  No stream could be opened.").toString());

                        }

                        int streamIndex = 0;

                        InputStream streamArray[] = new InputStream[streamList.size()];

                        for(Iterator streamIterator = streamList.iterator(); streamIterator.hasNext();)

                        {

                            InputStream is = (InputStream)streamIterator.next();

                            streamArray[streamIndex++] = is;

                        }

             

             

                        resources = new FormatterResources(streamArray);

                    }

                    catch(SAXException ex)

                    {

                        log.error("Skipping all formatter rules files.", ex);

                        throw new ServletException(ex);

                    }

            ...

             

            What sould I have to do?

            For the first error should I have to recompile the plugin and use javax.servlet.ServletContext#getResourceAsStream(java.lang.String)?

            And what to do to read the .dtd without the full file path?

             

            Thanks in advance.

            • 3. Re: Unable to locate .xml file on /WEB-INF/ folder
              Stephen Coy Master

              Try removing the space following the comma from '/WEB-INF/formatter-rules.xml, /WEB-INF/formatter.xml'.

              • 4. Re: Unable to locate .xml file on /WEB-INF/ folder
                Bruno Lacerda Newbie

                Thanks for the reply!

                 

                I already did it without success.

                • 5. Re: Unable to locate .xml file on /WEB-INF/ folder
                  Bruno Lacerda Newbie

                  I did a re-test using the FormatterPlugin and it's working.

                  The problem is now related to the second error. The full .dtd file path on the .xml file.

                  • 6. Re: Unable to locate .xml file on /WEB-INF/ folder
                    Stephen Coy Master

                    Try

                    {code}<?xml version="1.0"?>

                    <!DOCTYPE form-formatter SYSTEM "dtds/formatter_1_0.dtd">

                    <form-formatter>

                        ...

                    </form-formatter>{code}