In this post I’ll show how to add a little bit of inline scripting in your Apache Aries Blueprint xml files.
I wouldn’t call it necessarely a best practice, but I have always had the idea that this capability might be usueful; probably I started wanting this when I was forced to use xml to simulate imperative programming structures like when using Apache Ant.
And I have found the idea validated in projects like Gradle or Vagrant where a full programming language is actually hiding in disguise, pretending to be a Domain Specific Languge or a surprisingly flexible configuration syntax.
I have talked in past about something similar, when showing how to use MVEL in JBoss Fuse.
This time I will limit myself to show how to use small snippets of code that can be inlined in your otherwise static xml files, trick that might turn useful in case you need to perform simple operations like replacement of strings, aritmetics or anything else but you want to avoid writing a java class for that.
Let me say that I’m not inventing anything new around here. I’m just showing how to use a functionality that has been provided directly by the Apache Aries project but that I haven’t used that often out there.
The goal is to allow you to write snippet like this:
1 2 3 4 5 | ... < bean id = "accountFactory" class = "org.apache.aries.simple.AccountFactory" > < argument value = "$[karaf.home.replaceAll("\\\\", "/")]" > </ argument ></ bean > ... |
You can see that we are invoking java.lang.String.replaceAll()
method on the value of an environment variable.
We can do this thanks to the Apache Aries Bluerpint JEXL Evaluator, an extension to Apache Aries Blueprint, that implements a custom token processor that “extends” the base functionality of Aries Blueprint.
In this specific case, it does it, delegating the token interpolation to the project Apache JEXL.
JEXL, Java Expression Language, it’s just a library that exposes scripting capabilities to the java platorm. It’s not unique in what it does, since you could achieve the same with the native support for Javascript or with Groovy for instance. But we are going to use it since the integration with Blueprint has alredy been written, so we can use it straight away on our Apache Karaf or JBoss Fuse instance.
The following instructions have been verified on JBoss Fuse 6.2.1:
1 2 3 4 | # install JEXL bundle install -s mvn:org.apache.commons /commons-jexl/2 .1.1 # install JEXL Blueprint integration: install -s mvn:org.apache.aries.blueprint /org .apache.aries.blueprint.jexl.evaluator /1 .0.0 |
That was all the preparation that we needed, now we just need to use the correct XSD version, 1.2.0
in our Bluerpint file:
xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.2.0"
Done that, we can leverage the functionality in this way:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | < blueprint xmlns = "http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:ext = "http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.2.0" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns:jaas = "http://karaf.apache.org/xmlns/jaas/v1.0.0" xsi:schemalocation=" http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"> < ext:property-placeholder system-properties = "override" evaluator = "jexl" placeholder-prefix = "$[" placeholder-suffix = "]" > < bean id = "myString" class = "java.lang.String" > < argument value = "1" > </ argument ></ bean > < service interface = "java.lang.CharSequence" ref = "myString" > < service-properties > < entry key = "osgi.jndi.service.name" value = "$[karaf.home.toUpperCase()]___$[1+2]" > </ entry ></ service-properties > </ service > </ ext:property-placeholder ></ blueprint > |
Copy that blueprint.xml
directly into deploy/
folder, and you can check from Karaf shell that the dynamic invocation of those inline script has actually happened!
1 2 | JBossFuse:karaf@root> ls ( id blueprint.xml) | grep osgi.jndi.service.name osgi.jndi.service.name = /OPT/RH/JBOSS-FUSE-6 .2.1.REDHAT-107___3 |
This might turn useful in specific scenarios, when you look for a quick way to create dynamic configuration.
In case you might be interested into implementing your custom evaluator, this is the interface you need to provide an implementation of:
And this is an example of the service you need to expose to be able to refer it in your <property-placeholder>
node:
1 2 3 4 5 6 7 | < service interface = "org.apache.aries.blueprint.ext.evaluator.PropertyEvaluator" > < service-properties > < entry key = "org.apache.aries.blueprint.ext.evaluator.name" value = "jexl" > </ entry ></ service-properties > < bean class = "org.apache.aries.blueprint.jexl.evaluator.JexlPropertyEvaluator" > </ bean ></ service > |
this concepts are really well being and wonderful thus it is very much interesting and very well good too, really i got more information from your knowledge.
ReplyDeleteDigital Marketing Company in Chennai
The blog is very interesting and will be much useful for us. thank you for sharing the blog with us. please keep on updating.
ReplyDeleteROI Services in Chennai
for preparing bank exam and group exam , we are providing an online test model questions papers
ReplyDeleteBank Exam Questions and Answers
Group Exam Questions and Answers
Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing
ReplyDeletelenovo ideapad service center chennai
lenovo laptop service center in chennai
lenovo thinkpad service center chennai
Learning new technolgy would help oneself at hard part of their career. And staying updated is the only way to survive in current position. Your content tells the same. Thanks for sharing this information in here. Keep blogging like this.
ReplyDeleteiOS App Development Company in India
It's interesting that many of the bloggers to helped clarify a few things for me as well as giving.Most of ideas can be nice content.The people to give them a good shake to get your point and across the command.
ReplyDeletedigital marketing course in chennai
hadoop training in chennai
This comment has been removed by the author.
ReplyDeletehello sir,
ReplyDeletethanks for giving that type of information.
Glass Laminated Doors manufacturers in karnataka
I found your blog while searching for the updates, I am happy to be here. Very useful content and also easily understandable providing.. Believe me I did wrote an post about tutorials for beginners with reference of your blog.
ReplyDeleterpa training in chennai
rpa training in bangalore
rpa course in bangalore
best rpa training in bangalore
rpa online training
Nice information, valuable and excellent design, as share good stuff with good ideas and concepts, lots of great information and inspiration, both of which I need, thanks to offer such a helpful information here.
ReplyDeletepython training institute in marathahalli
python training institute in btm
Python training course in Chennai
All the points you described so beautiful. Every time i read your i blog and i am so surprised that how you can write so well.Selenium training in Chennai | Selenium training institute in Chennai | Selenium course in Chennai
ReplyDeleteSelenium training in Bangalore | Selenium training institute in Bangalore | Selenium course in Bangalore
Selenium interview questions and answers
Selenium training in Pune | Selenium training institute in Pune | Selenium course in Pune
All the points you described so beautiful. Every time i read your i blog and i am so surprised that how you can write so well.
ReplyDeleteData Science Training in Indira nagar
Data Science Training in btm layout
Python Training in Kalyan nagar
Data Science training in Indira nagar
Data Science Training in Marathahalli | Data Science training in Bangalore
This is a nice article here with some useful tips for those who are not used-to comment that frequently. Thanks for this helpful information I agree with all points you have given to us. I will follow all of them.
ReplyDeletebest rpa training in bangalore
rpa training in bangalore
rpa course in bangalore
RPA training in bangalore
rpa training in chennai
rpa online training
Hmm, it seems like your site ate my first comment (it was extremely long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog. I as well as an aspiring blog writer, but I’m still new to the whole thing. Do you have any recommendations for newbie blog writers? I’d appreciate it.
ReplyDeleteAdvanced AWS Course Interview Questions And Answers, Top 250+AWS Jobs Interviews Questions and Answers 2018
Advanced AWS Jobs Interview questions and answers |Best Top 110 AWS Interview Question and Answers – india
Best Amazon Web Services Training in Pune | Best AWS Training in Pune
Some us know all relating to the compelling medium you present powerful steps on this blog and therefore strongly encourage
ReplyDeletecontribution from other ones on this subject while our own child is truly discovering a great deal.
Have fun with the remaining portion of the year.
Selenium training in bangalore
Very informative blog! Thanks for sharing. Keep us updated.
ReplyDeleteLINUX Training in Chennai
Best LINUX Training in Chennai
Tally Course in Chennai
Tally Classes in Chennai
Embedded System Course Chennai
Embedded Training in Chennai
LINUX Training in OMR
LINUX Training in Anna Nagar
That was a great message in my carrier, and It's wonderful commands like mind relaxes with understand words of knowledge by information's.
ReplyDeleteAWS Training in pune
AWS Online Training
AWS Training in Bangalore
Thanks for sharing the information. It is very useful for my future. keep sharing
ReplyDeleteStill Hunting Method
Hunting psych tips Survival Tips Travel Touring Tips
ReplyDeleteThe blog you have shared really worth for me.Thanks for Sharing...
crm software development services in chennai
crm software development in chennai
erp in chennai
crm software development company in chennai
cloud erp in us
erp in india
Such a great information for blogger iam a professional blogger thanks…
ReplyDeleteGet Best Service Now Training in Bangalore from Real Time Industry Experts with 100% Placement Assistance in MNC Companies. Book your Free Demo with Softgen Infotech.
This article is very absolutely write content.
ReplyDeletePython Training in Chennai
Python Training in Bangalore
Python Training in Hyderabad
Python Training in Coimbatore
Python Training
python online training
python flask training
python flask online training
this concepts are really well being and wonderful thus it is very much interesting and very well good too, really i got more information from your knowledge.
ReplyDeletejava training in chennai
java training in omr
aws training in chennai
aws training in omr
python training in chennai
python training in omr
selenium training in chennai
selenium training in omr
Learning new technolgy would help oneself at hard part of their career. And staying updated is the only way to survive in current position. Your content tells the same. Thanks for sharing this information in here. Keep blogging like this.
ReplyDeletejava training in chennai
java training in omr
aws training in chennai
aws training in omr
python training in chennai
python training in omr
selenium training in chennai
selenium training in omr
You made such an interesting piece to read, giving every subject enlightenment for us to gain knowledge. Thanks for sharing the such information with us
ReplyDeletedata science training in chennai
data science training in tambaram
android training in chennai
android training in tambaram
devops training in chennai
devops training in tambaram
artificial intelligence training in chennai
artificial intelligence training in tambaram
Wonderful blog with great piece of information. Regards to your effort. Keep sharing more such blogs.Looking forward to learn more from you.
ReplyDeletehardware and networking training in chennai
hardware and networking training in porur
xamarin training in chennai
xamarin training in porur
ios training in chennai
ios training in porur
iot training in chennai
iot training in porur
I found your blog while searching for the updates, I am happy to be here.
ReplyDeletedata science training in chennai
data science training in annanagar
android training in chennai
android training in annanagar
devops training in chennai
devops training in annanagar
artificial intelligence training in chennai
artificial intelligence training in annanagar
I simply wanted to thank you so much again. I am not sure the things that I might have gone through without the type of hints revealed by you regarding that situation.
ReplyDeletesap training in chennai
sap training in velachery
azure training in chennai
azure training in velachery
cyber security course in chennai
cyber security course in velachery
ethical hacking course in chennai
ethical hacking course in velachery
I think this is one of the best blog for me because this is really helpful for me. Thanks for sharing this valuable information
ReplyDeleteinternship meaning | internship meaning in tamil | internship work from home | internship certificate format | internship for students | internship letter | Internship completion certificate | internship program | internship certificate online | internship graphic design
ReplyDeleteNice blog! Thanks for sharing this valuable information
German Classes in Bangalore
German Language Course in Hyderabad
J-Martino launches new Slots & Live Dealers for - JTHub
ReplyDeleteJ-Martino, 광명 출장마사지 an online 거제 출장안마 casino operator in Italy, is giving customers the opportunity to play all their 광주광역 출장마사지 favourite 포항 출장마사지 casino games, and slot 경주 출장샵
I really enjoyed reading this blog. Thank you for sharing your work. Thank you for Sharing such an amazing article.
ReplyDeleteBA 1st Year Result 2022 | BA 2nd Year Result 2022 | BA 3rd Year Result 2022.
Great blog the content is informative and engaging. Visit my website to get best Information
ReplyDeleteFrozen Shoulder Treatment in Surrey
Wonderful blog with great piece of information. Visit my website to get best Information
ReplyDeletevintage oval mirror