multithreading - @Context HttpServletRequest scope in Jersey ContainerResponseFilter -
i writing jersey response filter. using jersey 1.17. want access attributes of httpservletrequest in filter api. way doing right below. safe inject servletrequest in snippet below or cause kind of concurrency issues? if there multiple requests coming in conncurrently, servletrequest in different requests overwrite each other? hlep.
public class loggingfilter implements containerresponsefilter { @context private httpservletrequest servletrequest; @override public containerresponse filter(final containerrequest req, final containerresponse resp) { string s = this.servletrequest.getattribute("xxx"); .... } }
section 9.1 (latest, 5.1 previously) concurrency of jax-rs specification states:
context speciļ¬c particular request instances of jax-rs components (providers , resource classes lifecycle other per-request) may need support multiple concurrent requests. when injecting instance of 1 of types listed in section 9.2, instance supplied must capable of selecting correct context particular request. use of thread-local proxy common way achieve this.
so, per specification, jax-rs implementations (e.g. jersey) required ensure context safe. keep doing you're doing.
see also: extract request attributes container request of jersey
Comments
Post a Comment