RE: EJB question
Hi Nick, I seem to get the same problem ( orion returns a StatefulSessionHomeWrapper3 class instead of session home resulting in class cast exception). I have a feeling this has got something to do with jsps having different ClassLoader. The demo news app does something like pageContext.getPage().getClass().getClassLoader(...) in their taglibs. I am using Resin now as the servlet engine it works fine( as resin is just another java client for Orion and the same code works fine if i use it in a test java client.) Would prefer to use orion for everything instead of having separate web server but it seems to leave with very little option. BTW the bugs 37 and 45 have got resolved thanks to your efforts in posting them. Cheers Krishnan -Original Message- From: Nick Newman [mailto:[EMAIL PROTECTED]] Sent: Thursday, September 14, 2000 1:45 PM To: Orion-Interest Subject: Re: EJB question Hi Kit, I'm not sure that I tell you for SURE why it failed, but here are a few thoughts. Firstly, I think that some of the code you write is unnecessary. What I would have written is: Context context = new InitialContext(); // No properties required Object homeObject = context.lookup("java:comp/env/MyCart"); // Note the required "java:comp/env/" prefix CartHome home = (CartHome)PortableRemoteObject.narrow(homeObject,CartHome.class); Cart cart = home.create(); // No cast required - home.create() returns a Cart But that probably didn't cause your problem. I would guess that it was caused by a discrepancy between the class types specified in the XML and in the code. Firstly note that in the WEB-INF/web.xml you should have a section looking something like the following: ejb-ref ejb-ref-nameMyCart/ejb-ref-name ejb-ref-typeSession/ejb-ref-type homecom.acme.MyCartHome/home remotecom.acme.MyCart/remote /ejb-ref (If you don't, the "lookup" will fail, even though it may have worked without the "java:comp/env/" prefix.) Then the error you have seems to be saying that what is in the home part of the xml doesn't match the CartHome class that is being used in your Java code. Hope this helps! Nick At 03:05 PM 9/14/00 -0400, you wrote: Hi all I am trying to build a servlet client to look up an ejb. But, i got the following error. 500 Internal Server Error java.lang.ClassCastException: CartHome_StatefulSessionHomeWrapper1 at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java, Compiled Code) at testCart.doGet(testCart.java, Compiled Code) at javax.servlet.http.HttpServlet.service(HttpServlet.java, Compiled Code) at javax.servlet.http.HttpServlet.service(HttpServlet.java, Compiled Code) at javax.servlet.http.HttpServlet.service(HttpServlet.java, Compiled Code) at com.evermind.server.http.du.rr(JAX, Compiled Code) at com.evermind.server.http.du.forward(JAX, Compiled Code) at com.evermind.server.http.d5.rx(JAX, Compiled Code) at com.evermind.server.http.d5.rw(JAX) at com.evermind.util.f.run(JAX, Compiled Code) this is what i did to do the look up. final Properties properties = new Properties(); properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,"com.evermind.server. ApplicationClientInitialContextFactory"); properties.setProperty(Context.PROVIDER_URL,"ormi://localhost/ejbsamples"); properties.setProperty(Context.SECURITY_PRINCIPAL,"username"); properties.setProperty(Context.SECURITY_CREDENTIALS, "password"); Context context = new InitialContext(properties); Object homeObject = context.lookup("MyCart"); CartHome home = (CartHome)PortableRemoteObject.narrow(homeObject,CartHome.class); Cart cart = (Cart)PortableRemoteObject.narrow(home.create(), Cart.class); Can anyone tell me why it failed ? Thanks a lot. -kit
Re: EJB question
Hi Kit, I'm not sure that I tell you for SURE why it failed, but here are a few thoughts. Firstly, I think that some of the code you write is unnecessary. What I would have written is: Context context = new InitialContext(); // No properties required Object homeObject = context.lookup("java:comp/env/MyCart"); // Note the required "java:comp/env/" prefix CartHome home = (CartHome)PortableRemoteObject.narrow(homeObject,CartHome.class); Cart cart = home.create(); // No cast required - home.create() returns a Cart But that probably didn't cause your problem. I would guess that it was caused by a discrepancy between the class types specified in the XML and in the code. Firstly note that in the WEB-INF/web.xml you should have a section looking something like the following: ejb-ref ejb-ref-nameMyCart/ejb-ref-name ejb-ref-typeSession/ejb-ref-type homecom.acme.MyCartHome/home remotecom.acme.MyCart/remote /ejb-ref (If you don't, the "lookup" will fail, even though it may have worked without the "java:comp/env/" prefix.) Then the error you have seems to be saying that what is in the home part of the xml doesn't match the CartHome class that is being used in your Java code. Hope this helps! Nick At 03:05 PM 9/14/00 -0400, you wrote: Hi all I am trying to build a servlet client to look up an ejb. But, i got the following error. 500 Internal Server Error java.lang.ClassCastException: CartHome_StatefulSessionHomeWrapper1 at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java, Compiled Code) at testCart.doGet(testCart.java, Compiled Code) at javax.servlet.http.HttpServlet.service(HttpServlet.java, Compiled Code) at javax.servlet.http.HttpServlet.service(HttpServlet.java, Compiled Code) at javax.servlet.http.HttpServlet.service(HttpServlet.java, Compiled Code) at com.evermind.server.http.du.rr(JAX, Compiled Code) at com.evermind.server.http.du.forward(JAX, Compiled Code) at com.evermind.server.http.d5.rx(JAX, Compiled Code) at com.evermind.server.http.d5.rw(JAX) at com.evermind.util.f.run(JAX, Compiled Code) this is what i did to do the look up. final Properties properties = new Properties(); properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,"com.evermind.server. ApplicationClientInitialContextFactory"); properties.setProperty(Context.PROVIDER_URL,"ormi://localhost/ejbsamples"); properties.setProperty(Context.SECURITY_PRINCIPAL,"username"); properties.setProperty(Context.SECURITY_CREDENTIALS, "password"); Context context = new InitialContext(properties); Object homeObject = context.lookup("MyCart"); CartHome home = (CartHome)PortableRemoteObject.narrow(homeObject,CartHome.class); Cart cart = (Cart)PortableRemoteObject.narrow(home.create(), Cart.class); Can anyone tell me why it failed ? Thanks a lot. -kit
RE: ejb question
I would put this class at: \cart\cart-ejb\cart\CartHome.class The WEB-INF\classes directory is for servlet classes. -Original Message- From: Derek Akers [SMTP:[EMAIL PROTECTED]] Sent: September 6, 2000 10:38 AM To: Orion-Interest Subject: ejb question I am trying to access an ejb (stateful session) from a jsp using: Context initialContext = new InitialContext(); CartHome cartHome = (CartHome)javax.rmi.PortableRemoteObject.narrow(initialContext.lookup("jav a:comp/env/ejb/cart"),CartHome.class); where the bean is cart.CartBean the home interface is cart.CartHome the remote interface is cart.Cart (cart is the package) but I keep getting the error error: File D:\orion\applications\cart\cart-web\WEB-INF\classes\CartHome.class does not contain type CartHome as expected, but type cart.CartHome. Please remove the file, or make sure it appears in the correct subdirectory of the class path. Now, I have tried putting the *.java files in classes\cart directory, but this does not work. Does anyone have any ideas as to how to fix this problem so I can access the bean? jsp:useBean../ does not work. Are there other simple ways which I can use to access this bean?
Re: ejb question
Derek; Try using "java:comp/env/ejb/cart.CartBean" in the lookup. Cathy Derek Akers wrote: I am trying to access an ejb (stateful session) from a jsp using: Context initialContext = new InitialContext(); CartHome cartHome = (CartHome)javax.rmi.PortableRemoteObject.narrow(initialContext.lookup("java:comp/env/ejb/cart"),CartHome.class); where the bean is cart.CartBean the home interface is cart.CartHome the remote interface is cart.Cart (cart is the package) but I keep getting the error error: File D:\orion\applications\cart\cart-web\WEB-INF\classes\CartHome.class does not contain type CartHome as expected, but type cart.CartHome. Please remove the file, or make sure it appears in the correct subdirectory of the class path. Now, I have tried putting the *.java files in classes\cart directory, but this does not work. Does anyone have any ideas as to how to fix this problem so I can access the bean? jsp:useBean../ does not work. Are there other simple ways which I can use to access this bean?
Re: ejb question
Oops, I mean "java:comp/env/ejb/Cart". Cathleen Dull wrote: Derek; Try using "java:comp/env/ejb/cart.CartBean" in the lookup. Cathy Derek Akers wrote: I am trying to access an ejb (stateful session) from a jsp using: Context initialContext = new InitialContext(); CartHome cartHome = (CartHome)javax.rmi.PortableRemoteObject.narrow(initialContext.lookup("java:comp/env/ejb/cart"),CartHome.class); where the bean is cart.CartBean the home interface is cart.CartHome the remote interface is cart.Cart (cart is the package) but I keep getting the error error: File D:\orion\applications\cart\cart-web\WEB-INF\classes\CartHome.class does not contain type CartHome as expected, but type cart.CartHome. Please remove the file, or make sure it appears in the correct subdirectory of the class path. Now, I have tried putting the *.java files in classes\cart directory, but this does not work. Does anyone have any ideas as to how to fix this problem so I can access the bean? jsp:useBean../ does not work. Are there other simple ways which I can use to access this bean?
Re: EJB Question(s)
Hello Kevin, Kevin Duffey wrote: Ok..you've got me concerned here. I thought EJB was all the rage right now, which is the big reason everyone is going to it. But, you and some others have been saying lately that its slow compared to other solutions. I don't know who you mean by "you" but personally I don't agree that EJB is slow. BMP is slow, but CMP can be very fast according to the tests I've made. Regards, Karl Avedal
Re: EJB Question(s)
This is true. I think a lot of us just worry about the cost of RMI too much. Is it noticeable to the user? No, probably not. Right now we sit at about 300 concurrent sessions though and the cost of RMI then becomes pretty high. (actually I think you can actually go higher than 50 concurrent users. there will be an initial hit as they access the site, but then there will be some down time as they view and decide what to do next) Scalability is good with EJB, and it is HOT technology, one just needs to be aware of the costs involved in that. On the clustering side that is exactly why we are using EJB. You start to become overloaded in resources you just through another server onto the network. So yes, what you say about that is absolutely true. Actually a lot of my concerns about RMI costs and such are coming from a recent interview I had which made me think of some things. Some I have rethought and have come to the conclusion they were not exactly correct. But then EJB is so new to both me (I've only been using the technology a few months and just moved to the 1.1 spec) and the place I interviewed at that I had to do some tests to see if the theorys were true or false. :) The cost in network traffic using RMI is not going to go away, the question becomes is that cost higher than we can affford or is the scalability important enough to warrant that higher cost. Personally I don't think that the cost is any worse than using JSP's or servlets. But I have not actually done any timing or performance tests. The advantage in my mind at least is the database pooling Which is also why I am such a fan of Stateless session beans. Pooling is much easier and less costly with them than with stateful. Anyway I babble. Yes, everything you say is correct. Some of us just try to get every ounce of power possible from what we have. :) Sometimes that tends to make us worry worts. Jens probably has some figures on the costs and such, he has done much testing lately with these things. Al - Original Message - From: Kevin Duffey [EMAIL PROTECTED] To: Orion-Interest [EMAIL PROTECTED] Sent: Sunday, April 02, 2000 6:43 PM Subject: RE: EJB Question(s) Ok..you've got me concerned here. I thought EJB was all the rage right now, which is the big reason everyone is going to it. But, you and some others have been saying lately that its slow compared to other solutions. The question is, is it slow only because of network traffic? I mean, we have a T1 line, which is 1.5Mbps, but our network is 100Mbps, so if everyone is using 56K modems hitting our site, thus, about 50 people can use our site via T1 at the exact same moment, how is it being such a bottleneck to the 100Mbps network behind the scenes? Plus, from what I read, the reason to go to EJB is so you can scale the hardware and the app server on each machine works together to keep the same session from the client-side going to the right machine on the EJB tier, and thus as you scale and add more machines, you can handle more. Is this not the case now? Another question arises here. Doesn't the EJB server handle scalability automatically? Meaning, if I add another machine, is it alot of work to get a new app server installed and working with an existing one, so that the requests are divided between the two app servers now? Thanks.
RE: EJB Question(s)
Actually a lot of my concerns about RMI costs and such are coming from a recent interview I had which made me think of some things. Some I have rethought and have come to the conclusion they were not exactly correct. But then EJB is so new to both me (I've only been using the technology a few months and just moved to the 1.1 spec) and the place I interviewed at that I had to do some tests to see if the theorys were true or false. :) The cost in network traffic using RMI is not going to go away, the question becomes is that cost higher than we can affford or is the scalability important enough to warrant that higher cost. Personally I don't think that the cost is any worse than using JSP's or servlets. But I have not actually done any timing or performance tests. The advantage in my mind at least is the database pooling Which is also why I am such a fan of Stateless session beans. Pooling is much easier and less costly with them than with stateful. Well, let me tell you the "little" bit that I do know. Just recently I learned that two things will speed up EJB greatly. First, use statless ejb sessions. I assume this means store the session stuff on the JavaBean/HttpSession side of things, but this apparently cuts down in the network traffic. Exactly how I am unclear of. The second thing is to use EJB instance caching. This feature is built in to app servers I believe..but it is not a J2EE requirement, so if your app server doesn't do this, you would have to do this yourself. I think this may not be a trivial task though, because in essence your writing your own EJB container, or something similar. None the less, I believe the two tie in. By using stateless ejb, and cached instances, you'll speed up the logic tier by a lot. Again..I do not know for sure..but alot of people are confirming this is the way to do it, and it will speed things up. Anyway I babble. Yes, everything you say is correct. Some of us just try to get every ounce of power possible from what we have. :) Sometimes that tends to make us worry worts. Jens probably has some figures on the costs and such, he has done much testing lately with these things. You and me both. I am an optimizing freak! I am rewriting some things to take advantage of using single-instance classes and local variables to hopefully improve performance. I anyone is in the know..what is the course of action if you use statless ejb session beans? Do you store the sessional info on the HttpSession web-server side? The reason I ask is I need to know what hardware to use, how much memory, etc. We have a dual 500PIII as our front-end web server (IBM NetFinity 4000R) with 512MB RAM and dual 9GB SCSI III drives, and I am hoping this will be enough memory and power for some time to come. We only have about 50 or so people a day on our site, but in about 2 years it could exceed 1000 users a day. From what I have heard, this is SMALL potatoes compred to a high-traffic site with several 1000 every minute hitting the site. But, I would definitely like to keep in mind the ability to scale to this level of performance anyways, just so I know how to do it. So, is stateless/cacheable EJBs with JavaBean/HttpSession storage the way to go to get maximum performance? Thanks again.
RE: EJB Question(s)
Ok..you've got me concerned here. I thought EJB was all the rage right now, which is the big reason everyone is going to it. But, you and some others have been saying lately that its slow compared to other solutions. The question is, is it slow only because of network traffic? I mean, we have a T1 line, which is 1.5Mbps, but our network is 100Mbps, so if everyone is using 56K modems hitting our site, thus, about 50 people can use our site via T1 at the exact same moment, how is it being such a bottleneck to the 100Mbps network behind the scenes? Plus, from what I read, the reason to go to EJB is so you can scale the hardware and the app server on each machine works together to keep the same session from the client-side going to the right machine on the EJB tier, and thus as you scale and add more machines, you can handle more. Is this not the case now? Another question arises here. Doesn't the EJB server handle scalability automatically? Meaning, if I add another machine, is it alot of work to get a new app server installed and working with an existing one, so that the requests are divided between the two app servers now? Thanks.