I'm having a rather particular problem with heap space and the
DefaultContentTypeHandlerManager in the struts rest plugin.  I've got a
model driven rest controller with a few different methods that return rather
large result sets and it's causing heap space issues when the content type
handler tries to create a json string out of the result array.  I traced the
problem through to when the content type handler being passed a StringWriter
object to output to, eventually it tries to resize some internal
representation of the string and we get a heap space error.  I'd prefer to
write directly to the response output stream and not have the whole response
string buffered in memory.  So, I wrote my own extension of
DefaultContentTypeHandlerManager that will pass my custom JSON content
handler the response stream instead of a StringWriter.  All seems well,
except that I can't seem to find a way to override the class type of the
ContentTypeHandlerManager.  Here's my struts.xml:


<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd";>
<struts>
<constant name="struts.convention.package.locators" value="leadsService"/>
<constant name="struts.convention.action.suffix" value="Controller"/>
<constant name="struts.convention.action.mapAllMatches" value="true"/>
<constant name="struts.convention.default.parent.package"
value="rest-default"/>
<constant name="struts.convention.result.path" value="/WEB-INF/templates/"
/>
    <constant name="struts.rest.defaultExtension" value="json" />
<bean name="myJson"
type="org.apache.struts2.rest.handler.ContentTypeHandler"
class="com.myCode.LeadsJsonHandler" />
<bean type="org.apache.struts2.rest.ContentTypeHandlerManager"
class="com.myCode.MyContentTypeHandlerManager" />
</struts>

And my struts.properties:

struts.rest.handlerOverride.json=myJson

Is it even possible to override the ContentTypeHandlerManager?  When I try
to setup the bean in struts.xml as above, it just dies and throws  this
error:

Caused by: Bean type interface
org.apache.struts2.rest.ContentTypeHandlerManager with the name default has
already been loaded by [unknown location] - bean -
file:/home/user/myCode/trunk/target/classes/struts.xml:12:142
at
com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:205)

A quick grep of the source has yielded me nothing so far, but any help in
the right direction to look would be most appreciated.

Thank you,
Stephen Huenneke

Reply via email to