3

Can you use the <virtual-directory-mapping> to reference static content inside the deployed EAR and will it provide any benefit?

Disclaimer: Ideally static resources like fonts, javascript and css should be served by the webserver and not the application container.

There are a number of articles on SO regarding <virtual-directory-mapping> in Weblogic. It is also well documented here and here.

My application is deployed in the following location:

c:\weblogic\deploy\ACME.ear

Inside ACME.ear there exists the following folder structure for CSS, Fonts and JS

store.war\include\js\script.js
store.war\include\js\function.js
store.war\include\fonts\font.woff
store.war\include\fonts\font.woff2
store.war\include\css\css-output\ie.css
store.war\include\css\css-output\interactive\large.css
store.war\include\css\css-output\interactive\small.css

My context root is specified as /store.

In normal operation I would be able to access my script.js in the site as follow:

http://www.acme.com/store/include/js/script.js

This request will then pass through my application request pipeline. What I am trying to achieve is to simply serve the contents of the /include/ folder, inside the .war as static documents without having to pass through the entire request pipeline (in my case ATG).

I've added the following lines to my weblogic.xml

<virtual-directory-mapping>
    <local-path>C:/weblogic/deploy/ACME.ear/store.war/include</local-path>
    <url-pattern>/include/css/*</url-pattern>
    <url-pattern>/include/fonts/*</url-pattern>
    <url-pattern>/include/js/*</url-pattern>
    <url-pattern>/include/lib/*</url-pattern>
</virtual-directory-mapping>    

In the hope that this will, instead of passing the request through the entire pipeline, simply render it as a static resource.

According to the documentation it will first try and render it via the <virtual-directory-mapping> before trying to render it from the container document root.

Even with the above configuration, the static content in the /include/ folder is still being rendered by the container and not as a static resource through Weblogic. I have the following questions:

  1. Is this even a valid approach? Even though the static assets exist in the .war, can I render it as 'external' static assets using the using the above configuration?
  2. Should the <url-pattern> include the context-root? Should the <local-path> include the context-root? (I've tried various combinations of including and excluding but to no avail)
  3. How do I access files in folders and subfolders using the <url-pattern>. Do I need to specify each subfolder?
Community
  • 1
  • 1
radimpe
  • 3,197
  • 2
  • 27
  • 46
  • Why do you want to do the above and not serve them from the web server as you point out? – bated Sep 20 '16 at 04:09
  • Generally because the CSS, JS, Fonts and some icons (like favicon) are under source control while those assets served by Apache are not. I'm in the process of creating a separate .war for the non-JSP assets (like the CRS of late). In here I'm trying to configure the web.xml to simply pass the request to Weblogic and back but for some odd reason still get processed in ATG. Probably a web.xml misconfiguration on my part. Had I been running on Unix infrastructure, I'd easily do some symlinks across servers and all be happy. Priorities changed slightly so will look at this again soon. – radimpe Sep 20 '16 at 05:05
  • What is your ``? You probably need to change it for the path to your images. – bated Sep 20 '16 at 05:37

1 Answers1

0

The <virtual-mapping-directory> configuration above was incorrect. Because it is incorrect Weblogic will try to locate content in that folder and when failing to do so, revert back to serving it from the default doc-root. The correct configuration is:

<virtual-directory-mapping>
    <local-path>C:/weblogic/deploy/ACME.ear/store.war</local-path>
    <url-pattern>/include/*</url-pattern>
    <url-pattern>*.js</url-pattern>
    <url-pattern>*.css</url-pattern>
    <url-pattern>*.woff</url-pattern>
</virtual-directory-mapping>

What is important to note is that there MUST exist a folder called:

C:/weblogic/deploy/ACME.ear/store.war/include

in order for it to be found as a virtual directory.

Still haven't worked out if it provides any actual run-time benefit.

radimpe
  • 3,197
  • 2
  • 27
  • 46