My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
RequestFactoryInterfaceValidation  
Provides late validation of RequestFactory interfaces
Updated Dec 10, 2011 by t.broyer

Starting with GWT 2.4, RequestFactory interfaces must be validated before they can be used by the RequestFactory server code or JVM-based clients. This document explains the mechanisms for validating those interfaces.

Overview

ERRATA This page incorrectly guides you to find requestfactory-apt.jar in the GWT_TOOLS directory. Instead, Developers should find the requestfactory-apt.jar that came with their distribution. GWT contributors should use the appropriately dated jar in GWT_TOOLS (at this writing requestfactory-apt-2011-08-18.jar), or build their own via ant requestfactory. Note also that the screen shots are aimed at GWT contributors.

The RequestFactory annotation processor will validate the RequestFactory interface declarations and ensure that the mapping of proxy properties and context methods to their domain types is valid. The manner in which the errors are reported depends on the method by which the annotation processor is invoked.

In addition to validating the interfaces, the annotation processor also generates additional Java types which embed pre-computed metadata that is required by the RequestFactory server components. Users of RequestFactorySource must also run the annotation processor in order to provide the client code with obfuscated type token mappings. In the client-only case, the server domain types are not required.

If the validation process is not completed, a runtime error message will be generated:

The RequestFactory ValidationTool must be run for the com.example.shared.MyRequestFactory RequestFactory type

Annotation Processor

It most convenient for both the shared RequestFactory interfaces and their server domain counterparts to be available on the sourcepath or classpath during the compilation process. If this is not practical, see the ValidationTool section for information on post-processing pre-compiled shared interfaces and domain types as part of a deployment process.

javac builds

Users using javac to compile their entire project at once need only to include the requestfactory-apt.jar on the build classpath. The compiler will automatically load the annotation processor from the JAR file. The shared proxy interfaces must be included in the list of java files being compiled.

IDE configuration

Eclipse

Open the project properties dialog and navigate to Java Compiler -> Annotation Processing. Ensure that annotation processing is enabled -- by default it is not.

Add the requestfactory-apt.jar to the factory path.

The project will need to be rebuilt, but once this is done, any RequestFactory validation errors or warnings will be displayed in the editor upon saving:

ValidationTool

Not all build processes are amenable to compiling the shared proxy interfaces and the domain types at the same time. Cases where the ProxyForName and ServiceName annotation are used are typical of this build configuration. In these cases, it is possible to post-process pre-compiled shared and domain types using the RequestFactory ValidationTool.

To run the ValidationTool it is necessary to have the shared interfaces and domain types available on the classpath. The binary names of the RequestFactory interfaces are provided to the tool as well as an output location, which may be a directory or a jar file. The tool will produce one or more class files that contain precomputed metadata that will be used by the RequestFactory server code.

#!/bin/sh
java \
  -cp requestfactory-apt.jar:requestfactory-server.jar:your-shared-classes.jar:your-server-classes.jar \
  com.google.web.bindery.requestfactory.apt.ValidationTool \
  /path/to/output.jar \
  com.example.shared.MyRequestFactory \
  com.example.shared.AnotherRequestFactory

An optional client-only mode will produce the metadata required by RequestFactorySource clients using only the shared interfaces. This mode is activated by adding a -client flag before the output location.

Maven builds

Use the following recipe to run the ValidationTool. If you are using Maven with Google Plugin for Eclipse (see WorkingWithMaven), you do not need to configure Eclipse with the requestfactory-apt.jar as described above. The ValidationTool will be invoked via the POM instead.

      <!-- requestfactory-apt runs an annotation processor (APT) to
           instrument its service interfaces so that
           RequestFactoryServer can decode client requests. Normally
           you would just have a dependency on requestfactory-apt
           with <scope>provided</scope>, but that won't work in
           eclipse due to m2e bug
           https://bugs.eclipse.org/bugs/show_bug.cgi?id=335036 -->
      <plugin>
        <groupId>org.bsc.maven</groupId>
        <artifactId>maven-processor-plugin</artifactId>
        <version>2.0.5</version>
        <executions>
          <execution>
            <id>process</id>
            <goals>
              <goal>process</goal>
            </goals>
            <phase>generate-sources</phase>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>com.google.web.bindery</groupId>
            <artifactId>requestfactory-apt</artifactId>
            <version>${gwtVersion}</version>
          </dependency>
        </dependencies>
      </plugin>

      <!-- Google Plugin for Eclipse (GPE) won't see the source
           generated above by requestfactory-apt unless it is exposed
           as an additional source dir-->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>1.7</version>
        <executions>
          <execution>
            <id>add-source</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>add-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>${project.build.directory}/generated-sources/apt</source>
              </sources>
            </configuration>
          </execution>
        </executions>
      </plugin>

In order for the build-helper-maven-plugin to work, you must also install the buildhelper connector. This should happen automatically when you import a project that requires it. If not, you'll see an error in the POM. To install it, go to Window > Preferences > Discovery > Open Catalog and install the buildhelper connector, then re-import the project from scratch.

In Eclipse 3.7 (Indigo), the following additional POM snippet is needed:

    <pluginManagement>
      <plugins>
        <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
        <plugin>
          <groupId>org.eclipse.m2e</groupId>
          <artifactId>lifecycle-mapping</artifactId>
          <version>1.0.0</version>
          <configuration>
            <lifecycleMappingMetadata>
              <pluginExecutions>
                <pluginExecution>
                  <pluginExecutionFilter>
                    <groupId>org.bsc.maven</groupId>
                    <artifactId>maven-processor-plugin</artifactId>
                    <versionRange>[2.0.5,)</versionRange>
                    <goals>
                      <goal>process</goal>
                    </goals>
                  </pluginExecutionFilter>
                  <action>
                    <execute />
                  </action>
                </pluginExecution>
              </pluginExecutions>
            </lifecycleMappingMetadata>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
Comment by mauro.be...@gmail.com, Sep 12, 2011

IDE configuration for Intellij IDEA: http://goo.gl/6P6dT

Comment by khi...@gmail.com, Sep 20, 2011

someone's using netbeans ?

Comment by rmattis...@gmail.com, Sep 21, 2011

Unable to initialize a JSR 303 Bean Validator javax.validation.ValidationException?: Unable to find a default provider ???

Comment by project member larse...@gmail.com, Sep 21, 2011

If you don't include a jsr-303 validator, then you'll get this WARNING.

If you want it to go away, you can include the hibernate validator of versions greater than or equal to 4. I'm unaware of any other 303 bean validators out there.

Or you could just swallow the WARNING aswell.

Comment by rmattis...@gmail.com, Sep 26, 2011

Ty for this ~

Comment by dahl...@gmail.com, Oct 4, 2011

Hello, Can anyone help me ?

I import a example project from the svn site : http://code.google.com/p/google-web-toolkit/source/browse/trunk/samples/dynatablerf/ .

and I try to configure my gwt-maven-plugin and eclipse environment to run the project.

after that , I build this project and got errors :

error on execute: null

Build errors for dynatablerf; org.apache.maven.lifecycle.LifecycleExecutionException?: Failed to execute goal org.bsc.maven:maven-processor-plugin:2.0.5:process (process) on project DynaTableRf?: Error executing

Comment by branflak...@gmail.com, Oct 7, 2011

My notes on building a demo and the validator .sh here: http://code.google.com/p/gwt-examples/wiki/DemoRequestFactory

Comment by miroslaw...@gmail.com, Oct 13, 2011

I have got the same problem "error on execute: null "

Comment by mhamed.l...@gmail.com, Oct 15, 2011

I get the same error with eclipse Indigo but it seams to work fine with helios

Comment by branflak...@gmail.com, Oct 15, 2011

I couldn't find where to do this. To set this up, Right click on project goto properties.

Comment by qayshp, Oct 23, 2011

I was unable to use these tips in Eclipse Indigo (3.7) for my App Engine Connected Android Project. Does anyone have other tips?

Comment by sinisa...@gmail.com, Oct 25, 2011

I also have problems with my App Engine Connected Android Project on both eclipse 3.6, 3.7, only for the android part. When I change the annotation processing verbose parameter to true, i get "no domain mapping" warning while compiling. I have added the requestfactory-apt.jar in the annotation processing in both the Android and the Appengine/GWT project. I would appreciate if someone gave tips how to fix the android project.

Comment by mail.mic...@gmail.com, Nov 17, 2011

I searched for hours why it doesn't process annotations in eclipse. Very important to change JDK Compliance to 1.6, it was set automatically set in my case to 1.5. Maybe add this as a note.

Comment by peter.qu...@pq-solutions.de, Dec 13, 2011

I have problems to get this work in combination with Grails. The methods defined in my own RequestContext? should be resolved dynamically at runtime. I.e. in Grails every domain object has a save and delete method attached to the domain object at runtime. Hence, these methods cannot be discovered in compile time.

Does anyone have an idea?

Comment by peter.qu...@pq-solutions.de, Dec 16, 2011

Answer my own question: Annotate the appropriate interfaces with @SkipInterfaceValidation? to suppress compilation errors due to missing methods aso.

Comment by MikeBrey...@gmail.com, Dec 20, 2011

Very difficult to understand. "Use the following recipe to run the ValidationTool?." and then it gives some XML code. No idea where this code should go.

Comment by jmb...@gmail.com, Dec 20, 2011

Let me see if I understood, to use the validation tool you must:

Make available both the shared RequestFactory? interfaces and their server domain counterparts on the sourcepath or classpath during the compilation process.--Can you please explain how to do this .

If this is not practical then use the validation tool which consists in :

#!/bin/sh java \

-cp requestfactory-apt.jar:requestfactory-server.jar:your-shared-classes.jar:your-server-classes.jar \ com.google.web.bindery.requestfactory.apt.ValidationTool? \ /path/to/output.jar \ com.example.shared.MyRequestFactory? \ com.example.shared.AnotherRequestFactory?

--Can you please explain how to do this, is it done in cmd or in a property en eclipse ?

Are these two different solutions? or are both tasks supposed to be implemented.

Thank You very much

Comment by barbares...@gmail.com, Jan 30, 2012

After doing this, I'm still getting this error... and cant continue my work... does anyone knows how to solve it? "Caused by: java.lang.ClassFormatError?: Absent Code attribute in method that is not native or abstract in class file javax/validation/Validation"

Comment by master...@gmail.com, Feb 13, 2012

This is really frustrating. I've got a Android Engine Connected Project I'm trying to build using GWT2.4 RequestFactory? and Objectify on my Eclipse IDE.

Apparently I need to use the Validation Tool because there's no way I can have my domain classes on the server side camping in my android package. The problem is the example on this page really isn't very helpful.

Since I never worked on Unix, it took a while to figure out what the script was and what it apparently works.

So I tried running the validation tool from the windows command line, but get the following error: "This tool must be run with a JDK, not a JRE"

WTF??

There's gotta be a better way!

Comment by hex...@gmail.com, Feb 14, 2012

RequestFactory? is causing me nothing but headache.

Comment by koraygu...@gmail.com, Feb 19, 2012

For the one who is unable to find Annotion Processing in Java Compiler item in Eclipse Indigo, just download WTP from http://download.eclipse.org/webtools/repository/indigo/

Comment by ignacio.bacamt, Mar 7, 2012

If you have an "error on execute: null" when launch "update maven configuration" probably its because you are using maven with JRE but you need JDK.

Add something like this in your eclipse.ini file! -vm C:/dev/jdk1.6.0_29/bin

Comment by wippel.r...@gmail.com, Apr 4, 2012

This tool keep yacking when I use generics!

How do I get that to work?

Comment by far...@gmail.com, Apr 9, 2012

For those who met following message: [RuntimeException: The RequestFactory? ValidationTool? must be run for the ... ] running "App Engine connected Android project" sample on Eclipse Indigo, AppEnging? 1.6.4 without Maven. There is possible solution (worked in my case). Click YouProject?-Android > Properties > JavaBuildPath? > OrderAndExport? Tab > Check on all .jars. Same do in YourPeroject?-AppEngine?. (spent allll day installing Maven staff and googling other solutions but finally noticed unchecked jars mentioned above, checked on and TA-DAa:)

Comment by branflak...@gmail.com, Apr 29, 2012

I see you've updated this, nice work Thomas.

Comment by rob.whit...@gmail.com, May 8, 2012

It may be worth noting for those that do not use m2e:

Don't include maven-processor-plugin, and instead do what the comments say (include the requestfactory-apt as a dependency). For me, that plugin causes my gwt to go through the compile every time, even when nothing's changed. Removing that processor block still gives me good builds, and better yet, gwt doesn't compile when nothing's changed.

Comment by rmul...@gmail.com, May 10, 2012

When I try to validate Request Factory, I am getting the following error.

java? error: Unable to find RequestFactory? built-in type. Is requestfactory-[client|server].jar on the classpath? java? 1 error

my build.xml for validate looks like this.

<target name="validate.req.faq">
<java failonerror="true" classname="com.google.web.bindery.requestfactory.apt.ValidationTool">
<classpath>
<fileset dir="${lib.dir}" includes="requestfactory-apt.jar" /> <fileset dir="${lib.dir}" includes="requestfactory-server.jar" /> <fileset dir="${lib.dir}" includes="${jar.name}" />
</classpath>
<arg value="${lib.dir}/req-factory.jar" /> <arg value="com.bofa.msgmgmt.shared.RepairRequestFactory" />
</java>
</target>
<target name="gwt-compile" depends="jar, validate.req.faq">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
<classpath>
<!-- src dir is added to ensure the module.xml file(s) are on the classpath --> <pathelement location="${src.dir}"/> <pathelement location="${build.dir}"/> <path refid="project.classpath"/>
</classpath> <jvmarg value="-Xmx512M"/>
<arg line="-style OBFUSCATE" /> <arg line="-draftCompile" /> <arg line="-strict" />
<arg value="${gwt.module.name}"/>
</java>
</target>

Please help, Thanks in Advance.


Sign in to add a comment
Powered by Google Project Hosting