What is the difference between PortalUtil.getOriginalServletRequest and PortalUtil.getHttpServletRequest?

I want to know the difference between

PortalUtil.getOriginalServletRequest(portletRequest) 

and

 PortalUtil.getHttpServletRequest(portletRequest). 
+4
source share
2 answers

Looking at the source code for Liferay 6 (I assume you're talking about 6), you can see what PortalUtil.getOriginalServletRequest does, and I posted the code below:

 public HttpServletRequest getOriginalServletRequest( HttpServletRequest request) { HttpServletRequest originalRequest = request; while (originalRequest.getClass().getName().startsWith( "com.liferay.")) { // Get original request so that portlets inside portlets render // properly originalRequest = (HttpServletRequest) ((HttpServletRequestWrapper)originalRequest).getRequest(); } return originalRequest; } 

So, as the comment says: "Get the original request so that the portlets inside the portlets display correctly." You probably only need this for a nested portlet or similar situation. In most cases, you just need to use:

 PortalUtil.getHttpServletRequest(portletRequest); 

Hope this helps!

+4
source

Despite the fact that the question already has an accepted answer, I find there something worth thinking about: sometimes you want to send requests through the HttpServletRequest interface, because you need an interface for this. This will leave the entire PortletRequest name in place (for example, you can call getParameter ("name") without running it).

On the other hand, sometimes you may need to hack and get a virtually non-interacting parameter from the actual ("original") HttpServletRequest before it gets corrupted.

And what do you use both methods for: Just adapt the interface and get the actual data from the original Http level

+5
source

Source: https://habr.com/ru/post/1392017/


All Articles