I’m learning Scala at the moment. It is a wicked and very powerful language. I can recommend anyone who knows Java and is tiered of the huge amount of code that is needed to write even the most mundane functionality to give it a try. Anyway, on my quest to learn Scala I am using the book Scala in Action, which I can highly recommend. In chapter 2 a Java servlet is required. The book shows the code that is required for the servlet, but does not explain how to create a servlet. Not very complicated of course, but why create the servlet using Java when you can create a servlet using Scala? What a great exercise π So I gave it a try. This is the result. Enjoy. Continue reading
Uncategorized
For loop with implicit java.util.Map conversion in Scala
Today I was converting a servlet from a Java implementation to a Scala implementation. I needed to print out the parameters (getParameterMap) and headers (getHeaderNames). These are implemented as java.util.Map collections with the following definition.
java.util.Map<java.lang.String,java.lang.String[]>
Converting a java.util.Map to scala.collections.Map
While converting an Java servlet example to Scala I ran into a little snag when I had to convert a java.util.Map to a concatenated String in Scala. Actually, I initially couldn’t figure out how to convert java.util.Map to scala.collections.Map. It turned out to be very simple. Here is the code example I came up with and tested with Scala Worksheet in Eclipse. The example is a little more elaborate, because I also needed to convert the Map to a concatenated string of key value pairs. Continue reading
Learning Scala the interactive way with Scala Worksheet in Eclipse
Learning Scala is fun, but at times like it can be a daunting and frustrating experience. Like learning any new language I guess. I have found using the Scala command line interpreter can help. It turns out the the Scala IDE for Eclipse also provides an interactive interpreter. To start an interactive interpreter create a Scala project and add a Scala Worksheet (File | New… | Scala Worksheet). Give the Scala Worksheet a name, for example TestScala, and start testing and learning. After typing a statement hit CTRL+S to save and the results of each statement are displayed at the end of each line. How easy is this?
To compile XML syntax, the scala.xml package must be on the classpath
I was creating a servlet using Scala and got the following error message “To compile XML syntax, the scala.xml package must be on the classpath”. It turns out that Scala-XML has been factored out into a separate library as of Scala 2.11, so it is not included in Scala projects by default. So the dependency needs to be include in the project build.sbt using the following statement:
libraryDependencies += "org.scala-lang.modules" %% "scala-xml" % "1.0.2"
Note as always you should check that there isn’t a newer version available of the library. How? Google is your friend π
maven org.scala-lang.modules scala-xml
Happy coding!
Quick start tutorial to Simple Build Tool (SBT)
This is a quick start tutorial to get going with SBT. It is meant for myself, but you are welcome to use it too π
For the detailed documentation please checkout the documentation on the SBT website. Continue reading
Checking where the JDK is installed under Debian/Ubuntu/Mint
I needed to find out where the Oracle JDK 7 was installed. Using the whereis command did not help. I found that using the following command shows exactly where all available JDKs are installed:
sudo update-alternatives --config java
Installing Oracle JDK 7 in Debian/Ubuntu/Mint
I am currently learning Scala and wanted to install the Scala IDE. In the process I ran into some problems that it programs would not compile correctly, which seemed to be caused by the OpenJDK 7. So I decided to remove OpenJDK 7 and install Oracle JDK 7. All the instructions I could find to do this where downloading based on manually downloading the Oracle JDK 7 and installing it interactively. As I also wanted the installation to work in a Docker container I wanted a fully automated solution. Continue reading
What happened to the user and group management commands in QNAP?
Had an interesting time figuring out how user and group management works from the command line on my QNAP server. At first the usual Linux commands do not seem to exist:
useradd usermod userdel groupadd groupmod groupdel
After some Google research (who’s your friend?) I found some forum posts that pointed out the commands have been replaced by QNAP’s own special versions: Continue reading
Playing with WSO2 ESB
I was playing around with WSO2 ESB today trying out the store forward messaging pattern. I followed a tutorial by Charith Wickramarachchi “Implementing Store and Forward Messaging Patterns with WSO2 ESB Part 2“. Great tutorial.
When it was time to test, I initially tried to use the “Try this service” option of the proxy. Continue reading
