[Restlet 2.1-M2 jse/jee editions, Jackson 1.7.1. Posting to discussion list
because it refers to another message in the same list. I'll repost to code
list if folks think it belongs there instead.]

Class JacksonRepresentation (from Restlet's Jackson extension) creates an
ObjectMapper with the AUTO_CLOSE_TARGET disabled. I extended
JacksonRepresentation to override createObjectMapper in order to do my own
configuration, and I unintentionally left off this disable call.

It worked just fine, though, within a Restlet Component running
standalone. When I recently tried to run the Component within ServerServlet
(in Tomcat 6), however, I got the stack trace reported in this thread:


http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2436859

Disabling AUTO_CLOSE_TARGET didn't fix it -- instead of the error the server
just hangs (in standalone mode, at least).

I looked hard at the stack trace above and decided to try leaving auto-close
enabled and suppressing the final flush() in
WriterRepresentation.write(OutputStream). This worked. I don't get the
exception any more, and I *do* get the JSON content. The standalone
Component doesn't require the flush, either.

I can't say for sure that leaving AUTO_CLOSE_TARGET enabled and suppressing
the final flush in WriterRepresentation is really the right thing to do, but
it's the only combination that works for me in both servlet and standalone
settings.

I suppressed the flush by overriding write(OutputStream) in my
JacksonRepresentation subclass, but maybe WriterRepresentation should have a
setting for this, e.g.:

    WriterRepresentation rep = new JacksonRepresentation(...);
    rep.setFlushAfterWrite(false);
    ...

And if the auto-close-enabled and no-flush-after-write combination *is*
deemed the right thing to do, that could be the default for
JacksonRepresentation, and you could remove the auto-close disable logic
from JacksonRepresentation.createObjectMapper.

--tim

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2702864

Reply via email to