JAXB collation in WebSphere 8.5.5.3 results in elements from the interface in the XML SOAP response
We have a web service that uses JAXB to marshal and expose a SOAP request and response. We are using Sun / Oracle JDK7 on Tomcat and the corresponding IBM JDK7 on WebSphere 8.5.5.3. The application works as expected on Tomcat, however unmarshalling the response from WebSphere results in a null object due to an additional element from the Java interface that implements the class - in the XML response. The Java Dynamic Web Service Sample Project was created in Eclipse (Kepler Service Release 2) to reproduce an object marshalling error by returning a class that extends an abstract class that returns an interface to WebSphere. The project is structured as follows:
- Person.java - Person is an interface.
- Employee.java - Employee is a class that implements the Person interface.
-
Manager.java - Manager is a class that extends the Employee class.
-
Department.java is an abstract class that contains an abstract getPerson () method that returns the Person interface.
-
Finance.java - [This is a class that extends Department that polymorphizes the getPerson () method to return a Manager object.]
-
PersonnelEndPoint.java - [This is the Personnel web service endpoint that contains the getFinanceDepartment () method that returns the Finance object]
Note that there is an additional element in the XML returned from WebSphere below <person>
. Is there an option in WebSphere that suppresses returning an item from the base interface?
Capturing SoapUI from an application deployed to Tomcat looks like this:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns3:getFinanceDepartmentResponse xmlns:ppl="http://personnel.corporate.org" xmlns:ns3="http://application.corporate.org/">
<return>
<manager>
<firstName>Austin</firstName>
<internalId>1000</internalId>
<lastName>Smith</lastName>
<middleName>J</middleName>
<level>1</level>
<managerYn>true</managerYn>
</manager>
</return>
</ns3:getFinanceDepartmentResponse>
</S:Body>
</S:Envelope>
The WebSphere result looks like this:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns2:getFinanceDepartmentResponse xmlns:ppl="http://personnel.corporate.org" xmlns:ns2="http://application.corporate.org/">
<return>
<manager>
<firstName>Austin</firstName>
<internalId>1000</internalId>
<lastName>Smith</lastName>
<middleName>J</middleName>
<level>1</level>
<managerYn>true</managerYn>
</manager>
<person>
<firstName>Austin</firstName>
<internalId>1000</internalId>
<lastName>Smith</lastName>
<middleName>J</middleName>
<level>1</level>
<managerYn>true</managerYn>
</person>
</return>
</ns2:getFinanceDepartmentResponse>
</soapenv:Body>
</soapenv:Envelope>
Examples of java files:
Personnel.java
package org.corporate.personnel;
import java.io.Serializable;
// this is a base interface.
public interface Person extends Cloneable, Serializable{
public Long getInternalId();
public String getFirstName();
public String getLastName();
public String getMiddleName();
}
Employee.java
package org.corporate.personnel;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.bind.annotation.XmlType;
import org.corporate.personnel.Person;
import org.corporate.personnel.Manager;
// Employee class implements Person interface.
@XmlType(name="Employee")
@XmlSeeAlso({Manager.class})
public class Employee implements Person {
private static final long serialVersionUID = 2019814652839014485L;
private Long internalId;
private String firstName;
private String lastName;
private String middleName;
private Manager manager;
public Employee() {}
public Employee(Long pInternalId, String pFirstName, String pLastName,
String pMiddleName) {
internalId = pInternalId;
firstName = pFirstName;
lastName = pLastName;
middleName = pMiddleName;
}
public Long getInternalId() {
return internalId;
}
public void setInternalId(Long internalId) {
this.internalId = internalId;
}
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;
}
public String getMiddleName() {
return middleName;
}
public void setMiddleName(String middleName) {
this.middleName = middleName;
}
public Manager getManager() {
return manager;
}
public void setManager(Manager manager) {
this.manager = manager;
}
}
Manager.java
package org.corporate.personnel;
import java.util.List;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import org.corporate.personnel.Employee;
// this class inherits Employee class, which implements Person interface.
@XmlType(name = "Manager")
@XmlRootElement(name = "Manager")
public class Manager extends Employee {
private static final long serialVersionUID = -1750217675821392021L;
private Long managerId;
private Integer level;
private Boolean managerYn;
private List<Manager> alternateManagers;
private List<Employee> subordinates;
public Long getManagerId() {
return managerId;
}
public void setManagerId(Long managerId) {
this.managerId = managerId;
}
public Integer getLevel() {
return level;
}
public void setLevel(Integer level) {
this.level = level;
}
public Boolean getManagerYn() {
return managerYn;
}
public void setManagerYn(Boolean managerYn) {
this.managerYn = managerYn;
}
public List<Manager> getAlternateManagers() {
return alternateManagers;
}
public void setAlternateManagers(List<Manager> alternateManagers) {
this.alternateManagers = alternateManagers;
}
public List<Employee> getSubordinates() {
return subordinates;
}
public void setSubordinates(List<Employee> subordinates) {
this.subordinates = subordinates;
}
}
Department.java
package org.corporate.personnel;
import java.io.Serializable;
import javax.xml.bind.annotation.XmlType;
@XmlType(name="Department")
@javax.xml.bind.annotation.XmlSeeAlso({Manager.class, Finance.class})
public abstract class Department implements Cloneable, Serializable {
// eclipse auto generated serial version
private static final long serialVersionUID = -910358057883859853L;
// references Person interface.
public abstract Person getPerson();
}
Finance.java
package org.corporate.personnel;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
@XmlType(name = "Finance")
@XmlRootElement(name = "Finance")
public class Finance extends Department {
// eclipse auto generated serial version
private static final long serialVersionUID = 4012667746961776179L;
private Manager manager;
// note: the getPerson method returns Person interface.
// Manager is a class that extends Employee class, which implements Person
// interface.
// implements getPerson method from abstract class.
public Manager getPerson() {
return manager;
}
public void setPerson(Manager pManager) {
manager = pManager;
}
public Manager getManager() {
return manager;
}
public void setManager(Manager manager) {
this.manager = manager;
}
}
PersonnelEndPoint.java
package org.corporate.application;
import javax.jws.WebMethod;
import javax.jws.WebService;
import org.corporate.personnel.Finance;
import org.corporate.personnel.Manager;
/**
* This sample application demonstrates WebSphere returns
* properties from an interface.
* @author EXL Landa
*
*/
@WebService
@javax.xml.bind.annotation.XmlSeeAlso({Manager.class, Finance.class})
public class PersonnelEndPoint {
/**
* The public method that returns an interface implemented
* in a base class Department.
* @return
*/
@WebMethod
public Finance getFinanceDepartment() {
Finance lFinance = new Finance();
lFinance.setPerson(getManager());
return lFinance;
}
/**
* This method returns a local manager object.
* @return Manager
*/
private Manager getManager() {
Manager lManager = new Manager();
lManager.setInternalId(1000L);
lManager.setFirstName("Austin");
lManager.setMiddleName("J");
lManager.setLastName("Smith");
lManager.setLevel(1);
lManager.setManagerYn(true);
return lManager;
}
}
source to share
I tried your code on WASv8009 and it didn't work. There might be a difference in how Tomcat and WebSphere handle web services, but your finance class will return 2 complex types. Org.corporate.application.jaxws does nothing in WAS. To achieve what you want to add @XmlAccessorType (XmlAccessType.FIELD) to the Finance class.
This is from SoapUI after I made the changes: Austin 1000 smith J 1 true
source to share