Wednesday, June 17, 2015

Virtual Directory Mapping - Displaying images/pdf/documents on the browser from network folder

Virtual Directory Mapping is one of the ways where you can display the content from your folder directory onto a page. I have used this technique in the past to display generated reports from network systems folder onto a web page.

<virtual-directory-mapping> is one of the deployment descriptor element in weblogic.xml. It is commonly used to display images and files in browser from selected network folder.

Below is the link to oracle documentation:
http://docs.oracle.com/cd/E13222_01/wls/docs81/webapp/weblogic_xml.html#1039396

I will be using example from Oracle Documentation with minor modification for giving more information on how it can be used.
<virtual-directory-mapping>
     <local-path>//testpc/myimages</local-path>
     <url-pattern>/images/*</url-pattern>
     <url-pattern>*.jpg</url-pattern>
</virtual-directory-mapping>
The above mapping can be used to display all the images with .jpg extension on to a web page for matching url pattern.

Example1:
http://myexample.test.com/myapp/images/1.jpg will load 1.jpg image from //testpc/myimages/images folder.

Example2:
http://myexample.test.com/myapp/generatedReports/report1.pdf can be loaded from //testpc/reports/generatedReports folder.

<virtual-directory-mapping>
     <local-path>//testpc/reports</local-path>
     <url-pattern>/generatedReports/*</url-pattern>
</virtual-directory-mapping>


if you notice the <local-path> in my example is hard-coded. If you have to change the location according to the environment where the artifact is getting is installed, it may become pain.

I have used plan.xml (Deployment Plan) to modify the values in weblogic.xml after deploying the artifact in weblogic server.
http://docs.oracle.com/cd/E11035_01/wls100/deployment/config.html

You have to create plan.xml for each environment and apply to the installed artifact from weblogic console.



2 comments:

  1. Interesting decision. As I understand, these code can be applied to web-sites. And what about virtual data rooms such as Ideals? Or they have in-built such function?

    ReplyDelete
    Replies
    1. I am not familiar with virtual data rooms. Sorry, I don't have answer to your question. The question seems to be irrelevant to the topic, I have explained above.

      Delete