Archive

Posts Tagged ‘GWT’

Gwt and Maven2

August 7th, 2007

Trying to use Maven2 to build a GWT project, here is the simplest pom.xml I came up with, starting from Xavier’s

The project can be tested in debug mode with mvn gwt:gwt. It is tested in deployed mode with mvn jetty:run-war

Don’t forget to provide the gwt-user.jar in src/main/webapp/WEB-INF/lib.

Code legend:
Blue parts depend on your project and installation path.
Red part is only needed on a Mac.
Green part makes it easier to use the Jetty plugin.

<project>
  <properties>
    <google.webtoolkit.home>
    /Users/david/Applications/java/gwt-mac-1.4.10/
    </google.webtoolkit.home>
    <google.webtoolkit.extrajvmargs>
    -XstartOnFirstThread
    </google.webtoolkit.extrajvmargs>
  </properties>

  <repositories>
      <repository>
          <id>gwt-maven</id>
          <url>http://gwt-maven.googlecode.com/svn/trunk/mavenrepo</url>
      </repository>
  </repositories>

  <pluginRepositories>
      <pluginRepository>
          <id>gwt-maven</id>
          <url>http://gwt-maven.googlecode.com/svn/trunk/mavenrepo</url>
      </pluginRepository>
  </pluginRepositories>

  <build>
    <plugins>
      <plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>maven-jetty-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>com.totsp.gwt</groupId>
        <artifactId>maven-googlewebtoolkit2-plugin</artifactId>
        <version>1.5.1</version>
        <configuration>
            <logLevel>ERROR</logLevel>
            <runTarget>com.valtech.planning.Planning/JnfPage.html</runTarget>
            <compileTarget>com.valtech.planning.Planning</compileTarget>
        </configuration>
        <executions>
            <execution>
                <goals>
                    <goal>compile</goal>
                </goals>
            </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <dependency>
        <groupId>com.google.gwt</groupId>
        <artifactId>gwt-user</artifactId>
        <version>1.4.10</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.google.gwt</groupId>
        <artifactId>gwt-servlet</artifactId>
        <version>1.4.10</version>
    </dependency>
  </dependencies>
</project>

Blog, Valtech Blog ,

Spring and GWT integration

August 7th, 2007

Googling for ways to integrate GWT with Spring, I didn’t find any simple solution.

Here is what I need :

  • GWT RPC services should be Spring beans.
  • They should be POJOs NOT extending RemoteServiceServlet.
  • Mapping between Servlet paths and beans should be straightforward.

Here is what I came up with :

  • It’s a very simple Servlet that receives every RPC request.
  • It then gets a Spring bean by the name of the Servlet path used for the call.
  • The method call to the bean is done with reflection.

public class SpringDispatchService extends RemoteServiceServlet {
    private final ClassPathXmlApplicationContext context;

    public SpringDispatchServiceImpl() {
        context=new ClassPathXmlApplicationContext(”beans.xml”);
    }

    public String processCall(String payload)
        throws SerializationException {
        try {
            Object target=context.getBean(getServletName());

            RPCRequest rpcRequest=RPC.decodeRequest(
                payload,target.getClass());
            
            Method method=rpcRequest.getMethod();
            Object[] params=rpcRequest.getParameters();

            Object result=method.invoke(target,params);
            
            return RPC.encodeResponseForSuccess(method,result);
        } catch(Throwable ex) {
            return RPC.encodeResponseForFailure(null,ex);
        }
    }
}

Blog, Valtech Blog ,