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
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.
You can get by the casting error like this:
WebScriptRequest webScriptRequest = ((WrappingWebScriptRequest) request).getNext(); WebScriptServletRequest webScriptServletRequest = (WebScriptServletRequest) webScriptRequest;
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.