Adding Servlet to Vaadin Project and join to Enterprise Application Project

Hello Everyone, I’m new of Vaadin so i’m sorry in advance if I will ask for something that could “hurt” someone.

I’m creating an Enterprise Application. I did everything about EJB and about the classes connected to it. So far i was testing what done using a normal servlet that lookingUp to the EJB where able to comunicate.

My problem is that i’m trying now to apply a UI to my servlet. I don’t know if that is possible… so i tried something different.

I created the Vaadin project with deployment as servlet. then i add another servlet that lookup to the EJB.
I tried but once added in the Enterprise Project in order to deploy is not possible to accede to the servlet…
Not even directly bypassing the ClassUI from the localhost…

Please i’ve to deliver this project for Thursday…

Thanks in advance

PS: Vaadin seems really powerful and cool…just to say

Hi,

I don’t quite understand what you’re trying to do here. What’s the purpose of the other servlet? You could just access the EJB in a normal manner directly from the vaadin code (= code in the vaadin project and run by the vaadin servlet).

-tepi

Ok… I tried that too but then I’ve problems when try to join the vaadin project to the enterprise project…

To explain:

  1. I do vaadin project
  2. I make it possible for it to see Ejb using @
  3. I try with a simple button to send a string and add on list the returned string…
  4. When I click the button it gives an error on the button (! Red symbol) then in the huge error I see that he cannot comunicare with the Ejb even if it is able to see it in compile time.

I hope I explained myself better… Sorry but with Java2ee I’m a bit New

So basically your EJB injection is not working? The reference is null? Which server are you running this on? If all else fails, you could ditch the EJB annotation and just lookup your EJB with a basic JNDI lookup.

the EJB is not working in runtime I’m using JBOSS server
i get this error:



Unable to invoke method click in com.vaadin.shared.ui.button.ButtonServerRpc at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:170) at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:118) at com.vaadin.server.communication.ServerRpcHandler.handleBurst(ServerRpcHandler.java:207) at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:111) at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:91) at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:37) at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1390) at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:238) at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:139) at org.jboss.as.web.NamingValve.invoke(NamingValve.java:57) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:154) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:667) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:952) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.reflect.InvocationTargetException 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 com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:168) … 22 more Caused by: com.vaadin.event.ListenerMethod$MethodException: Invocation of method buttonClick in com.example.messagsender.MessageUI$1 failed. at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:528) at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:198) at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:161) at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:969) at com.vaadin.ui.Button.fireClick(Button.java:368) at com.vaadin.ui.Button$1.click(Button.java:57) … 27 more Caused by: java.lang.NoClassDefFoundError: com/gg/message/MessageSessionBean at com.example.messagsender.MessageUI$1.buttonClick(MessageUI.java:40) 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 com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:508)

sorry for the long “paste” but i hope you’ll find out something that i’m missing.

I’m really grateful for the help you are giving to me

The key part here is “Caused by: java.lang.NoClassDefFoundError: com/gg/message/MessageSessionBean”. What this means is that your ejb class is available at compile time, but not at deployment time. How are you deploying your vaadin application and ejb project? Please confirm that the deployment is done so that the vaadin webapp can see the ejb in its classpath.

yes i confirm now i did the whole process again.

to deploy the application i’m using an Enterprise Application project then right click on it properties → Deployment Assembly → add the vaadin prj then run the enterprise on server.

this is the error after this steps:


com.vaadin.server.ServerRpcManager$RpcInvocationException: Unable to invoke method click in com.vaadin.shared.ui.button.ButtonServerRpc at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:170) at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:118) at com.vaadin.server.communication.ServerRpcHandler.handleBurst(ServerRpcHandler.java:207) at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:111) at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:91) at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:37) at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1390) at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:238) at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:139) at org.jboss.as.web.NamingValve.invoke(NamingValve.java:57) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:154) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:667) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:952) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.reflect.InvocationTargetException 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 com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:168) … 22 more Caused by: com.vaadin.event.ListenerMethod$MethodException: Invocation of method buttonClick in com.example.messagewebvaad.MessageWebUI$1 failed. at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:528) at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:198) at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:161) at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:969) at com.vaadin.ui.Button.fireClick(Button.java:368) at com.vaadin.ui.Button$1.click(Button.java:57) … 27 more Caused by: java.lang.NullPointerException at com.example.messagewebvaad.MessageWebUI$1.buttonClick(MessageWebUI.java:40) 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 com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:508) … 32 more

And on server i’m getting that on the console:

see attachment
13599.txt (9.3 KB)

Ok, so now it’s an NPE so the injection isn’t done. I’ll repeat: can you do a basic JNDI lookup for the EJB instead of the annotation? There’s an example of that e.g. here:
http://tomee.apache.org/examples-trunk/lookup-of-ejbs/README.html
.

Yes I will try and post the results… thanks again for the help…i do it immediatly

do I need to create an interface also or i can do in other ways? probably is a stupid question for you, i understand, but I’m no expert with J2ee but i wonna learn.

You should not need an interface since the access is local. You just need the correct name of your ejb for the jndi lookup.

I’m trying but i’m not getting how should I implement the example on my project.

I’m trying to set in the vaadin project:

First:

I tryed to simply modify to the @EJB to @EJB(beanName=MessageSessionBean) it compiles but in runtime the button click thows errors again

Then i tried something different:

private Context context;

@EJB
MessageSessionBean messageSessionBean = context.lookup(“java:global/lookup-of-ejbs/MessageSessionBean”);
String prova=“Hi”;

protected void setUp() throws Exception {
    context = (Context) EJBContainer.createEJBContainer().getContext();
}

but i’m getting an error in the context.lookup:
The method lookup(String) is undefined for the type Context

Hmm, unfortunately I’m out of ideas now. It’s extremely difficult to give instructions without seeing the setup.

Anyway, looking up an EJB is not black magic; in the local host it’s probably one of the most simple things you can do with EJBs, and the internet is full of instructions on how to do it.

If you can submit your projects to e.g. github or somewhere else I could take a look at what’s wrong. I suspect this is some kind of project setup issue.

Btw. try to do the context lookup as in the example I linked:

new InitialContext().lookup("java:comp/env/MessageSessionBean")

anyways, the “lookup-of-ejbs” part of the JNDI name is specific to that example. Try the code InitialContext lookup above, assuming you have set your bean name to “MessageSessionBean”.

-tepi

i cannot share this project with the web for now but i can write here my email you send me a message and i send you the projects…next week i will be able also to share what i did withouth any problem