Frage

I have a problem with running my web service in WebLogic 12c (with OpenJPA 2.1.0). The response of the web service is a DTO which has list of specific entities. After executing the service, its response could not be generated (without any error or exception). I think there is a problem during MOXy’s unmarshalling operation of response entity (I haven’t had any problem in WebLogic 11, because it don’t use MOXy). What do you think about this problem and solution?

Thanks

The web service works well in GlassFish 3.1.2.

Here is my code:

Person entity

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "person")
@Entity
@Table(name = "PERSON")

public class Person {

@Id
@Column(name = "ID")
@XmlElement(required = false)
private Long id;

@Column(name = "BIRTHDATE")
@XmlElement(required = false)
@Temporal(TemporalType.DATE)
private Date birthDate;

@Transient
private String name;

Person DTO

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "personDto")
public class PersonDto implements Serializable{

@XmlElement(required = false)
List<Person> persons;

/**
 * list of person
 *
 * @return
 */
public List<Person> getPersons() {
    if (persons == null)
        persons = new LinkedList<Person>();

    return persons;
}

public void setpersons(List<Person> persons) {
    this.persons = persons;
}

DAO

@Stateless
public class PersonDaoImpl implements PersonDao{

@PersistenceContext(unitName = "pu-test")
private EntityManager em;

public List<Person> findAll() {
    List<Person> personList = null;
    Query query =  em.createNamedQuery("person.findAll");
    List<Person> results = (List<Person>)query.getResultList();
    return results;     
}

orm.xml

<named-query name="person.findAll">
    <query>select p from Person p</query>
</named-query>

WebService

@Stateless
@WebService
public class PersonServiceImpl implements IPersonService {

@EJB
private PersonDao personDao;


public PersonDto allPersons()  {
    PersonDto result = new PersonDto();
    List<Person> fList = personDao.findAll();       
    result.setPersons(fList);
    return result;
}

The list's size is 3, but there is no response.

War es hilfreich?

Lösung 2

Finally, by changing JAXB implementation from Moxy to Metro, my problem has been resolved temporary. Two jar files javax-xml-bind.jar, javax-xml-ws.jar should be added in the path of "/weblogic_home/wlserver/endorsed" in Weblogic server and also add following properties into java_properties part of setDomainEnv file:

    -Dcom.sun.xml.ws.spi.db.BindingContextFactory=com.sun.xml.ws.db.
glassfish.JAXBRIContextFactory 

-Djavax.xml.bind.JAXBContext=org.eclipse.persistence.jaxb.JAXBContextFactory

Andere Tipps

UPDATE

The problem appears to be that OpenJPA is populating properties of type java.util.Date with a subclass of java.util.Date. I have opened the following EclipseLink bug that you can use to track our progress on this issue:

I have posted a way to work around this problem in an answer I gave to related question here:

To get an official patch you should submit a WebLogic bug. If you cite the EclipseLink bug I gave above it will help move everything along faster.


EclipseLink JAXB (MOXy) did become the default JAXB provider in WebLogic 12.1.1 (see EclipseLink MOXy is the JAXB Provider in WebLogic Server 12c), but that does not appear to be the cause of your issue.

PersonServiceImpl

I simplified your service to remove as much that wasn't related to MOXy as possible. By removing the @Stateless annotation, I am able to get the service to work. I would recommend contacting Oracle support regarding the difference in behaviour between WebLogic 12.1.1 and GlassFish 3.1.2.

package forum10967587;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.ejb.*;
import javax.jws.WebMethod;
import javax.jws.WebService;

//@Stateless
@WebService
public class PersonServiceImpl implements IPersonService {

    @WebMethod
    public PersonDto allPersons() {
        PersonDto result = new PersonDto();
        List<Person> fList = new ArrayList<Person>(3);

        Person p1 = new Person();
        p1.setBirthDate(new Date());
        p1.setId(1L);
        p1.setName("Jane");
        fList.add(p1);

        Person p2 = new Person();
        p2.setBirthDate(new Date());
        p2.setId(2L);
        p2.setName("John");
        fList.add(p2);

        result.setPersons(fList);
        return result;
    }

}

Test Client Result

Below is the output I received when running the built in test client from the WebLogic Admin Console.

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Body>
    <ns0:allPersonsResponse xmlns:ns0="http://forum10967587/">
      <return>
        <persons>
          <id>1</id>
          <birthDate>2012-06-19T13:56:38.579</birthDate>
          <name>Jane</name>
        </persons>
        <persons>
          <id>2</id>
          <birthDate>2012-06-19T13:56:38.579</birthDate>
          <name>John</name>
        </persons>
      </return>
    </ns0:allPersonsResponse>
  </S:Body>
</S:Envelope>
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top