0% found this document useful (0 votes)
48 views

GWT RPC2

This document describes how to use GWT RPC (Remote Procedure Calls) to make asynchronous calls from the client side to server side code. It shows the interface and class definitions needed on both sides, deploying the service, creating an asynchronous callback to handle the response, and making an actual call by passing parameters and callback. Key aspects are creating the service interface/async interface, implementing it on the server, setting the service entry point on the client, and calling it with a callback to handle the response.

Uploaded by

ramji013
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

GWT RPC2

This document describes how to use GWT RPC (Remote Procedure Calls) to make asynchronous calls from the client side to server side code. It shows the interface and class definitions needed on both sides, deploying the service, creating an asynchronous callback to handle the response, and making an actual call by passing parameters and callback. Key aspects are creating the service interface/async interface, implementing it on the server, setting the service entry point on the client, and calling it with a callback to handle the response.

Uploaded by

ramji013
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 14

GWT - RPC

RPC plumbing diagram


RPC plumbing diagram

package com.mycompany.client;
import com.google.gwt.user.client.rpc.RemoteService;
public interface MyAddService extends RemoteService {
public int add(int a, int b);
}
RPC plumbing diagram

package com.mycompany.server;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.mycompany.client.MyAddService;
public class MyAddServiceImpl
extends RemoteServiceServlet implements MyAddService{
public int add(int a, int b) {
int z = a + b;
return z;
}
}
RPC plumbing diagram

package com.mycompany.client;
import com.google.gwt.user.client.rpc.AsyncCallback;
public interface MyAddServiceAsync {
public void add(int a, int b, AsyncCallback callback);
}
Deploy service
 Tomcat -> add Servlet
 Hosted mode -> modify module XML

<module>
<inherits name='com.google.gwt.user.User'/>
<entry-point class='com.mycompany.client.MyApplication'/>
<servlet path="/addService"
class="com.mycompany.server.MyAddServiceImpl“/>
</module>
Actually making a call
button.addClickListener(
new ClickListener() {
public void onClick(Widget sender) {
AddServiceAsync addService = (AddServiceAsync) GWT.create(AddService.class);
ServiceDefTarget endpoint = (ServiceDefTarget) addService;
String moduleRelativeURL = GWT.getModuleBaseURL() + "myAddService“;
endpoint.setServiceEntryPoint(moduleRelativeURL);

instantiate service interface


set service implementation url
Actually making a call
button.addClickListener(
new ClickListener() {
public void onClick(Widget sender) {
AddServiceAsync addService = (AddServiceAsync) GWT.create(AddService.class);
ServiceDefTarget endpoint = (ServiceDefTarget) addService;
String moduleRelativeURL = GWT.getModuleBaseURL() + "myAddService“;
endpoint.setServiceEntryPoint(moduleRelativeURL);
AsyncCallback callback = new AsyncCallback(){
public void onSuccess(Object result){
resultaatLabel.setText(result.toString());
}
public void onFailure(Throwable caught) {
resultaatLabel.setText(caught.getMessage());
}

create an asynchronous callback


to handle the result
Actually making a call
button.addClickListener(
new ClickListener() {
public void onClick(Widget sender) {
AddServiceAsync addService = (AddServiceAsync) GWT.create(AddService.class);
ServiceDefTarget endpoint = (ServiceDefTarget) addService;
String moduleRelativeURL = GWT.getModuleBaseURL() + "myAddService“;
endpoint.setServiceEntryPoint(moduleRelativeURL);
AsyncCallback callback = new AsyncCallback(){
public void onSuccess(Object result){
resultaatLabel.setText(result.toString());
}
public void onFailure(Throwable caught) {
resultaatLabel.setText(caught.getMessage());
}
};
addService.add(Integer.parseInt(aBox.getText()),
Integer.parseInt(bBox.getText()),
callback);
}

);
}
actually make the call
Actually making a call
button.addClickListener(
new ClickListener() {
public void onClick(Widget sender) {
AddServiceAsync addService = (AddServiceAsync) GWT.create(AddService.class);
ServiceDefTarget endpoint = (ServiceDefTarget) addService;
String moduleRelativeURL = GWT.getModuleBaseURL() + "myAddService“;
endpoint.setServiceEntryPoint(moduleRelativeURL);
AsyncCallback callback = new AsyncCallback(){
public void onSuccess(Object result){
resultaatLabel.setText(result.toString());
}
public void onFailure(Throwable caught) {
resultaatLabel.setText(caught.getMessage());
}
};
addService.add(Integer.parseInt(aBox.getText()),
Integer.parseInt(bBox.getText()),
callback);
}
}
);
In Eclipse: GWT Remote Service
code executed on client side
code executed on server side
In Eclipse: GWT Remote Service
 Cypal studio maakt zelf Async interface en
implementatie klasse aan, en past xml file aan
 Implementatie van methodes moet wel zelf
voorzien worden
 Refresh werkt enkel voor client-side
aanpassingen
 Bij server-side aanpassingen moet heel de
applicatie herstart worden
Meer info
 http://code.google.com/docreader/#p=google-
web-toolkit-doc-1-5&s=google-web-toolkit-doc-
1-5&t=DevGuideRemoteProcedureCalls

You might also like