TomEE
  1. TomEE
  2. TOMEE-47

ServletContext.getResource(path).getInputStream() fails

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0.0-beta-2
    • Fix Version/s: 1.0.0
    • Component/s: None
    • Labels:
      None

      Description

      Since apache-tomee-1.0.0-beta-2-20111029.082511-21-webprofile.tar.gz the method ServletContext.getResource(path).getInputStream() fails with FileNotFoundException:

      BasicException[1]
      Class = org.apache.naming.resources.DirContextURLConnection
      Method = getInputStream
      Line = 385
      ExceptionClass = java.io.FileNotFoundException
      ExceptionDomain = DefaultDomain
      ExceptionCode = GENERIC
      Description = jndi:/localhost/opencrx-core-CRX/WEB-INF/config/ui/Root/ro_RO/uom.xml
      StackTrace:
      at org.apache.naming.resources.DirContextURLConnection.getInputStream(DirContextURLConnection.java:385)
      at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:653)
      at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:186)
      at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:772)
      at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
      at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
      at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
      at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
      at org.openmdx.application.xml.spi.ImportHelper.importObjects(ImportHelper.java:226)
      at org.openmdx.application.xml.Importer.importObjects(Importer.java:129)
      at org.openmdx.portal.servlet.loader.UiLoader.load(UiLoader.java:328)
      at org.openmdx.portal.servlet.ObjectInspectorServlet.reloadUi(ObjectInspectorServlet.java:623)

        Activity

        Hide
        Werner Froidevaux added a comment -

        The reason could also be the function ServletContext.getResourcePaths() which returns wrong paths.

        Show
        Werner Froidevaux added a comment - The reason could also be the function ServletContext.getResourcePaths() which returns wrong paths.
        Hide
        Romain Manni-Bucau added a comment -

        which kind of path do you use? does it star with '/'?

        Show
        Romain Manni-Bucau added a comment - which kind of path do you use? does it star with '/'?
        Hide
        Werner Froidevaux added a comment -

        Yes, it starts with a '/', e.g. '/WEB-INF/config/ui/Root/en_US/test.xml'

        I use the paths returned by ServletContext.getResourcePaths(). According to the exception the paths are mapped to 'jndi:/localhost/opencrx-core-CRX/WEB-INF/config/ui/Root/en_US/test.xml' which does not seem to exist.

        This problem is new since apache-tomee-1.0.0-beta-2-20111029.082511-21-webprofile.

        Show
        Werner Froidevaux added a comment - Yes, it starts with a '/', e.g. '/WEB-INF/config/ui/Root/en_US/test.xml' I use the paths returned by ServletContext.getResourcePaths(). According to the exception the paths are mapped to 'jndi:/localhost/opencrx-core-CRX/WEB-INF/config/ui/Root/en_US/test.xml' which does not seem to exist. This problem is new since apache-tomee-1.0.0-beta-2-20111029.082511-21-webprofile.
        Hide
        Romain Manni-Bucau added a comment -

        can you correct this test please to be in your situation. My resource is directly in config folder which is in the root directory of the webapp and is called test.getresources.

        Here what i tested:
        https://svn.apache.org/repos/asf/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/getresources/GetResourcesServletExporter.java

        Show
        Romain Manni-Bucau added a comment - can you correct this test please to be in your situation. My resource is directly in config folder which is in the root directory of the webapp and is called test.getresources. Here what i tested: https://svn.apache.org/repos/asf/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/getresources/GetResourcesServletExporter.java
        Hide
        Werner Froidevaux added a comment -

        Your tests work indeed.

        However, I supply the URL returned by getServletContext().getResource() to Xerces. As you see from the stack trace Xerces fails in org.apache.naming.resources.DirContextURLConnection.getInputStream() with a FileNotFoundException. I am not sure what excactly DirContextURLConnection.getInputStream() does with the supplied URL. I did not look into the source so far.

        As already mentioned: the exception is only since apache-tomee-1.0.0-beta-2-20111029.082511-21-webprofile.

        Show
        Werner Froidevaux added a comment - Your tests work indeed. However, I supply the URL returned by getServletContext().getResource() to Xerces. As you see from the stack trace Xerces fails in org.apache.naming.resources.DirContextURLConnection.getInputStream() with a FileNotFoundException. I am not sure what excactly DirContextURLConnection.getInputStream() does with the supplied URL. I did not look into the source so far. As already mentioned: the exception is only since apache-tomee-1.0.0-beta-2-20111029.082511-21-webprofile.
        Hide
        Werner Froidevaux added a comment -

        In my opinion getServletContext().getResource().getFile() returns an invalid path. It returns something like '/localhost/opencrx-core-CRX/WEB-INF/config/ui/Root/en_US/text.xml' but it should return an absolute path pointing to the file on the file system.

        Show
        Werner Froidevaux added a comment - In my opinion getServletContext().getResource().getFile() returns an invalid path. It returns something like '/localhost/opencrx-core-CRX/WEB-INF/config/ui/Root/en_US/text.xml' but it should return an absolute path pointing to the file on the file system.
        Hide
        Romain Manni-Bucau added a comment -

        hmm,

        i'm not sure it is relevant since you are passing the file part of an url which is not a file (getFile() doesn't have to return a real file path in your snippet).

        However i think you are looking for getRealPath() method of ServletContext object.

        Show
        Romain Manni-Bucau added a comment - hmm, i'm not sure it is relevant since you are passing the file part of an url which is not a file (getFile() doesn't have to return a real file path in your snippet). However i think you are looking for getRealPath() method of ServletContext object.
        Hide
        Werner Froidevaux added a comment -

        In my opinion getFile() has to return a real file path. At least org.apache.naming.resources.DirContextURLConnection.connect() (which I am not the owner of) expects it:

        ...
        String path = getURL().getFile();
        ...

        I am using Xerces and I do not have any control over the URL handling (getRealPath(), getPath(), ...).

        You probably have to discuss this topic with the guy who implemented org.apache.naming.resources.DirContextURLConnection.

        Again: passing the getServletContext().getResource() URL to Xerces worked prior to TomEE snapshot 20111029.08251 and with all previous Tomcat/OpenEJB versions and other AppServers such as JBoss, WebSphere, WebLogic, etc.

        Show
        Werner Froidevaux added a comment - In my opinion getFile() has to return a real file path. At least org.apache.naming.resources.DirContextURLConnection.connect() (which I am not the owner of) expects it: ... String path = getURL().getFile(); ... I am using Xerces and I do not have any control over the URL handling (getRealPath(), getPath(), ...). You probably have to discuss this topic with the guy who implemented org.apache.naming.resources.DirContextURLConnection. Again: passing the getServletContext().getResource() URL to Xerces worked prior to TomEE snapshot 20111029.08251 and with all previous Tomcat/OpenEJB versions and other AppServers such as JBoss, WebSphere, WebLogic, etc.
        Hide
        Werner Froidevaux added a comment -

        The problem is solved with snapshot apache-tomee-1.0.0-beta-2-20111103.010356-23-webprofile.

        Thanks!

        Show
        Werner Froidevaux added a comment - The problem is solved with snapshot apache-tomee-1.0.0-beta-2-20111103.010356-23-webprofile. Thanks!
        Hide
        Werner Froidevaux added a comment -

        The problem is solved with snapshot apache-tomee-1.0.0-beta-2-20111103.010356-23-webprofile.

        Thanks!

        Show
        Werner Froidevaux added a comment - The problem is solved with snapshot apache-tomee-1.0.0-beta-2-20111103.010356-23-webprofile. Thanks!
        Show
        David Blevins added a comment - 2011-11-01 - http://svn.apache.org/viewvc?view=revision&revision=1196093 - rmannibucau 2011-11-01 - http://svn.apache.org/viewvc?view=revision&revision=1196180 - rmannibucau

          People

          • Assignee:
            Unassigned
            Reporter:
            Werner Froidevaux
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development