Add an Asynchronous (RPC) Service
This page describes how to add a standard RPC Service to the GWT client project. The web client typically uses this intermediary between other REST API calls and the actual client (JavaScript) application. This is done to avoid cross site server scripting browser limitations, as well as to abstract API implementations from the web client's code.
Steps
- Create two java interfaces XXXService.java and and XXXServiceAsync.java in org.sagebionetworks.web.client.services where XXX is the name of your service.
- ex: DatasetService.java and DatasetServiceAsync.java
- In the XXXService interface, add the service's relative web path via the @RemoteServiceRelativePath annotation
- ex: @RemoteServiceRelativePath("dataset")
- Create a class on the server side of the GWT project (in org.sagebionetworks.web.server.servlet) called XXXServiceImpl.java. It should extend RemoveServiceServlet and implement your XXXService interface.
- ex: DatasetServiceImpl.java
- Modify PortalServletModule (in org.sagebionetworks.web.server) to make your XXXServiceImpl class a singleton, and bind it to the path that you specified in the XXXService interface.
- ex: bind(DatasetServiceImpl.class).in(Singleton.class);
serve("/Portal/dataset").with(DatasetServiceImpl.class);
- ex: bind(DatasetServiceImpl.class).in(Singleton.class);
- Refresh your GWT Development server and you're (almost) all done.
- Write a test for your ServiceImpl.
- ex: DatasetServiceImplTest.java