Skip to main content

LMAppletserver in Glassfish - invoking EJB3 session bean methods from your applet

The previous blog entry showed how to use LMAppletserver in a web archive (WAR) without any enterprise beans or enterprise app. It could also have been deployed to e.g. Tomcat where you don't have EJB3 session beans.

In this example I'm showing how to call EJB3 session beans from your java applet using LMAppletserver.

Download and start netbeans 6.0 (http://netbeans.org)

Versioning -> Subversion -> Checkout

Checkout the following URL:

http://lmappletserver.svn.sourceforge.net/svnroot/lmappletserver/LMAppletServerEJB3

(no username or password)

Right click on the newly opened LMAppletServerEJB3 project and select "Undeploy and Deploy" to deploy the project.

When the server has started and everything is deployed then open this URL in your browser:

http://localhost:8080/LMAppletServerEJB3-war/

The applet shows a message that is obtained by calling an EJB3 session bean method method on the server, using the RPC features of LMAppletserver. This is what happens in the applet:

HelloWorldRemote helloObj = (HelloWorldRemote)AppletServiceClientProxy.newInstance(HelloWorldRemote.class);
add(new JLabel(helloObj.helloWorld()));

And on the server, a Stateless EJB3 session bean:

@Stateless
public class HelloWorldBean implements HelloWorldRemote {
public String helloWorld() {
return "Hello world from EJB3 session bean";
}
}


See? Calling EJB3 session bean methods using LMAppletServer clients is really simple too .. :)

Comments

Unknown said…
I get a ClassNotFoundException when running the example under glassfish. And I get a java.lang.ClassCastException: sun.net.www.protocol.file.FileURLConnection when running it under eclipse EE.

Popular posts from this blog

My VNC based development environment with Visual Studio Code running on Ubuntu

I've used this setup for my development environment for several years - giving me a developer desktop I can access anywhere. Even from my mobile phone. I've been fixing bugs, writing code and deployed emergency fixes from the bus, train and mountain tops. The setup is based on a lightweight desktop environment. There are lot of alternatives, but I've chosen fluxbox. From a plain AWS Amazon Ubuntu 16.04 ec2 instance I've started like this: sudo apt-get update sudo apt-get install fluxbox Download and extract tigervnc from https://github.com/TigerVNC/tigervnc/releases (I downloaded the binary file from https://bintray.com/tigervnc/stable/tigervnc/1.7.0 named tigervnc-1.7.0.x86_64.tar.gz ) then extract: tar -xvzf tigervnc-1.7.0.x86_64.tar.gz You need to install: sudo apt-get install x11-xkb-utils You need to edit .vnc/xstartup: nano .vnc/xstartup last line replace "twm &" with: fluxbox & Then you can start the

Angular components not reloading on route change

Spent a long time wondering why route changes caused strange effects on my component, and found out that it was because my component wasn't reloading at all. I had this assumption that when a route parameter changed (e.g. /projects/1 changed to /projects/2 ) the component for the route would be reloaded. But this is not the default behaviour of the Angular router. The default behaviour of the Angular router is to reuse the route if the configuration is the same (and not reload the component). But we can override this by providing a RouteReuseStrategy to our @NgModule: providers: [ { provide: RouteReuseStrategy, useClass: AARouteReuseStrategy } ] The full custom implementation of the RouteReuseStrategy will then be like this (and it's the shouldReuseRoute method that changes the behaviour so that the component is reloaded on route parameter change): export class AARouteReuseStrategy extends RouteReuseStrategy { shouldDetach(route: ActivatedRou

Intercepting and adjusting SQL generated by Eclipselink JPA

In some cases it might be useful to intercept and adjust the SQL generated by EclipseLink JPA. E.g. if you want to force an index in mysql you need to append force index (myindex) to the table name. If you create a query on the entitymanager: Query q = em.createQuery("select e from MyEntity"); you can cast it to the EclipseLink JpaQuery: JpaQuery jq = (JpaQuery)q; and the JpaQuery gives you access to the EclipseLink DataBaseQuery where you can prepare it before executing it: DatabaseQuery dbQuery = q.getDatabaseQuery(); dbQuery.prepareCall(((org.eclipse.persistence.jpa.JpaEntityManager)em).getActiveSession(),new DatabaseRecord()); You can now get the sql string and add the forced index: dbQuery.setSQLString(dbQuery.getSQLString()+" force index (myindex)"); and finally you can get the resultset using q.getResultList(). If you have parameters in the sql it's a bit more to it. Currently I've only found one option - probably not optimal since the query is transl