Spring SOAP WebService Producers using Gradle

This tutorial will show you how we can create and publish SOAP based webservice in Contract-first approach using Spring and Gradle. There are mainly two approaches to create the Webservice – Contract-first & Contract-last. The Contract-first approach tells us to create first XSD/WSDL and then create end-point interface and implementation class. The Contract-last approach tells us to create first end-point interface and implementation class then create WSDL file. This example will show you mainly Spring SOAP Webservice Producers using Gradle, i.e., it will only publish or deploy the web service into the server.

Prerequisites

Java at least version 8 needs to be installed and configured
Gradle plugin needs to be installed into Eclipse
Gradle 4.x needs to installed and configured
Dependencies : Spring boot, wsdl

Continue reading “Spring SOAP WebService Producers using Gradle”

Generating jaxb classes from xsd using Gradle

This tutorial will show you how to generate Jaxb classes from Xsd file using Gradle. Generating jaxb classes from xsd using Gradle is not an easy task because Gradle does not have yet any ready-made plugin like Maven. So to generate java classes from xsd schema using Gradle we have to write an an Ant Task. The below example will show you how to do it.

Prerequisites

Eclipse

JDK 8 or 9

Have Gradle installed and configured

Required dependencies in Gradle’s build file

Now follow the below steps in order to complete the example.

Create Gradle project GradleXsdToJaxb in Eclipse Continue reading “Generating jaxb classes from xsd using Gradle”

JAXB – Java API for XML Binding

XML Binding

  • XML binding maps XML to objects
  • It generates Classes to represent XML elements. Classes follow JavaBean property access conventions.
  • Supports three principal operations. Marshalling – it marshalls a tree of objects into XML document. Unmarshalling – it unmarshalls an XMl document into a tree of objects. It also validates XML against the schema used to generate classes of objects. Validation of object trees against the schema used to generate classes.

XML Binding Relationships

Why use XML Bindings

  • We do not need to write much code while we have to if we use SAX or DOM
  • We do not need to learn SAX or DOM parser
  • It is less error prone because we do not have to manually implement them and all features of schema are utilized
  • It allows us to customize the XML structure

JAXB Use Cases

  • It is used to create, read or modify XML using Java but without using SAX or DOM parser
  • Using rules defined in XML schema it can validate user input

Continue reading “JAXB – Java API for XML Binding”

RESTful webservice using Jersey

Here I am going to give an example on how REST webservice works.

Introduction

The most important concept in REST is resources, which are identified by global IDs — typically using URIs. Client applications use HTTP methods (GET/ POST/ PUT/ DELETE) to manipulate the resource or collection of resources. A RESTful Web service is implemented using HTTP and the principles of REST. Typically, a RESTful Web service should define the following aspects:

The base/root URI for the Web service such as http://<host>/<appcontext/contextpath>/<url pattern>/<resources>.
The MIME type of the response data supported, which are JSON/XML/TEXT/HTML etc.
The set of operations supported by the service. (for example, POST, GET, PUT or DELETE).

Methods

HTTP methods are mapped to CRUD (create, read, update and delete) actions for a resource. Although you can make slight modifications such as making the PUT method to be create or update, the basic patterns are listed as follows.

HTTP GET: Get/List/Retrieve an individual resource or a collection of resources.
HTTP POST: Create a new resource or resources.
HTTP PUT: Update an existing resource or collection of resources.
HTTP DELETE: Delete a resource or collection of resources. Continue reading “RESTful webservice using Jersey”