AnsweredAssumed Answered

java backed webscript get HttpServletRequest and httpSession

Question asked by isy on Jul 4, 2013
Latest reply on Jul 4, 2013 by isy
I made a java backed web script and i want to access HttpServletRequest in order to store a variable in the http session.

Here is what i tried

public class GetValidationProgressionBean extends DeclarativeWebScript {

      protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {

         HttpServletRequest httpReq = ((WebScriptServletRequest) req).getHttpServletRequest(); //org.alfresco.repo.web.scripts.RepositoryContainer$BufferedRequest cannot be cast to
                        //org.springframework.extensions.webscripts.servlet.WebScriptServletRequest"  => WebScriptServletRequest wraps the HttpServletRequest

         ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); //returns null
         HttpServletRequest request = requestAttributes.getRequest(); //Exception due to requestAttributes = null
         HttpSession httpSession = request.getSession();

                        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes() //No thread-bound request found: Are you referring to
                        //request attributes outside of an actual web request, or processing a request outside of the originally receiving thread?

                        HttpSession session = ServletUtil.getSession(); //returns null

what is the correct way ?