Spring GWT Integration using the RequestFactory API

Beginning from GWT 2.4 the integration of the RequestFactory API with Spring services on the backend is easy all you need to do is create a custom ServiceLocator on your server which will be used by GWT to locate properly the called services :
 
 
 
 
 
 
 
 

public class SpringServiceLocator implements ServiceLocator {

 public Object getInstance(Class clazz) {
  ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(
    RequestFactoryServlet.getThreadLocalServletContext());
  return context.getBean(clazz);
 }
}

The second step is to declare you RequestFactory servlet on your web.xml like this, (I assume that you have already spring set up) :

<servlet>

 <servlet-name>requestFactoryServlet</servlet-name>

 <servlet-class>org.gxpenses.util.SpringRequestServlet</servlet-class>

 <load-on-startup>1</load-on-startup>

</servlet>



<servlet-mapping>

 <servlet-name>requestFactoryServlet</servlet-name>

 <url-pattern>/gwtRequest</url-pattern>

</servlet-mapping>

As usual on the GWT part you have to configure your Proxies (because you use service style backend, you have to use ValueProxy instead of the EntityProxy) and your Requests which are the remote interfaces of your services :

//Note that I inherit from the ValueProxy object

@ProxyFor(Account.class)

public interface AccountProxy extends ValueProxy {

 public String getId();

 public void setId(String id);

 public String getName();

 public void setName(String name);

 public Double getBalance();

 public void setBalance(Double balance);

 public String getType();

 public void setType(String type);

}



//You have to provide you service Impl class, and the ServiceLocator you created

//Note that Account is automatically to AccountProxy on the client

@Service(value=AccountsServiceImpl.class, locator=SpringServiceLocator.class)

public interface AccountRequest extends RequestContext {

 abstract Request<Void> createNewAccount(AccountProxy account);

 abstract Request<Void> updateAccountBalance(String accountId, Double transactionAmount, String type);

 abstract Request<Double> totalAmountByAccountAndPeriodeAndType(String accountId, Date start, Date end, String type);

}

That’s it for the integration, for more informations on how to use the RequestFactory API see : RequestFactory API

Reference: Spring GWT Integration using the RequestFactory API from our JCG partner Idriss Mrabti at the Fancy UI blog.

Related Articles :

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

JPA Mini Book

Learn how to leverage the power of JPA in order to create robust and flexible Java applications. With this Mini Book, you will get introduced to JPA and smoothly transition to more advanced concepts.

JVM Troubleshooting Guide

The Java virtual machine is really the foundation of any Java EE platform. Learn how to master it with this advanced guide!

Given email address is already subscribed, thank you!
Oops. Something went wrong. Please try again later.
Please provide a valid email address.
Thank you, your sign-up request was successful! Please check your e-mail inbox.
Please complete the CAPTCHA.
Please fill in the required fields.

Leave a Reply


× five = 20



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy | Contact
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
Do you want to know how to develop your skillset and become a ...
Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

Get ready to Rock!
You can download the complementary eBooks using the links below:
Close