Skip to main content

Directory Listing - A Simple WebLogic Application

In this article I will show how to create a simple WebLogic application that lets you navigate directories and files on a server. This can be one of the handiest utilities. I use it all the time to give developers access to logs in test and pre-production environments.


But first, a warning... Be careful what files you make available to others. Some files, especially within a WebLogic domain directory, contain information that MUST be kept secret if the domain is to remain secure. NEVER provide read-access to all files in a WebLogic domain directory.

Like any WebLogic application, you must create a WAR file with the following components inside:
  • WEB-INF (directory)
  • WEB-INF\web.xml
  • WEB-INF\weblogic.xml
The first step is to create a new directory called 'WEB-INF'.

The web.xml descriptor

Inside the WEB-INF directory, create a new file called web.xml, and paste the following XML code:


<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
</web-app>


I won't explain this XML code, but it is essentially an empty deployment descriptor.

The weblogic.xml descriptor

Create another file in the WEB-INF directory called weblogic.xml, and paste the following into it:


<!DOCTYPE weblogic-web-app PUBLIC "-//BEA Systems, Inc.//DTD Web Application 8.1//EN" "http://www.bea.com/servers/wls810/dtd/we
blogic810-web-jar.dtd">

<weblogic-web-app>

<container-descriptor>
<index-directory-enabled>true</index-directory-enabled>
</container-descriptor>

<virtual-directory-mapping>
<local-path>../../../logs/</local-path>
<url-pattern>*</url-pattern>
</virtual-directory-mapping>

<context-root>/getlogs</context-root>

</weblogic-web-app>


XML Elements Explained

<index-directory-enabled> If true, WebLogic will display a list of directories and files. Unfortunately, you cannot filter this list. WebLogic does not provide much in the way of directory/file listing functionality - either you list them or don't.

<local-path> The path component of a URL where you will find the application. For example, the XML code above will make the application accessible at http://localhost:7001/getlogs/

<url-pattern> Specifies the local directory that will be displayed when a user navigates to the context-root.

<context-root> A pattern that URLs must match in order for them to be mapped to the local directory.

Sample Applications (update)

The sample apps from this article can be downloaded here. These sample applications are NOT SAFE for a production environment as they could potentially expose sensitive information.

Deployment Notes:
  • For WebLogic 8.1 or older, when deploying you must select "Copy this Web Application module onto every target for me".
  • For WebLogic 9 or newer, deploy with default options.

Comments

  1. Thanks, do you have like a sample war file which you can send me at ravi_tiwari_786@yahoo.com, i really need this kind of features for the dvelopers and the testing team.

    ReplyDelete
  2. Hi Ravi, the sample war files are now available from the links above.

    ReplyDelete
  3. It worked. I made the WAR file with WinRAR as a Zip, and just changed the extension to WAR. I had to deploy the application (Prepared), then start the deployment (Active). Thank you.

    ReplyDelete
  4. hello, I was looking for your sample war file and the link was not working at all. Will you be kind enough to send the sample war file to me chua.mykel@gmail.com

    Thanks.

    ReplyDelete
  5. Hello, I would like to do the same; publish log files to developers. My issue is, that the directory listing shows the files, but if I want to download files, which are not small, they are getting truncated.
    Is there a configuration, which has to be changed. Interesting is also, that the size seems to be different between broswers.

    Thanks

    ReplyDelete
  6. after deployment...i got 403 requesting getlogs. why?

    ReplyDelete
  7. hello, I was looking for your sample war file and the link was not working at all. Will you be kind enough to send the sample war file to me yu.randy@gmail.com

    Thanks.

    ReplyDelete
  8. hello, I was looking for your sample war file and the link was not working at all. Will you be kind enough to send the sample war file to me fongtsz@gmail.com

    ReplyDelete
  9. hello, I was as well looking for your sample war file and the link was not working, will you be so kind enough to send me the sample war file @ gmail addess srinivas.bnglr@gmail.com

    ReplyDelete
  10. Nice post, I have used the same approach to retrieve logs from a remote WLS, a war file can be retrieved from:
    https://github.com/devwebcl/wls_contraption

    ReplyDelete
  11. Thanks for the article. Its pretty simple

    Sample download link doesn't works. Anyways easy to create the 2 xml files.

    ReplyDelete
  12. Is there any way to change the file date modified format? for my it is listing as DD-MM-YYYY, but wanted to change to YYYY-MM-DD?

    ReplyDelete

Post a Comment

Popular posts from this blog

BAD_CERTIFICATE - A corrupt or unuseable certificate...

This is a simple symptom-cause-solution blog entry only. I hope these blogs will help fellow administrators.
Symptom
In wls_utc, when trying to test a webservice using SSL, the following error message is received: javax.net.ssl.SSLKeyException: FATAL Alert:BAD_CERTIFICATE - A corrupt or unuseable certificate was received.
If SSL debugging is enabled, the following error also appears in the logs: ExecuteThread: '4' for queue: 'weblogic.kernel.Default (self-tuning)' <1254822672320>>
verification failed because RSA key public exponent [3] is too small
Cause
The certificate encryption is of a weaker strength than expected by newer versions of Java.
Solution
Add the flag "-Dweblogic.security.SSL.allowSmallRSAExponent=true" to the server startup parameters.
References


None.

Connection refused: No available router to destination

This is a simple symptom-cause-solution blog entry only. I hope these blogs will help fellow administrators.
Symptom

The following exception occurs in WebLogic server logs. Most likely to occur during WebLogic server start-up, but similar exceptions may occur at other times.
java.net.ConnectException: t3://myserver:8000: Destination unreachable; nested exception is: java.net.ConnectException: Connection refused: connect; No available router to destination] at weblogic.jndi.internal.ExceptionTranslator.toNamingException(ExceptionTranslator.java:49) at weblogic.jndi.WLInitialContextFactoryDelegate.toNamingException(WLInitialContextFactoryDelegate.java:773) at weblogic.jndi.WLInitialContextFactoryDelegate.getInitialContext(WLInitialContextFactoryDelegate.java:363) at weblogic.jndi.Environment.getContext(Environment.java:307) at weblogic.jndi.Environment.getContext(Environment.java:277)
Cause
This message (Connection refused: connect; No available router to destination) is a kind of "catch…

BEASVC.EXE - WebLogic as a Windows Service

I remember the first time I had to work out why WebLogic wouldn't run as a service. It was a frustrating experience. There were no error messages. No Windows error dialog. No console output.

How do you troubleshoot something like this??!!

This short article will show you. For simplicity I'll talk about the node manager, but the same principles apply for running an admin or managed server as a service.

First Steps

First, you still have your server logs. Sure the console output is better, but it's a starting point. Check this log for errors and especially take note of the start up variables such as PATH and CLASSPATH. If the server log isn't being created, that tells you WebLogic probably isn't even being started. (Check that you have a license file if you haven't already.)

Ok, so the logs were no help. The next step is to look at how the service is trying to start WebLogic.

When you install WebLogic as a service, you're really setting up beasvc.exe as the service.…