Blog

[Lab-Analysis] Setting Up For Rest Web Services Development Using Maven Jersey Archetype

In the lab @ http://javajee.com/setting-up-the-environment-for-developing-rest-web-services-with-jersey-using-maven, you setup the environment and executed a REST service.

Below are the important files generated, as you can see from the eclipse Project Explorer:

[Lab] Setting Up For Rest Web Services Development Using Maven Jersey Archetype

Jersey is a popular JAX-RS implementation.

Jersey is the open source, production quality, JAX-RS (JSR 311) Reference Implementation for building RESTful Web services.

In addition to being the Reference Implementation, Jersey also provides an API so that developers may extend Jersey to suit their needs.

You can download JAX-RS from Jersy Homepage at jersey.java.net. You can also set it up using a build tool such a maven.

 

REST Based Web Services Development with JAX-RS

Java API for XML – Restful web services (JAX–RS) is the standard specification for developing REST web services.

JAX-RS uses annotations to simplify the development and deployment of web service clients and endpoints. Important JAX-RS annotations can be used @ http://javajee.com/important-jax-rs-annotations.

 

Getting Familiar with the BlockingQueue Interface

A Queue is a first in first out (FIFO) data structure, as we have already seen.

BlockingQueue is a queue that additionally supports operations that wait for the queue to become non-empty when retrieving an element, and wait for space to become available in the queue when storing an element.

BlockingQueue methods come in four forms:

  1. those that throws an exception,

[Problem] Three Thread Synchronization Using State Pattern

Problem

Create three threads

  • one that print '1' for 5 times.

  • one that print '2' for 5 times.

  • one that print '3' for 5 times.

Need to implement coordination between them so that  1, 2 and 3 should be printed in order from the three threads:

1

2

3

1

2

3

...

Hint: The order should be same theoretically and practically. Putting a sleep while printing might work in some cases, but it cannot be guaranteed always.

[Lab-Analysis] Using JAXB Annotations with SOAP Web Services

In the previous lab we created the web service with an annotation @XmlType with attribute propOrder  on top of Employee class to define order of field elements.

[Lab] Using JAXB Annotations with SOAP Web Services

We can use JAXB annoatations to specify the XML element names within the SOAP request and response.

JAXB will be making use of your default constructor and setters/getters. Remember to give a default constructor for your class in case you are having parameterized constrcutors.

 

Commonly Used JAXB 2 Annotations

In JAXB2, annotations are used both in generated Java content classes and in Java classes as input to generate schema definitions.

These binding annotations are defined in the javax.xml.bind.annotation package.

Below are some of the more commonly used annotations defined in the javax.xml.bind.annotation package.

  1. XmlAccessorType

    • Specifies the default serialization of fields and properties

    • Annotation Elements

SOAP Faults

We have already seen what SOAP faults are and how they are reprecented in the WSDL and SOAP message in the WSDL and SOAP overview notes respectively. Here we will try to consolidate the basic information related to SOAP faults.

Java application exceptions can be mapped to SOAP faults in WSDL/SOAP message.

 

Fault element in SOAP message

  • A SOAP message can have fault elements within it.

  • Fault elements contain errors and status information.

  • Fault is an optional element.

[Lab] SOAP Fault Demo

Java application exceptions can be mapped to SOAP faults in WSDL/SOAP message.

 

Problem statement

We will create a simple web service class with a single method that will accept an integer and check if it is even. If even we will return “Received even N” where N is the received even number.

If received number is not even, then we will throw a custom exception NotEvenNumberException that extends Exception.

Pages

Search the Web

Custom Search

Searches whole web. Use the search in the right sidebar to search only within javajee.com!!!