Struts Ajax的OutOfMemory异常在使用非原始Java对象时调用

时间:2012-10-19 19:28:14

标签: ajax jquery struts2 enums

我对Struts 2.2.3.1操作进行了一个相对简单的Ajax调用,返回一个简单的Java POJO。一旦我们向该POJO添加一个简单的Enum并执行该操作,我们就会在服务器的日志中收到一堆这样的消息:

[10/19/12 14:55:07:124 EDT] 00000047 BeanAdapter   I com.opensymphony.xwork2.util.logging.commons.CommonsLogger info Class com.ibm.ws.ejbcontainer.jitdeploy.JIT_StubPluginImpl has no readable properties,  trying to adapt JIT_StubClassPlugin with StringAdapter...
[10/19/12 14:55:07:124 EDT] 00000047 BeanAdapter   I com.opensymphony.xwork2.util.logging.commons.CommonsLogger info Class com.ibm.ws.ejbcontainer.jitdeploy.JIT_StubPluginImpl has no readable properties,  trying to adapt JIT_StubClassPlugin with StringAdapter...
[10/19/12 14:55:07:139 EDT] 00000047 BeanAdapter   I com.opensymphony.xwork2.util.logging.commons.CommonsLogger info Class com.ibm.ws.ejbcontainer.jitdeploy.JIT_StubPluginImpl has no readable properties,  trying to adapt JIT_StubClassPlugin with StringAdapter...
[10/19/12 14:55:07:139 EDT] 00000047 BeanAdapter   I com.opensymphony.xwork2.util.logging.commons.CommonsLogger info Class com.ibm.ws.ejbcontainer.jitdeploy.JIT_StubPluginImpl has no readable properties,  trying to adapt JIT_StubClassPlugin with StringAdapter...

然后最终看到OutOfMemory Exception。

Out Struts XML用于Ajax调用类似于:

    <action name="ajaxRetrieveThing" class="x.y.z.action.Thing" method="ajaxRetrieveThing">
        <result type="xslt">
            <param name="exposedValue">actionResponse</param>
        </result>
    </action>

我们的ActionResponse类的相关部分是:

public class ActionResponse {
    // a bunch of primitive types and associated getters and setters skipped

    private List<Object> results = new ArrayList<Object>();
    public List<?> getResults() {
        return results;
    }

    public void addResult(Object o) {
        results.add(o);
    }
    public void setResultList(List results) {
        this.results = results;
    }
}

在我们的行动中,我们在结果列表中添加了一个Thing。 Thing是一个带有原始字段的POJO和我们的ThingEnum。

我们的Enum看起来像这样:

public enum ThingEnum {
    VALUE_1( "1" ), VALUE_2( "2" ); // etc

    String description;
    private ThingEnum( String description ) {
        this.description = description;
    }

    public String getDescription() {
        return description;
    }   
}

该操作将起作用,我们可以将数据添加到JavaScript中,直到我们添加ThingEnum。我假设这是因为Struts在尝试将ThingEnum转换为XML时遇到问题。我们遇到了与其他类型的对象(例如Hibernate实体)类似的问题,并通过在结果对象中存储我们需要的字符串和其他基元来解决它们。

解决此问题的正确方法是什么?我想避免在传回JS之前手动将Enum转换为String,这是我们当前的解决方案 - 而不是拥有ThingEnum字段,我们在Result对象中基本上有一个thingDescription字符串。

0 个答案:

没有答案