LDSTechForumProjects

GWT Stack Integration Lab 3

GWT RPC With the Java Stack

Add the stack-gwt-spring Dependency

  1. Open the file "/StackGWT-web/pom.xml".
  2. Add to the dependencies section of the pom the following:
    <dependency>
        <groupId>org.lds.stack.gwt</groupId>
        <artifactId>stack-gwt-spring</artifactId>
    </dependency>

Add the GWT RPC Dispatcher Servlet to web.xml

  1. Open the file "/StackGWT-web/src/main/webapp/WEB-INF/web.xml".
  2. In the Servlets section of the web.xml (around line 78) add the following:
	<servlet>
		<servlet-name>gwtrpc</servlet-name>
		<servlet-class>org.lds.stack.gwt.rpc.GwtRpcDispatcherServlet</servlet-class>
	</servlet>
	
	<servlet-mapping>
		<servlet-name>gwtrpc</servlet-name>
		<url-pattern>*.gwtrpc</url-pattern>
	</servlet-mapping>

This adds the GWT RPC Dispatcher Servlet to your application and maps it to *.gwtrpc. This means that any web request that has a URI ending in *.gwtrpc will be handling by the GWT RPC mechanism.

Add the GWT RPC Spring context file

  1. Right click on the folder /StackGWT-web/src/main/webapp/WEB-INF and select New | File.
  2. Give the file the name "gwtrpc-servlet.xml".
  3. Select Finish.
  4. Paste into the file the following:
<?xml version="1.0" encoding="UTF-8"?>
<!-- =========================================================== -->
<!-- GWT RPC Configuration File					             -->
<!-- =========================================================== -->
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:gwt="http://dev.lds.org/schema/spring/gwt"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
		http://dev.lds.org/schema/spring/gwt  http://dev.lds.org/schema/spring/gwt/stack-gwt-3.0.xsd
       ">

	<context:component-scan base-package="org.lds.gwt.service" use-default-filters="false">
		<context:include-filter expression="org.springframework.stereotype.Controller" type="annotation"/>
	</context:component-scan>

	<gwt:gwt-rpc-dispatcher />

</beans>

You're probably thinking to yourself, this is a lot of boilerplate. You're right. Yes, we will be adding this to Stack Starter in the near future so hopefully you'll never have to do all of this again. Sorry for the inconvenience.

Create an RPC Service

  1. Create a RemoteService interface. Remember this must go in the package org.lds.gwt.client . When annotating this interface with @RemoteInterfaceRelativePath be sure the value ends with .gwtrpc.
  2. Create its corresponding Async interface.
  3. Implement the RemoteService in the org.lds.gwt.service package.
  4. Annotate the implementation with @org.springframework.stereotype.Controller.
  5. Instantiate your async interface using GWT deferred binding. GWT deferred binding is the GWT.create(...) stuff.
  6. Add a call to the remote service in your entry point.
  7. Restart Tomcat. If you're not sure how to do this, ask an experienced Stack developer sitting close to you.
  8. Test the call to your remote service

You may want to refer back to Lab 1 when doing this part of the lab.

This page was last modified on 10 June 2010, at 12:06.

Note: Content found in this wiki may not always reflect official Church information. See Terms of Use.