Avatar billede fredand Forsker
25. oktober 2008 - 21:50 Der er 8 kommentarer og
1 løsning

Problems with applet calling an ejb!

Hello!

I'm playing around with a small server-client-arch at home.

At this image you see a map over it:
http://eunvwq.blu.livefilestore.com/y1pWpW8wJEKiroPdHFWKlL3nN-QSPntjmXLQcW5INXMV3Mo6kY8X_JXii1hui-ulB1N9VgJJayIlZs/applet.jpghttp://eunvwq.blu.livefilestore.com/y1pWpW8wJEKiroPdHFWKlL3nN-QSPntjmXLQcW5INXMV3Mo6kY8X_JXii1hui-ulB1N9VgJJayIlZs/applet.jpg

Now I got a problem.
The problem is that a signed java applet does not manage to call a ejb.

The problem I get is this exception:
java.lang.ClassNotFoundException: namesejb.server.NameManagerSessionBean_o0oo54_HomeImpl_816_WLStub
at sun.applet.AppletClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at weblogic.rmi.internal.StubInfo.readResolve(StubInfo.java:138)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeReadResolve(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at weblogic.common.internal.ChunkedObjectInputStream.readObject(ChunkedObjectInputStream.java:120)
at weblogic.rjvm.MsgAbbrevInputStream.readObject(MsgAbbrevInputStream.java:135)
at weblogic.rmi.internal.ObjectIO.readObject(ObjectIO.java:56)
at weblogic.rjvm.ResponseImpl.unmarshalReturn(ResponseImpl.java:164)
at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:293)
at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:248)
at weblogic.jndi.internal.ServerNamingNode_816_WLStub.lookup(Unknown Source)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:375)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:363)
at javax.naming.InitialContext.lookup(Unknown Source)
at namesjavaapplication.panels.EjbPanel.addName(EjbPanel.java:71)
...

At row 71 I got this code:
Object object1 = context.lookup("namesejb/client/NameManagerEJBHome");
System.out.println( object1.getClass().getName() );
NameManagerEJBHome nameManagerEJBHome = (NameManagerEJBHome)PortableRemoteObject.narrow(object1, NameManagerEJBHome.class);
NameManangerEJBObject nameManangerEJBObject = nameManagerEJBHome.create();    nameManangerEJBObject.addName(textField.getText());

How ever the strange thing is that the same code works fine from a java_webstart_app downloaded from the same html.

The code also works fine from a standalone app.

The applet and the java_webstart just wraps the standalone app.

The html for the applet looks like:
<HTML>
        <HEAD>
        </HEAD>
        <BODY>
     
            <APPLET CODE="namesapplet.NamesApplet" ARCHIVE="namesapplet_signed.jar" WIDTH="450" HEIGHT="600">
            </APPLET>
               
        </BODY>
</HTML>

The jnlp for the java_webstart looks like:
<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+">
  <information>
      <title>Signed Names Web Start App XXXbuild_timeXXX</title>
      <vendor>Fredrik Andersson</vendor>
  </information>
    <security>
        <all-permissions/>
    </security>
    <resources>
      <j2se version="1.2+" />
      <jar href="http://192.168.1.35:7021/nameswebapplication/nameswebstart_signed.jar"/>
    </resources>
    <application-desc main-class="namesjavaapplication.NamesJavaApplication" >
        <argument> -verbose </argument>
    </application-desc>
</jnlp>

Is there a way to pack a applet-jar and add some jar files?
My guess is that it tries to load a wrong class file.

When I run it from the standalone the System.out.println( object1.getClass().getName() ); gives me:
namesejb.server.NameManagerSessionBean_o0oo54_HomeImpl_816_WLStub

This problem is very similar to this problem of mine:
http://www.eksperten.dk/spm/816761

Any suggetstions is most welcome.

Best regards
Fredrik
Avatar billede arne_v Ekspert
25. oktober 2008 - 22:45 #1
I have practically no experience with WebLogic.

Does WL generate the client classes dynamicly or does it generate a jar file with
them when the EJB's are deployed ?

If a jar file is generated, then it should be available and referenced by the applet jar file.
Avatar billede arne_v Ekspert
25. oktober 2008 - 22:46 #2
BTW, applet-EJB is a bit unusual in today, applet-web service-EJB would be much more
natural today (but applet-EJB will perform much better !).
Avatar billede fredand Forsker
25. oktober 2008 - 23:25 #3
Hello Arne!

Acctually I create two jars during my build:

    <target name="jar_server" depends="add_build_properties">
        <jar destfile="namesejb_server.jar" basedir="distribution/">
        </jar>
    </target>
   
    <target name="jar_client" depends="jar_server">
        <delete dir="distribution/namesejb/server"/>
        <delete dir="distribution/META-INF"/>
        <jar destfile="namesejb_client.jar" basedir="distribution/">
        </jar>
    </target>

In server I got the following:
NameManagerEJBHome extends EJBHome
NameManangerEJBObject extends EJBObject
NameManagerSessionBean implements SessionBean

In client I gotthe following:
NameManagerEJBHome extends EJBHome
NameManangerEJBObject extends EJBObject

To me I thought that:
Object object1 = context.lookup("namesejb/client/NameManagerEJBHome");
Would give me an object of NameManagerSessionBean
But it seems like the WLS wrapps it in a namesejb.server.NameManagerSessionBean_o0oo54_HomeImpl_816_WLStub.
Perhaps this is most natural?

I serached my wls for a jar with this class above, but I did not find any.
I then guess wls generates them on the fly?

But since the same code runs fine from a java web start, shouldn't that be the same?

Best regards
Fredrik
Avatar billede arne_v Ekspert
26. oktober 2008 - 02:17 #4
No.

I believe that in the client you will have:
  home interface
  remote interface
  a generated stub class that implements home interface
  a generated stub class that implements remote interface
and in server you will have:
  home interface
  remote interface
  a generated skeleton class that implements home interface
  a generated skeleton class that implements remote interface (this one calls your EJB implementation)
  your EJB implementation

Apparanetly client can not find:

namesejb.server.NameManagerSessionBean_o0oo54_HomeImpl_816_WLStub = a generated stub class that implements home interface

If the stubs are generated automaticly, then they should be downloadable from the server.

So I am out of good ideas.

Have you tried googling ?
Avatar billede arne_v Ekspert
26. oktober 2008 - 02:19 #5
http://edocs.beasys.com/wls/docs81/applets/usingapplets.html says:

If you use an applet in a Web Application and the applet accesses an EJB deployed with another application, you must include the EJB stubs as part of the Web application. To do this, generate stubs using the -disableHotCodeGen option to ejbc, and package the stubs as part of the Web Application.

If the stubs are not included as part of the Web Application, the applet will generate a ClassNotFoundException when it attempts to access the EJB.
Avatar billede arne_v Ekspert
26. oktober 2008 - 02:20 #6
Avatar billede fredand Forsker
26. oktober 2008 - 13:16 #7
Hello Arne!

Very interesting articles you found, I'm reading them right now, but I'm not done yet.

But I would be very interesting about what you think about this teory that might be the reason for the error:

The applet is downloaded from 192.168.1.1:7021 in a signed jar.
Then it should have permissions like call other servers.
(I do manage to call a webservice located at 192.168.1.1:7031)

But when it tries to call the ejb located at 192.168.1.1:7011 with:
Object object1 = context.lookup("namesejb/client/NameManagerEJBHome");

...it receives a object of:
namesejb.server.NameManagerSessionBean_o0oo54_HomeImpl_816_WLStub

..but perhaps it insists to find the class for that object inside my signed jar
or from the server it got downloaded from.

Perhaps even a signed applet will not find classes from another places?

I guess my clone of this applet in shape of a java web start gets the classes from the ejb-server?

Perhaps my only chance is to add the class file for namesejb.server.NameManagerSessionBean_o0oo54_HomeImpl_816_WLStub into my signed_applet.jar.

Really interesting to hear what you think of this teory.

Best regards
Fredrik
Avatar billede fredand Forsker
26. oktober 2008 - 16:42 #8
Hello Arne!

You solved it!

I put the generated stubs into my client jar.

Then it worked!

I guess that when I use my java web start the stub classes get downloaded from the ejb server during the call to the ejb when needed?
(Please take a look at the image at the link above)
... else I do not understand how it could work.

And from the applet, the stub classes needs to get available in the jar or located at the server where the applet was downloaed from.

If you think I'm wrong please let me know!

Best regards mate and please give a svar so I can reward you!

/Fredrik
Avatar billede arne_v Ekspert
27. oktober 2008 - 01:04 #9
Either the JWS could download the stub or the JWS could generate the classes.

I don't know.

I do know about manually generating stubs and adding them to client jars, because
some (especially older) app servers force you to do that for all types of clients.

+svar
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester





White paper
Tidsbegrænset kampagne: Overvejer du at udskifte eller tilføje printere i din forretning? Vi kan tilbyde én eller flere maskiner gratis