Building and consuming RESTful JSON services with Apache CXF ...

unalaskaweepingInternet and Web Development

Jul 19, 2012 (5 years and 5 months ago)

379 views

1
Building and consuming RESTful
JSON services with Apache CXF
and Google Web Toolkit
Adrian Trenaman,
Distinguished Consultant,
IONA Technologies
services@iona.com
2
©2008 IONA Technologies
Introduction
3
©2008 IONA Technologies
Google Web Toolkit (GWT) –a brief overview
4
©2008 IONA Technologies
GWT –overview
5
©2008 IONA Technologies
GWT –overview (cont’)
6
©2008 IONA Technologies
<<browser>>
:
<<servlet-engine>>
:Tomcat
GWT and RPC
7
©2008 IONA Technologies
GWT and AJAX
8
©2008 IONA Technologies
RESTful JSON Services with
Fuse Service Framework / Apache CXF
9
©2008 IONA Technologies
RESTful services with FUSE
10
©2008 IONA Technologies
RESTful services with FUSE (cont’)
11
©2008 IONA Technologies
A RESTful “Hello, World”
12
©2008 IONA Technologies
Hello World
13
©2008 IONA Technologies
Parameters bean…
14
©2008 IONA Technologies
Business Logic
@WebService
public class HelloWorld{
@Get
@HttpResource(
location="/sayHello/user={user}&msg={msg}“
)
public String sayHello(SayHelloparams) {
System.out.println(params.getUser()+ " said '" +
params.getMsg()+ "'");
return "Thanks for your message!";
}
}
Annotate the class
as a web service.
Annotate the class
as a web service.
This method will
respond to a HTTP
GET…
This method will
respond to a HTTP
GET…
…at this
location!
…at this
location!
Everything
else is just
plain old Java.
Everything
else is just
plain old Java.
15
©2008 IONA Technologies
Deploying your service
16
©2008 IONA Technologies
Testing your service
17
©2008 IONA Technologies
“Hello, world”: lessons learnt
18
©2008 IONA Technologies
A RESTful resource-basedservice.
19
©2008 IONA Technologies
Resource-based service
20
©2008 IONA Technologies
Update
Delete
Create
Retrieve
RESTful HTTP verbs
21
©2008 IONA Technologies
RESTful HTTP verbs
22
©2008 IONA Technologies
Contact service: interface
23
©2008 IONA Technologies
Contacts service: interface (cont’)
@Get
@HttpResource(location="/contacts")
public Contacts getContacts();
@Get
@HttpResource(location="/contacts/id={id}")
public Contact getContact(GetContactgc) throws NotFound;
@Get @HttpResource( location=
"/contacts/firstName={firstName}&lastName={lastName}“
)
public ContactsfindContacts(FindContactsByNameparams);
24
©2008 IONA Technologies
Contacts service: interface (cont’)
@Post
@HttpResource(location="/contacts/{id}")
public void updateContact(Contactparams);
25
©2008 IONA Technologies
Convention-based RESTful-services
26
©2008 IONA Technologies
RESTful services by convention
27
©2008 IONA Technologies
Conventions
28
©2008 IONA Technologies
Conventions (cont’)
29
©2008 IONA Technologies
Support for JSON
30
©2008 IONA Technologies
JSON -JavaScript Object Notation
31
©2008 IONA Technologies
Badgerfishvs. mapped notation
32
©2008 IONA Technologies
Badgerfishvs. mapped notation (cont’)
33
©2008 IONA Technologies
Badgerfishvs. mapped notation (cont’)
34
©2008 IONA Technologies
Configuring an endpoint for JSON
35
©2008 IONA Technologies
Configuring an endpoint for JSON (cont’)
36
©2008 IONA Technologies
Aside: HTTP content-type
37
©2008 IONA Technologies
GWT client code
38
©2008 IONA Technologies
GWT and AJAX –boilerplate Java code
RequestBuilderbuilder=
new RequestBuilder(RequestBuilder.GET, "http://...");
try {
Requestreq= builder.sendRequest(null, new RequestCallback() {
public void onError(Requestrequest, Throwableexception) {
}
public void onResponseReceived(Requestrequest,
Response response) {
}
});
}
catch (RequestExceptione) {
}
39
©2008 IONA Technologies
GWT and AJAX –boilerplate Java code -notes
40
©2008 IONA Technologies
GWT support for JSON
41
©2008 IONA Technologies
GWT support for JSON (cont’)
42
©2008 IONA Technologies
Summary
43
©2008 IONA Technologies
Summary
44
©2008 IONA Technologies
Resources