Results 1 to 3 of 3

Thread: How to get HttpServletRequest in a component?

  1. #1
    Join Date
    Dec 2010
    Location
    Brno
    Posts
    15

    Default [SOLVED] 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 at 09:42 AM. Reason: Solved

  2. #2

    Default

    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

  3. #3
    Join Date
    Dec 2010
    Location
    Brno
    Posts
    15

    Default

    wau, it works!!
    Many thanks Kev!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •