EjbHome = (EJBHome) PortableRemoteObject.narrow(homeObject, EJBHome.class);
please explain the below given code , It is used in servicelocator (J2EE Pattern), basically to find the EjB Home
ejbHome = (EJBHome) PortableRemoteObject.narrow(homeObject, EJBHome.class);
If we plain old cast, we are assuming that the server is using the regular old RMI (which assumes that the server objects are always java objects.
RMI/IIOP allows connecting RMI objects to non-Java objects regardless of the implementation language (for interface to any native legacy code). So, in such cases (where client and server are separated by a network), one should use the
PortableRemoteObject.narrow(), which assumes that the objects that we are talking to are not always java objects.
The plain old cast will work when we use local home and component interfaces as both client and server run on the same JVM.
Rishi
Similar Messages
-
ClassCastException in PortableRemoteObject.narrow inside Weblogic
Hello,
I'm trying to invoke EJB residing on WLS 6.1 SP2 server from EJB on another exacly
the same server.
Properties properties = new Properties();
properties.put(javax.naming.Context.PROVIDER_URL, "t3://host:7001");
properties.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
ivjInitContext = new InitialContext(properties);
Object homeObject = ivjInitContext.lookup("jndiName");
BeanHome home = (BeanHome)PortableRemoteObject.narrow(homeObject,BeanHome.class);
And I get java.lang.ClassCastException: $Proxy74
on narrow line.
Everything works fine when I invoke the same code from regular java application
instead of EJB.Is it the ClassLoader problem ?
Does any workaround exists ?
Thank you.How are you generating your stubs? i.e. are you using the -iiop option? if so
then you would need to call the EJB in question using iiop://host:7001. So you
can either take out the iiop option and recompile the stubs or change the call
to iiop but then you would also need to replace this line: properties.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
with this (javax.naming.Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.cosnaming.CNCtxFactory");
hope this helps!
-geoff.
"Elena Neroslavskaya" <[email protected]> wrote:
>
Hello,
I'm trying to invoke EJB residing on WLS 6.1 SP2 server from EJB on another
exacly
the same server.
Properties properties = new Properties();
properties.put(javax.naming.Context.PROVIDER_URL, "t3://host:7001");
properties.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
ivjInitContext = new InitialContext(properties);
Object homeObject = ivjInitContext.lookup("jndiName");
BeanHome home = (BeanHome)PortableRemoteObject.narrow(homeObject,BeanHome.class);
And I get java.lang.ClassCastException: $Proxy74
on narrow line.
Everything works fine when I invoke the same code from regular java application
instead of EJB.Is it the ClassLoader problem ?
Does any workaround exists ?
Thank you. -
HomeInterface.class in PortableRemoteObject.narrow
Hi
I understand we do a JNDI look up to get the stub (HomeInterface object) and then narrow it down to ensure the object becomes RMI/IIOP compliant and it is of HomeInterface type, the following code snippet does what I have hence stated
Context cx = new InitialContext();
Object obj = cx.lookup("java:comp/env/beanString");
HomeInterface hI = PortableRemoteObject.narrow(obj, HomeInterface.class) // NOW hI is the STUB object
I am aware the Home interface will reside in the server side only, the object (obj) that is being returned is of type HomeInterface but then as we are not sure of its RMI/IIOP complaincy we narrow down the object to the Homeinterface type, as the code of HomeInterface resides in the server side how does this snippet (narrowing code) that resides in the client side identify and narrow down, the object returned, to the respective Home Interface type?
The analogy to this I could think of is ordinary type casting while we pick a object from ArrayList, as all that reside in collection is of type Object we are to typecast to the respective Object type, but here the actual object resides in the JVM so I could understand how this casting happens, but what is the case with PortableRemoteObject.narrow as the Home Interface code resides in the remote server?
Kindly replyDont you know the concept of "client.jar" ??
well, the following reside at server side:
remote interface,
home interface,
bean implementation class.
the following must reside at client side. These are packaged in a jar taht is typically called client.jar:
remote interface
home interface
Check the classpath of your client. I am sure these two interfaces are there in it. Otherwise there will be some exception.
Note that the system is sensitive to difference in the versions of home/remote. ie. if these are differet, serializationException may be thrown.
Hope that helps.
regards -
PortableRemoteObject.narrow
Why is it necessary to use and cast the result of this method call, which appears to return the same object as was passed as the first argument? In other words, why do this:
Object myObj = ctx.lookup(MYHOME);
MyHome myHome = (MyHome)
PortableRemoteObject.narrow(myObj, MyHome.class);
MyEjb myEjb = myHome.create();
-in code that must know each EJB, when you can do this:
//In a generic HomeFactory class
Object myObj = ctx.lookup(MYHOME);
Class beanHome = Class.forName(MYHOME);
PortableRemoteObject.narrow(myObj, beanHome);
return myObj
//In some other class
MyHome myHome = (MyHome) HomeFactory.getHome(MYHOME);
MyEjb = myHome.create();
I left out the try-catch blocks and all of that for compactness. The reason I ask is because a generic Home Factory can store EJBHome objects in a collection, testing them first and returning them without creating the actual remote reference, so it does not need to know the specific EJB, allowing the specific client code to cast the generic Object to the specific EJBHome object.
A Sun-certified instructor once told me that it was absolutely necessary to use the Object returned from the narrow method because it performed some essential RMI activity on the object, but I have never had a problem using it the second way I describe above in the HomeFactory. Also, I have never been able to find any documentation to substantiate his claim. Any thoughts as to the necessity of using the object returned from the narrow method? It appears to be the exact same object that is passed in to the method, and likely un-changed at that.The narrow method is there to allow an implementation to do some extra work or return a different object if it needs to. It appears that your implementation does not need to do these things so it just returns the object that was passed. If you take your shortcut, you will limit yourself to running only on your current implementation. If you try to switch implementations or even upgrade to a later version it might break. If you follow the correct method the your code will be portable.
-
PortableRemoteObject.narrow causes NoClassDefFoundError
I exhaustively searched for this error in this, and other forums, and
tried some suggested techniques, but none worked.
/* Following causes NoClassDefFoundError */
Entity1RemoteHome printHome = (Entity1RemoteHome)
PortableRemoteObject.narrow( prrefHome, Entity1RemoteHome.class );
RemoteClient1.java contains:
package com.zbeans;
import com.zbeans.Entity1Remote;
import com.zbeans.Entity1RemoteHome;
import javax.naming.InitialContext;
Context prinitctx = new InitialContext();
Context prenvctx = (Context) prinitctx.lookup("java:comp/env");
/* 'ejb/Entity1 EJB ref1' is the Reference Name appearing under the JNDI
Names tab under the application object, for the deployment tool. */
Object prrefHome = prenvctx.lookup("ejb/Entity1 EJB ref1");
/* Following causes NoClassDefFoundError */
Entity1RemoteHome printHome = (Entity1RemoteHome)
PortableRemoteObject.narrow( prrefHome, Entity1RemoteHome.class );
Binding name:`java:comp/env/ejb/Entity1 EJB ref1`
RemoteClient1.main(): NoClassDefFoundError has occurred!!
getMessage(): com.zbeans.Entity1RemoteHome
toString(): java.lang.NoClassDefFoundError: com.zbeans.Entity1RemoteHome
I ran using C:\j2sdkee1.3.1\bin>runclient -client D:\zJava\zsamples\EJB\application1\application1.ear -name RemoteClient1 -textauth
I ensured j2ee and cloudscape were running, and
set APPCPATH=application1Client.jar (application1Client.jar was generated by the deployment tool)
Entity1RemoteHome.java contains:
package com.zbeans;
import java.rmi.RemoteException;
import javax.ejb.*;
public interface Entity1RemoteHome extends javax.ejb.EJBHome {
public Entity1Remote create (Integer id)
throws CreateException, RemoteException, EJBException;
Remote1Client1, Entity1RemoteHome.java, etc. resides under
C:\JRun4\servers\default\default-ear\default-war\WEB-INF\classes\com\zbeans
I was thinking of moving RemoteClient1.java one level higher in the
directory tree. But maybe this is not necessary since the sample
Converter app. has the client in the same folder as the EJB interfaces?
- should I move the .java, and .class files from c:\jrun4\...\classes\com\zbeans
to D:\zJava\zsamples\EJB\application1\com\zbeans since this is where the
.ear, .jar are generated?
My environment settings are:
java version "1.4.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_01-b03)
Java HotSpot(TM) Client VM (build 1.4.0_01-b03, mixed mode)
WinNT 4.0 SP5
CLASSESDIR=c:\j2sdkee1.3.1\lib\classes
CLASSPATH=.;c:\j2sdkee1.3.1\lib\j2ee.jar;D:\jakarta-tomcat-3.3.1\lib\common\serv
let.jar;C:\JRun4\servers\default\default-ear\default-war\WEB-INF\classes;D:\zJav
a\zsamples\EJB\application1
J2EEJARS=c:\j2sdkee1.3.1\lib\j2ee.jar
J2EETOOL_CLASSES=c:\j2sdkee1.3.1\lib\toolclasses
J2EETOOL_JAR=c:\j2sdkee1.3.1\lib\j2eetools.jar
J2EE_HOME=c:\j2sdkee1.3.1
JAVA_HOME=C:\j2sdk1.4.0_01
etc.Refer to
http://access1.sun.com/FAQSets/ejbfaq.html#17 -
A error from javax.rmi.PortableRemoteObject.narrow
--run envrionment: jdk1.4.2_01 / oc4j9.0.4
--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 void doGet(
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());
--My application client can run correctly, but my servlet code can't run.
--If I start oc4j by follow statement:
java -jar oc4j.jar
--the error display:
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)
--If I start oc4j by follow statement:
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
--the error is:
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--run envrionment: jdk1.4.2_01 / oc4j9.0.4
--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 void doGet(
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());
--My application client can run correctly, but my servlet code can't run.
--If I start oc4j by follow statement:
java -jar oc4j.jar
--the error display:
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)
--If I start oc4j by follow statement:
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
--the error is:
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 -
Hi All,
I got a big head ache of this problem for several days, much appreciated if
I can get help from you.
The problem is, I wrote an EJB and already deployed it into Weblogic5.1. I
also wrote a java EJB client to access this EJB. Everything seemed ok at
this moment.
The problem occured after i convert this EJB client to ActiveX and test it
with Microsoft ActiveX Control Test Container. I log each step in the
ActiveX, and find the problem is caused by
javax.rmi.PortableRemoteObject.narrow(). Below is my source code and log
information. My environment is Server side(weblogic5.1),Client side(java
run-time3.1 with plug-in).
Source code:
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFacto
ry");
env.put(Context.PROVIDER_URL,"t3://"+ip+":"+port);
try{
Log("Init jndi ");
InitialContext ctx = new InitialContext(env);
Log("Search Home ");
Object obj = ctx.lookup("ServiceManagerHome");
Log("home is "+obj);
Log("narrow from "+obj.getClass().getName());
Log("narrow to "+ServiceManagerHome.class.getName());
obj = PortableRemoteObject.narrow(obj,ServiceManagerHome.class);
Log("narrow home is "+obj);
serviceHome = (ServiceManagerHome)obj;
Log("cast home"+serviceHome);
serviceManager = serviceHome.create();
Log("Create EJB bean "+serviceManager);
} catch (Exception e){
Log("Err-"+e);
Log("Err-"+e.getLocalizedMessage());
Log("Err-"+e.getMessage());
Log information for ActiveX:
Init jndi
Search Home
home is ServiceManagerHome [
-4611900794319518045S155.161.96.26:[7001,7001,7002,7002,7001,-1]/259]
narrow from rm.service.ejbimpl.ServiceManagerBeanHomeImpl_ServiceStub
narrow to crm.service.ejbimpl.ServiceManagerHome
Err-java.lang.ClassCastException
Err-null
Err-null
Log information for java EJB Client:
Init jndi
Search Home
home is
crm.service.ejbimpl.ServiceManagerBeanHomeImpl_ServiceStub@-4611900794319518
045S155.161.96.26:[7001,7001,7002,7002,7001,-1] ServiceManagerHome [
-4611900794319518045S155.161.96.26:[7001,7001,7002,7002,7001,-1]/259
narrow from crm.service.ejbimpl.ServiceManagerBeanHomeImpl_ServiceStub
narrow to crm.service.ejbimpl.ServiceManagerHome
narrow home
crm.service.ejbimpl.ServiceManagerBeanHomeImpl_ServiceStub@-4611900794319518
045S155.161.96.26:[7001,7001,7002,7002,7001,-1] ServiceManagerHome [
-4611900794319518045S155.161.96.26:[7001,7001,7002,7002,7001,-1]/259]
cast
homecrm.service.ejbimpl.ServiceManagerBeanHomeImpl_ServiceStub@-461190079431
9518045S155.161.96.26:[7001,7001,7002,7002,7001,-1] ServiceManagerHome [
-4611900794319518045S155.161.96.26:[7001,7001,7002,7002,7001,-1]/259
Create serviceManager
crm.service.ejbimpl.ServiceManagerBeanEOImpl_ServiceStub@-461190079431951804
5S155.161.96.26:[7001,7001,7002,7002,7001,-1] ServiceManagerHome_EO [
-4611900794319518045S155.161.96.26:[7001,7001,7002,7002,7001,-1]/258Contact support.
Yuan Ming Lei wrote:
Hi All,
I got a big head ache of this problem for several days, much appreciated if
I can get help from you.
The problem is, I wrote an EJB and already deployed it into Weblogic5.1. I
also wrote a java EJB client to access this EJB. Everything seemed ok at
this moment.
The problem occured after i convert this EJB client to ActiveX and test it
with Microsoft ActiveX Control Test Container. I log each step in the
ActiveX, and find the problem is caused by
javax.rmi.PortableRemoteObject.narrow(). Below is my source code and log
information. My environment is Server side(weblogic5.1),Client side(java
run-time3.1 with plug-in).
Source code:
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFacto
ry");
env.put(Context.PROVIDER_URL,"t3://"+ip+":"+port);
try{
Log("Init jndi ");
InitialContext ctx = new InitialContext(env);
Log("Search Home ");
Object obj = ctx.lookup("ServiceManagerHome");
Log("home is "+obj);
Log("narrow from "+obj.getClass().getName());
Log("narrow to "+ServiceManagerHome.class.getName());
obj = PortableRemoteObject.narrow(obj,ServiceManagerHome.class);
Log("narrow home is "+obj);
serviceHome = (ServiceManagerHome)obj;
Log("cast home"+serviceHome);
serviceManager = serviceHome.create();
Log("Create EJB bean "+serviceManager);
} catch (Exception e){
Log("Err-"+e);
Log("Err-"+e.getLocalizedMessage());
Log("Err-"+e.getMessage());
Log information for ActiveX:
Init jndi
Search Home
home is ServiceManagerHome [
-4611900794319518045S155.161.96.26:[7001,7001,7002,7002,7001,-1]/259]
narrow from rm.service.ejbimpl.ServiceManagerBeanHomeImpl_ServiceStub
narrow to crm.service.ejbimpl.ServiceManagerHome
Err-java.lang.ClassCastException
Err-null
Err-null
Log information for java EJB Client:
Init jndi
Search Home
home is
crm.service.ejbimpl.ServiceManagerBeanHomeImpl_ServiceStub@-4611900794319518
045S155.161.96.26:[7001,7001,7002,7002,7001,-1] ServiceManagerHome [
-4611900794319518045S155.161.96.26:[7001,7001,7002,7002,7001,-1]/259
narrow from crm.service.ejbimpl.ServiceManagerBeanHomeImpl_ServiceStub
narrow to crm.service.ejbimpl.ServiceManagerHome
narrow home
crm.service.ejbimpl.ServiceManagerBeanHomeImpl_ServiceStub@-4611900794319518
045S155.161.96.26:[7001,7001,7002,7002,7001,-1] ServiceManagerHome [
-4611900794319518045S155.161.96.26:[7001,7001,7002,7002,7001,-1]/259]
cast
homecrm.service.ejbimpl.ServiceManagerBeanHomeImpl_ServiceStub@-461190079431
9518045S155.161.96.26:[7001,7001,7002,7002,7001,-1] ServiceManagerHome [
-4611900794319518045S155.161.96.26:[7001,7001,7002,7002,7001,-1]/259
Create serviceManager
crm.service.ejbimpl.ServiceManagerBeanEOImpl_ServiceStub@-461190079431951804
5S155.161.96.26:[7001,7001,7002,7002,7001,-1] ServiceManagerHome_EO [
-4611900794319518045S155.161.96.26:[7001,7001,7002,7002,7001,-1]/258 -
Confusion in PortableRemoteObject.narrow() method
In EJB 1.0 reference of home object is obtained through external casting as HelloHome home = (HelloHome)ctx.lookup("HelloHome")
My question is that since IIOP has not been designed for Java, but for generic languages, and this means that there are some limitations. Some languages, in fact, do not have the concept of casting.
Still why we have to cast the Object if we use PortableRemoteObject.narrow method for obtaining the home interface reference in EJB2.0.
HelloHome home = (HelloHome)javax.rmi.PortableRemoteObject.narrow(object, HelloHome.class)If the client is built using Java, you can not explicitly cast from the Naming.lookup() function. Instead, you must use lookup() to return a generic java.lang.Object, and then cast to the specific object type with the PortableRemoteObject.Narrow(objectReference, interfaceName) method.
-
How to solve PortableRemoteObject.narrow exception
Hi ,
I am getting portableRemoteObject exception... when i tried to narrow the stub with home class.
Please find my code:
Object objRef = ctx.lookup("java:comp/env/ejb/ejbSchedularBean"
TaskHandlerHome home = (TaskHandlerHome) javax.rmi.PortableRemoteObject.narrow(objRef,TaskHandlerHome.class);
Please help me to solve.
cannot cast class com.ibm.websphere.schedular._TaskHandlerHome_Stub to interface com.ibm.websphere.scheduler.TaskHandlerHome
at com.ibm.rmi.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:396)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:156)
at com.ibm.websphere.schedular.CallBeanTask.getBeanClassInstance(CallBeanTask.java:66)
at com.sched.servlet.SchedulerServlet.init(SchedulerServlet.java:25)
at javax.servlet.GenericServlet.init(GenericServlet.java:256)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.init(ServletWrapper.java:185)
at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.init(ServletWrapper.java:316)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.initialize(ServletWrapper.java:1119)
at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.initialize(ServletWrapper.java:149)
at com.ibm.wsspi.webcontainer.extension.WebExtensionProcessor.createServletWrapper(WebExtensionProcessor.java:99)
at com.ibm.ws.webcontainer.webapp.WebApp.getServletWrapper(WebApp.java:742)
at com.ibm.ws.webcontainer.webapp.WebApp.initializeTargetMappings(WebApp.java:422)
at com.ibm.ws.webcontainer.webapp.WebApp.commonInitializationFinish(WebApp.java:275)
at com.ibm.ws.wswebcontainer.webapp.WebApp.initialize(WebApp.java:272)
at com.ibm.ws.wswebcontainer.webapp.WebGroup.addWebApplication(WebGroup.java:88)
at com.ibm.ws.wswebcontainer.VirtualHost.addWebApplication(VirtualHost.java:157)
at com.ibm.ws.wswebcontainer.WebContainer.addWebApp(WebContainer.java:655)
at com.ibm.ws.wswebcontainer.WebContainer.addWebApplication(WebContainer.java:608)
at com.ibm.ws.webcontainer.component.WebContainerImpl.install(WebContainerImpl.java:333)
Regards.
surI have created a simple applet.
import java.lang.*;
import java.awt.*;
public class jawtex3 extends java.applet.Applet
public void init()
add(new Button("One"));
add(new Button("Two"));
public Dimension preferredSize()
return new Dimension(200, 100);
public static void main(String [] args)
Frame f = new Frame(" jawtex3");
jawtex3 ex = new jawtex3();
ex.init();
f.add("Center", ex);
f.pack();
f.show();
In this no compilation errors.
I am getting runtime exception.as Exception in thread "main"java.lang.NoClassDefFound Error: jawtex
reply me soon.
thankyou. -
ClassCastException while PortableRemoteObject.narrow
Hello,
I am getting the ClassCastException when I am narrowing the looked up home object.
Here is the exception:
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 samples.ejb.client.HelloClient.main(HelloClient.java:50)
Here is the code :
try {
System.out.println("Looking up greeter bean home interface");
String JNDIName = "HelloGreet";
System.out.println("Looking up: " + JNDIName);
Object objref = initContext.lookup(JNDIName);
System.out.println("Object from the look up -->"+objref);
home = (HelloHome)javax.rmi.PortableRemoteObject.narrow(objref, HelloHome.class);
any help appreciated. Thanks in advance
With Regards,
J. P. NaiduHi Pullaiah,
I've same problem with Sun ONE AS (notice that I encounter same problem on J2EE Reference Implementation too).I looked up for a solution everywhere but I did't find it and I'd be very happy if someone could post one.
Thanks ,
Fil -
Javax.rmi.portableRemoteObject.narrow
Hi
Pls tell me why we narrow the instance of the object we looked up,
before type casting it to a home referance by using javax.rmi.portableRemoteObject.narrow(Object,Home.class)In the early days of EJB this call was required to ensure portability due to some intracacies of how
RMI-IIOP and CORBA ORBs are implemented. Some implementations are able to directly return
the correctly typed object from the lookup, but in others the extra PortableRemoteObject.narrow
call is necessary, so always using it ensures portability.
Starting in Java EE 5, PortableRemoteObject.narrow is not needed if the code is either accessing
a Remote 3.0 Business Interface or if the code is accessing a 2.x style Home object using
@EJB or the new EJBContext.lookup method.
--ken -
ClassCastException with PortableRemoteObject.narrow call
I want to call an ejb component located on a different machine and I can not get it to work. So I tried to deploy it under my version of jboss and try to invoke it. I was able to call it but when I added Context.PROVIDER_URL to my properties I get a classCastException.
String host = "jnp://localhost:1099";
props.setProperty(Context.PROVIDER_URL, host);
I started getting the following exception
2006-11-03 10:17:18,319 ERROR [STDERR] java.lang.ClassCastException
2006-11-03 10:17:18,319 ERROR [STDERR] at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narr
ow(PortableRemoteObject.java:229)
2006-11-03 10:17:18,319 ERROR [STDERR] at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObjec
t.java:137)
As soon as I uncomment that props.setProperty(Context.PROVIDER_URL, host);
line everything works fine.
I have seen this type of exception before when I tried invoking the ejb on a different computer as well. When I inspect the object with reflection I see that it found the right interface.
This is my code again:
Properties props = new Properties();
props.setProperty(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.security.jndi.JndiLoginInitialContextFactory");
props.setProperty(Context.SECURITY_PRINCIPAL, "admin");
props.setProperty(Context.SECURITY_CREDENTIALS, "admin");
props.put(javax.naming.Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
String host = "jnp://localhost:1099";
props.setProperty(Context.PROVIDER_URL, host);
ctx = new InitialContext( props );
Object object = ctx.lookup( "ejb/com/blah/Manager" );
ManagerRemoteHome home = (ManagerRemoteHome)PortableRemoteObject.narrow ( object, ManagerRemoteHome.class);
ManagerRemote manager = home.create();
Thanks1099 is the RMI/JRMP Registry. You are using RMI/IIOP. Is this port number really correct?
-
Classcastexception on portableremoteobject narrow
I was successfully connecting to an EJB on my WebLogic server from a Java
IDL client using the iiop protocol, cosnaming initialcontextfactory. I'm at
a loss as to what is different now that is causing this to fail. I'm sure
it has something to do with how I'm generating the stubs and/or the
client/server classpath, but can't see what I'm doing wrong now. My steps
are as follows.
1) Create the EJB jar (call it jar1) using weblogic.ejbc
2) Run jar1 through weblogic.ejbc using -idl -iiop, creating jar2
3) Deploy jar2 in the java client's classpath
I get the initial context fine, but when I get to this line:
_home = (myHome)(PortableRemoteObject.narrow(ctx, myHome.class));
I get the following error:
java.lang.ClassCastException
at
com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemo
teObject.java:296)
Can anyone give me some assistance?
Thx!
Sandy BarlettaOk, here's what's going on here. The problem happens when I use
com.sun.jndi.cosnaming.CNCtxFactory as my initial context factory. After the
lookup of the home interface, what I get back in my context object if I call
getClass().getName() is the following:
com.sun.jndi.cosnaming.CNCtx
The class cast exception occurs when I try to narrow this to my home
interface.
If I use weblogic.jndi.WLInitialContextFactory instead of
com.sun.jndi.cosnaming.CNCtxFactory, what I get back in my context object if
I call getClass().getName() is
com.sun.corba.se.internal.iiop.CDRInputStream$1 and the narrow succeeds.
What gives? Do I have to use the weblogic context factory? I was hoping to
avoid the need for weblogic packages on the client. Also, our whole reason
for using IIOP was to avoid compatibility problems between weblogic servers
running at different version levels. If I have to use the weblogic context
factory, and we have a weblogic client running at a different version from
the server, will there be problem?
Sandy Barletta
"Sandy Barletta" <[email protected]> wrote in message
news:[email protected]...
I was successfully connecting to an EJB on my WebLogic server from a Java
IDL client using the iiop protocol, cosnaming initialcontextfactory. I'mat
a loss as to what is different now that is causing this to fail. I'm sure
it has something to do with how I'm generating the stubs and/or the
client/server classpath, but can't see what I'm doing wrong now. My steps
are as follows.
1) Create the EJB jar (call it jar1) using weblogic.ejbc
2) Run jar1 through weblogic.ejbc using -idl -iiop, creating jar2
3) Deploy jar2 in the java client's classpath
I get the initial context fine, but when I get to this line:
_home = (myHome)(PortableRemoteObject.narrow(ctx, myHome.class));
I get the following error:
java.lang.ClassCastException
at
com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemo
teObject.java:296)
Can anyone give me some assistance?
Thx!
Sandy Barletta -
Why PortableRemoteObject.narrow()
Hello,
Can any one please suggest me the difference in looking Up of the components in 2 ways..??
1) HelloHome home = (HelloHome)ctx.lookup("HelloHome")
2) Object ref = getInitialContext().lookup(eb/HelloBean);
HelloHome home = (HelloHome)javax.rmi.PortableRemoteObject.narrow(ref, HelloHome.class)
Why we need option 2 when we get a home object when we make a look up as in 1.
why PortableRemoteObject.narrow()
Please make ur suggestions.
Thanks.Hi,
From an article at http://java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/ejb-tier/ejb-tier9.html
Type narrowing is needed because many application servers use RMI-IIOP as the communication protocol to access remote beans. However, some application servers do not use RMI-IIOP and hence allow the use of Java language typecasts as well. For portability you cannot rely on an application server allowing Java language typecasts; you should always use the PortableRemoteObject.narrow method. The overhead on this method call is usually quite small
-Amol -
PortableRemoteObject.narrow(...) error , why?
when I execute
PortableRemoteObject.narrow(objred, SBeanHome.class);
the system throw an exception
java.lang.ClassCastException: $Proxy78
Please help me!
(my application server is weblogic 6.1)Object obj = (MyHomeInterface) ctx.lookup("Invoice.MyHomeInterface");
MyHomeInterface home = (MyHomeInterface) PortableRemoteObject.narrow(obj, MyHomeInterface.class);
use this code instead.
i hope that this will solve your problem change the code according to your classes.
Maybe you are looking for
-
Iphone 4s wifi grayed out after updating to ios 8.1.2
iphone 4s users any body facing wifi grayed out issue after updating to ios 8.1.2?..please help me out to solve it.
-
On my iphone 4 settings-- how do I "ADD ACCOUNT" on mail, contacts, calendars, should I wish to BACKUP my icloud settings to my MS OUTLOOK on my Windows 7computer? The only MS accounts listed on the iphone ate MS Hotmail and MS Exchange, but not Out
-
Cannot View the Employee Salary Report in BI Publisher
Hi, everyone, I have installed the Standalone version of bi publisher for windows (bipublisher_windows_x86_101341). I have logged in as administrator, I have connected to my oracle database 11g thru jdbc succesfully. i cannot view the Employee Salary
-
HP Officejet Pro 8620 e-all-in-one printer & dual band router
Hi, I'm hoping someone will be able to confirm whether this printer is compatible with my router which is a dual band 2.4 GHz and 5 GHz. I am not able to connect it to the internet. The box says that the printer is compatible only with 2.4 GHz router
-
Problems with java.util.zip
I've got a odd problem here. I'm not sure if this is the appropriate forum but I couldn't find anyplace more appropriate. So the problem is... I create my ZIP file and if I open it in WinZip, no problem. But if I open the ZIP file using the 'Compress