[Actionframework-users] Support for Jetty + Unexpanded Wars
Status: Inactive
Brought to you by:
ptoman
|
From: Mark A. <ma...@pa...> - 2003-05-15 11:22:04
|
Jetty supports running webapps from wars without expanding them and I wou=
ld like to do this with ActionServlet. The problem is that as the war is =
not expanded
there is no filesystem for the webapp so all templates and property files=
have to be loaded as resources or via the classpath.
I have had to patch two files in ActionServlet to support running from un=
expanded wars. These are used to load the velocity properties and action =
config files.
Details below:
1) org.actionframework.engines.velocity.VelocityServlet
If loading the velocity properties file by the real path fails then we tr=
y loading as a resource. (The diff below also contains the change for abs=
olute log file paths
noted in another thread)
--- VelocityServlet.java.orig Thu May 15 11:00:35 2003
+++ VelocityServlet.java Thu May 15 12:13:11 2003
@@ -110,7 +110,14 @@
String realPath =3D getServletContext().getRealPath(=
propsFile);
if (realPath =3D=3D null) {
- log.error("[init] " + "Cannot get real path of V=
elocity properties file '" + propsFile + "'");
+ // try loading as resource
+ InputStream resourceStream =3D getServletContext(=
).getResourceAsStream(propsFile);
+ if (resourceStream =3D=3D null ) {
+ log.error("[init] " + "Cannot get Velocity p=
roperties file as resource");
+ } else {
+ p.load(resourceStream);
+ log.info("[init] " + "Property file loaded a=
s resource");
+ }
} else {
p.load(new FileInputStream(realPath));
log.info("[init] " + "Property file '" + realPat=
h + "' loaded");
@@ -122,7 +129,7 @@
if (logFile =3D=3D null)
logClass =3D VelocityServletLog.class;
else {
- String realLogFile =3D getServletContext().getRealPath(l=
ogFile);
+ String realLogFile =3D (logFile.charAt(0)=3D=3D'/') ? lo=
gFile : getServletContext().getRealPath(logFile);
if (realLogFile =3D=3D null) {
log.error("[init] " + "Cannot get real path of log f=
ile '" + logFile + "'");
@@ -280,4 +287,4 @@
super.error(request, response, cause);
}
}
-}
\ No newline at end of file
+}
2) org.actionframework.runtime.ActionRuntime
When running from a war file the url returned by servlet.getClass().getRe=
source("/" + configFilename) is a jar url and trying to use a FileInputSt=
ream on this
causes a FileNotFoundException. The patch checks the protocol and, if it =
is jar, gets the InputStream from the URL directly.
--- ActionRuntime.java.orig Sun Apr 20 10:26:10 2003
+++ ActionRuntime.java Thu May 15 11:00:06 2003
@@ -479,10 +479,15 @@
"' loaded via servlet realpath from " +=
realPath);
}
} else {
+ if (url.getProtocol().equals("jar")) {
+ in =3D url.openStream();
+ log.info("[init] " + "ActionConfig '" + configF=
ilename + "' loaded as resource from " =
+ url);
+ } else {
actionConfigFile =3D new File(url.getFile());
in =3D new FileInputStream(actionConfigFile);
log.info("[init] " + "ActionConfig '" + configFilen=
ame + "' loaded as resource from " +
url.getFile());
+ }
}
}
actionConfigFileTimestamp =3D actionConfigFile.lastModified(=
);
@@ -1981,4 +1986,4 @@
return component;
}
-}
\ No newline at end of file
+}
I hope you find these patches suitable for inclusion.
--=20
Regards,
Mark
|