Question

I'm trying to get a minimum Vaadin 7.1.12 app running spitting out a string from a session bean injected via CDI, on Wildfly (final version)


EDIT: Problem solved - should have injected my gui component instead of using 'new'. See bottom of post for details


This is just a helloworld/poc project with one ui-button and an event-handler calling a method in a stateless sessionbean. It basically works until the handler is invoked, then I get a NPE because the bean has not been initialized. (You can see the whole log at the bottom, it's not nicely formatted :o).

I have two Maven projects, a service-project and a web project, both modules of a parent pom. I have bean.xml (in META-INF of service project and WEB-INF of web project), but no web.xml or ejb-jar.xml or any other xml-config-file.

Using wildfly maven plugin for deployment, everything running on Java 8

The service project just contains one really simple Session bean:

package com.xy.zzy.service.session;

import javax.ejb.Stateless;

@Stateless
public class Pingu {

    public String ping() {
        return "Pingu is alive!";
    }  
}

The web project contains a simple UI.

package com.xy.zzy;

import com.vaadin.cdi.CDIUI;
import com.vaadin.server.Constants;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.server.VaadinSession;
import com.vaadin.ui.UI;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;


@CDIUI
public class MyVaadinUI extends UI {

    @WebServlet(urlPatterns = "/*", initParams = { 
        @WebInitParam(name = VaadinSession.UI_PARAMETER,
        value = "com.xy.zzy.MyVaadinUI"), 
        @WebInitParam(name = Constants.PARAMETER_WIDGETSET, 
        value =     "com.xy.zzy.AppWidgetSet"), 
        @WebInitParam(name = Constants.SERVLET_PARAMETER_UI_PROVIDER, 
        value =     "com.vaadin.cdi.CDIUIProvider") 
        })
    public static class UIApplicationServlet extends VaadinServlet {}

    @Override
    protected void init(VaadinRequest request) {
        setContent(new MyCompositeEvents());
    }

}

Finally, the actual useage of the Pingu EJB in MyCompositeEvent (this is a subclass of a UI component generated by the eclipse vaadin plugin, and it just displays a button.

package com.xy.zzy;

import com.xy.zzy.service.session.Pingu;
import com.vaadin.ui.Button;
import javax.inject.Inject;

public class MyCompositeEvents extends MyComposite {

@Inject Pingu pingu;

@Override
void doInitialize() {
    button_1.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
button_1.setCaption(pingu.ping());

        }
    });
}
}

In the parent pom.xml I'm pulling in

    <dependencies>
    <dependency>
        <groupId>javax.enterprise</groupId>
        <artifactId>cdi-api</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.inject</groupId>
        <artifactId>javax.inject</artifactId>    
        <scope>provided</scope>
    </dependency> 
    <dependency>
        <groupId>javax.annotation</groupId>
        <artifactId>javax.annotation-api</artifactId>
        <version>1.2</version>      
        <scope>provided</scope>
    </dependency>         
    <dependency>
        <groupId>org.jboss.spec.javax.annotation</groupId>
        <artifactId>jboss-annotations-api_1.2_spec</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.jboss.spec.javax.ejb</groupId>
        <artifactId>jboss-ejb-api_3.2_spec</artifactId>
        <scope>provided</scope>
    </dependency>
</dependencies>

service pom (hibernate for entities when the basic cdi injection works):

    <dependencies>
    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.1-api</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.jboss.spec.javax.ejb</groupId>
        <artifactId>jboss-ejb-api_3.2_spec</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.jboss.spec.javax.transaction</groupId>
        <artifactId>jboss-transaction-api_1.2_spec</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <scope>provided</scope>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <scope>provided</scope>
    </dependency>

</dependencies>

and the web pom:

    <dependencies>

    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>vaadin-server</artifactId>
        <version>${vaadin.version}</version>
    </dependency>
    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>vaadin-client-compiled</artifactId>
        <version>${vaadin.version}</version>
    </dependency>

    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>vaadin-client</artifactId>
        <version>${vaadin.version}</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>vaadin-push</artifactId>
        <version>${vaadin.version}</version>
    </dependency>
    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>vaadin-themes</artifactId>
        <version>${vaadin.version}</version>
    </dependency>
    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>vaadin-cdi</artifactId>
        <version>1.0.0.alpha1</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.0.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.xy.zzy</groupId>
        <artifactId>xyzzy-service</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <type>ejb</type>

    </dependency>

</dependencies>

This is what happens when the session bean is invoked (NPE):

13:16:52,165 INFO  [org.jboss.as.repository] (management-handler-thread - 17) JBAS014900: Content added at location /Users/xyzzy/Local/wildfly-8.0.0.Final/standalone/data/content/2d/7a1b2b61aca1ab04c8c64a48929d6fa5932084/content
13:16:52,166 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015876: Starting deployment of "xyzzy-web.war" (runtime-name: "xyzzy-web.war")
13:16:52,724 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-1) JBAS015877: Stopped deployment xyzzy-web.war (runtime-name: xyzzy-web.war) in 557ms
13:16:52,725 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-7) JBAS015876: Starting deployment of "xyzzy-web.war" (runtime-name: "xyzzy-web.war")
13:16:53,197 INFO  [org.jboss.weld.deployer] (MSC service thread 1-2) JBAS016002: Processing weld deployment xyzzy-web.war
13:16:53,200 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-2) JNDI bindings for session bean named Pingu in deployment unit deployment "xyzzy-web.war" are as follows:

    java:global/xyzzy-web/Pingu!com.xy.zzy.service.session.Pingu
    java:app/xyzzy-web/Pingu!com.xy.zzy.service.session.Pingu
    java:module/Pingu!com.xy.zzy.service.session.Pingu
    java:global/xyzzy-web/Pingu
    java:app/xyzzy-web/Pingu
    java:module/Pingu

13:16:53,212 INFO  [org.jboss.weld.deployer] (MSC service thread 1-16) JBAS016005: Starting Services for CDI deployment: xyzzy-web.war
13:16:53,216 INFO  [org.jboss.weld.deployer] (MSC service thread 1-11) JBAS016008: Starting weld service for deployment xyzzy-web.war
13:16:53,379 INFO  [com.vaadin.cdi.internal.VaadinExtension] (MSC service thread 1-12) UIScopedContext registered
13:16:53,442 INFO  [com.vaadin.cdi.internal.ContextDeployer] (MSC service thread 1-14) Initializing web context for path /xyzzy-web
13:16:53,442 INFO  [com.vaadin.cdi.internal.ContextDeployer] (MSC service thread 1-14) Discovering Vaadin UIs...
13:16:53,443 INFO  [com.vaadin.cdi.internal.ContextDeployer] (MSC service thread 1-14) 1 beans inheriting from UI discovered!
13:16:53,443 INFO  [com.vaadin.cdi.internal.ContextDeployer] (MSC service thread 1-14) Vaadin UI com.xy.zzy.MyVaadinUI is marked as @CDIUI without context path, this UI is accessible from context root of deployment
13:16:53,443 INFO  [com.vaadin.cdi.internal.ContextDeployer] (MSC service thread 1-14) Available Vaadin UIs for CDI deployment []
13:16:53,444 WARNING [com.vaadin.cdi.internal.ContextDeployer] (MSC service thread 1-14) Vaadin related servlet is defined in deployment descriptor, automated deployment of VaadinCDIServlet is now disabled
13:16:53,444 INFO  [com.vaadin.cdi.internal.ContextDeployer] (MSC service thread 1-14) Done deploying Vaadin UIs
13:16:53,445 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-14) JBAS017534: Registered web context: /xyzzy-web
13:16:53,461 INFO  [org.jboss.as.server] (management-handler-thread - 17) JBAS018562: Redeployed "xyzzy-web.war"
13:16:53,461 INFO  [org.jboss.as.server] (management-handler-thread - 17) JBAS018565: Replaced deployment "xyzzy-web.war" with deployment "xyzzy-web.war"
13:16:53,462 INFO  [org.jboss.as.repository] (management-handler-thread - 17) JBAS014901: Content removed from location /Users/martin/Local/wildfly-8.0.0.Final/standalone/data/content/81/50420b5c937c94c75d3c543ad8b6560901f198/content
13:29:36,571 WARNING [com.vaadin.server.DefaultDeploymentConfiguration] (default task-13) 
=================================================================
Vaadin is running in DEBUG MODE.
Add productionMode=true to web.xml to disable debug features.
To show debug window, add ?debug to your application URL.
=================================================================
13:29:36,594 INFO  [org.atmosphere.cpr.AtmosphereFramework] (default task-13) Installed AtmosphereHandler com.vaadin.server.communication.PushHandler mapped to context-path: /*
13:29:36,621 INFO  [org.atmosphere.cpr.AtmosphereFramework] (default task-13) Auto detecting WebSocketHandler in /WEB-INF/classes/
13:29:36,622 INFO  [org.atmosphere.cpr.AtmosphereFramework] (default task-13) Installed WebSocketProtocol org.atmosphere.websocket.protocol.SimpleHttpProtocol 
13:29:36,624 INFO  [org.atmosphere.cpr.AtmosphereFramework] (default task-13) Atmosphere is using async support: org.atmosphere.container.Servlet30CometSupport running under container: WildFly 8.0.0.Final - 1.0.0.Final using javax.servlet/3.0
13:29:36,627 INFO  [org.atmosphere.cpr.AtmosphereFramework] (default task-13) Installed Default AtmosphereInterceptor [Android Interceptor Support, SSE Interceptor Support, JSONP Interceptor Support, Long-Polling Padding Interceptor Support, Atmosphere JavaScript Protocol, Browser disconnection detection]. Set org.atmosphere.cpr.AtmosphereInterceptor.disableDefaults in your xml to disable them.
13:29:36,627 WARNING [org.atmosphere.cpr.AtmosphereFramework] (default task-13) No BroadcasterCache configured. Broadcasted message between client reconnection will be LOST. It is recommended to configure the org.atmosphere.cache.UUIDBroadcasterCache
13:29:36,627 INFO  [org.atmosphere.cpr.AtmosphereFramework] (default task-13) Shared ExecutorService supported: true
13:29:36,627 INFO  [org.atmosphere.cpr.AtmosphereFramework] (default task-13) HttpSession supported: true
13:29:36,628 INFO  [org.atmosphere.cpr.AtmosphereFramework] (default task-13) Using BroadcasterFactory: org.atmosphere.cpr.DefaultBroadcasterFactory
13:29:36,628 INFO  [org.atmosphere.cpr.AtmosphereFramework] (default task-13) Using WebSocketProcessor: org.atmosphere.websocket.DefaultWebSocketProcessor
13:29:36,628 INFO  [org.atmosphere.cpr.AtmosphereFramework] (default task-13) Using Broadcaster: org.atmosphere.cpr.DefaultBroadcaster
13:29:36,628 INFO  [org.atmosphere.cpr.AtmosphereFramework] (default task-13) Atmosphere Framework 1.0.18.vaadin3 started.
13:29:36,628 INFO  [org.atmosphere.cpr.AtmosphereFramework] (default task-13) Installed AtmosphereInterceptor  Track Message Size Interceptor using |. 
13:29:36,772 INFO  [com.vaadin.cdi.internal.BeanStoreContainer] (default task-5) New BeanStoreContainer created
13:29:37,685 ERROR [stderr] (default task-10) Kooo
13:29:37,688 SEVERE [com.vaadin.server.DefaultErrorHandler] (default task-10) : 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) [vaadin-server-7.1.12.jar:7.1.12]
    at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:118) [vaadin-server-7.1.12.jar:7.1.12]
    at com.vaadin.server.communication.ServerRpcHandler.handleBurst(ServerRpcHandler.java:207) [vaadin-server-7.1.12.jar:7.1.12]
    at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:111) [vaadin-server-7.1.12.jar:7.1.12]
    at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:91) [vaadin-server-7.1.12.jar:7.1.12]
    at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:37) [vaadin-server-7.1.12.jar:7.1.12]
    at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1382) [vaadin-server-7.1.12.jar:7.1.12]
    at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:238) [vaadin-server-7.1.12.jar:7.1.12]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]
    at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
    at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
    at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
    at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
    at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:113) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
    at io.undertow.security.handlers.AuthenticationCallHandler.handleRequest(AuthenticationCallHandler.java:52) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
    at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
    at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
    at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
    at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
    at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
    at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:240) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
    at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
    at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:73) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
    at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:146) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
    at io.undertow.server.Connectors.executeRootHandler(Connectors.java:168) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
    at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:687) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0]
    at java.lang.Thread.run(Thread.java:744) [rt.jar:1.8.0]
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [rt.jar:1.8.0]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0]
    at java.lang.reflect.Method.invoke(Method.java:483) [rt.jar:1.8.0]
    at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:168) [vaadin-server-7.1.12.jar:7.1.12]
    ... 32 more
Caused by: com.vaadin.event.ListenerMethod$MethodException: Invocation of method buttonClick in com.xy.zzy.MyCompositeEvents$1 failed.
    at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:528) [vaadin-server-7.1.12.jar:7.1.12]
    at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:198) [vaadin-server-7.1.12.jar:7.1.12]
    at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:161) [vaadin-server-7.1.12.jar:7.1.12]
    at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:969) [vaadin-server-7.1.12.jar:7.1.12]
    at com.vaadin.ui.Button.fireClick(Button.java:368) [vaadin-server-7.1.12.jar:7.1.12]
    at com.vaadin.ui.Button$1.click(Button.java:57) [vaadin-server-7.1.12.jar:7.1.12]
    ... 37 more
Caused by: java.lang.NullPointerException
    at com.xy.zzy.MyCompositeEvents$1.buttonClick(MyCompositeEvents.java:21) [classes:]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [rt.jar:1.8.0]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0]
    at java.lang.reflect.Method.invoke(Method.java:483) [rt.jar:1.8.0]
    at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:508) [vaadin-server-7.1.12.jar:7.1.12]
    ... 42 more

SOLUTION:

Found another answer that put me on the right track here: Vaadin: CDI Inject is null after referencing

I just needed to inject my gui-component as well as the ejb, instead of creating it with new.

Changing

@Override
protected void init(VaadinRequest request) {
    setContent(new MyCompositeEvents());
}

to

@Inject MyComopsiteEvents mce;
@Override
protected void init(VaadinRequest request) {
    setContent(mce);
}

did the trick. Noob-problem i guess, but this is my first attempt to use cdi with vaadin.

Seems I'm not allowed to answer my own question, so feel free to copy this into an answer-posting :-)

Was it helpful?

Solution

Found another answer that put me on the right track here: Vaadin: CDI Inject is null after referencing

I just needed to inject my gui-component as well as the ejb, instead of creating it with new.

Changing

@Override
protected void init(VaadinRequest request) {
    setContent(new MyCompositeEvents());
}

to

@Inject MyComopsiteEvents mce;
@Override
protected void init(VaadinRequest request) {
    setContent(mce);
}

did the trick. Noob-problem i guess, but this is my first attempt to use cdi with vaadin.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top