Announcement Announcement Module
Collapse
No announcement yet.
How to get HttpServletRequest in a component? Page Title Module
Move Remove Collapse
This topic is closed
X
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to get HttpServletRequest in a component?

    Hi,
    I'm trying to create a webscript, which renders a login/logout link. My authentication is done by Alfresco user factory. I did a working java-backed webscript, which after direct access in browser works correctly, but when I add this webscript as a component into page, I can't access HttpServletRequest, which is needed by AuthenticationUtil.
    I tried following snippets:
    Code:
    HttpServletRequest httpRequest = ((WebScriptServletRequest)req).getHttpServletRequest();
    
    produces
    
    java.lang.ClassCastException - org.springframework.extensions.webscripts.LocalWebScriptRequest cannot be cast to org.springframework.extensions.webscripts.servlet.WebScriptServletRequest
    and

    Code:
    HttpServletRequest httpRequest = WebScriptServletRuntime.getHttpServletRequest(req);
    which returns null :-(.

    So my question is: how can I get HttpServletRequest inside java-backed webscript, which is inside page as a component?

    Thanks in advance!
    Last edited by shmoula; Dec 9th, 2010, 10:42 AM. Reason: Solved

  • #2
    HttpServletRequest request = ServletUtil.getRequest();

    This is a Surf feature i.e. not available in a pure webscript based tier. But of course you wouldn't be rendering your webscript as a component in a page unless you were running in Surf

    Cheers,

    Kev

    Comment


    • #3
      wau, it works!!
      Many thanks Kev!

      Comment

      Working...
      X