具有可选实体过滤的 Jersey 在 URI 上没有 SELECT 时停止响应

Jersey with Selectable Entity Filtering stops responding without SELECT on URI

我正在尝试通过 Entity Data Filtering Dynamic and Configurable Query Parameters 改进我的服务。所有资源在 GET 上都能正确响应。当我执行 POST 方法时,服务器冻结。应用服务器内存不足。

问题:有人知道为什么会这样吗?我做错了什么?

编辑:激活LoggingFilter.class后,可以在其他情况下看到确认响应,而不仅仅是使用POST方法。

在第二个请求中,服务器收到它并且 LoggingFilter 显示状态代码 200。所以我认为问题出在编组器上。

配置:

该应用程序部署在 WSO2 AS 5.2.1。

应用程序配置class:

@javax.ws.rs.ApplicationPath("rest")
public class ApplicationConfig extends ResourceConfig {

    public ApplicationConfig() {

        property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true);
        property(ServerProperties.BV_DISABLE_VALIDATE_ON_EXECUTABLE_OVERRIDE_CHECK, true);
        property(MarshallerProperties.BEAN_VALIDATION_MODE, BeanValidationMode.NONE);

        register(SelectableEntityFilteringFeature.class);
        property(SelectableEntityFilteringFeature.QUERY_PARAM_NAME, "select");

        register(new MoxyJsonConfig().setFormattedOutput(true).resolver());

    }
}

Error.log

java.lang.OutOfMemoryError: Java heap space
        at org.eclipse.persistence.core.queries.CoreAttributeGroup.newItem(CoreAttributeGroup.java:711)
        at org.eclipse.persistence.core.queries.CoreAttributeGroup.getItem(CoreAttributeGroup.java:488)
        at org.eclipse.persistence.core.queries.CoreAttributeGroup.addAttribute(CoreAttributeGroup.java:178)
        at org.eclipse.persistence.core.queries.CoreAttributeGroup.addAttribute(CoreAttributeGroup.java:144)
        at org.eclipse.persistence.internal.jaxb.ObjectGraphImpl.addAttributeNodes(ObjectGraphImpl.java:36)
        at org.glassfish.jersey.moxy.internal.MoxyObjectProvider.createSubgraphs(MoxyObjectProvider.java:131)
        at org.glassfish.jersey.moxy.internal.MoxyObjectProvider.createSubgraphs(MoxyObjectProvider.java:141)
        at org.glassfish.jersey.moxy.internal.MoxyObjectProvider.createSubgraphs(MoxyObjectProvider.java:141)
        at org.glassfish.jersey.moxy.internal.MoxyObjectProvider.createSubgraphs(MoxyObjectProvider.java:141)
        at org.glassfish.jersey.moxy.internal.MoxyObjectProvider.createSubgraphs(MoxyObjectProvider.java:141)
        at org.glassfish.jersey.moxy.internal.MoxyObjectProvider.createSubgraphs(MoxyObjectProvider.java:141)
        at org.glassfish.jersey.moxy.internal.MoxyObjectProvider.createSubgraphs(MoxyObjectProvider.java:141)
        at org.glassfish.jersey.moxy.internal.MoxyObjectProvider.createSubgraphs(MoxyObjectProvider.java:141)
        at org.glassfish.jersey.moxy.internal.MoxyObjectProvider.createSubgraphs(MoxyObjectProvider.java:141)
        at org.glassfish.jersey.moxy.internal.MoxyObjectProvider.createSubgraphs(MoxyObjectProvider.java:141)
        at org.glassfish.jersey.moxy.internal.MoxyObjectProvider.createSubgraphs(MoxyObjectProvider.java:141)
        at org.glassfish.jersey.moxy.internal.MoxyObjectProvider.createSubgraphs(MoxyObjectProvider.java:141)
        at org.glassfish.jersey.moxy.internal.MoxyObjectProvider.createSubgraphs(MoxyObjectProvider.java:141)
        at org.glassfish.jersey.moxy.internal.MoxyObjectProvider.createSubgraphs(MoxyObjectProvider.java:141)
        at org.glassfish.jersey.moxy.internal.MoxyObjectProvider.createSubgraphs(MoxyObjectProvider.java:141)
        at org.glassfish.jersey.moxy.internal.MoxyObjectProvider.createSubgraphs(MoxyObjectProvider.java:141)
        at org.glassfish.jersey.moxy.internal.MoxyObjectProvider.createSubgraphs(MoxyObjectProvider.java:141)
        at org.glassfish.jersey.moxy.internal.MoxyObjectProvider.createSubgraphs(MoxyObjectProvider.java:141)
        at org.glassfish.jersey.moxy.internal.MoxyObjectProvider.createSubgraphs(MoxyObjectProvider.java:141)
        at org.glassfish.jersey.moxy.internal.MoxyObjectProvider.createSubgraphs(MoxyObjectProvider.java:141)
        at org.glassfish.jersey.moxy.internal.MoxyObjectProvider.createSubgraphs(MoxyObjectProvider.java:141)
        at org.glassfish.jersey.moxy.internal.MoxyObjectProvider.createSubgraphs(MoxyObjectProvider.java:141)
        at org.glassfish.jersey.moxy.internal.MoxyObjectProvider.createSubgraphs(MoxyObjectProvider.java:141)
        at org.glassfish.jersey.moxy.internal.MoxyObjectProvider.createSubgraphs(MoxyObjectProvider.java:141)
        at org.glassfish.jersey.moxy.internal.MoxyObjectProvider.createSubgraphs(MoxyObjectProvider.java:114)
        at org.glassfish.jersey.moxy.internal.MoxyObjectProvider.createObjectGraph(MoxyObjectProvider.java:90)
        at org.glassfish.jersey.moxy.internal.MoxyObjectProvider.transform(MoxyObjectProvider.java:76)

经过一些调试后,同事发现这是因为我有双向实体。

假设我们有客户地址:

@Entity
public class Customer {

    @Id
    private long id;

    @OneToOne(mappedBy="customer", cascade={CascadeType.ALL})
    private Address address;

}

@Entity
public class Address implements Serializable {

    @Id
    private long id;

    @OneToOne
    @JoinColumn(name="ID")
    @MapsId
    @XmlInverseReference(mappedBy="address")
    private Customer customer;

}

在这种情况下,Selectable 过滤器在尝试构建 ObjectGraph 时会忽略 @XmlInverseReference,但它会 OOM。