cancel
Showing results for 
Search instead for 
Did you mean: 

webscript HttpServletRequest WebScriptServletRequest

robain
Champ in-the-making
Champ in-the-making
going through some samples for java backed webscript. found something like

// NOTE: This web script must be executed in a HTTP Servlet environment
        if (!(req instanceof WebScriptServletRequest))‍‍

what does it mean to be executed in a HTTP Servlet environment? is this something thats configurable? what are the other options?
any info is appreciated.

Am running on 2.1.2 e,
somehow (res instanceof WebScriptServletResponse) returns true
but (req instanceof WebScriptServletRequest) returns false.
any ideas ?

Thanks
3 REPLIES 3

robain
Champ in-the-making
Champ in-the-making
i get the exception below everytime i try to cast WebScriptRequest as WebScriptServletRequest
java.lang.ClassCastException - org.alfresco.web.scripts.WebScriptServletRequest

code:
HttpServletRequest httpReq = ((WebScriptServletRequest)req).getHttpServletRequest();

help please!!

mrogers
Star Contributor
Star Contributor
I'm not sure what you are trying to do but the WebScriptServletRequest wraps the HttpServletRequest.   Which is why you can't cast it.
   
public WebScriptServletRequest(Runtime container, HttpServletRequest req, Match serviceMatch, ServerProperties serverProperties)
{
        super(container, req, serviceMatch, serverProperties);
}

robain
Champ in-the-making
Champ in-the-making
I am just trying access the HttpServletRequest in the java backed webscript.

public class MyWebScript extends AbstractWebScript
{
   public void execute(WebScriptRequest req, WebScriptResponse res)
   throws IOException
   {
      HttpServletRequest httpReq = ((WebScriptServletRequest)req).getHttpServletRequest();
   }
   
}‍‍‍‍‍‍‍‍‍

Thats where i am getting the error. Could you explain why i am getting this error in this context.

Thanks for the help with this.