java - Weblogic 12 中的 MOXy 解码

标签 java weblogic eclipselink moxy weblogic12c

我在 WebLogic 12c(使用 OpenJPA 2.1.0)中运行 Web 服务时遇到问题。 Web 服务的响应是一个包含特定实体列表的 DTO。执行服务后,无法生成其响应(没有任何错误或异常)。我认为 MOXy 对响应实体的解码操作存在问题(我在 WebLogic 11 中没有遇到任何问题,因为它不使用 MOXy)。您对这个问题和解决方案有何看法?

谢谢

Web 服务在 GlassFish 3.1.2 中运行良好。

这是我的代码:

人实体

@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;

人员 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;
}

列表大小为3,但没有响应。

最佳答案

更新

问题似乎是 OpenJPA 使用 java.util.Date 的子类填充 java.util.Date 类型的属性。我已经打开了以下 EclipseLink bug,您可以使用它来跟踪我们在这个问题上的进展:

我在此处给出的相关问题的答案中发布了解决此问题的方法:

要获得官方补丁,您应该提交 WebLogic 错误。如果您引用我上面给出的 EclipseLink bug,它将有助于更快地推进一切。

<小时/>

EclipseLink JAXB (MOXy)确实成为 WebLogic 12.1.1 中的默认 JAXB 提供程序(请参阅 EclipseLink MOXy is the JAXB Provider in WebLogic Server 12c ),但这似乎不是问题的原因。

PersonServiceImpl

我简化了您的服务,尽可能删除与 MOXy 无关的内容。通过删除 @Stateless 注释,我能够使服务正常工作。我建议联系 Oracle 支持人员了解 WebLogic 12.1.1 和 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;
    }

}

测试客户端结果

下面是我从 WebLogic 管理控制台运行内置测试客户端时收到的输出。

<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>

关于java - Weblogic 12 中的 MOXy 解码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10967587/

相关文章:

java - 连接池中的最佳连接数

postgresql - 带有 GlassFish 4 和 PostGIS 的 JPA 实体

java - 使用EclipseLink Modelgen处理器和Spring Security时如何解决CompletionFailure?

java - JPA 多对多关系导致无限递归和堆栈溢出错误

plugins - 带有ssl问题的Weblogic maven插件

jakarta-ee - WebLogic 的 JavaEE API

java - 为具有可编辑列数和行数的 JTable 设置列名称

java - .jar 文件无法在某些计算机上运行

java - 如何覆盖 Android 设备中的电源按钮

java - 尝试在空对象引用上调用虚拟方法 '...(java.util.ArrayList)'