users@jersey.java.net

Re: [Jersey] NPE at AbstractMessageReaderWriterProvider.readFromAsString()

From: Gili <cowwoc_at_bbs.darktech.org>
Date: Thu, 11 Dec 2008 01:34:36 -0800 (PST)

Paul Sandoz wrote:
>
> For the case you are describing is it not just as easy for the
> application to retain the object returned from the getEntity?
>

In my particular case, yes, simply because it turns out that my code wasn't
supposed to read the entity twice (this was caused by a bug). But I can see
the need for this kind of code:

public isPoem(ClientResponse response)
{
  if (response.getEntity(String.class).equals("my poem"))
    return true;
  else
    return super.isPoem(response);
}

you can then imagine super.isPoem() reads the entity and parses the content
differently. In short, anyone wishing to implement the
chain-of-responsibility design pattern will be hard-pressed to do so.
Ideally they want to pass the ClientResponse around, not a ClientResponse
with an external copy of the Entity. Also, from an end-user perspective
they'd prefer for you to handle all the complexity of handling the bytes and
handling type conversion instead. For example, right now users can invoke
getEntity(String.class), getEntity(Foo.class) and conversions will be
handled internally. Your suggestion, if I understand you correctly, would
push the conversions onto the end-users. They would have to retrieve the
byte[] the first time, pass it around alongside the ClientResponse and
handle conversions themselves.

With respect to performance I think we also need to take into consideration
that we're talking about client-side code here. It is understandable that
servers try to avoid retaining client state whenever possible (to improve
scalability) but client-side code doesn't have the same problem: you're
retaining your own data, not the data belonging to 100s of other clients.
Furthermore, even if we buffer this data it is still very short-lived. I
argue that whatever "data churn" this creates will be well worth the
ease-of-use benefits to the resulting API.

Good night,
Gili
-- 
View this message in context: http://n2.nabble.com/NPE-at-AbstractMessageReaderWriterProvider.readFromAsString%28%29-tp1636314p1642507.html
Sent from the Jersey mailing list archive at Nabble.com.