I found a couple of questions somewhat related to this:
httpclient-request-set-attribute-question
commons-httpclient-adding-query-string-parameters-to-get-post-request
but I think I am trying to do something different here:
I have a servlet which will set an attribute into the request. In my Java client, I am using HTTP Components library, and I want to read the attribute in my client.
- Is this an invalid use case for the HTTP Components library?
- If not, one way would be to serialize the object in the servlet and de-serialize it back in the client, but I am not sure if that is the best practice.
- Is there an API I am missing here?
Request attributes are not accessible to the client.
You should send them as response somehow (write them as key-value pairs, serialize the object graph with JSON, etc.). So yes, that’s the accepted practice