I think my problems is that I don't really understand how JRun registers an
EJB home interface with JNDI.
I can access the home interface fine from JRUN itself by using:
Context context = new InitialContext();
Object object = context.lookup( "java:comp/env/ebj/OAS" );
OASHome oasHome = (OASHome) PortableRemoteObject.narrow( object,
OASHome.class);
This code does not work if the JSP is run from Tomcat. It fails with a
javax.naming.NoInitialContextException, which is not surprising.
I modified the code to specify a context factory and provider URL:
Properties environment = new Properties ();
environment.setProperty( Context.INITIAL_CONTEXT_FACTORY,
"allaire.ejipt.ContextFactory" );
environment.setProperty( Context.PROVIDER_URL,
"ejipt://penguin.mindwrap.com;2323" );
Context context = new InitialContext( environment );
Object object = context.lookup( "java:comp/env/ebj/OAS" );
OASHome oasHome = (OASHome) PortableRemoteObject.narrow( object,
OASHome.class);
I also added "ejipt_client.jar" to the WEB-INF/lib directory of the webapp
where the JSP resides. (see attached TC-OASTest.jsp)
This JSP fails with the following output genereated:
1
2
--- context is: javax.naming.InitialContext@2265e6f8
3
Error: 500
Location: /tomcat-ejb-test/TC-OASTest.jsp
Internal Servlet Error:
java.lang.IllegalStateException: Response has already been committed
at org.apache.tomcat.core.HttpServletResponseFacade.sendError(
HttpServletResponseFacade.java, Compiled Code)
at org.apache.jasper.runtime.JspServlet.unknownException(
JspServlet.java, Compiled Code)
at org.apache.jasper.runtime.JspServlet.service(
JspServlet.java, Compiled Code)
at javax.servlet.http.HttpServlet.service(
HttpServlet.java, Compiled Code)
at org.apache.tomcat.core.ServletWrapper.handleRequest(
ServletWrapper.java, Compiled Code)
at org.apache.tomcat.core.ContextManager.service(
ContextManager.java, Compiled Code)
at org.apache.tomcat.service.connector.
Ajp12ConnectionHandler.processConnection(
Ajp12ConnectionHandler.java, Compiled Code)
at org.apache.tomcat.service.TcpConnectionThread.run(
SimpleTcpEndpoint.java, Compiled Code)
at java.lang.Thread.run(Thread.java, Compiled Code)
I added some code to try to dump to context that (see attached
TC-OASTestDump.jsp) but get:
1
2
--- context is: javax.naming.InitialContext@ffc9e6fb
2a
Failure doing dump context:
javax.naming.NamingException: Failed to unmarshal proxy [Root exception is j
java.lang.ClassNotFoundException:
allaire.ejipt.ejbeans.ConnectorHomeObject_Stub]
<%@ page import = "java.util.*, com.optix.ejb.*, com.optix.database.*, javax.naming.*, javax.rmi.*" %>
<%!
String function = "";
%>
<%
try
{
// --- Lookup OJBHome using JNDI -----------------------------------------
function = "set environment";
%>1<br><%
Properties environment = new Properties();
environment.setProperty( Context.INITIAL_CONTEXT_FACTORY, "allaire.ejipt.ContextFactory" );
environment.setProperty( Context.PROVIDER_URL, "ejipt://penguin.mindwrap.com:2323" );
function = "new InitialContext";
%>2<br><%
Context context = new InitialContext ( environment );
%> --- context is: <%= context %> <%
function = "context.lookup";
%>3<br><%
Object obj = context.lookup( "java:comp/env/ejb/OAS" );
function = "narrow";
%>4<br><%
OASHome oasHome = (OASHome) PortableRemoteObject.narrow( obj, OASHome.class );
// --- Use OASHome to create a new OAS Instance --------------------------
function = "create";
%>5<br><%
com.optix.ejb.OAS oas = oasHome.create( "penguin.mindwrap.com",
"optix",
"optix" );
function = "listScreen";
%>6<br><%
ScreenRec [] screens = oas.listScreen( 7 );
// function = "closeConnection";
// oas.closeConnection();
%>
<h1>OAS Test</h1>
<hr />
<%
for (int i = 0; i < screens.length; ++i)
{
%>
<p><%= screens[i].screenName %></p>
<%
}
}
catch ( Exception e )
{
%>
<h2>Failure doing <%= function %>:</h2><p><%= e.toString() %></p>
<%
}
%>
<%@ page import = "java.util.*, com.optix.ejb.*, com.optix.database.*, javax.naming.*, javax.rmi.*" %>
<%!
String function = "";
%>
<%
try
{
// --- Lookup OJBHome using JNDI -----------------------------------------
function = "set environment";
%>1<br><%
Properties environment = new Properties();
environment.setProperty( Context.INITIAL_CONTEXT_FACTORY, "allaire.ejipt.ContextFactory" );
environment.setProperty( Context.PROVIDER_URL, "ejipt://penguin.mindwrap.com:2323" );
function = "new InitialContext";
%>2<br><%
Context context = new InitialContext ( environment );
%> --- context is: <%= context %> <%
function = "list context";
NamingEnumeration enum = context.list( "" );
%>2a<br><%
function = "dump context";
int ii = 0;
while( enum.hasMore())
{
NameClassPair np = (NameClassPair) enum.next();
%>
--<%= ++ii %>-- <%= np.getClassName() %> <%= np.getName() %>
<%
}
function = "context.lookup";
%>3<br><%
Object obj = context.lookup( "java:comp/env/ejb/OAS" );
function = "narrow";
%>4<br><%
OASHome oasHome = (OASHome) PortableRemoteObject.narrow( obj, OASHome.class );
// --- Use OASHome to create a new OAS Instance --------------------------
function = "create";
%>5<br><%
com.optix.ejb.OAS oas = oasHome.create( "penguin.mindwrap.com",
"optix",
"optix" );
function = "listScreen";
%>6<br><%
ScreenRec [] screens = oas.listScreen( 7 );
// function = "closeConnection";
// oas.closeConnection();
%>
<h1>OAS Test</h1>
<hr />
<%
for (int i = 0; i < screens.length; ++i)
{
%>
<p><%= screens[i].screenName %></p>
<%
}
}
catch ( Exception e )
{
%>
<h2>Failure doing <%= function %>:</h2><p><%= e.toString() %></p>
<%
}
%>