[ https://issues.apache.org/jira/browse/CXF-4986?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13641646#comment-13641646 ]
abdelgadiri edited comment on CXF-4986 at 4/25/13 10:54 AM: ------------------------------------------------------------ I have now tried an alternative approach. I have my @Prematching filter call sessionId = ... //non null session id requestContext.setProperty("sessionId", sessionId); according to the specification/java-doc of setProperty() method "In a Servlet container, the properties are synchronized with the ServletRequest and expose all the attributes available in the ServletRequest. Any modifications of the properties are also reflected in the set of properties of the associated ServletRequest." so in my resource, I am trying: public Response dosomething(UriInfo uriInfo, HttpServletRequest request) { //this fails - sessionId is always null Object sessionId = request.getAttribute("sessionId") //this also fails - sessionId is always null sessionId = request.getParameter("sessionId"); return Response.ok().build(); } so, it looks like cxf is not allowing filters to modify the request was (Author: abdelgadiri): I have now tried an alternative approach. I have my @Prematching filter call sessionId = ... //non null session id requestContext.setProperty("sessionId", sessionId); according to the specification/java-doc of setProperty() method "In a Servlet container, the properties are synchronized with the ServletRequest and expose all the attributes available in the ServletRequest. Any modifications of the properties are also reflected in the set of properties of the associated ServletRequest." so in my resource, I am trying: public Response dosomething(UriInfo uriInfo, HttpServletRequest request) { //this fails - sessionId is always null sessionId = request.getAttribute("sessionId") //this also fails - sessionId is always null sessionId = request.getParameter("sessionId") return null; } so, it looks like cxf is not allowing filters to modify the request > jax-rs2 request filter is unable to modify request header by adding a new > header > --------------------------------------------------------------------------------- > > Key: CXF-4986 > URL: https://issues.apache.org/jira/browse/CXF-4986 > Project: CXF > Issue Type: Bug > Components: JAX-RS > Affects Versions: 2.7.2 > Environment: cxf on tomcat > Reporter: abdelgadiri > Assignee: Sergey Beryozkin > Fix For: 2.8.0, 2.7.5 > > > I have a filter implementation as follows > @Provider > public class AuthSessionFilter implements ContainerRequestFilter { > public AuthSessionFilter() { > } > @Override > public void filter(ContainerRequestContext requestContext) throws > IOException { > //another @Prematching filter is setting this session id so it is > definitely not null > Object sessionId = requestContext.getProperty("sessionId"); > if (sessionId == null || GeneralUtils.isNullOrBlank(sessionId + "")) { > > requestContext.abortWith(Response.status(Response.Status.UNAUTHORIZED) > .entity("missing sessionId").build()); > } > //this line gets invoked without problems, however, the added header > is not available from the resource class > requestContext.getHeaders().putSingle("sessionId", sessionId+""); > } > } > The line requestContext.getHeaders().putSingle("sessionId", sessionId+""); is > not making the added sessionId header available when trying to obtain it from > my resource. getHeaders() is supposed to return a mutable map in accordance > with the spec, but its implementation 'ContainerRequestContextImpl' is > returning a readonly map instead. it returning: > return new MetadataMap<String, String>( > (Map<String, List<String>>)m.get(Message.PROTOCOL_HEADERS), > false, true, true); > where it is passing 'true' for the readonly parameter. > in my resource, I am trying to obtain the header using > public Response doSomething(UriInfo uriInfo, HttpServletRequest request) { > //this is always null even though it shouldn't be null > String sessionId = request.getHeader("sessionId"); > } -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators For more information on JIRA, see: http://www.atlassian.com/software/jira