%@ page import="
javax.naming.InitialContext,
javax.naming.Context,
javax.naming.*,
java.util.Properties,
javax.naming.Context,
javax.naming.InitialContext,
javax.servlet.ServletConfig,
javax.servlet.ServletException,
javax.servlet.http.HttpServlet,
javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse,
javax.servlet.jsp.JspWriter,
java.io.PrintWriter,
java.util.*,
java.io.*,
java.lang.reflect.Method,
java.lang.reflect.InvocationTargetException,
java.lang.reflect.Modifier
"%>
OpenEJB Tomcat Integration/1.0
<%!
String tab = " ";
static String invLock = "lock";
static int invCount;
HttpSession session;
HttpServletRequest request;
JspWriter out;
String OK = "OK | ";
String FAIL = "FAIL | ";
String HR = "
";
String pepperImg = "";
/**
* The main method of this JSP
*/
public void main(HttpServletRequest request, HttpSession session, JspWriter out) throws Exception{
this.request = request;
this.session = session;
this.out = out;
InitialContext ctx = null;
try{
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "org.openejb.client.LocalInitialContextFactory");
ctx = new InitialContext( p );
} catch (Exception e){
formatThrowable(e);
}
try{
out.print(HR);
out.print("");
// ---------------------------------------------------
// Were the OpenEJB classes installed?
// ---------------------------------------------------
printTest("Were the OpenEJB classes installed");
ClassLoader myLoader = null;
Class openejb = null;
try{
myLoader = this.getClass().getClassLoader();
openejb = Class.forName("org.openejb.OpenEJB",true, myLoader);
out.print(OK);
} catch (Exception e){
out.print(FAIL);
}
// ---------------------------------------------------
// Are the EJB libraries visible?
// ---------------------------------------------------
printTest("Were the EJB classes installed");
try{
Class.forName("javax.ejb.EJBHome",true, myLoader);
out.print(OK);
} catch (Exception e){
out.print(FAIL);
}
// ---------------------------------------------------
// Was OpenEJB initialized (aka started)?
// ---------------------------------------------------
printTest("Was OpenEJB initialized (aka started)");
try{
Class[] params = new Class[0];
Method isInitialized = null;
isInitialized = openejb.getDeclaredMethod("isInitialized", params);
Object val = isInitialized.invoke(openejb, new Object[0]);
boolean running = ((Boolean)val).booleanValue();
if (running) out.print(OK);
} catch (Exception e){
out.print(FAIL);
}
// ---------------------------------------------------
// Can I lookup anything?
// ---------------------------------------------------
printTest("Performing a test lookup");
try{
Object obj = ctx.lookup("");
if (obj.getClass().getName().equals("org.openejb.core.ivm.naming.IvmContext")) {
out.print(OK);
} else {
out.print(FAIL);
}
} catch (Exception e){
out.print(FAIL);
}
out.print("
");
out.print(HR);
try{
Object obj = ctx.lookup( "client" );
if (obj instanceof Context) {
out.print("
");
}
} catch (Exception e){}
} catch (Exception e){
out.print(FAIL);
out.print("");
out.print(HR);
out.print(e.getMessage());
}
}
protected void printTest(String test) throws IOException{
out.print("" );
out.print(test);
out.print(" | ");
}
public String formatThrowable(Throwable err) throws Exception{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
err.printStackTrace(new PrintStream(baos));
byte[] bytes = baos.toByteArray();
StringBuffer sb = new StringBuffer(bytes.length);
for (int i=0; i < bytes.length; i++){
char c = (char)bytes[i];
switch (c) {
case ' ': sb.append(" "); break;
case '\n': sb.append("
"); break;
case '\r': break;
default: sb.append(c);
}
}
return sb.toString();
}
%>