Home » Java » Enterprise Java » Spring GWT Integration using the RequestFactory API

About Idriss Mrabti

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 our best selling eBooks for FREE!

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design

and many more ....

 

Leave a Reply

Your email address will not be published. Required fields are marked *

*


6 − four =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Do you want to know how to develop your skillset and become a ...

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!
Get ready to Rock!
To download the books, please verify your email address by following the instructions found on the email we just sent you.

THANK YOU!

Close