From the servlet spec (9.3) about includes:
It can only write information to the ServletOutputStream or Writer of the response object
and commit a response by writing content past the end of the response buffer, or by
explicitly calling the flushBuffer method of the ServletResponse interface. It cannot set
headers or call any method that affects the headers of the response, with the exception of
the HttpServletRequest.getSession() and HttpServletRequest.getSession(boolean) methods.
As addCookie will modify the response headers, it is not allowed so we ignore it.
Stuart
----- Original Message -----
From: "John Sipher" <jasipher(a)gmail.com>
To: undertow-dev(a)lists.jboss.org
Sent: Thursday, 4 June, 2015 8:06:26 PM
Subject: [undertow-dev] Undertow doesn't write cookie to response
Copy/pasted from
https://developer.jboss.org/message/932789?et=watches.email.thread#932789 .
Any help would be appreciated...
I'm trying to migrate an application from JBoss 7,.2.0.Final to WildFly
8.2.0.Final, and I find that some cookies are not written to the servlet
response. I've tracked it down to
io.undertow.servlet.spec.HttpServletResponseImpl.addCookie().
1. @Override
2. public void addCookie( final Cookie cookie) {
3. if (insideInclude) {
4. return ;
5. }
6. final ServletCookieAdaptor servletCookieAdaptor = new
ServletCookieAdaptor(cookie);
7. if (cookie.getVersion() == 0 ) {
8.
servletCookieAdaptor.setVersion(servletContext.getDeployment().getDeploymentInfo().getDefaultCookieVersion());
9. }
10. exchange.setResponseCookie(servletCookieAdaptor);
11. }
Apparently the insideCookie flag has been set to true at the point we're
calling HttpServletResponse.addCookie(), so WildFly/Undertow just quietly
throws it away and leaves me scratching my head trying to figure out what
went wrong.
When I search back up the call stack I see that our servlet is including a
JSP page in its response like this
1. RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher(page);
2. dispatcher.include(state.getRequest(), state.getResponse());
So, it makes sense that insideInclude is true, since the code that's trying
to set the cookie is being called from inside RequestDispatcher.include(),
but I don't understand why WildFly/Undertow just arbitrarily throws it away.
- See more at:
https://developer.jboss.org/message/932789?et=watches.email.thread#932789
_______________________________________________
undertow-dev mailing list
undertow-dev(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/undertow-dev