cancel
Showing results for 
Search instead for 
Did you mean: 

java backed webscript get HttpServletRequest and httpSession

isy
Champ in-the-making
Champ in-the-making
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 {

                @Override
      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 ?

Thx
1 REPLY 1

isy
Champ in-the-making
Champ in-the-making
  <java>
WebScriptSession session = req.getRuntime().getSession();
</java>

seems to do what i want
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.