100 likes | 139 Views
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;
E N D
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); } } );