AnsweredAssumed Answered

Set attrubute to WebScriptRequest, or cast it to a class which allows setting attribute to it

Question asked by raghav on Feb 27, 2018
Latest reply on Feb 27, 2018 by krutik.jayswal

My question:

How to set attributes in the WebScriptRequest, or cast WebScriptRequest to another class which allows setting attributes to it? 

 

My approach:

The issue is, WebScriptRequest does not have set methods. In order to overcome this, I attempted to cast WebScriptRequest to HttpServletRequest. Next in the HttpServletRequest, I set my attribute.

 

I am attempting code as the one below (which compiles, but throws the runtime error):

 

public class MyWebScript extends AAbstractWebScript{

 

public void execute(WebScriptRequest request, WebScriptResponse response) throws IOException {

      HttpServletRequest httpReq = ((WebScriptServletRequest) request).getHttpServletRequest();
      httpReq.setAttribute("name", "John");

}

 

The issue is: 

With the approach above, the code compiles, but I get runtime error as below:

 

org.alfresco.repo.web.scripts.BufferedRequest cannot be cast to org.springframework.extensions.webscripts.servlet.WebScriptServletRequest

Outcomes