Sie sind auf Seite 1von 17

Web Services

Web service is a technology to communicate one programming language with


another. For example, java programming language can interact with PHP and .Net
by using web services. In other words, web service provides a way to achieve
interoperability.
http://openweathermap.org/api
https://dev.twitter.com/rest/public

Types of Web Services

SOAP(Simple Object Access Protocol.) web services.


RESTful(Representational State Transfer) web services.

SOAP
SOAP is an acronym for Simple Object Access Protocol.

SOAP is a XML-based protocol for accessing web services.

SOAP uses different transport protocols, such as HTTP and SMTP.

SOAP is XML based, so it is platform independent and language independent. In


other words, it can be used with Java, .Net or PHP language on any platform.

RESTful
REST stands for REpresentational State Transfer.

RESTful web service permits different data format such as Plain Text, HTML,
XML and JSON.

REST uses only HTTP protocols.

REST is an architectural style not a protocol.

RESTful Web Services are fast because there is no strict specification like
SOAP. It consumes less bandwidth and resource.

HTTP Request

Verb- Indicate HTTP methods such as GET, POST, DELETE, PUT etc.

URI- Uniform Resource Identifier (URI) to identify the resource on server

HTTP Version- Indicate HTTP version, for example HTTP v1.1 .

Request Header- Contains metadata for the HTTP Request message as keyvalue pairs. For example, client ( or browser) type, format supported by client,
format of message body, cache settings etc.

Request Body- Message content or Resource representation.

HTTP Response

Status/Response Code- Indicate Server status for the requested resource. For
example 404 means resource not found and 200 means response is ok.

HTTP Version- Indicate HTTP version, for example HTTP v1.1 .

Response Header- Contains metadata for the HTTP Response message as keyvalue pairs. For example, content length, content type, response date, server type
etc.

Response Body- Response message content or Resource representation.

Real Preview of HTTP Req/Res

HTTP Methods
GET - Provides a read only access to a resource.

PUT - Used to create a new resource.

DELETE - Used to remove a resource.

POST - Used to update a existing resource or create a new resource.

Real World Mapping


Method
URL
Action
Type
GET
/api/wines
Retrieve all wines
GET
/api/wines/10 Retrieve wine with id == 10
POST
/api/wines
Add a new wine
PUT
/api/wines/10 Update wine with id == 10
DELETE
/api/wines/10
Delete wine with id == 10

Operation
Read Only
Read Only
Read/Write
Idempotent
Idempotent

Java Web Services API

JAX-WS: for SOAP web services. The are two ways to write JAX-WS application
code: by RPC style and Document style.

import javax.jws
JAX-RS: for RESTful web services. There are mainly 2 implementation currently in
use for creating JAX-RS application: Jersey and RESTeasy.

import javax.ws.rs

JAX-RS Annotations

@GET, @POST, @PUT, @DELETE: HTTP method the class method


responds to.

@Path: path the method responds to.

@Consumes: type of data the method can take as input. The data
will automatically be deserialized into a method input parameter. For
example, you can pass a wine object to the addWined() method either
as JSON or XML. The JSON or XML representation of a new wine is
automatically deserialized into the Wine object passed as an
argument to the method.

@Produces: One or more response content type(s) the method can


generate. The methods return value will be automatically serialized
using the content type requested by the client. If the client didnt
request a specific content type, the first content type listed in the
@Produces annotation will be used. For example, if you access

Webservice API Server Structure

Web.xml

Entity Class

DAO(Data Access Object) Class

What is a Resource?
REST architecture treats every
content as a resource. These
resources can be text files,
html pages, images, videos or
dynamic business data. REST
Server simply provides access
to resources and REST client
accesses and modifies the
resources. Here each resource
is identified by URIs/ global
IDs. REST uses various
representations to represent a
resource where text, JSON,
XML. XML and JSON are the
most popular representations
of resources

Webservice Client
Postman Rest webservice testing tool.

Using Jersey API Actual java code.

Webservice Client

Using Jersey Client API Actual java code.

Webservice Jargon Words

SOAP(Simple Object Access Protocol): SOAP is a XML-based protocol for accessing web services

Rest:Representational State Transfer

WSDL(Web Services Description Language): WSDL is a xml document containing information about
web services such as method name, method parameter and how to access it, read more
http://www.tutorialspoint.com/wsdl/wsdl_example.htm.

WADL(Web Application Description Language): WADL is a XML description of a deployed RESTful web
application, read more https://jersey.java.net/documentation/latest/wadl.html

UDDI(Universal Description, Discovery and Integration):A directory of web service interfaces described
by WSDL, containing information about web services.

JSON: JavaScript Object Notation.

XML: Extensible Markup Language.

Marshalling

Das könnte Ihnen auch gefallen