02-27-2018 11:10 AM
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
02-27-2018 01:32 PM
There are few basic rule/need when we do casting of an object in javaIn your case it does not satisfy those.For more details of it you can check below link.
Casting variables in Java - Stack Overflow
You just mentioned that you would like to cast an WebScriptServletRequest in to HttpServletRequest , can you tell me the reason behind this.If not what is the exact requirement which you would like to achieve.If possible both.
10-25-2019 12:54 PM
You can get by the casting error like this:
WebScriptRequest webScriptRequest = ((WrappingWebScriptRequest) request).getNext(); WebScriptServletRequest webScriptServletRequest = (WebScriptServletRequest) webScriptRequest;
Explore our Alfresco products with the links below. Use labels to filter content by product module.