WS Implementation



Web Services developed by two ways
  • Contract First (Top - Down, XML Schema & WSDL first)
  • Contract Last (Bottom - Up, Java Service first)
Contract-first Web services developing web services that start with the XML Schema/WSDL contract first followed by the Java code second. Spring-WS focuses on this development style

The most important thing when doing contract-first Web service development is to try and think in terms of XML. This means that Java-language concepts are of lesser importance. It is the XML that is sent across the wire, and you should focus on that. The fact that Java is used to implement the Web service is an implementation detail. An important detail, but a detail nonetheless.

Contract-last Web services  you start with the Java code, and let the Web service contract (WSDL & XSD Schema) be generated from that.

Contract-first development style is prefered on compared to Contract last - Find reasons below.



WSDL stands for Web Services Description Language. A WSDL file is an XML document that describes a Web service. It specifies the location of the service and the operations (or methods) the service exposes.
WSDL are defined using six major elements:
  • types, which provides data type definitions used to describe the messages exchanged.
  • message, which represents an abstract definition of the data being transmitted. A message consists of logical parts, each of which is associated with a definition within some type system.
  • portType, which is a set of abstract operations. Each operation refers to an input message and output messages.
  • binding, which specifies concrete protocol and data format specifications for the operations and messages defined by a particular portType.
  • port, which specifies an address for a binding, thus defining a single communication endpoint.
  • service, which is used to aggregate a set of related ports.
 More Information & examles on WSDL - http://www.w3.org/TR/wsdl
----------------------------------------
JAXB (Convert the XML <=> Java Objects)



The Java Architecture for XML Binding (JAXB) provides a fast and convenient way to bind XML schemas to Java representations, making it easy for Java developers to incorporate XML data and processing functions in Java applications. As part of this process, JAXB provides methods for unmarshalling XML instance documents into Java content trees, and then marshalling Java content trees back into XML instance documents.


 Steps in the JAXB Binding Process

The general steps in the JAXB data binding process are:
  1. Generate classes. An XML schema is used as input to the JAXB binding compiler to generate JAXB classes based on that schema.
  2. Compile classes. All of the generated classes, source files, and application code must be compiled.
  3. Unmarshal. XML documents written according to the constraints in the source schema are unmarshalled by the JAXB binding framework. Note that JAXB also supports unmarshalling XML data from sources other than files/documents, such as DOM nodes, string buffers, SAX Sources, and so forth.
  4. Generate content tree. The unmarshalling process generates a content tree of data objects instantiated from the generated JAXB classes; this content tree represents the structure and content of the source XML documents.
  5. Validate (optional). The unmarshalling process optionally involves validation of the source XML documents before generating the content tree. Note that if you modify the content tree in Step 6, below, you can also use the JAXB Validate operation to validate the changes before marshalling the content back to an XML document.
  6. Process content. The client application can modify the XML data represented by the Java content tree by means of interfaces generated by the binding compiler.
  7. Marshal. The processed content tree is marshalled out to one or more XML output documents. The content may be validated before marshalling.
To summarize, using JAXB involves two discrete sets of activities:
  • Generate and compile JAXB classes from a source schema, and build an application that implements these classes
  • Run the application to unmarshal, process, validate, and marshal XML content through the JAXB binding framework
These two steps are usually performed at separate times in two distinct phases. Typically, for example, there is an application development phase in which JAXB classes are generated and compiled, and a binding implementation is built, followed by a deployment phase in which the generated JAXB classes are used to process XML content in an ongoing "live" production setting.

Note: Unmarshalling is not the only means by which a content tree may be created. Schema-derived content classes also support the programmatic construction of content trees by direct invocation of the appropriate factory methods. Once created, a content tree may be revalidated, either in whole or in part, at any time. See Create Marshal Example for an example of using the ObjectFactory class to directly add content to a content tree.
-------------------------------------------
Restfull Web Services (Jersy - JAX-RS)
Ref- http://www.vogella.de/articles/REST/article.html

What this all means is that you can leverage the flexibility of platform-neutral XML data in Java applications without having to deal with or even know XML programming techniques. Moreover, you can take advantage of XML strengths without having to rely on heavyweight, complex XML processing models like SAX or DOM. JAXB hides the details and gets rid of the extraneous relationships in SAX and DOM--generated JAXB classes describe only the relationships actually defined in the source schemas. The result is highly portable XML data joined with highly portable Java code that can be used to create flexible, lightweight applications and Web services.