jlaskowski 2004/07/05 11:47:46
Modified: modules/core/src/java/org/openejb/loader
EmbeddingLoader.java LoaderServlet.java
Log:
Further enhancements to make OpenEJB instances to not interfere with each other when
embedded in separate webapps
Revision Changes Path
1.2 +3 -10
openejb1/modules/core/src/java/org/openejb/loader/EmbeddingLoader.java
Index: EmbeddingLoader.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb1/modules/core/src/java/org/openejb/loader/EmbeddingLoader.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- EmbeddingLoader.java 26 Mar 2004 21:42:41 -0000 1.1
+++ EmbeddingLoader.java 5 Jul 2004 15:47:46 -0000 1.2
@@ -90,19 +90,12 @@
// Sets the openejb.home system variable
private void importOpenEJBLibraries( Hashtable env ) throws Exception{
- // Sets the openejb.home system variable
- try{
- if ( env.get("openejb.home") != null ) {
- System.setProperty("openejb.home", (String)env.get("openejb.home"));
- }
- } catch (Exception e){}
-
try{
// Loads all the libraries in the openejb.home/lib directory
- org.openejb.util.ClasspathUtils.addJarsToPath("lib");
+ ClasspathUtils.addJarsToPath("lib", "tomcat-webapp", env);
// Loads all the libraries in the openejb.home/dist directory
- org.openejb.util.ClasspathUtils.addJarsToPath("dist");
+ ClasspathUtils.addJarsToPath("dist", "tomcat-webapp", env);
} catch (Exception e){
throw new Exception( "Could not load OpenEJB libraries. Exception: "+
1.3 +98 -89
openejb1/modules/core/src/java/org/openejb/loader/LoaderServlet.java
Index: LoaderServlet.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb1/modules/core/src/java/org/openejb/loader/LoaderServlet.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- LoaderServlet.java 25 May 2004 07:43:11 -0000 1.2
+++ LoaderServlet.java 5 Jul 2004 15:47:46 -0000 1.3
@@ -60,94 +60,103 @@
*/
public class LoaderServlet extends HttpServlet {
- public void init(ServletConfig config) throws ServletException {
- try {
+ public void init(ServletConfig config) throws ServletException {
+ try {
- Properties p = new Properties();
- p.put(Context.INITIAL_CONTEXT_FACTORY,
"org.openejb.client.LocalInitialContextFactory");
- p.put("openejb.loader", "embed");
-
- Enumeration enum = config.getInitParameterNames();
-
- while (enum.hasMoreElements()) {
- String name = (String) enum.nextElement();
- String value = config.getInitParameter(name);
- p.put(name, value);
- }
-
- if (p.getProperty("openejb.loader").endsWith("tomcat-webapp"))
{
- ServletContext ctx = config.getServletContext();
- System.setProperty("openejb.base",
ctx.getRealPath("WEB-INF"));
- }
-
- InitialContext ctx = new InitialContext(p);
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- String NO_HOME = "The openejb.home is not set.";
- String BAD_HOME = "Invalid openejb.home: ";
- String NOT_THERE = "The path specified does not exist.";
- String NOT_DIRECTORY = "The path specified is not a directory.";
- String NO_DIST = "The path specified is not correct, it does not contain a
'dist' directory.";
- String NO_LIBS = "The path specified is not correct, it does not contain any
OpenEJB libraries.";
- String INSTRUCTIONS = "Please edit the web.xml of the openejb_loader webapp
and set the openejb.home init-param to the full path where OpenEJB is installed.";
-
- private void checkOpenEjbHome() throws ServletException {
- try {
-
- // The openejb.home must be set
- String homePath = System.getProperty("openejb.home");
- if (homePath == null)
- handleError(NO_HOME, INSTRUCTIONS);
-
- // The openejb.home must exist
- File openejbHome = new File(homePath);
- if (!openejbHome.exists())
- handleError(BAD_HOME + homePath, NOT_THERE,
INSTRUCTIONS);
-
- // The openejb.home must be a directory
- if (!openejbHome.isDirectory())
- handleError(BAD_HOME + homePath, NOT_DIRECTORY,
INSTRUCTIONS);
-
- // The openejb.home must contain a 'dist' directory
- File openejbHomeDist = new File(openejbHome, "dist");
- if (!openejbHomeDist.exists())
- handleError(BAD_HOME + homePath, NO_DIST,
INSTRUCTIONS);
-
- // The openejb.home there must be openejb*.jar files in the
'dist'
- // directory
- String[] libs = openejbHomeDist.list();
- boolean found = false;
- for (int i = 0; i < libs.length && !found; i++) {
- found = (libs[i].startsWith("openejb-") && libs[i]
- .endsWith(".jar"));
- }
- if (!found)
- handleError(BAD_HOME + homePath, NO_LIBS,
INSTRUCTIONS);
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- private void handleError(String m1, String m2, String m3)
- throws ServletException {
- System.err.println("--[PLEASE
FIX]-------------------------------------");
- System.err.println(m1);
- System.err.println(m2);
- System.err.println(m3);
-
System.err.println("---------------------------------------------------");
- throw new ServletException(m1 + " " + m2 + " " + m3);
- }
- private void handleError(String m1, String m2) throws ServletException {
- System.err.println("--[PLEASE
FIX]-------------------------------------");
- System.err.println(m1);
- System.err.println(m2);
-
System.err.println("---------------------------------------------------");
- throw new ServletException(m1 + " " + m2);
- }
+ Properties p = new Properties();
+ p.put(Context.INITIAL_CONTEXT_FACTORY,
"org.openejb.client.LocalInitialContextFactory");
+
+ Enumeration enum = config.getInitParameterNames();
+
+ System.out.println("OpenEJB init-params:");
+ while (enum.hasMoreElements()) {
+ String name = (String) enum.nextElement();
+ String value = config.getInitParameter(name);
+ p.put(name, value);
+ System.out.println("\tparam-name: " + name + ", param-value: " +
value);
+ }
+
+ String openejbLoaderPropValue = p.getProperty("openejb.loader");
+ if (openejbLoaderPropValue != null) {
+ if (openejbLoaderPropValue.endsWith("tomcat-webapp") &&
p.getProperty("openejb.base") == null) {
+ ServletContext ctx = config.getServletContext();
+ p.setProperty("openejb.base", ctx.getRealPath("WEB-INF"));
+ }
+ }
+
+ new InitialContext(p);
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ String NO_HOME = "The openejb.home is not set.";
+
+ String BAD_HOME = "Invalid openejb.home: ";
+
+ String NOT_THERE = "The path specified does not exist.";
+
+ String NOT_DIRECTORY = "The path specified is not a directory.";
+
+ String NO_DIST = "The path specified is not correct, it does not contain a
'dist' directory.";
+
+ String NO_LIBS = "The path specified is not correct, it does not contain any
OpenEJB libraries.";
+
+ String INSTRUCTIONS = "Please edit the web.xml of the openejb_loader webapp and
set the openejb.home init-param to the full path where OpenEJB is installed.";
+
+ private void checkOpenEjbHome() throws ServletException {
+ try {
+
+ // The openejb.home must be set
+ String homePath = System.getProperty("openejb.home");
+ if (homePath == null)
+ handleError(NO_HOME, INSTRUCTIONS);
+
+ // The openejb.home must exist
+ File openejbHome = new File(homePath);
+ if (!openejbHome.exists())
+ handleError(BAD_HOME + homePath, NOT_THERE, INSTRUCTIONS);
+
+ // The openejb.home must be a directory
+ if (!openejbHome.isDirectory())
+ handleError(BAD_HOME + homePath, NOT_DIRECTORY, INSTRUCTIONS);
+
+ // The openejb.home must contain a 'dist' directory
+ File openejbHomeDist = new File(openejbHome, "dist");
+ if (!openejbHomeDist.exists())
+ handleError(BAD_HOME + homePath, NO_DIST, INSTRUCTIONS);
+
+ // The openejb.home there must be openejb*.jar files in the 'dist'
+ // directory
+ String[] libs = openejbHomeDist.list();
+ boolean found = false;
+ for (int i = 0; i < libs.length && !found; i++) {
+ found = (libs[i].startsWith("openejb-") &&
libs[i].endsWith(".jar"));
+ }
+ if (!found)
+ handleError(BAD_HOME + homePath, NO_LIBS, INSTRUCTIONS);
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void handleError(String m1, String m2, String m3) throws
ServletException {
+ System.err.println("--[PLEASE FIX]-------------------------------------");
+ System.err.println(m1);
+ System.err.println(m2);
+ System.err.println(m3);
+ System.err.println("---------------------------------------------------");
+ throw new ServletException(m1 + " " + m2 + " " + m3);
+ }
+
+ private void handleError(String m1, String m2) throws ServletException {
+ System.err.println("--[PLEASE FIX]-------------------------------------");
+ System.err.println(m1);
+ System.err.println(m2);
+ System.err.println("---------------------------------------------------");
+ throw new ServletException(m1 + " " + m2);
+ }
}