[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.

Please note that, to change the response tag name or anything on the top level you will have to use JAX-WS annotations like @WebResult annoatation on top of an exposed method. For example, to change the grouping element name from <return> to employee, add the annotation @WebResult(name = “”) on top of public List<Employee> getAllEmployees() as:

@WebResult(name="Employee")
public List<Employee> getAllEmployees() {

 

We will compare the results through some screen shots. I have removed the annotation and taken the screenshots without annotation to compare the difference. I have also added the screenshot with @WebResult annotation applied.

 

Comparing XSDs referenced from WSDL

XSD without JAXB annotation

 

XSD with JAXB XmlType annotation

Annotation was applied on top of the Employee class:

import javax.xml.bind.annotation.XmlType;

@XmlType(propOrder={"empNumber", "empName", "age"})
public class Employee {

 

XSD with JAXB XmlType and JAX-WS WebResult annotations

@WebResult annotation was applied on top of the exposed WebMethod in EmployeeManager web service class:

@WebResult(name="Employee")
  public List<Employee> getAllEmployees() {
    return this.empList;
  }

 

Comparing SOAP Request and Response

These screens were generated using the glassfish tester.

SOAP Response without JAXB annotation

 

SOAP Response with JAXB XmlType annotation

 

SOAP Response with JAXB XmlType and JAX-WS WebResult annotations

 

Summary

I have not added much explanations here. Feel free to ask if you have any doubts.

Search the Web

Custom Search

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