1

Within a web application I want to create a "virtual directory" that lives under the WEB-INF directory. In effect what I am trying to accomplish is the same effect as creating a soft link in the filesystem if the application were run exploded. I am trying to accomplish this in both (most importantly) weblogic, as well as (in an ideal world) jetty.

I am aware of the virtual directory configurations, however these do not suit my purposes as I do not want the content served directly via a URL (hence why it lives in WEB-INF). I have found nothing in the configuration document for jetty or weblogic that seems to provide a similar concept for resource resolution (I did try adding "extraClassPath" to jetty, but that was not successful). As further background the applications is using spring MVC and the view resolvers are pointing to JSPs under WEB-INF

<bean id="myResolverBean"
    class="org.springframework.web.servlet.view.InternalResourceViewResolver"
    p:viewClass="org.springframework.web.servlet.view.JstlView"
    p:prefix="/WEB-INF/foo/baz/" p:suffix=".jsp" />

After looking through the spring code I am under the belief, that it is doing nothing in regards to the resource loading, it is the container (weblogic / jetty) that resolves the paths. I have also tried using file URIs but it seems the container will always interpret the path as relative to the context root (i.e. there are no absolute paths).

So my question is, is it possible to add any kind of configuration directive to the web.xml, server configurations, or spring configuration to accomplish this?

1 Answer 1

1

Not surprisingly the answer to this question in weblogic is the virtual directory. The directive provides both (what I consider to be) the standard behavior of mapping a URL to some set of (usually static files) to be served, but also acts as a "virtual soft link" when the path is under WEB-INF and still provides the desired behavior of giving a 404 if you make a request via to the browser for such a URL (I think I misconfigured something the first time I tried this). So the following will produce the desired behavior:

<virtual-directory-mapping>
  <local-path>/absolute/path/outside/of/webapp</local-path>
  <url-pattern>/WEB-INF/foo/*</url-pattern>
</virtual-directory-mapping>

I have also discovered a similar functionality in Jetty. It is accomplished by specifying multiple "base resources" in the configuration. There is some jetty documentation that provides an explanation and some examples. One feature (I can see this being both helpful and harmful depending on the situation) is that the structures are merged so you can have paths that collide and they will be resolved in order of specification. The above example for jetty:

<Set name="baseResource">
  <New class="org.mortbay.resource.ResourceCollection">
    <Arg>
      <Array type="java.lang.String">
        <Item>/path/to/normal/webapp</Item>
        <Item>/absolute/path/outside/of/webapp</Item>
      </Array>
    </Arg>
  </New>
</Set> 

One catch for both of these is the directory structure must be recreated in the external directories (i.e. it must be /absolute/path/outside/of/webapp/WEB-INF/foo) to work correctly, as far as I can tell there is no way to map one directory to another arbitrarily named directory.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .