[MAGNOLIA-2270] Better logs and avoid NPEs when magnolia is started from an unexpanded war Created: 16/Jul/08  Updated: 23/Jan/13  Resolved: 17/Jul/08

Status: Closed
Project: Magnolia
Component/s: None
Affects Version/s: 3.6 RC1
Fix Version/s: 3.6

Type: Improvement Priority: Major
Reporter: Fabrizio Giustina Assignee: Fabrizio Giustina
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Date of First Response:

 Description   

Magnolia doesn't work with if started from an unexpanded war, as we know, but we also should give a better output.
3.6-rc1 dies with an unhelpful NPE in MgnlServletContextListener



 Comments   
Comment by Fabrizio Giustina [ 16/Jul/08 ]

fixed in r16847, will merge on branch

Comment by Magnolia International [ 16/Jul/08 ]

svn propedit --revprop svn:log -r <revision-number> please

Comment by Fabrizio Giustina [ 16/Jul/08 ]

you can see the diff from the branch, I committed it using the jira number. Please don't be too picky with this kind of changes, it could become really annoying...

Comment by Jan Haderka [ 16/Jul/08 ]

Fabrizio,
what makes you think Magnolia doesn't run on unexpanded war file? We have quite few clients running on war files without any problems. It is all just a matter of configuration. Could you please describe environment in which you had problems with current code? I would prefer not to make changes to this kind of very central classes while being in RC.
Thanks,
Jan

Comment by Fabrizio Giustina [ 16/Jul/08 ]

> I would prefer not to make changes to this kind of very central classes while being in RC.

the only change is the exception message, there is nothing else changed here... we just tried to run it on tomcat6 from an unexpanded war and we saw that it crashes since context.getRealPath(StringUtils.EMPTY) returns a null, nothing more.

Comment by Magnolia International [ 16/Jul/08 ]

Changing the exception message (and mostly avoiding the npe when generating it) is a good thing, but i'd like to get rid of the false statement that was introduced in it. thanks.

Comment by Fabrizio Giustina [ 16/Jul/08 ]

mh, I am not so sure it's a false statement, at least not for any appserver: servletContext.getRealPath() can return null for unexpanded wars and magnolia crashes at startup for that...
on which container did you run magnolia unexpanded?

Comment by Jan Haderka [ 17/Jul/08 ]

The only app server I've seen so far returning null was Weblogic 9 and older. And for this we have a solution in form of special module that takes care of the things (since there was more customization necessary then just this listener).
As for which App servers I've tested those were various versions of Glassfish, JBoss, Weblogic and Websphere.
I haven't tested on Tomcat 6 (and I will), but see no reason why it should not run. And even if it doesn't for some reason it is not correct to give false impression that you can't run as a war file in general.

Comment by Fabrizio Giustina [ 17/Jul/08 ]

> it is not correct to give false impression that you can't run as a war file in general.

the check here is clean and simple:

  • if servletContext.getRealPath() returns null you are using an unexpanded war in a container where magnolia will not run unexpanded.
  • If you are using a expanded war or a unexpanded war in a server where magnolia can run you will never see this message. If servletContext.getRealPath() returns null it means that you are running a unexpanded war in a server where this is not supported and the log clearly helps you in fixing your configuration.
Comment by Jan Haderka [ 17/Jul/08 ]
  • if servletContext.getRealPath() returns null you are using an unexpanded war in a container where magnolia will not run unexpanded.
  • If you are using a expanded war or a unexpanded war in a server where magnolia can run you will never see this message. If servletContext.getRealPath() returns null it means that you are running a unexpanded war in a server where this is not supported and the log clearly helps you in fixing your configuration.

My take on this is as follows:

  • if servletContext.getRealPath() returns null, either server is not configured properly or magnolia is not configured properly (if it still relies on the value). And configuration change doesn't necessarily mean that you have to expand the war file. It can be many different things, for example Weblogic 10 has a flag that can be put in deployment descriptors specifying if you want to get real value or not.

So the statement in the error message Magnolia needs to be run from an expanded webapp is not correct. The correct message in this case would be "Real path can't be obtained. Magnolia is not configured properly and therefore unable to start. Please refer to Magnolia documentation for installation instructions specific for your environment (OS, app server)."

Comment by Magnolia International [ 17/Jul/08 ]

corrected error message on trunk and 3.6-rc branch

Generated at Mon Feb 12 03:35:04 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.