SlideShare uma empresa Scribd logo
1 de 19
GWT Training – Session III

Communicating with the
Server

Snehal Masne
www.TechProceed.com
Contents



Asynchronous HTTP Request
Submitting Data using HTML Form





Traditional
GWT

GWT RPC

www.TechProceed.com
Asynchronous HTTP Requests
/ /create a new GET request
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, "/info.php”);
try{
//send the request
builder.sendRequest( null, new RequestCallback() {
public void onError(Request request, Throwable exception){
//log the error
}
public void onResponseReceived(Request request, Response response){
//process response
}
});
}
catch (RequestException e){
//handle request exception
}
www.TechProceed.com
Asynchronous HTTP Requests
– cont'd




builder.sendRequest() method receives a
string data to be sent with the request and
RequestCallback object that handles the
response from the server
null is passed if there is no data to be sent to
the data

www.TechProceed.com
Submitting Data to Server Using
HTML Form
<form name="input" action="register.php" method="post">
Username: <input type="text" name="user"><br/>
Email: <input type="text" name="email"><br/>
Password: <input type="password" name="password"><br/>
<input type="submit" value="Submit">
</form>

Data Submitted
POST /register.php HTTP/1.1
Content-Type: application/x-www-form-urlencoded
username=Faiz&email=faizbash%40gmail.com&password=secret

www.TechProceed.com
GWT Equivalent for Form Data Submission Constructing HTTP Request Manually
//build the data to post
StringBuffer postBuilder = new StringBuffer();
postBuilder.append("username=" );
postBuilder.append( URL.encodeComponent( username ) );
postBuilder.append("&email=" );
postBuilder.append( URL.encodeComponent( email ) );
postBuilder.append("&password=" );
postBuilder.append( URL.encodeComponent( password ) );
try{
//create and submit the request
RequestBuilder requestBuilder = new RequestBuilder( RequestBuilder.POST,
GWT.getModuleBaseURL()+"/register.php" );
requestBuilder.sendRequest( postBuilder.toString(), new RequestCallback(){
public void onError(Request request, Throwable exception){
// handle error
}
public void onResponseReceived(Request request, Response response){
// handle response
}
});
}catch( Exception e){ // handle exception }
www.TechProceed.com
GWT Equivalent for Form Data Submission
– Using FormPanel
//create the form panel, set its action and method
final FormPanel form = new FormPanel();
form.setAction("/register.php");
form.setMethod(FormPanel.METHOD_POST);

//set the main widget for the panel to a vertical panel
VerticalPanel panel = new VerticalPanel();
form.setWidget(panel);
//create the username field
TextBox tb = new TextBox();
tb.setName("username");
panel.add(tb);
//create the e-mail field
TextBox tb = new TextBox();
tb.setName("email ");
panel.add(tb);

www.TechProceed.com
GWT Equivalent for Form Data Submission
– Using FormPanel (cont'd)‫‏‬
//create the password field
PasswordTextBox ptb = new PasswordTextBox();
ptb.setName("password");
panel.add(ptb);
//create the Submit button
Button submit = new Button(“Submit”);
submit.addClickHandler( new ClickHandler() {
public void onClick(Widget sender) {
form.submit();
}
});
//add submit button to panel
panel.add(submit);

www.TechProceed.com
GWT RPC








GWT extends a browser’s capability to asynchronously
communicate with the server by providing a remote procedure call
(RPC) library.
Calls to the server are simplified by providing you with an
interface of methods that can be called similarly to regular method
calls.
GWT marshal the calls (convert to a stream of data) and send to
the remote server.
At the server side, the data, is un-marshalled the method on the
server is invoked

www.TechProceed.com
GWT RPC – cont'd




In GWT, the RPC library is divided into two packages:
 com.google.gwt.user.client.rpc package used for clientside RPC support
 com.google.gwt.user.server.rpc package used for serverside RPC support The client side provides interfaces that
you can use to tag
When the client code is compiled to Javascript using the
GWT compiler, the code required to do the RPC marshaling
will be generated

www.TechProceed.com
GWT RPC Implementation


To understand how GWT RPC works, we
would implement the data form submission
using it

www.TechProceed.com
GWT RPC Implementation – Step 1


Create the RPC interface (stub) on the client side
 Create a new interface named LoginService under the
my.utm.kase.gwttraining.client package
 Edit the code to look like the one below:
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
@RemoteServiceRelativePath("login")
public interface LoginService extends RemoteService {
boolean login(String username, String email, String password);
}


Add the following in /war/WEB-INF/web.xml

www.TechProceed.com
GWT RPC Implementation – Step 2


Configure the servlet


Add the following in /war/WEB-INF/web.xml
<servlet>
<servlet-name>loginServlet</servlet-name>
<servlet-class>
my.utm.kase.gettraining.server.LoginServiceImpl
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>loginServlet</servlet-name>
<url-pattern>/gwttraining/login</url-pattern>
</servlet-mapping>

www.TechProceed.com
GWT RPC Implementation – Step 3


Create an async counterpart interface of the LoginService. This interface
defines the callback method that will be called when the server generates
a response
 Create another interface, LoginServiceAsync under
my.utm.kase.gwttraining.client package
 Edit the code to look like the one below:
import com.google.gwt.user.client.rpc.AsyncCallback;
public interface LoginServiceAsync {
boolean login(String username, String email,
String password, AsyncCallback<Boolean> callback);
}


The async method always returns void and takes parameters similar
to its stub counterpart plus an AsyncCallback parameter which
specifies the return value of the stub method which is Void in this case
www.TechProceed.com
GWT RPC Implementation – Step 4


Implement the remote method on the server side
 Create a class, LoginServiceImpl under my.utm.kase.gwttraining.server
package
 Edit the code to look like the one below:
import my.utm.kase.gwttraining.client.LoginService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
public class LoginServiceImpl extends RemoteServiceServlet implements
LoginService {
public boolean login(String username, String email, String password)

{
if( username.equals("faizbash") && password.equals("secret") )
{
return true;
}
else return false;
}
}
www.TechProceed.com
GWT RPC Implementation – Step 5


Call the remote method
 Create a login widget in my.utm.kase.gwttraining.client package to get
username, email and password from user. It also captures login event and
makes a RPC to loign user.
public class LoginWidget extends Composite {
public LoginWidget() {
//login panel
FlexTable loginTable = new FlexTable();
final TextBox usernameBox = new TextBox();
final TextBox emailBox = new TextBox();
final PasswordTextBox passwordBox = new PasswordTextBox();
Button loginButton = new Button("Login");
loginButton.addClickHandler( new ClickHandler() {
public void onClick(ClickEvent event) {
login(usernameBox.getText(), emailBox.getText(), passwordBox.getText();
}
});
//username widget
loginTable.setWidget(0, 0, new Label("Username"));
loginTable.setWidget(0, 1, usernameBox);
//email widget
loginTable.setWidget(1, 0, new Label("Email"));
loginTable.setWidget(1, 1, emailBox);

www.TechProceed.com
GWT RPC Implementation –
Step 5 (cont'd)‫‏‬
//password widget
loginTable.setWidget(2, 0, new Label("Password"));
loginTable.setWidget(2, 1, passwordBox);
//login button widget
loginTable.setWidget(3, 0, loginButton);
loginTable.getFlexCellFormatter().setColSpan(3, 0, 2);
//init loginTable
initWidget(loginTable);
}
public void login(String username, String email, String password) {
//create a callback method
AsyncCallback<Boolean> callback = new AsyncCallback<Boolean>() {
public void onFailure(Throwable caught) {
//handle failure
Window.alert("Failed to login");
}
public void onSuccess(Boolean status) {
if( status )
Window.alert("Login successful");
else
Window.alert("Invalid username or passord");
}
};

www.TechProceed.com
GWT RPC Implementation –
Step 5 (cont'd)‫‏‬
//Create a remote service proxy to talk to the server-side Greeting service.
final LoginServiceAsync loginService = GWT.create(LoginService.class);
//invoke the remote method
loginService.login(username, email, password, callback);
}
}



Instantiate the widget in the GWTTrainingWidgets entry point class:
//login widget
LoginWidget loginWidget = new LoginWidget();
tabPanel.add(loginWidget, "Login");



Run or refresh to test

www.TechProceed.com
Thank you

www.TechProceed.com

Mais conteúdo relacionado

Mais procurados

Implementing Comet using PHP
Implementing Comet using PHPImplementing Comet using PHP
Implementing Comet using PHPKing Foo
 
Cracking JWT tokens: a tale of magic, Node.js and parallel computing - Code E...
Cracking JWT tokens: a tale of magic, Node.js and parallel computing - Code E...Cracking JWT tokens: a tale of magic, Node.js and parallel computing - Code E...
Cracking JWT tokens: a tale of magic, Node.js and parallel computing - Code E...Luciano Mammino
 
Mobile web performance - MoDev East
Mobile web performance - MoDev EastMobile web performance - MoDev East
Mobile web performance - MoDev EastPatrick Meenan
 
Web II - 02 - How ASP.NET Works
Web II - 02 - How ASP.NET WorksWeb II - 02 - How ASP.NET Works
Web II - 02 - How ASP.NET WorksRandy Connolly
 
Asynchronous web apps with the Play Framework 2.0
Asynchronous web apps with the Play Framework 2.0Asynchronous web apps with the Play Framework 2.0
Asynchronous web apps with the Play Framework 2.0Oscar Renalias
 
MongoDB.local Berlin: App development in a Serverless World
MongoDB.local Berlin: App development in a Serverless WorldMongoDB.local Berlin: App development in a Serverless World
MongoDB.local Berlin: App development in a Serverless WorldMongoDB
 
HTTP 프로토콜의 이해와 활용
HTTP 프로토콜의 이해와 활용HTTP 프로토콜의 이해와 활용
HTTP 프로토콜의 이해와 활용SangJin Kang
 
Robert Kubis - gRPC - boilerplate to high-performance scalable APIs - code.t...
 Robert Kubis - gRPC - boilerplate to high-performance scalable APIs - code.t... Robert Kubis - gRPC - boilerplate to high-performance scalable APIs - code.t...
Robert Kubis - gRPC - boilerplate to high-performance scalable APIs - code.t...AboutYouGmbH
 
EAI design patterns/best practices
EAI design patterns/best practicesEAI design patterns/best practices
EAI design patterns/best practicesAjit Bhingarkar
 
MongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and Typescript
MongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and TypescriptMongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and Typescript
MongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and TypescriptMongoDB
 
Devoxx France: Fault tolerant microservices on the JVM with Cassandra
Devoxx France: Fault tolerant microservices on the JVM with CassandraDevoxx France: Fault tolerant microservices on the JVM with Cassandra
Devoxx France: Fault tolerant microservices on the JVM with CassandraChristopher Batey
 
Legacy Dependency Kata v2.0
Legacy Dependency Kata v2.0Legacy Dependency Kata v2.0
Legacy Dependency Kata v2.0William Munn
 
Legacy Code Kata v3.0
Legacy Code Kata v3.0Legacy Code Kata v3.0
Legacy Code Kata v3.0William Munn
 
I/O Extended (GDG Bogor) - Sidiq Permana
I/O Extended (GDG Bogor) - Sidiq PermanaI/O Extended (GDG Bogor) - Sidiq Permana
I/O Extended (GDG Bogor) - Sidiq PermanaDicoding
 

Mais procurados (18)

Implementing Comet using PHP
Implementing Comet using PHPImplementing Comet using PHP
Implementing Comet using PHP
 
Cracking JWT tokens: a tale of magic, Node.js and parallel computing - Code E...
Cracking JWT tokens: a tale of magic, Node.js and parallel computing - Code E...Cracking JWT tokens: a tale of magic, Node.js and parallel computing - Code E...
Cracking JWT tokens: a tale of magic, Node.js and parallel computing - Code E...
 
Mobile web performance - MoDev East
Mobile web performance - MoDev EastMobile web performance - MoDev East
Mobile web performance - MoDev East
 
Pushing the Web: Interesting things to Know
Pushing the Web: Interesting things to KnowPushing the Web: Interesting things to Know
Pushing the Web: Interesting things to Know
 
Web II - 02 - How ASP.NET Works
Web II - 02 - How ASP.NET WorksWeb II - 02 - How ASP.NET Works
Web II - 02 - How ASP.NET Works
 
Asynchronous web apps with the Play Framework 2.0
Asynchronous web apps with the Play Framework 2.0Asynchronous web apps with the Play Framework 2.0
Asynchronous web apps with the Play Framework 2.0
 
Android and REST
Android and RESTAndroid and REST
Android and REST
 
MongoDB.local Berlin: App development in a Serverless World
MongoDB.local Berlin: App development in a Serverless WorldMongoDB.local Berlin: App development in a Serverless World
MongoDB.local Berlin: App development in a Serverless World
 
HTTP 프로토콜의 이해와 활용
HTTP 프로토콜의 이해와 활용HTTP 프로토콜의 이해와 활용
HTTP 프로토콜의 이해와 활용
 
Robert Kubis - gRPC - boilerplate to high-performance scalable APIs - code.t...
 Robert Kubis - gRPC - boilerplate to high-performance scalable APIs - code.t... Robert Kubis - gRPC - boilerplate to high-performance scalable APIs - code.t...
Robert Kubis - gRPC - boilerplate to high-performance scalable APIs - code.t...
 
2310 b 11
2310 b 112310 b 11
2310 b 11
 
EAI design patterns/best practices
EAI design patterns/best practicesEAI design patterns/best practices
EAI design patterns/best practices
 
MongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and Typescript
MongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and TypescriptMongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and Typescript
MongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and Typescript
 
Node.js cluster
Node.js clusterNode.js cluster
Node.js cluster
 
Devoxx France: Fault tolerant microservices on the JVM with Cassandra
Devoxx France: Fault tolerant microservices on the JVM with CassandraDevoxx France: Fault tolerant microservices on the JVM with Cassandra
Devoxx France: Fault tolerant microservices on the JVM with Cassandra
 
Legacy Dependency Kata v2.0
Legacy Dependency Kata v2.0Legacy Dependency Kata v2.0
Legacy Dependency Kata v2.0
 
Legacy Code Kata v3.0
Legacy Code Kata v3.0Legacy Code Kata v3.0
Legacy Code Kata v3.0
 
I/O Extended (GDG Bogor) - Sidiq Permana
I/O Extended (GDG Bogor) - Sidiq PermanaI/O Extended (GDG Bogor) - Sidiq Permana
I/O Extended (GDG Bogor) - Sidiq Permana
 

Destaque

聖徳ゼロテック株式会社 事業紹介
聖徳ゼロテック株式会社 事業紹介聖徳ゼロテック株式会社 事業紹介
聖徳ゼロテック株式会社 事業紹介zerotec
 
Orsys - Cycle certifiant - Administrateur Reseaux
Orsys - Cycle certifiant - Administrateur ReseauxOrsys - Cycle certifiant - Administrateur Reseaux
Orsys - Cycle certifiant - Administrateur ReseauxORSYS
 
Herramientas del sistema
Herramientas del sistemaHerramientas del sistema
Herramientas del sistemasdfsdgaegd
 
A/B Testing and MultiVariate Testing
A/B Testing and MultiVariate TestingA/B Testing and MultiVariate Testing
A/B Testing and MultiVariate TestingEvgeny Tsarkov
 
Rashid_Feroze_AState_2016_Poster
Rashid_Feroze_AState_2016_PosterRashid_Feroze_AState_2016_Poster
Rashid_Feroze_AState_2016_PosterFEROZE RASHID
 
Gli uomini del paleolitico
Gli uomini del paleoliticoGli uomini del paleolitico
Gli uomini del paleoliticoCiari110
 

Destaque (9)

聖徳ゼロテック株式会社 事業紹介
聖徳ゼロテック株式会社 事業紹介聖徳ゼロテック株式会社 事業紹介
聖徳ゼロテック株式会社 事業紹介
 
Algoritmos
AlgoritmosAlgoritmos
Algoritmos
 
Orsys - Cycle certifiant - Administrateur Reseaux
Orsys - Cycle certifiant - Administrateur ReseauxOrsys - Cycle certifiant - Administrateur Reseaux
Orsys - Cycle certifiant - Administrateur Reseaux
 
Herramientas del sistema
Herramientas del sistemaHerramientas del sistema
Herramientas del sistema
 
Caldentalinsurance
CaldentalinsuranceCaldentalinsurance
Caldentalinsurance
 
Proyecto de vida
Proyecto de vidaProyecto de vida
Proyecto de vida
 
A/B Testing and MultiVariate Testing
A/B Testing and MultiVariate TestingA/B Testing and MultiVariate Testing
A/B Testing and MultiVariate Testing
 
Rashid_Feroze_AState_2016_Poster
Rashid_Feroze_AState_2016_PosterRashid_Feroze_AState_2016_Poster
Rashid_Feroze_AState_2016_Poster
 
Gli uomini del paleolitico
Gli uomini del paleoliticoGli uomini del paleolitico
Gli uomini del paleolitico
 

Semelhante a GWT training session 3

Google Web Toolkits
Google Web ToolkitsGoogle Web Toolkits
Google Web ToolkitsYiguang Hu
 
GWT Training - Session 3/3
GWT Training - Session 3/3GWT Training - Session 3/3
GWT Training - Session 3/3Faiz Bashir
 
Consuming GRIN GLOBAL Webservices
Consuming GRIN GLOBAL WebservicesConsuming GRIN GLOBAL Webservices
Consuming GRIN GLOBAL WebservicesEdwin Rojas
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
 Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4... Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...WebStackAcademy
 
using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'sAntônio Roberto Silva
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods pptkamal kotecha
 
13 asp.net session19
13 asp.net session1913 asp.net session19
13 asp.net session19Vivek chan
 
Java Web Programming [2/9] : Servlet Basic
Java Web Programming [2/9] : Servlet BasicJava Web Programming [2/9] : Servlet Basic
Java Web Programming [2/9] : Servlet BasicIMC Institute
 
Web services in java
Web services in javaWeb services in java
Web services in javamaabujji
 
Sencha Roadshow 2017: Build Progressive Web Apps with Ext JS and Cmd
Sencha Roadshow 2017: Build Progressive Web Apps with Ext JS and Cmd Sencha Roadshow 2017: Build Progressive Web Apps with Ext JS and Cmd
Sencha Roadshow 2017: Build Progressive Web Apps with Ext JS and Cmd Sencha
 
Solving anything in VCL
Solving anything in VCLSolving anything in VCL
Solving anything in VCLFastly
 
Bt0083 server side programing
Bt0083 server side programing Bt0083 server side programing
Bt0083 server side programing Techglyphs
 
Esposito Ajax Remote
Esposito Ajax RemoteEsposito Ajax Remote
Esposito Ajax Remoteask bills
 
SCWCD 2. servlet req - resp (cap3 - cap4)
SCWCD 2. servlet   req - resp (cap3 - cap4)SCWCD 2. servlet   req - resp (cap3 - cap4)
SCWCD 2. servlet req - resp (cap3 - cap4)Francesco Ierna
 
An approach to responsive, realtime with Backbone.js and WebSockets
An approach to responsive, realtime with Backbone.js and WebSocketsAn approach to responsive, realtime with Backbone.js and WebSockets
An approach to responsive, realtime with Backbone.js and WebSocketsAndrei Sebastian Cîmpean
 

Semelhante a GWT training session 3 (20)

Google Web Toolkits
Google Web ToolkitsGoogle Web Toolkits
Google Web Toolkits
 
GWT Training - Session 3/3
GWT Training - Session 3/3GWT Training - Session 3/3
GWT Training - Session 3/3
 
Consuming GRIN GLOBAL Webservices
Consuming GRIN GLOBAL WebservicesConsuming GRIN GLOBAL Webservices
Consuming GRIN GLOBAL Webservices
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
 Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4... Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
 
using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API's
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods ppt
 
13 asp.net session19
13 asp.net session1913 asp.net session19
13 asp.net session19
 
Java Web Programming [2/9] : Servlet Basic
Java Web Programming [2/9] : Servlet BasicJava Web Programming [2/9] : Servlet Basic
Java Web Programming [2/9] : Servlet Basic
 
Servlet
ServletServlet
Servlet
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Power ai image-pipeline
Power ai image-pipelinePower ai image-pipeline
Power ai image-pipeline
 
Web services in java
Web services in javaWeb services in java
Web services in java
 
Sencha Roadshow 2017: Build Progressive Web Apps with Ext JS and Cmd
Sencha Roadshow 2017: Build Progressive Web Apps with Ext JS and Cmd Sencha Roadshow 2017: Build Progressive Web Apps with Ext JS and Cmd
Sencha Roadshow 2017: Build Progressive Web Apps with Ext JS and Cmd
 
Solving anything in VCL
Solving anything in VCLSolving anything in VCL
Solving anything in VCL
 
Bt0083 server side programing
Bt0083 server side programing Bt0083 server side programing
Bt0083 server side programing
 
SignalR
SignalRSignalR
SignalR
 
Esposito Ajax Remote
Esposito Ajax RemoteEsposito Ajax Remote
Esposito Ajax Remote
 
SCWCD 2. servlet req - resp (cap3 - cap4)
SCWCD 2. servlet   req - resp (cap3 - cap4)SCWCD 2. servlet   req - resp (cap3 - cap4)
SCWCD 2. servlet req - resp (cap3 - cap4)
 
Ajax
AjaxAjax
Ajax
 
An approach to responsive, realtime with Backbone.js and WebSockets
An approach to responsive, realtime with Backbone.js and WebSocketsAn approach to responsive, realtime with Backbone.js and WebSockets
An approach to responsive, realtime with Backbone.js and WebSockets
 

Último

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 

Último (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

GWT training session 3

  • 1. GWT Training – Session III Communicating with the Server Snehal Masne www.TechProceed.com
  • 2. Contents   Asynchronous HTTP Request Submitting Data using HTML Form    Traditional GWT GWT RPC www.TechProceed.com
  • 3. Asynchronous HTTP Requests / /create a new GET request RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, "/info.php”); try{ //send the request builder.sendRequest( null, new RequestCallback() { public void onError(Request request, Throwable exception){ //log the error } public void onResponseReceived(Request request, Response response){ //process response } }); } catch (RequestException e){ //handle request exception } www.TechProceed.com
  • 4. Asynchronous HTTP Requests – cont'd   builder.sendRequest() method receives a string data to be sent with the request and RequestCallback object that handles the response from the server null is passed if there is no data to be sent to the data www.TechProceed.com
  • 5. Submitting Data to Server Using HTML Form <form name="input" action="register.php" method="post"> Username: <input type="text" name="user"><br/> Email: <input type="text" name="email"><br/> Password: <input type="password" name="password"><br/> <input type="submit" value="Submit"> </form> Data Submitted POST /register.php HTTP/1.1 Content-Type: application/x-www-form-urlencoded username=Faiz&email=faizbash%40gmail.com&password=secret www.TechProceed.com
  • 6. GWT Equivalent for Form Data Submission Constructing HTTP Request Manually //build the data to post StringBuffer postBuilder = new StringBuffer(); postBuilder.append("username=" ); postBuilder.append( URL.encodeComponent( username ) ); postBuilder.append("&email=" ); postBuilder.append( URL.encodeComponent( email ) ); postBuilder.append("&password=" ); postBuilder.append( URL.encodeComponent( password ) ); try{ //create and submit the request RequestBuilder requestBuilder = new RequestBuilder( RequestBuilder.POST, GWT.getModuleBaseURL()+"/register.php" ); requestBuilder.sendRequest( postBuilder.toString(), new RequestCallback(){ public void onError(Request request, Throwable exception){ // handle error } public void onResponseReceived(Request request, Response response){ // handle response } }); }catch( Exception e){ // handle exception } www.TechProceed.com
  • 7. GWT Equivalent for Form Data Submission – Using FormPanel //create the form panel, set its action and method final FormPanel form = new FormPanel(); form.setAction("/register.php"); form.setMethod(FormPanel.METHOD_POST); //set the main widget for the panel to a vertical panel VerticalPanel panel = new VerticalPanel(); form.setWidget(panel); //create the username field TextBox tb = new TextBox(); tb.setName("username"); panel.add(tb); //create the e-mail field TextBox tb = new TextBox(); tb.setName("email "); panel.add(tb); www.TechProceed.com
  • 8. GWT Equivalent for Form Data Submission – Using FormPanel (cont'd)‫‏‬ //create the password field PasswordTextBox ptb = new PasswordTextBox(); ptb.setName("password"); panel.add(ptb); //create the Submit button Button submit = new Button(“Submit”); submit.addClickHandler( new ClickHandler() { public void onClick(Widget sender) { form.submit(); } }); //add submit button to panel panel.add(submit); www.TechProceed.com
  • 9. GWT RPC     GWT extends a browser’s capability to asynchronously communicate with the server by providing a remote procedure call (RPC) library. Calls to the server are simplified by providing you with an interface of methods that can be called similarly to regular method calls. GWT marshal the calls (convert to a stream of data) and send to the remote server. At the server side, the data, is un-marshalled the method on the server is invoked www.TechProceed.com
  • 10. GWT RPC – cont'd   In GWT, the RPC library is divided into two packages:  com.google.gwt.user.client.rpc package used for clientside RPC support  com.google.gwt.user.server.rpc package used for serverside RPC support The client side provides interfaces that you can use to tag When the client code is compiled to Javascript using the GWT compiler, the code required to do the RPC marshaling will be generated www.TechProceed.com
  • 11. GWT RPC Implementation  To understand how GWT RPC works, we would implement the data form submission using it www.TechProceed.com
  • 12. GWT RPC Implementation – Step 1  Create the RPC interface (stub) on the client side  Create a new interface named LoginService under the my.utm.kase.gwttraining.client package  Edit the code to look like the one below: import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; @RemoteServiceRelativePath("login") public interface LoginService extends RemoteService { boolean login(String username, String email, String password); }  Add the following in /war/WEB-INF/web.xml www.TechProceed.com
  • 13. GWT RPC Implementation – Step 2  Configure the servlet  Add the following in /war/WEB-INF/web.xml <servlet> <servlet-name>loginServlet</servlet-name> <servlet-class> my.utm.kase.gettraining.server.LoginServiceImpl </servlet-class> </servlet> <servlet-mapping> <servlet-name>loginServlet</servlet-name> <url-pattern>/gwttraining/login</url-pattern> </servlet-mapping> www.TechProceed.com
  • 14. GWT RPC Implementation – Step 3  Create an async counterpart interface of the LoginService. This interface defines the callback method that will be called when the server generates a response  Create another interface, LoginServiceAsync under my.utm.kase.gwttraining.client package  Edit the code to look like the one below: import com.google.gwt.user.client.rpc.AsyncCallback; public interface LoginServiceAsync { boolean login(String username, String email, String password, AsyncCallback<Boolean> callback); }  The async method always returns void and takes parameters similar to its stub counterpart plus an AsyncCallback parameter which specifies the return value of the stub method which is Void in this case www.TechProceed.com
  • 15. GWT RPC Implementation – Step 4  Implement the remote method on the server side  Create a class, LoginServiceImpl under my.utm.kase.gwttraining.server package  Edit the code to look like the one below: import my.utm.kase.gwttraining.client.LoginService; import com.google.gwt.user.server.rpc.RemoteServiceServlet; public class LoginServiceImpl extends RemoteServiceServlet implements LoginService { public boolean login(String username, String email, String password) { if( username.equals("faizbash") && password.equals("secret") ) { return true; } else return false; } } www.TechProceed.com
  • 16. GWT RPC Implementation – Step 5  Call the remote method  Create a login widget in my.utm.kase.gwttraining.client package to get username, email and password from user. It also captures login event and makes a RPC to loign user. public class LoginWidget extends Composite { public LoginWidget() { //login panel FlexTable loginTable = new FlexTable(); final TextBox usernameBox = new TextBox(); final TextBox emailBox = new TextBox(); final PasswordTextBox passwordBox = new PasswordTextBox(); Button loginButton = new Button("Login"); loginButton.addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { login(usernameBox.getText(), emailBox.getText(), passwordBox.getText(); } }); //username widget loginTable.setWidget(0, 0, new Label("Username")); loginTable.setWidget(0, 1, usernameBox); //email widget loginTable.setWidget(1, 0, new Label("Email")); loginTable.setWidget(1, 1, emailBox); www.TechProceed.com
  • 17. GWT RPC Implementation – Step 5 (cont'd)‫‏‬ //password widget loginTable.setWidget(2, 0, new Label("Password")); loginTable.setWidget(2, 1, passwordBox); //login button widget loginTable.setWidget(3, 0, loginButton); loginTable.getFlexCellFormatter().setColSpan(3, 0, 2); //init loginTable initWidget(loginTable); } public void login(String username, String email, String password) { //create a callback method AsyncCallback<Boolean> callback = new AsyncCallback<Boolean>() { public void onFailure(Throwable caught) { //handle failure Window.alert("Failed to login"); } public void onSuccess(Boolean status) { if( status ) Window.alert("Login successful"); else Window.alert("Invalid username or passord"); } }; www.TechProceed.com
  • 18. GWT RPC Implementation – Step 5 (cont'd)‫‏‬ //Create a remote service proxy to talk to the server-side Greeting service. final LoginServiceAsync loginService = GWT.create(LoginService.class); //invoke the remote method loginService.login(username, email, password, callback); } }  Instantiate the widget in the GWTTrainingWidgets entry point class: //login widget LoginWidget loginWidget = new LoginWidget(); tabPanel.add(loginWidget, "Login");  Run or refresh to test www.TechProceed.com