NPE when running @Inject Caller<t>
wschilpzand Nov 29, 2012 5:58 AMHi,
I am trying to get errai to call a rest service. My project was created from the JBoss quick starts (GWT project), and compiles properly.
My class is a view implementation. I have created the annotated interface for the rest service and injected using @Inject. However, when I run the applicaiton, I get a NPE on the line in the button click event that makes the call to the service. In debug, the service variable is null. I have tried adding dependencies through the POM etc with no joy. I haven't yet tried using the RestClient call, as CDI is much more elegant.
I am using JBoss AS7 and JBoss Developer Studio 5.0.1GA.
I would love for this to work, any help would be greatly appreciated.
here is my view class
{code}/*******************************************************************************
* Copyright 2011 Google Inc. All Rights Reserved.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
package org.ws.vehiclelogbook.webapp.client.ui.security;
import java.util.Map;
import org.jboss.errai.bus.client.api.RemoteCallback;
import org.jboss.errai.enterprise.client.jaxrs.api.RestClient;
import org.jboss.errai.ioc.client.api.Caller;
import org.ws.vehiclelogbook.webapp.client.rest.LoginService;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.place.shared.Place;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
/**
* Sample implementation of {@link LoginView}.
*/
public class LoginViewImpl extends Composite implements LoginView {
interface Binder extends UiBinder<Widget, LoginViewImpl> {
}
@Inject private Caller<LoginService> loginService;
private static final Binder binder = GWT.create(Binder.class);
private Presenter listener;
@UiField Label lbl_error;
@UiField TextBox txt_username;
@UiField TextBox txt_password;
@UiField Button btn_login;
public LoginViewImpl() {
initWidget(binder.createAndBindUi(this));
lbl_error.setVisible(false);
RestClient.setApplicationRoot("http://localhost:8080/VehicleLogBookApp/rest");
}
@Override
public void setName(String name) {
}
@Override
public void setPresenter(Presenter listener) {
this.listener = listener;
}
@UiHandler("btn_login")
void onButtonClick(ClickEvent event){
loginService.call(callBack).login();
}
RemoteCallback<Map<String, String>> callBack = new RemoteCallback<Map<String, String>>(){
public void callback(Map<String, String> response){
Window.alert("Success: " + response.get("success"));
}
};
}
{code}
here is my WebApp.gwt.xml
{code:xml}<module>
<inherits name="com.google.gwt.user.User"/>
<inherits name="com.google.gwt.user.theme.standard.Standard"/>
<inherits name="com.google.gwt.place.Place"/>
<inherits name="com.google.gwt.activity.Activity"/>
<inherits name="org.jboss.errai.common.ErraiCommon"/>
<inherits name="org.jboss.errai.bus.ErraiBus"/>
<inherits name="org.jboss.errai.ioc.Container"/>
<inherits name="org.jboss.errai.enterprise.CDI"/>
<inherits name="org.jboss.errai.enterprise.Jaxrs"/>
<inherits name="com.smartgwt.SmartGwt"/>
<entry-point class="org.ws.vehiclelogbook.webapp.client.WebApp"/>
<replace-with class="org.ws.vehiclelogbook.webapp.client.ClientFactoryImpl">
<when-type-is class="org.ws.vehiclelogbook.webapp.client.ClientFactory"/>
</replace-with>
</module>
{code}
and here is my pom.xml
{code:xml}<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.ws.vehiclelogbook</groupId>
<artifactId>VehicleLogBookWebApp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>JBoss AS Quickstarts: Errai kitchensink</name>
<description>A starter Java EE 6 webapp project for use on JBoss AS 7 / EAP 6, generated from the jboss-javaee6-webapp archetype</description>
<properties>
<!-- Explicitly declaring the source encoding eliminates the following
message: -->
<!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered
resources, i.e. build is platform dependent! -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- Define the version of JBoss' Java EE 6 APIs we want to import. Any
dependencies from org.jboss.spec will have their version defined by this
BOM -->
<version.org.jboss.spec.jboss.javaee6>3.0.0.Final</version.org.jboss.spec.jboss.javaee6>
<!-- Alternatively, comment out the above line, and un-comment the line
below to use version 3.0.0.Final-redhat-1 which is a release certified to
work with JBoss EAP 6. It requires you have access to the JBoss EAP 6 maven
repository. -->
<!-- <version.org.jboss.spec.jboss.javaee6>3.0.0.Final-redhat-1</version.org.jboss.spec.jboss.javaee6> -->
<version.org.jboss.errai>2.0.0.Final</version.org.jboss.errai>
<version.com.google.gwt>2.4.0</version.com.google.gwt>
<version.org.codehaus.mojo.gwt.maven.plugin>${version.com.google.gwt}</version.org.codehaus.mojo.gwt.maven.plugin>
</properties>
<dependencyManagement>
<dependencies>
<!-- JBoss distributes a complete set of Java EE 6 APIs including a
Bill of Materials (BOM). A BOM specifies the versions of a "stack" (or a
collection) of artifacts. We use this here so that we always get the correct
versions of artifacts. Here we use the jboss-javaee-6.0 stack (you can read
this as the JBoss stack of the Java EE 6 APIs). You can actually use this
stack with any version of JBoss AS that implements Java EE 6, not just JBoss
AS 7! -->
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<version>${version.org.jboss.spec.jboss.javaee6}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- Errai Core and ErraiBus -->
<dependency>
<groupId>org.jboss.errai</groupId>
<artifactId>errai-bus</artifactId>
<version>${version.org.jboss.errai}</version>
<exclusions>
<exclusion>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</exclusion>
<exclusion>
<groupId>javax.annotation</groupId>
<artifactId>jsr250-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jboss.errai</groupId>
<artifactId>errai-ioc</artifactId>
<version>${version.org.jboss.errai}</version>
<exclusions>
<exclusion>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</exclusion>
<exclusion>
<groupId>javax.annotation</groupId>
<artifactId>jsr250-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jboss.errai</groupId>
<artifactId>errai-tools</artifactId>
<version>${version.org.jboss.errai}</version>
</dependency>
<!-- Errai JAX-RS -->
<dependency>
<groupId>org.jboss.errai</groupId>
<artifactId>errai-jaxrs-client</artifactId>
<version>${version.org.jboss.errai}</version>
</dependency>
<dependency>
<groupId>org.jboss.errai</groupId>
<artifactId>errai-jaxrs-provider</artifactId>
<version>${version.org.jboss.errai}</version>
</dependency>
<!-- Errai CDI Integration Modules -->
<dependency>
<groupId>org.jboss.errai</groupId>
<artifactId>errai-cdi-client</artifactId>
<version>${version.org.jboss.errai}</version>
</dependency>
<dependency>
<groupId>org.jboss.errai</groupId>
<artifactId>errai-javax-enterprise</artifactId>
<version>${version.org.jboss.errai}</version>
</dependency>
<dependency>
<groupId>org.jboss.errai</groupId>
<artifactId>errai-weld-integration</artifactId>
<version>${version.org.jboss.errai}</version>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${version.com.google.gwt}</version>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-dev</artifactId>
<version>${version.com.google.gwt}</version>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<type>jar</type>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- First declare the APIs we depend on and need for compilation. All
of them are provided by JBoss AS 7 -->
<!-- Import the CDI API, we use provided scope as the API is included
in JBoss AS 7 -->
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the JPA API, we use provided scope as the API is included
in JBoss AS 7 -->
<dependency>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.1_spec</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the Common Annotations API (JSR-250), we use provided scope
as the API is included in JBoss AS 7 -->
<dependency>
<groupId>org.jboss.spec.javax.annotation</groupId>
<artifactId>jboss-annotations-api_1.1_spec</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the JAX-RS API, we use provided scope as the API is included
in JBoss AS 7 -->
<dependency>
<groupId>org.jboss.spec.javax.ws.rs</groupId>
<artifactId>jboss-jaxrs-api_1.1_spec</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the JPA API, we use provided scope as the API is included
in JBoss AS 7 -->
<!-- Import the EJB API, we use provided scope as the API is included
in JBoss AS 7 -->
<dependency>
<groupId>org.jboss.spec.javax.ejb</groupId>
<artifactId>jboss-ejb-api_3.1_spec</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the Bean Validation API, which is used both on the server
and the client. -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
<!-- JSR-303 (Bean Validation) Implementation -->
<!-- Provides portable constraints such as @Email -->
<!-- Hibernate Validator is shipped in JBoss AS 7 -->
<!-- GWT validation uses Hibernate Validator, and requires the sources
at compile time. -->
<!-- GWT validation also requires the validation API sources at compile
time -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
<classifier>sources</classifier>
</dependency>
<!-- The next set of dependencies are for Errai -->
<dependency>
<groupId>org.jboss.errai</groupId>
<artifactId>errai-bus</artifactId>
<exclusions>
<exclusion>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</exclusion>
<exclusion>
<groupId>javax.annotation</groupId>
<artifactId>jsr250-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jboss.errai</groupId>
<artifactId>errai-ioc</artifactId>
<exclusions>
<exclusion>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</exclusion>
<exclusion>
<groupId>javax.annotation</groupId>
<artifactId>jsr250-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jboss.errai</groupId>
<artifactId>errai-tools</artifactId>
</dependency>
<!-- Errai CDI Integration Modules -->
<dependency>
<groupId>org.jboss.errai</groupId>
<artifactId>errai-cdi-client</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.errai</groupId>
<artifactId>errai-javax-enterprise</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.errai</groupId>
<artifactId>errai-weld-integration</artifactId>
<exclusions>
<!-- errai-cdi-jetty is only required for integration testing -->
<exclusion>
<groupId>org.jboss.errai</groupId>
<artifactId>errai-cdi-jetty</artifactId>
</exclusion>
<exclusion>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- gwt-user is required at runtime because we use some of the client/server
shared APIs such as RegExp, so scope is 'compile' rather than 'provided'. -->
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-dev</artifactId>
<scope>provided</scope>
</dependency>
<!-- End of Errai dependencies -->
<!-- Now we declare any tools needed -->
<!-- Annotation processor to generate the JPA 2.0 metamodel classes for
typesafe criteria queries -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>1.1.1.Final</version>
<scope>provided</scope>
</dependency>
<!-- Needed for running tests (you may also use TestNG) -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.smartgwt</groupId>
<artifactId>smartgwt</artifactId>
<version>2.5-patch</version>
</dependency>
<dependency>
<groupId>com.smartgwt</groupId>
<artifactId>smartgwt-skins</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.jboss.errai</groupId>
<artifactId>errai-jaxrs-client</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.errai</groupId>
<artifactId>errai-jaxrs-provider</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Compiler plugin enforces Java 1.6 compatibility and activates
annotation processors -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<!-- Maven will append the version to the finalName (which is the name
given to the generated war, and hence the context root) -->
<warName>${project.artifactId}</warName>
<!-- We must exclude GWT client local classes from the deployment,
or classpath scanners such as Hibernate and Weld get confused when the webapp
is bootstrapping. -->
<packagingExcludes>**/javax/**/*.*,**/client/local/**/*.class</packagingExcludes>
<archive>
<manifestEntries>
<Dependencies>org.jboss.as.naming,org.jboss.as.server,org.jboss.msc</Dependencies>
</manifestEntries>
</archive>
</configuration>
</plugin>
<!-- GWT plugin to compile client-side java code to javascript and
to run GWT development mode -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>${version.org.codehaus.mojo.gwt.maven.plugin}</version>
<configuration>
<inplace>true</inplace>
<logLevel>INFO</logLevel>
<extraJvmArgs>-Xmx512m</extraJvmArgs>
<!-- Configure GWT's development mode (formerly known as hosted
mode) to not start the default server (embedded jetty), but to download the
HTML host page from the configured runTarget. -->
<noServer>true</noServer>
<runTarget>http://localhost:8080/VehicleLogBookWebApp/KitchenSink.html</runTarget>
</configuration>
<executions>
<execution>
<goals>
<goal>resources</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>gwt-clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- The JBoss AS plugin deploys your war to a local JBoss AS container -->
<!-- To use, run: mvn package jboss-as:deploy -->
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.1.0.Final</version>
<configuration>
<filename>${project.artifactId}.${project.packaging}</filename>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<filesets>
<fileset>
<directory>${basedir}</directory>
<includes>
<include>www-test/**</include>
<include>.gwt/**</include>
<include>.errai/**</include>
<include>src/main/webapp/KitchenSink/**</include>
<include>src/main/webapp/WEB-INF/deploy/**</include>
<include>src/main/webapp/WEB-INF/lib/**</include>
<include>**/gwt-unitCache/**</include>
<include>**/*.JUnit/**</include>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!-- m2e (Maven integration for Eclipse) requires the following configuration -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<versionRange>[2.3.0,)</versionRange>
<goals>
<goal>resources</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<profiles>
<profile>
<!-- The default profile skips all tests, though you can tune it to
run just unit tests based on a custom pattern -->
<!-- Seperate profiles are provided for running all tests, including
Arquillian tests that execute in the specified container -->
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<!-- We add the JBoss repository as we need the JBoss AS connectors
for Arquillian -->
<repositories>
<!-- The JBoss Community public repository is a composite repository
of several major repositories -->
<!-- see http://community.jboss.org/wiki/MavenGettingStarted-Users -->
<repository>
<id>jboss-public-repository</id>
<name>JBoss Repository</name>
<url>http://repository.jboss.org/nexus/content/groups/public</url>
<!-- These optional flags are designed to speed up your builds
by reducing remote server calls -->
<releases>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>jboss-public-repository</id>
<name>JBoss Repository</name>
<url>http://repository.jboss.org/nexus/content/groups/public</url>
<releases>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<!-- An optional Arquillian testing profile that executes tests in
your JBoss AS instance -->
<!-- This profile will start a new JBoss AS instance, and execute the
test, shutting it down when done -->
<!-- Run with: mvn clean test -Parq-jbossas-managed -->
<id>arq-jbossas-managed</id>
<dependencies>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-arquillian-container-managed</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
<profile>
<!-- We add the JBoss repository as we need the JBoss AS connectors
for Arquillian -->
<repositories>
<!-- The JBoss Community public repository is a composite repository
of several major repositories -->
<!-- see http://community.jboss.org/wiki/MavenGettingStarted-Users -->
<repository>
<id>jboss-public-repository</id>
<name>JBoss Repository</name>
<url>http://repository.jboss.org/nexus/content/groups/public</url>
<!-- These optional flags are designed to speed up your builds
by reducing remote server calls -->
<releases>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>jboss-public-repository</id>
<name>JBoss Repository</name>
<url>http://repository.jboss.org/nexus/content/groups/public</url>
<releases>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<!-- An optional Arquillian testing profile that executes tests in
a remote JBoss AS instance -->
<!-- Run with: mvn clean test -Parq-jbossas-remote -->
<id>arq-jbossas-remote</id>
<dependencies>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-arquillian-container-remote</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
<profile>
<!-- When built in OpenShift the 'openshift' profile will be used when
invoking mvn. -->
<!-- Use this profile for any OpenShift specific customization your
app will need. -->
<!-- By default that is to put the resulting archive into the 'deployments'
folder. -->
<!-- http://maven.apache.org/guides/mini/guide-building-for-different-environments.html -->
<id>openshift</id>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<outputDirectory>deployments</outputDirectory>
<warName>ROOT</warName>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<!-- We only need this repository for Errai components. When Errai is published
to Maven Central, we won't require this anymore. -->
<repositories>
<!-- The JBoss Community public repository is a composite repository
of several major repositories -->
<!-- see http://community.jboss.org/wiki/MavenGettingStarted-Users -->
<repository>
<id>jboss-public-repository</id>
<name>JBoss Repository</name>
<url>http://repository.jboss.org/nexus/content/groups/public</url>
<!-- These optional flags are designed to speed up your builds by reducing
remote server calls -->
<releases>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</project>
{code}