Follow Us on Twitter

Using ID and IDREF in your WSDLs response messages with JAXB

by rcats on August 8, 2014 · 0 comments

For one of my projects, I have implemented the ID/IDREF XML pattern inside one of my Web Services. When I created with JDeveloper a Web Service from it everything looked fine, no errors or what soever. I could receive this pattern inside my request messages without any problems. After I filled in the same String inside the IDREF as I did in ID the only response I get is a HTTP 200 without any body. For getting more information about the problem I used a custom SchemaValidationHandler inside my Web Service implementation.

@SchemaValidation( handler = SchemaValidationErrorHandler.class )

The source code for the custom SchemaValidationErrorHandler is:

package nl.whitehorses.idref.handler;
import org.xml.sax.SAXParseException;
public class SchemaValidationErrorHandler extends ValidationErrorHandler {
  public static final String WARNING = "SchemaValidationWarning";
  public static final String ERROR = "SchemaValidationError";
  public static final String FATAL_ERROR = "SchemaValidationFatalError";
  public void warning(SAXParseException exception) {
    packet.invocationProperties.put(WARNING, exception);
  public void error(SAXParseException exception) {
    packet.invocationProperties.put(ERROR, exception);
  public void fatalError(SAXParseException exception) {
    packet.invocationProperties.put(FATAL_ERROR, exception);

After using the schema validation I got response from the Web Service it was a SAXparser Exception. After some puzzling I figured out that it was the relationship between the ID and the IDREF. The IDREF couldn’t find the the ID during marshalling of the response message. I was looking around the internet for two days but I didn’t find any direct answer to my problem. What I found strange is that the ID is always a String and the IDREF is a Object. And in the examples the IDREF was a specified Object like a Car a Book or a Employee. After seeing this multiple times I put in the parent object of the ID inside the IDREF.

Here is a example of the code where I implemented the ID/IDREF pattern.

    public GetAllEmployeesResponseMessageType operation(GetAllEmployeesRequestMessageType input) throws FaultMessage {
        GetAllEmployeesResponseMessageType employeeResponse = new GetAllEmployeesResponseMessageType();
        for(CompanyType company : employeeResponse.getCompanies().getCompany())
        return employeeResponse;
    private GetAllEmployeesResponseMessageType.Companies setCompanies() {
        GetAllEmployeesResponseMessageType.Companies companies = new GetAllEmployeesResponseMessageType.Companies();
        return companies;
    private GetAllEmployeesResponseMessageType.Employees setEmployees(CompanyType company) throws FaultMessage {
        GetAllEmployeesResponseMessageType.Employees employees = new GetAllEmployeesResponseMessageType.Employees();
        return employees;
    private CompanyType setCompany() {
        CompanyType company = new CompanyType();
        return company;
    private EmployeeType setEmployee(CompanyType company) throws FaultMessage {
        EmployeeType employee = new EmployeeType();
        employee.setCommissionPct(new BigDecimal("0.25"));
        employee.setFirstName("first name");
        employee.setLastName("last name");
        employee.setSalary(new BigDecimal("1234.25"));
        return employee;

After that I got response from the Web Service with the value of the ID inside the IDREF attribute.

<ns0:GetAllEmployeesResponseMessage xmlns:ns2="" xmlns:ns1="nl.whitehorses.entity.employee" xmlns:ns0="nl.whitehorses.message.employee">
            <Company id="hello123">
                  <description>company department</description>
            <Employee CompanyId="hello123">
               <FirstName>first name</FirstName>
               <LastName>last name</LastName>
                  <description>dit is een job</description>
                  <description>employee department</description>
VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)

{ 0 comments… add one now }

Leave a Comment


Previous post:

Next post:

About Whitehorses
Company profile

Whitehorses website

Home page

Follow us
Blog post RSS
Comment RSS