C
cloudjava
Unregistered / Unconfirmed
GUEST, unregistred user!
--运行环境:jdk1.4.2_01 / oc4j9.0.4
--servlet source code
import java.util.*;
import java.io.IOException;
import java.rmi.RemoteException;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.ejb.*;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
import java.sql.*;
public class ProductServlet extends HttpServlet
{
server.ProductHome myProductHome;
public void init() throws ServletException {
try {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.evermind.server.rmi.RMIInitialContextFactory");
env.put(Context.PROVIDER_URL, "ormi://localhost/JDBCEJB");
env.put(Context.SECURITY_PRINCIPAL, "store_user");
env.put(Context.SECURITY_CREDENTIALS, "store_password");
Context myInitialContext = new InitialContext(env);
Object homeObject = myInitialContext.lookup("ProductBean");
myProductHome = (server.ProductHome)PortableRemoteObject.narrow(homeObject,server.ProductHome.class);
} catch(NamingException e) {
throw new ServletException("Error looking up home", e);
}
}
public voiddo
Get(
HttpServletRequest request, HttpServletResponse response
) throws ServletException, IOException {
response.setContentType("text/html;charset=BIG5");
ServletOutputStream out = response.getOutputStream();
out.println("<html>");
out.println("<head><title>Product</title></head>");
out.println("<body>");
out.println("<table width=100% border=1>");
out.println("<tr>");
out.println("<th>Id</th>");
out.println("<th>Name</th>");
out.println("<th>Address</th>");
out.println("<th>Bdate</th>");
out.println("</tr>");
try {
server.ProductRemote myProductRemote = myProductHome.create();
server.Product myProduct = myProductRemote.query(request.getParameter("guess"));
if (myProduct != null) {
out.println("<tr>");
out.println("<td>" + myProduct.id + "</td>");
out.println("<td>" + myProduct.name + "</td>");
out.println("<td>" + myProduct.ads + "</td>");
out.println("<td>" + myProduct.bdate + "</td>");
out.println("</tr>");
}
out.println("</table>");
out.println("</body></html>");
} catch(RemoteException e) {
out.println("Error communicating with EJB-server: " +
e.getMessage());
} catch(CreateException e) {
out.println("Error creating EJB: " + e.getMessage());
} catch(SQLException e) {
out.println("SQL Exception: " + e.getMessage());
}
}
}
--我用application client可以正确运行,上述代码在oc4j9.0.2上也可运行,但是在oc4j 9.0.4版就不行了
--如果我改成以下方式运行oc4j
java -jar oc4j.jar
--显示错误信息如下:
java.lang.ClassCastException
at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:293)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)
at ProductServlet.init(ProductServlet.java:39)
at javax.servlet.GenericServlet.init(GenericServlet.java:258)
at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpApplication.loadServlet(HttpApplication.java:2091)
at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpApplication.findServlet(HttpApplication.java:4507)
at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpApplication.getRequestDispatcher(HttpApplication.java:2410)
at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:629)
at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpRequestHandler.run(HttpRequestHandler.java:264)
at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpRequestHandler.run(HttpRequestHandler.java:107)
at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:186)
at java.lang.Thread.run(Thread.java:534)
--假如我照一些论坛介绍的加-D参数运行
java -jar -Djavax.rmi.CORBA.PortableRemoteObjectClass=com.sun.corba.se.internal.javax.rmi.PortableRemoteObject -Djavax.rmi.CORBA.UtilClass=com.sum.corba.se.internal.POA.ShutdownUtilDelegate oc4j.jar
--显示错误信息是:
java.lang.ExceptionInInitializerError
at javax.rmi.PortableRemoteObject.createDelegateIfSpecified(PortableRemoteObject.java:179)
at javax.rmi.PortableRemoteObject.<clinit>(PortableRemoteObject.java:58)
at ProductServlet.init(ProductServlet.java:39)
at javax.servlet.GenericServlet.init(GenericServlet.java:258)
at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpApplication.loadServlet(HttpApplication.java:2091)
at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpApplication.findServlet(HttpApplication.java:4507)
at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpApplication.getRequestDispatcher(HttpApplication.java:2410)
at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:629)
at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpRequestHandler.run(HttpRequestHandler.java:264)
at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpRequestHandler.run(HttpRequestHandler.java:107)
at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:186)
at java.lang.Thread.run(Thread.java:534)
Caused by: org.omg.CORBA.INITIALIZE: cannot instantiate com.sum.corba.se.internal.POA.ShutdownUtilDelegate vmcid: 0x0 minor code: 0 completed: No
at javax.rmi.CORBA.Util.createDelegateIfSpecified(Util.java:341)
at javax.rmi.CORBA.Util.<clinit>(Util.java:51)
... 12 more
这些问题困扰我很久,我查遍oracle网站的forum,得到结果只是认为有类重复加载,
但.PortableRemoteObject方法在jdk中的rt.jar本身就重复存在,怎么样才能消去这种对oc4j的影响?
--servlet source code
import java.util.*;
import java.io.IOException;
import java.rmi.RemoteException;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.ejb.*;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
import java.sql.*;
public class ProductServlet extends HttpServlet
{
server.ProductHome myProductHome;
public void init() throws ServletException {
try {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.evermind.server.rmi.RMIInitialContextFactory");
env.put(Context.PROVIDER_URL, "ormi://localhost/JDBCEJB");
env.put(Context.SECURITY_PRINCIPAL, "store_user");
env.put(Context.SECURITY_CREDENTIALS, "store_password");
Context myInitialContext = new InitialContext(env);
Object homeObject = myInitialContext.lookup("ProductBean");
myProductHome = (server.ProductHome)PortableRemoteObject.narrow(homeObject,server.ProductHome.class);
} catch(NamingException e) {
throw new ServletException("Error looking up home", e);
}
}
public voiddo
Get(
HttpServletRequest request, HttpServletResponse response
) throws ServletException, IOException {
response.setContentType("text/html;charset=BIG5");
ServletOutputStream out = response.getOutputStream();
out.println("<html>");
out.println("<head><title>Product</title></head>");
out.println("<body>");
out.println("<table width=100% border=1>");
out.println("<tr>");
out.println("<th>Id</th>");
out.println("<th>Name</th>");
out.println("<th>Address</th>");
out.println("<th>Bdate</th>");
out.println("</tr>");
try {
server.ProductRemote myProductRemote = myProductHome.create();
server.Product myProduct = myProductRemote.query(request.getParameter("guess"));
if (myProduct != null) {
out.println("<tr>");
out.println("<td>" + myProduct.id + "</td>");
out.println("<td>" + myProduct.name + "</td>");
out.println("<td>" + myProduct.ads + "</td>");
out.println("<td>" + myProduct.bdate + "</td>");
out.println("</tr>");
}
out.println("</table>");
out.println("</body></html>");
} catch(RemoteException e) {
out.println("Error communicating with EJB-server: " +
e.getMessage());
} catch(CreateException e) {
out.println("Error creating EJB: " + e.getMessage());
} catch(SQLException e) {
out.println("SQL Exception: " + e.getMessage());
}
}
}
--我用application client可以正确运行,上述代码在oc4j9.0.2上也可运行,但是在oc4j 9.0.4版就不行了
--如果我改成以下方式运行oc4j
java -jar oc4j.jar
--显示错误信息如下:
java.lang.ClassCastException
at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:293)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)
at ProductServlet.init(ProductServlet.java:39)
at javax.servlet.GenericServlet.init(GenericServlet.java:258)
at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpApplication.loadServlet(HttpApplication.java:2091)
at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpApplication.findServlet(HttpApplication.java:4507)
at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpApplication.getRequestDispatcher(HttpApplication.java:2410)
at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:629)
at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpRequestHandler.run(HttpRequestHandler.java:264)
at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpRequestHandler.run(HttpRequestHandler.java:107)
at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:186)
at java.lang.Thread.run(Thread.java:534)
--假如我照一些论坛介绍的加-D参数运行
java -jar -Djavax.rmi.CORBA.PortableRemoteObjectClass=com.sun.corba.se.internal.javax.rmi.PortableRemoteObject -Djavax.rmi.CORBA.UtilClass=com.sum.corba.se.internal.POA.ShutdownUtilDelegate oc4j.jar
--显示错误信息是:
java.lang.ExceptionInInitializerError
at javax.rmi.PortableRemoteObject.createDelegateIfSpecified(PortableRemoteObject.java:179)
at javax.rmi.PortableRemoteObject.<clinit>(PortableRemoteObject.java:58)
at ProductServlet.init(ProductServlet.java:39)
at javax.servlet.GenericServlet.init(GenericServlet.java:258)
at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpApplication.loadServlet(HttpApplication.java:2091)
at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpApplication.findServlet(HttpApplication.java:4507)
at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpApplication.getRequestDispatcher(HttpApplication.java:2410)
at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:629)
at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpRequestHandler.run(HttpRequestHandler.java:264)
at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpRequestHandler.run(HttpRequestHandler.java:107)
at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:186)
at java.lang.Thread.run(Thread.java:534)
Caused by: org.omg.CORBA.INITIALIZE: cannot instantiate com.sum.corba.se.internal.POA.ShutdownUtilDelegate vmcid: 0x0 minor code: 0 completed: No
at javax.rmi.CORBA.Util.createDelegateIfSpecified(Util.java:341)
at javax.rmi.CORBA.Util.<clinit>(Util.java:51)
... 12 more
这些问题困扰我很久,我查遍oracle网站的forum,得到结果只是认为有类重复加载,
但.PortableRemoteObject方法在jdk中的rt.jar本身就重复存在,怎么样才能消去这种对oc4j的影响?