Hi,
I think I agree that the spec is not completely clear on this point.
While it doesn't explicitly say
that attributes are per-exchange, it does kind of imply that. My
preference would be to tighten
up the spec; make clear what is normative (the current behavior) and
distinguish from that
what is informative, (the example of how filters could use the mechanism).
Go ahead and file a bug and we can take it from there.
Thanks
Michael.
On 10/12/2019 11:10, Julien Royer wrote:
Hi,
I’m having some troubles understanding how com.sun.net.HttpExchange
attributes (setAttribute and getAttribute methods) work. Looking at
the Javadoc, I understood that these attributes were specific to a
given HttpExchange instance:
https://hg.openjdk.java.net/jdk/jdk/file/a4fb32538898/src/jdk.httpserver/share/classes/com/sun/net/httpserver/HttpExchange.java#l219
Filter modules may store arbitrary objects with HttpExchange
instances as an out-of-band communication mechanism.
This was also my intuition since these methods are defined on
HttpExchange and HttpContext (similar
to javax.servlet.ServletRequest#setAttribute
and javax.servlet.ServletContext#setAttribute).
When using them on a project, I realised that my intuition was wrong
though. The source code is very explicit:
https://hg.openjdk.java.net/jdk/jdk/file/a4fb32538898/src/jdk.httpserver/share/classes/sun/net/httpserver/ExchangeImpl.java#l366
if (attributes == null) {
attributes = getHttpContext().getAttributes();
}
Is the code wrong or is my understanding of the Javadoc incorrect? If
so, shouldn’t it be clarified somehow?
Thank you,
Julien
P.S. this question was also asked on stackoverflow:
https://stackoverflow.com/questions/59178977/are-com-sun-net-httpserver-httpexchange-attributes-broken