LRP-614 practice question 10 of 25

The recommended way to strip content from the outgoing response is to:

Full set: 144 questions
Answer options
A: Create a hook plugin that implements a service post action to strip content from the response
B: Create an Ext plugin that implements a servlet filter to strip content from the response
C: Create a hook plugin that implements a servlet filter to strip content from the response Correct answer
D: Create a hook that implements a request post processor to strip content from the response
Correct Answer:
C. Create a hook plugin that implements a servlet filter to strip content from the response
Explanation

The standard Java EE pattern for intercepting and modifying an HTTP request or response is a servlet filter. In the context of Liferay 6.1/6.2, the recommended and least invasive method to deploy a custom servlet filter is through a hook plugin. The hook's liferay-hook.xml descriptor file allows a developer to define a custom filter class and its URL mapping. Liferay then dynamically injects this filter into the portal's filter chain upon the hook's deployment. This approach provides the necessary functionality to "strip content" by wrapping the response object, without modifying Liferay's core source code or web.xml file, making it the preferred, modular, and maintainable solution.

Why Incorrect

A. Service post actions execute after a Struts action but before the JSP is rendered; they cannot access or modify the final, complete HTTP response stream.
B. An Ext plugin can achieve this but is considered highly invasive as it modifies core portal files. It is not the recommended way for tasks achievable with hooks.
D. A request post processor is a portal event handler. While it has access to the response object, a servlet filter is the standard, more direct pattern for modifying the response body.

References

1. Liferay Portal 6.2 Developer's Guide: In the chapter "Customizing Liferay with Hooks," the guide explicitly details how to implement custom servlet filters. It states, "You can use a hook to add a servlet filter to Liferay... To add a servlet filter, you need to specify the filter class and the filter mapping in your hook’s liferay-hook.xml file." This directly supports using a hook to implement a servlet filter. (Reference: Liferay Portal 6.2 Developer's Guide, Chapter 10: Customizing Liferay with Hooks, Section: "Application Adapter Hooks and Servlet Filter Hooks").

2. Liferay in Action (Manning Publications): While a commercial book, it is authored by a Liferay expert and reflects official best practices for the platform version. It describes hooks as the primary mechanism for customizations like adding servlet filters, contrasting them with the more heavyweight and discouraged Ext plugins. It reinforces that hooks are the standard for this type of customization. (Reference: Liferay in Action, by Rich Sezov, Chapter 13: "Customizing the Liferay Platform," Section 13.2.5: "Using hooks to insert servlets and filters").

Scroll to Top