Servlet / EJB Communication
Hello,
I have a very simple stateless session bean that I've developed for testing. A Client.java class gets the initial context, gets the home interface of the bean, creates the bean, and removes the bean, all without any problems. However, when I instantiate the same client class in a servlet that I've registered in the weblogic.properties file, I get a ClassCastException when the Client casts the Home interface stub into the home interface class. ??? Any idea why I can't successfully use an EJB from within the servlet?
Thanks in advance,
Sam
java.lang.ClassCastException: path.TestSessionBeanBeanHomeImpl_ServiceStub
Sam,
This is a common problem starting out developing in WebLogic with servlets
and EJBs. In the J2EE reference implementation and other servers, the WAR
and JAR both have to contain the home/remote interfaces, since the EJB in
the JAR needs them and the Servlets in the WAR need them. In WebLogic, to
support a call-by-reference optimization (and because of some problems in
the class loader design employed by WebLogic previous to v6), you must NOT
put them (home/remote) into the WAR file.
If you do not deploy as WAR and JAR, then just replace WAR with
"servletclasses" and replace JAR with "serverclasses" in the paragraph
above.
Peace,
Cameron Purdy
Tangosol, Inc.
http://www.tangosol.com
+1.617.623.5782
WebLogic Consulting Available
"Sam Eubanks" <[email protected]> wrote in message
news:[email protected]...
>
> Hello,
>
> I have a very simple stateless session bean that I've developed for
testing. A Client.java class gets the initial context, gets the home
interface of the bean, creates the bean, and removes the bean, all without
any problems. However, when I instantiate the same client class in a
servlet that I've registered in the weblogic.properties file, I get a
ClassCastException when the Client casts the Home interface stub into the
home interface class. ??? Any idea why I can't successfully use an EJB from
within the servlet?
>
> Thanks in advance,
> Sam
>
> java.lang.ClassCastException: path.TestSessionBeanBeanHomeImpl_ServiceStub
Similar Messages
-
Servlets/JDBC vs. servlets/EJB performance comparison/benchmark
I have a PHB who believes that EJB has no ___performance___ benefit
against straightforward servlets/JSP/JDBC. Personally, I believe that
using EJB is more scalable instead of using servlets/JDBC with
connection pooling.
However, I am at a lost on how to prove it. There is all the theory, but
I would appreciate it if anyone has benchmarks or comparison of
servlets/JSP/JDBC and servlets/JSP/EJB performance, assuming that they
were tasked to do the same thing ( e.g. performance the same SQL
statement, on the same set of tables, etc. ).
Or some guide on how to setup such a benchmark and prove it internally.
In other words, the PHB needs numbers, showing performance and
scalability. In particular, I would like this to be in WLS 6.0.
Any help appreciated.First off, whether you use servlets + JDBC or servlets + EJB, you'll
most likely spend much of your time in the database.
I would strongly suggest that you avoid the servlets + JDBC
architecture. If you want to do straight JDBC code, then it's
preferable to use a stateless session EJB between the presentation layer
and the persistence layer.
So, you should definitely consider an architecture where you have:
servlets/jsp --> stateless session ejb --> JDBC code
Your servlet / jsp layer handles presentation.
The stateless session EJB layer abstracts the persistence layer and
handles transaction demarcation.
Modularity is important here. There's no reason that your presentation
layer should be concerned with your persistence logic. Your application
might be re-used or later enhanced with an Entity EJB, or JCA Connector,
or a JMS queue providing the persistence layer.
Also, you will usually have web or graphic designers who are modifying
the web pages. Generally, they should not be exposed to transactions
and jdbc code.
We optimize the RMI calls so they are just local method calls. The
stateless session ejb instances are pooled. You won't see much if any
performance overhead.
-- Rob
jms wrote:
>
I have a PHB who believes that EJB has no ___performance___ benefit
against straightforward servlets/JSP/JDBC. Personally, I believe that
using EJB is more scalable instead of using servlets/JDBC with
connection pooling.
However, I am at a lost on how to prove it. There is all the theory, but
I would appreciate it if anyone has benchmarks or comparison of
servlets/JSP/JDBC and servlets/JSP/EJB performance, assuming that they
were tasked to do the same thing ( e.g. performance the same SQL
statement, on the same set of tables, etc. ).
Or some guide on how to setup such a benchmark and prove it internally.
In other words, the PHB needs numbers, showing performance and
scalability. In particular, I would like this to be in WLS 6.0.
Any help appreciated.--
Coming Soon: Building J2EE Applications & BEA WebLogic Server
by Michael Girdley, Rob Woollen, and Sandra Emerson
http://learnweblogic.com -
Best practice for Servlet EJB integration
I'm wondering what the best practice is for Servlet EJB integration in terms of
caching the home and remote objects. My understanding is that the Home object
is threadsafe and could therefore be cached as an attribute of the Servlet. This
would remove the need for a JNDI lookup for each request. Similarly caching the
ProxyObject would yield further savings. However, I have noticed that most examples
don't use either of these practices. Why not?
Thanks in advance,
Geordie
This has been answered repeatedly. WL allows you to cache JNDI context
objects, ejb homes and remotes without any problems. (EJB remote interfaces
must only be used by one thread at a time, but that requirement is provided
by the EJB spec itself.)
Peace,
Cameron Purdy
Tangosol, Inc.
http://www.tangosol.com
+1.617.623.5782
WebLogic Consulting Available
"Geordie" <[email protected]> wrote in message
news:3af9579f$[email protected]..
>
> I'm wondering what the best practice is for Servlet EJB integration in
terms of
> caching the home and remote objects. My understanding is that the Home
object
> is threadsafe and could therefore be cached as an attribute of the
Servlet. This
> would remove the need for a JNDI lookup for each request. Similarly
caching the
> ProxyObject would yield further savings. However, I have noticed that
most examples
> don't use either of these practices. Why not?
>
> Thanks in advance,
> Geordie
-
Servlet/Applet communication, data limit?
I have an applet that uses a servlet as a proxy to load/retrieve images from an Oracle database. I have a problem when trying to retrieve images larger than 9-10kb from the database. When using JDBC from a Java Application I don't have any probelms but through the Applet-Servlet configuration I do.
I use the following code in the Applet:
URL url =new URL("http","myserver",myport,"/servlet/MyServlet");
HttpURLConnection imageServletConn = (HttpURLConnection)url.openConnection();
imageServletConn.setDoInput(true);
imageServletConn.setDoOutput(true);
imageServletConn.setUseCaches(false);
imageServletConn.setDefaultUseCaches (false);
imageServletConn.setRequestMethod("GET");
byte buf[] = new byte[imageServletConn.getContentLength()];
BufferedInputStream instr = new BufferedInputStream(imageServletConn.getInputStream());
instr.read(buf);
Image image = Toolkit.getDefaultToolkit().createImage(buf);
// then code to display the image
And the following for the Servlet:
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("image/gif");
byte[] buff = loadImage(); // this method returns a byte array representing the image.
response.setContentLength(contentLength);//contentLength is the size of the image
OutputStream os = response.getOutputStream();
os.write(buff);
os.close();
thanks in advance!thanks for your replay,
I tried your suggestion but whatever I do it seems that tha applet only brings the first 5-10k of the image from the servlet. This is the value I get from instr.read() or any other type of read method. The value of bytes is not always the same.
Now I also have something new. For images greater than 100k or so I get this error:
java.io.IOException: Broken pipe
at java.net.SocketOutputStream.socketWrite(Native Method)
at java.net.SocketOutputStream.socketWrite(Compiled Code)
at java.net.SocketOutputStream.write(Compiled Code)
at java.io.BufferedOutputStream.write(Compiled Code)
at org.apache.jserv.JServConnection$JServOutputStream.write(Compiled Code)
at java.io.BufferedOutputStream.write(Compiled Code)
at java.io.FilterOutputStream.write(Compiled Code)
at interorient.DBProxyServlet.doGet(Compiled Code)
at javax.servlet.http.HttpServlet.service(Compiled Code)
at javax.servlet.http.HttpServlet.service(Compiled Code)
at org.apache.jserv.JServConnection.processRequest(Compiled Code)
at org.apache.jserv.JServConnection.run(Compiled Code)
at java.lang.Thread.run(Compiled Code)
I am using the Oracle Internet application server (ias 9i) which actualy uses the apache web listener.
It seems that this servlet-applet communication is really unstable. If you have anything that may help me it will be greatly appriciated. You can even e-mail me at [email protected]
thanks! -
Hi,
What is that you are trying to accomplish ? Is it deployment or
trying to develop applications ? Are you getting any errors ? If so,
please post them to help you. I think the documentation is the best place
for you to begin with.
Regards & Happy New Year
Raj
Arif Khan wrote:
New To Iplanet app server.Can some one help me getting started by
delpoying and calling one of each of these:JSP,Servlet,EJB.Tried with
iplanet docs..didnt quite get it. thanx
Try our New Web Based Forum at http://softwareforum.sun.com
Includes Access to our Product Knowledge Base! -
Best way to see changes done to jsps/servlets/ejb/xmls in EAR
I am using iPlanet app server with iPlanet web server. Everytime i make any change jsp/servlet/ejb i have to redeploy whole ear application again. This takes a long time. Even when i use the "iasdeploy redployapp " command to deploy, it takes same amount of time as it takes for the orignal deployment.
So Is there any way to decrease the amount of the time it needs for me to re-deploy the applications when slight changes are made to application. I would really be thankful to anybody who can help me.Hi,
I am facing this problem with a simple EAR file also. It does not contain any EJBs.
It has just JSPs, XML, and JAVA Classes.
The file size is about 481Kb.
Earlier this used to get deployed using the "iasdeploy" command within 1 minute.
Now it is taking more than 5 minutes to deploy the EAR file.
I am using the following command :
iasdeploy deployapp -verbose XYZ.ear
The same holds true for the "iasdeploy removeapp -verbose XYZ.ear" also.
Please help.
Thanks,
Samar -
Problem configuring TassieDB database to work with JBoss Servlets + EJB app
Hi everybody
I have been unable to get Budi Kurniawan's Tassie Onine Bookstore example (
http://benmira.free.fr/en/j2ee/sessionEJB.htm#ch29lev1sec4) application to read anything from the database TassieDB . I am not sure what is wrong. I downloaded the database from the CD. Then since this was an older version of Access, I had to let my Access convert it to the newer form.
I then configured the Database the way I thought I should in order for it to work. I created a Data Source Name called TassieDB, by following the procedure to create a System DSN on Windows. I selected the Microsoft Access Driver and associated my Database which I named TassieDB1, which I deposited under C:\budibookstore which also contains the package com.brainysoftware.tassie.servlet.ejb
When I access the SearchServlet page and type in "Computer" in the search box nothing turns up. I wonder what is going on?
The following errors are spewed out by Apache in this process:
May 18, 2005 8:27:24 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Starting service Tomcat-Standalone
Apache Tomcat/4.1.31
May 18, 2005 8:27:28 PM org.apache.struts.util.PropertyMessageResources
INFO: Initializing, config='org.apache.struts.util.LocalStrings', returnNull=tru
e
May 18, 2005 8:27:28 PM org.apache.struts.util.PropertyMessageResources
INFO: Initializing, config='org.apache.struts.action.ActionResources', returnNul
l=true
May 18, 2005 8:27:29 PM org.apache.struts.util.PropertyMessageResources
INFO: Initializing, config='org.apache.webapp.admin.ApplicationResources', retur
nNull=true
May 18, 2005 8:27:33 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
May 18, 2005 8:27:33 PM org.apache.jk.common.ChannelSocket init
INFO: JK2: ajp13 listening on /0.0.0.0:8009
May 18, 2005 8:27:33 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=10/150 config=C:\tomcatj\conf\jk2.properties
javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interf
aces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: o
rg.jnp.interfaces.NamingContextFactory]
javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interf
aces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: o
rg.jnp.interfaces.NamingContextFactory]
All help is gratefully acknowledged and accepted. Thanks in advanceHi
Did you notyfy the Exception ?
class not found Exception "org.jnp.interfaces.NamingContextFactory"
add these packages to your class path.
Vinoth -
Hi,
I have Oracle 9i installed. It comes bundled with Apache web server minus documentation. Can I deploy Servlets/ EJBs. on this. Where can i get hold of documentation.
ArunAre you using the SunONE portal server in your architecture? If your question is related to the Application server, you would find a greater chance of obtaining a solution through the web/app server forum.
-
Hi,
I get User Details in a Servlet which parses a certificate and gets the details. Now, I am trying to pass in these details to some stateless session & entity ejb's. I don't want to pass them as parameters as then I have to do them for all the ejb functions. I don't want to use stateful beans because of it's resource intensiveness.
I was looking at passing them thru the ejbContext, but couldn't find a way of setting them thru the servlet. Is there any way I can do this?
Thanks.
Once again thanks for your reply. I have tried what you said. There is one problem though. I am not using weblogic.properties to authorize users. I am solely depending on the Certificate presented by the browser to validate an user. In this case I don't have a password to put in the initialContext. And as a result weblogic doesn't let me add this user to the initialContext(since this user doesn't exist in the properties file). So everything fails. Is it possible for me to pass just the username via some other property or any other means to the EJB via the servlet? Can I add passwords to the properties file like this:
weblogic.password.*=password
I mean I tried this but didn't work...is there something like this that could serve as a workaround? Or can I pass SECURITY_PRINCIPAL without passing SECURITY_CREDENTIALS?
Thanks.
Alexander Petrushko <[email protected]> wrote:
>Andy G wrote:
>>
>> Thank You Very Much. That is useful. I will try that out.
>> But I was just wondering what happens between method calls to that same bean? What if the container
>> passivates it? Will the same caller get that same bean context? Or will it get a bean with a
>> different context?
>
>Good question although you should have posted it to the EJB newsgroup.
>The EJB spec (sec 15.5) requires the client (your servlet) to have the
>same principal for the duration of the communication with the session
>bean. Therefore if you create the naming context with the correct
>principal, look up a bean and call two methods on it, it doesn't matter
>whether passivation has occurred between these two method calls as the
>container picks up the principal from the client for both calls.
>
>Cheers,
>
>--
>Alexander Petrushko
>mailto:[email protected]
>Consulting Services available
-
Invoking BPEL process from Servlet : ejb/collaxa/system/DeliveryBean error
Hi All,
My requirement is as below:
Servlet will receive the delimited HTTP request and convert it into XML. The xml payload will be used to invoke the BPEL Process deployed on Weblogic 10.3 (SOA-INFRA) using Idelivery Class Method.
The problem I am facing is :
that while servlet calls the BPEL process it gives "ejb/collaxa/system/DeliveryBean" not created error. javax.naming.exception. The name "ejb" is reloved but subcontext "collaxa/system/DeliveryBean" not resolved.
Please let me know whether I am missing any step.
This is urgent. Please suggest.
Thanks.Please make sure that your bpel connectivity properties are correct.
This error ll come only if host bpel pm server is not visible to your servlet.
So please make sure all your parameters are correct.
example, server IP / host name, port number,
Properties props = new Properties();
props.put("orabpel.platform", "ias_10g");
props.put("java.naming.factory.initial","com.evermind.server.rmi.RMIInitialContextFactory");
props.put("java.naming.provider.url","opmn:ormi://server_name/IP_Address:Port_NO:Instance_name/orabpel");
props.put("java.naming.security.principal", "oc4jadmin");
props.put("java.naming.security.credentials", "welcome1");
Locator locator = new Locator("default","welcome1",props);
Regards
Rajesh -
Pros/Cons of separating servlet/EJB clusters
What and the pros and cons of establishing a cluster for the servlet layer and
a separate cluster for the EJB layer?
The rational behind this decision would be to take advantage of a shared infrastructure
where multiple EJB components could be deployed in a cluster where they are accessed
from multiple servlet/clusters.
The obvious con is the fact that all calls between the servlet layer and the EJB
layer will be remote calls however, there should be a greater level of availability
and scalability.
What are the other issues behind this deployment strategy?
I don't recall any other problems with this topology other than the one
that you already mentioned. Infact i have seen several customer using
this topology. i.e. having WebTier Cluste and EJB tier cluster.
Kumar
JD wrote:
> What and the pros and cons of establishing a cluster for the servlet layer and
> a separate cluster for the EJB layer?
>
> The rational behind this decision would be to take advantage of a shared infrastructure
> where multiple EJB components could be deployed in a cluster where they are accessed
> from multiple servlet/clusters.
>
> The obvious con is the fact that all calls between the servlet layer and the EJB
> layer will be remote calls however, there should be a greater level of availability
> and scalability.
>
> What are the other issues behind this deployment strategy?
>
-
ClassCastException at narrow (Servlet/EJB)
Hi
I am new to this EJB concept.
I try to use an EJB in a servlet but I have a ClassCastException thrown by the narrow method.
I've already looked through the forums , but I haven't seen a solution for me.
I use JBOSS-3.0.8 and TOMCAT-4.0.1.
I include the client jar file generated by the deploytool in my client classpath.
Here is the part of the servlet calling the EJB:
Properties props= new Properties();
props.put(Context.PROVIDER_URL, "jnp://localhost:1099");
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
try {
Context jndiContext = new InitialContext(props);
System.out.println("Lookup");
Object object = jndiContext.lookup("ejb/eltUtil");
System.out.println("Object =>" + object.getClass()+"<=");
System.out.println("Object =>" + object.toString()+"<=");
System.out.println("PortableRemoteObject");
UtilHome lUtilHome = (UtilHome)PortableRemoteObject.narrow(object,UtilHome.class);
Here is the result in the jsp page:
java.lang.ClassCastException
at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:296)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
at fr.gouv.defense.cimd.authentification.servlet.ServletListeUtil.doGet(ServletListeUtil.java:87)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:201)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2344)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:462)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:163)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1011)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1106)
at java.lang.Thread.run(Thread.java:484)
And the log message in Tomcat:
Lookup
Object =>class org.jnp.interfaces.MarshalledValuePair<=
Object =>org.jnp.interfaces.MarshalledValuePair@53cdaa<=
PortableRemoteObject
When I run the code in a Client interface in Eclipse, that works and the log is :
Lookup
Objet =>class $Proxy0
Objet =>ejb/eltUtilHome
PortableRemoteObject
I don't know what to do.
Does anybody got the answer?
Thanks.even if isAssignableFrom returns false, still it can work.....
here is how
Object notificationServiceObject = initialContext.lookup(NotificationServiceHome.JNDI_NAME);
//Key Step
Object notificationServiceRawObject = ((org.jnp.interfaces.MarshalledValuePair)
notificationServiceObject).get();
NotificationServiceHome notificationServiceHome =
(NotificationServiceHome)javax.rmi.PortableRemoteObject.narrow
(notificationServiceRawObject,NotificationServiceHome.class);
NotificationService notificationService = notificationServiceHome.create(); -
Servlet - EJB, caching home & context problem
Hello,
I just run into the following problem:
I created a thin client which accesses the EJB's via a servlet.
In this servlet I cached the InitialContext und and the reference
to the Home interface. While creating the initial context I provided
login/password to access the EJB so it can't be accessed from the guest
user.
The first method call works as expected, any further call results
in a RemoteException - Insufficent permissions.
Any hints? I'm using 5.1, SP6.
Zhanxs in advance
MarcelThe security creditials you suppplied to the IntialContext are only applied
to the thread that created the InitialContext. I have only found one
work-around - Construct an otherwise useless IntialContext each time a
thread attempts to use and EJB or its home. This is inefficient and almost
(not quite) destroys the advantage of caching the stubs.
Is there any other solution? Any thing coming down the pike?
Chuck McCorvey
"Marcel Zielinski" <[email protected]> wrote in message
news:[email protected]..
Hello,
I just run into the following problem:
I created a thin client which accesses the EJB's via a servlet.
In this servlet I cached the InitialContext und and the reference
to the Home interface. While creating the initial context I provided
login/password to access the EJB so it can't be accessed from the guest
user.
The first method call works as expected, any further call results
in a RemoteException - Insufficent permissions.
Any hints? I'm using 5.1, SP6.
Zhanxs in advance
Marcel -
Tomcat servlets & EJB's in 8i JVM
Has anybody successfully deployed a servlet / JSP on Tomcat which communicates with and EJB in JServer?
I keep getting a javax.naming.NoInitialContextException, but when I explicitly set the INITIAL_CONTEXT_FACTORY, I get IllegalArgumentException.
Oracle's official response to this is not to use Tomcat, but to use mod_ose and the OSE in 8.1.7 (though I've had very little success with this either), but I'd like to be able to use any compliant servlet engine, not just Oracle.
nullI suggest you start looking at the J2EE tutorial and the sample applications. Both the tutorial and the sample applications included with the J2EE SDK will help you write a J2EE application that utilizes both a web component and an EJB component. The tutorial also contains useful information concerning the deploytool. If this doesn't help feel free to post again and include as much detail as possible, including error messages and log file contents.
-
Servlet, ejb, wls 510, ClassCastException
Hello,
I have an Entity Bean deployed in WLS 5.1.0.
I wrote a standalone application that obtains the initial context, does a
lookup, get back
a home interface, then the business interface (using narrow...), and calls
business methods...
Everything works fine...
BUT....
The SAME code within a servlet (doGET) does NOT work and throws a
ClassCastException.
Is there any issues using EJBs from Servlets?
Thank you a lot.
--Thierry
PS: Here is the code.
import javax.servlet.http.*;
import javax.servlet.*;
import javax.naming.*;
import javax.ejb.*;
import javax.rmi.*;
import org.zol.webstore.ejbs.person.*;
import java.util.*;
public final class TestServlet extends HttpServlet {
* Method init, called when the servlet is initialized
public void init(ServletConfig sc) throws ServletException {
System.err.println("@@@@@@@@@@@@ init "+sc);
* doPost
* @param req
* @param res
protected void doGet(HttpServletRequest req, HttpServletResponse res)
throws java.io.IOException {
ServletOutputStream sos = null;
System.err.println("@@@@@@@@@@@@ doGet ");
try{
sos = res.getOutputStream();
sos.println("<HTML><BODY>");
sos.println("Test "+new Date()+" <BR>");
InitialContext initialContext = getInitialContext();
System.err.println("@@@@@@@@@@@@ Got ic "+initialContext);
Object pO = initialContext.lookup("person.PersonEntityHome");
sos.println("<BR>pO: "+pO);
System.err.println("@@@@@@@@@@@@ Got Object PO ");
System.err.println("@@@@@@@@@@@@ Checking if we can narrow
PersonEntityHome");
Object toNarrow = PortableRemoteObject.narrow(pO,
PersonEntityHome.class);
System.err.println("@@@@@@@@@@@@ YES!!!");
PersonEntityHome pehome = (PersonEntityHome) toNarrow; // FAILS
sos.println("<BR>pehome: "+pehome);
System.err.println("@@@@@@@@@@@@ Got PE HOME ");
sos.println("</BODY></HTML>");
} catch (Exception eee) {
sos.println(eee.getMessage());
eee.printStackTrace();
public InitialContext getInitialContext() {
InitialContext ic = null;
try {
Hashtable h = new Hashtable();
h.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
h.put(Context.PROVIDER_URL, "t3://localhost:7001");
ic = new InitialContext(h);
} catch (Exception e) {
e.printStackTrace();
return ic;
Doesn't that mean that you can't hot deploy the EJB now?
-rrc
Thierry Janaudy wrote:
> Put the classes in the WEBLOGICCLASSPATH...
> And now it does work....
>
> Thank you Thierry,
>
> Your Welcome.
>
> Thierry
>
> Thierry Janaudy <[email protected]> wrote in message
> news:[email protected]...
> > Hello,
> >
> > I have an Entity Bean deployed in WLS 5.1.0.
> > I wrote a standalone application that obtains the initial context, does a
> > lookup, get back
> > a home interface, then the business interface (using narrow...), and calls
> > business methods...
> > Everything works fine...
> >
> > BUT....
> >
> > The SAME code within a servlet (doGET) does NOT work and throws a
> > ClassCastException.
> > Is there any issues using EJBs from Servlets?
> >
> > Thank you a lot.
> > --Thierry
> >
> > PS: Here is the code.
> > --------------------------------------------------------------------------
> --
> > ----------------
> >
> > import javax.servlet.http.*;
> > import javax.servlet.*;
> > import javax.naming.*;
> > import javax.ejb.*;
> > import javax.rmi.*;
> > import org.zol.webstore.ejbs.person.*;
> > import java.util.*;
> >
> > public final class TestServlet extends HttpServlet {
> >
> > /**
> > * Method init, called when the servlet is initialized
> > */
> > public void init(ServletConfig sc) throws ServletException {
> > System.err.println("@@@@@@@@@@@@ init "+sc);
> > }
> >
> > /**
> > * doPost
> > * @param req
> > * @param res
> > */
> > protected void doGet(HttpServletRequest req, HttpServletResponse res)
> > throws java.io.IOException {
> > ServletOutputStream sos = null;
> >
> > System.err.println("@@@@@@@@@@@@ doGet ");
> >
> > try{
> > sos = res.getOutputStream();
> >
> > sos.println("<HTML><BODY>");
> > sos.println("Test "+new Date()+" <BR>");
> >
> > InitialContext initialContext = getInitialContext();
> >
> > System.err.println("@@@@@@@@@@@@ Got ic "+initialContext);
> >
> > Object pO = initialContext.lookup("person.PersonEntityHome");
> > sos.println("<BR>pO: "+pO);
> >
> > System.err.println("@@@@@@@@@@@@ Got Object PO ");
> >
> > System.err.println("@@@@@@@@@@@@ Checking if we can narrow
> > PersonEntityHome");
> > Object toNarrow = PortableRemoteObject.narrow(pO,
> > PersonEntityHome.class);
> >
> > System.err.println("@@@@@@@@@@@@ YES!!!");
> >
> > PersonEntityHome pehome = (PersonEntityHome) toNarrow; // FAILS
> >
> > sos.println("<BR>pehome: "+pehome);
> >
> > System.err.println("@@@@@@@@@@@@ Got PE HOME ");
> >
> > sos.println("</BODY></HTML>");
> > } catch (Exception eee) {
> > sos.println(eee.getMessage());
> > eee.printStackTrace();
> > }
> > }
> >
> >
> > public InitialContext getInitialContext() {
> > InitialContext ic = null;
> >
> > try {
> > Hashtable h = new Hashtable();
> > h.put(Context.INITIAL_CONTEXT_FACTORY,
> > "weblogic.jndi.WLInitialContextFactory");
> > h.put(Context.PROVIDER_URL, "t3://localhost:7001");
> > ic = new InitialContext(h);
> > } catch (Exception e) {
> > e.printStackTrace();
> > }
> >
> > return ic;
> > }
> > }
> >
> >
Russell Castagnaro
Chief Mentor
SyncTank Solutions
http://www.synctank.com
Earth is the cradle of mankind; one does not remain in the cradle forever
-Tsiolkovsky
Maybe you are looking for
-
How to reinstall OS without losing installed applications
Hi folks, Question for you about software installations and if they can be backed up to overcome the need to reinstall them when reinstalling the MacBook's OS. I have a newish (bought last Autumn) 15" 2.3 GHz Intel Core i7 MacBook Pro running OSX 10.
-
I've tried to burn two separate DVD files to disc using iDVD 5.0.1. Both times a dialogue box came up saying "Burning Finished. Errors were found during the burning process" The recording device reported the illegal request: Cannot write medium – inc
-
Can't get NYTimes Crossword app to download onto my wife's IPad Air. It shows as "purchased" but when trying to download with the Cloud icon, it just circles for a while, then stops. The app works fine on my IPad. Any suggestions? Thanks
-
Linksys WRT54GL - illegal subnet mask message
Hello everybody, I just changed the ISP and the new one is on optic fiber, and they arrived with theirs equipment, wich is a Huawey EchoLife HG856 and I connected it to my Linksys WRT54GL. When I tried to configure the router with the settings gived
-
Firewire File Transfer Problem/ Dual Drive G4 to iMac
Bought a new iMac. My old G4 (OSX10.3.9) has two internal HDs (30Gb & 40GB <my startup>) but only 30Gb drive shows up in target mode. Can't mount 40 Gb drive on iMac desktop to do file transfer when G4 is in "Target" mode? Called Apple "help" and was