Jmeter与Liferay DXP兼容性问题:登录脚本执行后Portlet不可用
Hey there, let’s figure out why you’re hitting that frustrating "Portlet is Unavailable" error even after setting up the HTTP Cookie Manager and handling the p_auth CSRF token. Here are targeted checks and fixes to get your script working:
Verify your request sequence is correct
Portlets often depend on prior page loads to initialize their context. Make sure your sampler order matches what a real browser does:- First send a GET request to the login page (to grab p_auth and initial cookies)
- Then send the POST login request with the extracted p_auth
- Only after successful login, send the request to access the Portlet. Skipping these steps can leave the Portlet uninitialized.
Double-check your p_auth extraction and usage
- Use the View Results Tree’s Response Data tab to confirm the p_auth value is present in the login page’s response.
- Verify your extractor (Regex, CSS/JQuery) is correctly capturing the exact p_auth value—no extra characters, no missing parts.
- Check the POST login request’s parameters: ensure the parameter name matches exactly what the browser sends (sometimes it’s
_p_authinstead ofp_auth, so don’t guess!).
Tweak your HTTP Cookie Manager settings
- Ensure the Cookie Manager is placed at the top of your Thread Group so all requests inherit its cookies.
- Try enabling Clear cookies each iteration to avoid stale session cookies from messing with new test runs.
- Right-click the Cookie Manager and select View Cookies to confirm that after login, you have a valid session cookie stored.
Mirror real browser request headers
Many systems block requests that don’t look like they’re coming from a real browser. Add an HTTP Header Manager and copy these critical headers from your browser’s dev tools (Network tab):User-Agent: Match your browser’s exact string (e.g.,Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 ...)Referer: For the login POST, set this to the login page URL; for the Portlet request, set it to the post-login homepage URL.Accept-Language,Accept-Encoding: Include these to mimic a real user’s request.
Validate Portlet request details
- Confirm the Portlet’s URL is 100% correct, including the full context path (e.g.,
/web/portal/dashboardinstead of just/dashboard). - Check for Portlet-specific parameters like
p_p_id,p_p_lifecycle,p_p_state—these are often required to load the Portlet properly. Copy these directly from your browser’s request.
- Confirm the Portlet’s URL is 100% correct, including the full context path (e.g.,
Check server logs for root cause
If all else fails, dive into your application server’s logs. Look for errors related to Portlet initialization, session validation, or permission issues. The log stack trace will give you a precise clue about what’s breaking behind the scenes.
内容的提问来源于stack exchange,提问作者Mayank Mishra

