Tuesday, January 7, 2014

Java Web Service: Up and running

Java Web Service: Up and running
1. Source code:
http://www.oreilly.com/catalog/9780596521127
2. Chap 1
a SOAP-based service delivered over HTTP is a special case of a REST-style service.
web services play a central role in the SOA approach to software design and development.
REST stands for REpresentational State Transfer.
Language transparency is the key to web service interoperability;
JAX-WS (Java API for XML-Web Service) supports SOAP based and REST style service. JAX-WS is commonly shorten to JWS for Java Web Services.
JAX-WS preserves but also significantly extends the capabilities of JAX-RPC.
A SOAP-based web service could be implemented as a single Java class but, following
best practices, there should be an interface that declares the methods, which are the
web service operations, and an implementation, which defines the methods declared
in the interface. The interface is called SEI: Service Endpoint Interface. The implementation is called the SIB: Service Implementation Bean. The SIB
can be either a POJO or a Stateless EJB.

WSDL is pronounced "whiz dull".
The core Java utility is now called wsimport but the earlier names wsdl2java and java2wsdl were more descriptive

On the web service side, the underlying Java libraries process the HTTP request (the SOAP envelope is the body of an HTTP message), extract
the SOAP envelope, determine the identity of the requested service operation, invoke
the corresponding Java method getTimeAsString, and then generate the appropriate
SOAP message to carry the method’s return value back to the client.

In SOAP-based web services, the XML Schema type system
is the default type system that mediates between the client’s types and the service’s
types.

@SOAPBinding(style = Style.RPC)
This annotation requires that the service use only very simple types such as string and
integer. By contrast, the Teams service uses richer data types, which means that
Style.DOCUMENT, the default, should replace Style.RPC.

If the @WebResult annotation were applied, say, only to the getTimeAsString
operation, then the SOAP response for this operation would use the time_response tag
but the response for the getTimeAsElapsed operation still would use the default
return tag.
there is usually no need for programmer-generated code to use the @WebResult
annotation.

The wsimport tool reads a WSDL and generates all the required artifacts for web service development, deployment, and invocation.
The wsgen tool reads an existing web service implementation class (SIB) and generates the required JAX–WS portable artifacts for
web service development and deployment. The wsgen tool can be used for bottoms-up approach, where you are starting from a service
endpoint implementation (SIB) rather than a wsdl.

JWS still supports both rpc and document styles, with document as the default
If and when an ItemSearchResponse comes from the E-Commerce service, the method
handleResponse in the MyHandler class executes as a separate thread and prints out the
books’ titles.


REST and SOAP are quite different. SOAP is a messaging protocol, whereas REST is a
style of software architecture for distributed hypermedia systems; that is, systems in
which text, graphics, audio, and other media are stored across a network and interconnected
through hyperlinks. The World Wide Web is the obvious example of such
a system.

In a RESTful request/response service, the service response is raw XML but the incoming
request might not be XML at all. A GET request does not have a body; hence,
arguments sent as part of the request occur as attributes in the query string, a collection
of key/value pairs. Here is a sample:
http://www.onlineparlor.com/bets?horse=bigbrown&jockey=kent&amount=25

// There are two ServiceModes: PAYLOAD, the default, signals that the service
// wants access only to the underlying message payload (e.g., the
// body of an HTTP POST request); MESSAGE signals that the service wants
// access to entire message (e.g., the HTTP headers and body).
@ServiceMode(value = javax.xml.ws.Service.Mode.MESSAGE)

In the symmetric approach, the same key—called the secret
key or the single key—is used to encrypt and decrypt (see Figure 5-4). The symmetric
approach has the advantage of being relatively fast, but the disadvantage of what is
known as the key distribution problem. How is the secret key itself to be distributed
to the sender and the receiver?

In the asymmetric approach, the starting point is a key pair, which consists of a private
key and a public key. As the names suggest, the private key should not be distributed
but safeguarded by whoever generated the key pair. The public key can be distributed
freely and publicly. If message bits are encrypted with the public key, they can be decrypted
only with the private key, and vice-versa. Figure 5-5 illustrates. The asymmetric
approach solves the key distribution problem, but asymmetric encryption and decryption
are roughly a thousand times slower than their symmetric counterparts

Done

No comments:

Post a Comment