December 16, 2011

EclipseLink MOXy is the JAXB Provider in WebLogic Server 12c

I am very happy to announce that EclipseLink JAXB (MOXy) is now the default JAXB (JSR-222) provider in WebLogic Server 12c.  I would like to thank the EclipseLink committers and the WebLogic team for all their hard work to make this happen.

In this post I will introduce how MOXy can be leveraged to create a JAX-WS service.  In future posts I will cover more of the extensions in greater detail.

WebLogic Server 12c can be downloaded from OTN at the following link:

Web Service (JAX-WS)

For this post we will implement a simple service that finds a customer by ID.  As this is just a "Hello World" type example the service will always return a customer with the name "Jane Doe".

package blog.jaxws.service;

import javax.jws.*;
import blog.jaxws.model.Customer;

public class FindCustomer {

 public Customer findCustomer(int id) {
  Customer customer = new Customer();
  return customer;



Since MOXy is the default JAXB provider we can leverage all of its mapping extensions.  In this example we will use @XmlPath to do XPath based mapping.

package blog.jaxws.model;

import javax.xml.bind.annotation.*;
import org.eclipse.persistence.oxm.annotations.XmlPath;

@XmlType(propOrder={"firstName", "lastName"})
public class Customer {

 private int id;

 private String firstName;
 private String lastName;

 public int getId() {
  return id;

 public void setId(int id) { = id;

 public String getFirstName() {
  return firstName;

 public void setFirstName(String firstName) {
  this.firstName = firstName;

 public String getLastName() {
  return lastName;

 public void setLastName(String lastName) {
  this.lastName = lastName;



Below is the WSDL that was generated for this service:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Published by JAX-WS RI at RI's version is 
 JAX-WS RI 2.2.6hudson-86 svn-revision#12773. -->
<!-- Generated by JAX-WS RI at RI's version is 
 JAX-WS RI 2.2.6hudson-86 svn-revision#12773. -->
 xmlns:wsp="" xmlns:wsp1_2=""
 xmlns:wsam="" xmlns:soap=""
 xmlns:tns="" xmlns:xsd=""
 xmlns="" targetNamespace=""
   <xsd:import namespace=""
    schemaLocation="" />
 <message name="findCustomer">
  <part name="parameters" element="tns:findCustomer" />
 <message name="findCustomerResponse">
  <part name="parameters" element="tns:findCustomerResponse" />
 <portType name="FindCustomer">
  <operation name="findCustomer">
   <input wsam:Action=""
    message="tns:findCustomer" />
   <output wsam:Action=""
    message="tns:findCustomerResponse" />
 <binding name="FindCustomerPortBinding" type="tns:FindCustomer">
  <soap:binding transport=""
   style="document" />
  <operation name="findCustomer">
   <soap:operation soapAction="" />
    <soap:body use="literal" />
    <soap:body use="literal" />
 <service name="FindCustomerService">
  <port name="FindCustomerPort" binding="tns:FindCustomerPortBinding">
    location="http:/" />

XML Schema

Below is the XML schema referenced by the WSDL that was generated for the model.  Notice how it includes the "personal-info" element that was specified in the @XmlPath annotation.

<?xml version="1.0" encoding="UTF-8"?>
<!-- Published by JAX-WS RI at RI's version is 
 JAX-WS RI 2.2.6hudson-86 svn-revision#12773. -->
<xsd:schema xmlns:ns0="" xmlns:xsd=""
 <xsd:complexType name="findCustomerResponse">
   <xsd:element name="return" type="ns0:customer" minOccurs="0" />
 <xsd:complexType name="findCustomer">
   <xsd:element name="arg0" type="xsd:int" />
 <xsd:complexType name="customer">
   <xsd:element name="personal-info" minOccurs="0">
      <xsd:element name="first-name" type="xsd:string"
       minOccurs="0" />
      <xsd:element name="last-name" type="xsd:string"
       minOccurs="0" />
  <xsd:attribute name="id" type="xsd:int" use="required" />
 <xsd:element name="findCustomerResponse" type="ns0:findCustomerResponse" />
 <xsd:element name="findCustomer" type="ns0:findCustomer" />

Service Request

Below is what a request to our service looks like:

<env:Envelope xmlns:env="">
  <env:Header />
    <findCustomer xmlns="">
      <arg0 xmlns="">123</arg0>

Service Response

The response leverages the @XmlPath annotation we used on the Customer class to map the firstName and lastName properties to XML.

<S:Envelope xmlns:S="">
    <ns0:findCustomerResponse xmlns:ns0="">
      <return id="123">

Further Reading

If you enjoyed this post, then you may be interested in:

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.