tapa icon indicating copy to clipboard operation
tapa copied to clipboard

Commands for auto adding the correct XML nodes to applicationContext

Open usbrandon opened this issue 7 years ago • 2 comments

xmlstarlet ed --pf --ps -N util="http://www.springframework.org/schema/util" -N sec="http://www.springframework.org/schema/security" --insert "/:beans/:bean[@id="filterChainProxy"]/:constructor-arg[1]/util:list/sec:filter-chain[1]" --type elem -n ResourceTMP -v ""
-i "/
:beans/:bean[@id="filterChainProxy"]/:constructor-arg[1]/util:list/ResourceTMP" -t attr -n "pattern" -v "/content/tapa/resources/templates/*/assets/**"
-i "/:beans/:bean[@id="filterChainProxy"]/:constructor-arg[1]/util:list/ResourceTMP" -t attr -n "filters" -v "securityContextHolderAwareRequestFilterForWS,httpSessionPentahoSessionContextIntegrationFilter,httpSessionContextIntegrationFilter,basicProcessingFilter,requestParameterProcessingFilter,anonymousProcessingFilter,exceptionTranslationFilterForWS,filterInvocationInterceptorForTapa"
-r "/
:beans/:bean[@id="filterChainProxy"]/:constructor-arg[1]/util:list/ResourceTMP" -v "sec:filter-chain" applicationContext-spring-security.xml

You then follow with xmllint --format applicationContext-spring-security.xml --output applicationContext-spring-security.xml

This approach is more readable than sed or other kinds of contortions. It also reliably places the xml nodes where they need to be and the attributes with absolutely the correct values and formatting. Another command for the other bean settings. This is the approach I am using in my dockerfile where I am incorporating your superior login screen plugin as a default.

usbrandon avatar Sep 01 '17 02:09 usbrandon

Nice, @usbrandon. I saw that xmlstarlet is multiplatform. This will be good to tidy up the deploy. Thank you!

marpontes avatar Sep 06 '17 08:09 marpontes

I've had a change of heart on the xmlstartlet thing. It goofed up the XML output where you have to run it through something else that can reformat out the /> hanging out on the end. What I've been working up is a python version of this that uses the LXML library. It's very multiplatform compatible too and more importantly, it uses structured libraries as well to handle updating these structured documents.

I was attempteing to use xmlstartlet to add the other large beans and properties to the files and it was just getting very convoluted. I think you'll like the Python approach better. It's code is more readable and obvious what is happening there.

To give you a taste, look at this repo for tomcat configs for docker. It's just beautiful. https://github.com/Promact/docker-tomcat/blob/master/dbconfiguration_replacement.py

usbrandon avatar Sep 11 '17 15:09 usbrandon