0

Weblogic Server cant get RealPath?

asked 2012-02-08 02:14:53 +0800

FujitsuConsulting gravatar image FujitsuConsulting
165 1

Hi,

I am currently testing Oracle's Weblogic Server with our application. I have deployed our app, but it crashes when it tries to do this:

String xmlFileName = Executions.getCurrent().getDesktop().getWebApp().getRealPath("/WEB-INF/menus.xml");

File xmlFile = new File(xmlFileName);

The Java crash is this:

java.lang.NullPointerException
java.io.File.(File.java:222)

And points to the new File line...

Any ideas on how to fix this? This code works fine on Tomcat, OC4J and GlassFish.

Thanks!

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2012-02-08 09:50:17 +0800

cvarona gravatar image cvarona
554 1 6

You shouldn't use real paths in a production environment. According to the javadoc for ServletContext.getRealPath() (the java equivalent for WebApp.getRealPath()) :

getRealPath

String getRealPath(String path)

Returns a String containing the real path for a given virtual path. For example, the path "/index.html" returns the absolute file path on the server's filesystem would be served by a request for "http://host/contextPath/index.html", where contextPath is the context path of this ServletContext..

The real path returned will be in a form appropriate to the computer and operating system on which the servlet container is running, including the proper path separators. This method returns null if the servlet container cannot translate the virtual path to a real path for any reason (such as when the content is being made available from a .war archive).

In a production environment you would normally use a war file, either standlone or enclosed in an ear file. You're surely deploying such a file in your weblogic test.

link publish delete flag offensive edit

answered 2012-02-08 20:50:07 +0800

FujitsuConsulting gravatar image FujitsuConsulting
165 1

Thanks for the reply cvarona - yes we are deploying the app as an ear file.

This app has a lot of legacy code in it...

I did manage to get this to work by doing the following:

ServletContext serv = (ServletContext)Sessions.getCurrent().getWebApp().getNativeContext();
InputStream xmlFile = serv.getResourceAsStream("/WEB-INF/menus.xml");

link publish delete flag offensive edit

answered 2012-02-09 00:26:49 +0800

FujitsuConsulting gravatar image FujitsuConsulting
165 1

Also I have just found out that you can enable an option within Weblogic to get getRealPath to work:

Home > Domains > Web Applications, tick Archived Real Path and restart the server - done :)

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2012-02-08 02:14:53 +0800

Seen: 333 times

Last updated: Feb 09 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More