icon-arrow icon-check icon-mail icon-phone icon-facebook icon-linkedin icon-youtube icon-twitter icon-cheveron icon-download icon-instagram play close close icon-arrow-uturn icon-calendar icon-clock icon-search icon-chevron-process icon-skills icon-knowledge icon-kite icon-education icon-languages icon-tools icon-experience icon-coffee-cup
Werken bij Integration & Application Talents
Blog 08/08/2014

Using ID and IDREF in your WSDLs response messages with JAXB

Response messages

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 com.sun.xml.ws.developer.ValidationErrorHandler;

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="nl.whitehorses.entity.company" 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>


Overzicht blogs

Geen reacties

Geef jouw mening

Reactie plaatsen

Reactie toevoegen

Jouw e-mailadres wordt niet openbaar gemaakt.


  • Geen HTML toegestaan.
  • Regels en alinea's worden automatisch gesplitst.
  • Web- en e-mailadressen worden automatisch naar links omgezet.

Wil je deel uitmaken van een groep gedreven en ambitieuze experts? Stuur ons jouw cv!