Friday, November 29, 2013

Review of Getting Started with SBT for Scala (Packt-Pub)

I got the opportunity to review a book in the scala domain published by Packt on SBT. I am very glad that so many books are coming up in this domain. SBT is one of the most important components in scala infra. Most, if not all, of the projects use SBT as the build tool in the scala projects. 

The book itself is very well written and has a good flow through out. The installation, running, and structure of SBT has also been explained. There is a very nice history of evolution of all the relevant build tools that are in the industry. I like chapter 1 esp for the way it quickly lets you get into code and start writing simple build scripts and to become aware of the minimum commands in the SBT that you ought to know. The chapter 1 provides intro to run, compile, test, scala REPL with real code examples that are easy to comprehend. One of the most important concepts of SBT has been clearly mentioned- Blank lines act as delimiter in a .sbt file. There are many operators in SBT like :=, +=, ++= etc which can be used in build definitions which has been covered clearly. There are nice tips which are present through out the book. Maven, Ivy has also been introduced. Ivy and its work lifecycle has been explained a bit in detail. I can live without that. Ivy itself is a big topic that can be read separately. The different types of scopes has also been covered. There is also a good list of commands/types in SBT which is presented.

The version's specified in the dependency need not be a single version as SBT is based on Ivy. There can be more constraints on it like 1.0.+ means select latest in 1.0.x in the dependency. This has been mentioned but no adequate examples has been given. I think this could have easily been added in one or two lines in a beginners book. This is a pretty useful feature. Next, scalaz ex in the full build definition is hardly understood. It should have been expanded a bit more. The full build definition chapter itself could have been explained a bit more. It is one of the key functionalities that allows a lot of flexibility in SBT. The multi project builds in that chapter has been explained well though.

Overall, I like the book. It gets you started in SBT as the title states pretty quickly. No book can replace your own research and work. This book can definitely serve as a quick reference to common commands, operators etc when in need after you have learned and worked with SBT.

The book is available on packt-pub here.

Tuesday, October 29, 2013

Apache Camel JMX with remote jconsole using host : port

By default when JMX is enabled in apache camel, it binds such that you will have to use a rather encrypted path in jconsole URI for connecting remotely. From there documentation-

You will not be able to connect using localhost:1099 in the jconsole. This was very important to me as I was not just using jconsole but zabbix to gather data from JMX. In case of zabbix the only option that is available was host:port. The reason this does not work is the serviceUrlPath which by default in camel is customized to /jmxrmi/camel instead of the more known /jmxrmi. The fix is easy as show below-

<camelContext id="camelAppContext" xmlns="">
<propertyPlaceholder id="properties"
<jmxAgent id="camelAppJmxAgent" registryPort="{{jmx.registry.port}}" connectorPort="{{jmx.connector.port}}"
createConnector="true" serviceUrlPath="/jmxrmi"/>

Or by using the JMX from –D options.

With this configuration you can connect using host:port (localhost:1099) to JMX using jconsole.

Monday, October 21, 2013

Liftweb 2.4 and Jamon 2.74 request monitoring

I like Jamon as a library for collecting performance statistics. It is well established and provides sufficient types of statistics. One of the favorites statistics of mine being the frequency distribution of response times. Using Jamon in simple but with Lift 2.4 it was little challenging. The Jamon MonitorFactory returns an instance of Timing Monitor that maintains the statistics. For the collection to occur the same instance must be accessed to call stop after method execution. i.e-
Monitor monitor = MonitorFactory.start("key1");
//Code whose performance needs to be measured

The problem with older version of Liftweb is there is no way of wrapping every request such that this monitor can be used. The S.addAround can be used with LoanWrapper but this gets executed multiple times as described here. As from the discussion from that thread you can see that a common LoanWrapper surrounding all requests would be (or has already been) added in Liftweb. But, if you can not upgrade the Liftweb to newer version then here is the solution. The idea is to use the LiftRules onBeginServicing and onEndServicing. But note that we need to use the same instance of Monitor created in onBeginServicing method. The request/response lifecycle in liftweb is described very well here. This will catch both Statefull GET and Ajax requests. The code below uses the setAttribute method of the original HHTPServletRequest to save and retrieve the Monitor between methods. Have fun with scala, liftweb and jamon!
def boot {
val labelPrefix: String = "LIFT_WEB_HTTP."
val monitorInReq: String = "monitorInReq"
val extensionsNotToMonitor = List(".jpg", ".png", ".jpeg", ".ico", ".gif", ".bmp")

def pathFilter = {
req: Req =>
req.path.wholePath.takeRight(1) match {
case x :: _ if (extensionsNotToMonitor.contains(x.substring(x.lastIndexOf(".")))) => None
case _ => Some(req.path.wholePath.mkString("/"))

LiftRules.onBeginServicing.append((req: Req) => {
val label: Option[String] = pathFilter(req)
if (label.isDefined) {
val start: Monitor = MonitorFactory.start(labelPrefix + label.get) => (r.asInstanceOf[HTTPRequestServlet]).req.setAttribute(monitorInReq, start))

LiftRules.onEndServicing.append((req, respBox) => { => {
val attribute: AnyRef = (r.asInstanceOf[HTTPRequestServlet]).req.getAttribute(monitorInReq)
if (null != attribute) {

Sunday, June 16, 2013

SoapUI: Inserting an external XML node dynamically into an existing XML Response using XmlHolder

The Problem: I have a Soap Response, and I have to modify that xml such that I insert a new XML node into response. The new XML is a string that I can declare in a groovy script or I can retrieve from a property.

Few exceptions I encountered while trying to solve the problem: CData missing, can not add external document, Can not add groovy Node class to java Node class, viceversa and etc etc etc

Hints to solve the problem on internet: There are many websites that provides sample which helps to solve a particular case, but could not exactly find the one I present here. The most useful one was here "" where in the coments he gives sample related to owner doc and importing into it.


Lets say you have a soap request and response in a test step of a test case. The body of the response is like below.
<Traveler xmlns="">
<Customer BirthDate="2001-01-01">
<Person Language="EN-US">
<Email Type="HOM" Address=""/>

And I want add a new XML node Payment to Customer. Lets say his payment information like credit card number which is an XML fragment like below. Later I will add the card number to it.

def pay="""<Payment>
<Card Type="INTERNATIONAL" Vendor="VISA" Number="">
Huntsville Townhall
<Issuer Name="Bank of Nowhere"/>

Create a new property transfer from Traveler xml in the Soap Response to copy the Customer node to a TestCase property "customer". You can do that by using the below configuration in a new Propperty transfer step after the Soap RQ/RS step.

Source: SoapRequestStepName Property: Response
declare namespace ns1='';
Target: TestCaseName Property: nodeCustomer

Add a new test step with groovy script called updatePaymentInXML. First step is to create a XmlHolder for the source XML Traveler and extract Customer node out of it.
def getXmlHolder(){
def groovyUtils = new context )
def nodeCustStr=testRunner.testCase.getProperty("nodeCustomer").getValue() "Pre Update: " + nodeCustStr
def holder = groovyUtils.getXmlHolder(nodeCustStr)
holder.namespaces["ex"] =""
return holder

Next lets get the Customer node from it as a Node.

def holder = getXmlHolder()
def nodeCustomer = holder.getDomNode("//ex:Customer")

Next lets insert payment in the customer node.

def insertPaymentInCustomer(holder, nodeCustomer, pay){
def ownerDoc=nodeCustomer.getOwnerDocument()
def payHolder=new
payHolder.namespaces["ex"] =""
def nodePay = payHolder.getDomNode("//ex:Payment")

def importedNodePay=ownerDoc.importNode(nodePay, true)
holder.updateProperty() "Post Update: " + holder.getXml()
insertPaymentInCustomer(holder, nodeCustomer, pay)

Things to note in the above snippet is that we get the owner document and import the newly extracted Payment xml node from the xml string using a new XmlHolder instance. Lets add the card number to it.

def updateCCNumberInHolder(holderIn, ccNumberIn){
testRunner.testCase.setPropertyValue("nodeCustomerUpdated",holderIn.getXml()) "Post Update: " + holderIn.getXml()
updateCCNumberInHolder(holder, testRunner.testCase.getPropertyValue("ccNumber"))

Now, the holder.getXml() gives you the latest XML with updated Payment and cc number in it. Test case property nodeCustomerUpdated has the all updated XML that you can use.

Thursday, April 04, 2013

Instant Lift web application how to (PACKT-PUB book) review

I would categorize myself as advanced beginner as I know about liftweb/scala and have built applications for my company. I am not a advanced user and not an expert who has gone through the source of the liftweb. I state this because this allows you to gauge my level before deciding to buy the book. I rate the book as excellent for a beginner. The book starts with advantage of liftweb, setting up scala, setting up sbt along with using sbt basics, setting up eclipse environment, boot.scala and so on and on. The author intends the book for a beginner as he even explains for example what is a servlet container, and how JNDI works. Lift snippets, CSS selector bindings, embed tags, sitemap, and so many more concepts are explained in simple words. Let me be honest and say that I have gone through around 70 pages of the 96 page book. I like the book as it provides a very good starting point for everyone to start learning lift. So, back to my criteria for the review:

1. It should be easily understandable for the beginners and must be useful for advanced users as quick reference.

The author is really good in explaining the concepts in very simple words. The book can be used by advanced users as quick reference like google. I would provide a score of 4/5 for this.

2. Must be more than the many available tutorials you find on the web about scala/lift technologies.

Definitely this is true since there is flow through the topics introduced and you are never overwhelmed. The author covers a lot of concepts needed to build an application E2E. 5/5.

3. Should not beat around the bush and get to the point quickly, which is develop a application using scala and liftweb.

You will be up and running in no time. 5/5

4. The most important thing would be, I should be able to build a simple yet useful application from end to end using the knowledge in the book and by expanding on it.

I did not have time to build an application based only on the knowledge in this book. But, I feel the book covers many topics that I have used in my app development. This book definitely will help to build application E2E. Always remember that a book can spoon feed you only to a certain level after which you need to pickup by reading api docs, forums etc.

5. Last but not least, it should encourage the users to proceed with using Liftweb and learn more about the awesome framework and the unique design approach taken by that framework at more depth and by themselves.

The book provides relevant links when appropriate. It is simple enough to encourage anyone scared of entering the world of liftweb. Do note that I feel it is more easy to understand the book and concepts if you are well versed in scala. 4/5

In summary, I like the book and would thank Pack Pub for giving me an opportunity to read and comment on it.

Saturday, March 16, 2013

Jquery Browser Select Dialog Plugin

I have been developing my website, using jquery and in the process have used certain jquery components that are not compatible with IE version less than 9. I started searching for a jquery plugin that shows a dialog when browser is less than IE 9, but could not find one on the internet. I decided to write one highly configurable plugin using which you can show a dialog on website based on your requirements suggesting users new better browser to upgrade to. The plugin is hosted on github and is available under the liberal MIT license at . The plugin can be used to show the dialog not just when it is IE, but when it is IE, Firefox, Chrome, Safari, iCab of the many supported browsers. The dialog can be customized with different backgrounds, different upgrade browser suggestions etc. The github URL has the detailed description of how to use the plugin. To ease users in configuring their desired dialog with the required configuration I have developed the website hosted on github pages here. The same website is present in the example folder in the downloaded zip here along with the real plugin. I plan to include this plugin on all my websites and show dialog to any internet users still on the age old browsers especially IE 8 and below or the users using non-standard browser. One of the main reason of increase in development cost and time is due to the fact that we end up testing and supporting all the major older version of browser which are inherently buggy and non-standard compliant. Hopefully, this plugin will help some number of these users in migrating to newer browsers.

Thursday, February 28, 2013

Liftweb book

I was recently contacted by PACKT Publishing to do a review on their book about lift web framework. The book present here is authored by Torsten Uhlmann and is intended for beginners. Since, I like to read technical books and have read many in the past including a few of the reference manuals, I decided to say yes and have a go at it.
This is what I plan to base my reviews upon.
  • It should be easily understandable for the beginners and must be useful for advanced users as quick reference. 
  • Must be more than the many available tutorials you find on the web about scala/lift technologies. 
  • Should not beat around the bush and get to the point quickly, which is develop a application using scala and liftweb. 
  • The most important thing would be, I should be able to build a simple yet useful application from end to end using the knowledge in the book and by expanding on it. I have not yet decided the application, but it will be something that I plan to showcase when my current projects - an application (not yet released) using nodejs/mongodb stack and a website for myself using jquery/html that indexes all my projects - are completed to a beta level release.
  • Last but not least, it should encourage the users to proceed with using Liftweb and learn more about the awesome framework and the unique design approach taken by that framework at more depth and by themselves.
The good news and the part that excites me is the book website claims to have the "Get the Job done" approach.
Btw, I believe that all technologies are awesome and have there specific usage. Point to note though is, I like liftweb framework and I am a strong proponent of the same and I have used it for real world production deployed application during my work at Sabre Holdings. But this has nothing and has no relation to the results of my review which is strictly about the book and not the liftweb in itself. I will probably take couple of weeks before I write the review as I am working hard at my work place and involved in two other projects that I mentioned above along with my other commitments.