Modifying or transforming response data generated by the web server is a great use of servlet filters. I read a nice Stack Overflow thread that discusses the idea of injecting text into the head of an HTML response using a servlet filter. The code provided in this thread is a great example of how to modify HTML response data that gets sent to the client. I made some slight modifications to this code so that I can inject custom scripts and styles in the HTML responses generated by the PeopleSoft web server. This servlet filter will be a bolt-on solution to achieve global script and style injection in PeopleSoft. Below are the steps to configure this servlet filter for the PeopleSoft web server.
CLICK HERE to download the project.
Extract the zip and you should see the following files:
Take the folder named “custom” and place it in the following directory:
Take the folder named “psm” and place it in the following directory:
Navigate to and open up the web.xml file. The web.xml file is located in the following directory:
Copy the text from the downloaded file named “webxml.txt” and paste the text into your web.xml file. Paste in the text so that it is the first <filter> to show up in the web.xml file. For my environment, I pasted the filter before the delivered “psfilter”.
Go to the web profile configuration page in the PIA and select the web profile that you are applying this servlet filter to. You will need to uncheck the checkbox for the “Compress Responses” option.
You will need to bounce the web server at this point.
After bouncing the web server, login to the PIA and navigate around. You will notice that the script defined in the global.js file gets fired when every page is loaded.
Any scripts that are defined in the global.js file as well as any styling defined in the global.css file will get injected into every page with the configuration that I have provided.
The servlet filter also has the ability to inject multiple script and style sheets if needed. The paths to the script files need to be specified as comma separated values for the “scripts” param-value in the web.xml file. Similarly, the paths to the style sheets need to be specified as comma separated values for the “styles” param-value in the web.xml file.
The alert script that I defined in the global.js file is not very practical, but it gives you an idea as to when and where the injected script fires. To enhance this solution, one could write a simple JSP page on the web server that is capable of modifying the files that get injected. This JSP page can then be consumed through the PIA as an external content reference. That will allow this global script and style injection solution to be configured from within the PeopleSoft application itself.