Base64 is a straight forward encoding for binary data into readable characters (RFC 4648 and RFC 2045). Although you can do it by yourself, more often than not you would like use an existing library, for example, Apache common. If you just need the Base64 encoding but have to import the whole library, it’s not a good idea. There is actually a better way without introducing extra dependency, which is to hack Java standard library 1.6.
Thrift is mostly used for distributed systems which run mostly in house. There is no strong demand for securing the traffic on the wire. There are however use cases in which the Thrift services are exposed as a public service. In these use cases, the Thrift traffic should be secured with SSL/TLS. It comes with a price which more work on client and server on encryption and decryption. This is not a big deal for light load server, but for heavy load server it could be a problem. It can be mitigated with hardware acceleration on load balance servers between which and the client can be SSL, but not after that to the Thrift server.
As mentioned in my last post, Thrift is a cross-language and cross platform RPC framework. We’ve seen how a Java based Thrift server and client work there. Let’s take a look how to write a quick python script that connects to the Java Thrift server. It’s all possibe to write a Python based Thrift server, but probably not what most people want to do due to performance and scalability.
Since I left VCE four months ago, I have been working intensively on a commercial version of the open source vijava API supporting all versions of vSphere APIs (5.5 is the latest). If you have used the open source API, you know the vijava is much faster than other alternatives. Since its debut, it has been used in many commercial products from companies like Cisco, EMC, HP, etc.
In my recent consulting projects, I used Python on various projects including the VMware pyVmomi () for managing vSphere. Because XML is ubiqutous these days, I had to use XML for configuration, passing information, etc. Parsing XML is a very basic part of using XML. The following sample code can achieve the same thing (print out may be different) as the C# sample that parses XML I wrote before.
In one of my recent consulting projects, I had to use SSH from Python. After a little research, I ended up with using the paramiko package as library.
To download the paramiko package, just check out this link. What I downloaded was paramiko-1.12.0.tar.gz. After it’s uncompressed with 7-Zip to a temparary directory, just issue the following command and the needed library got installed into the site-packages directory.
If you have a log file that you want to monitor the incremental changes, you can use the following simple code. Whatever new log entries written to the log will be quickly picked up and printed out to console. It does not interfere with the application that writes the log file. To test the code, you can use any text editor to append more entries to the end of log file (don’t forget to save it).
It’s pretty straight forward to run Maven based projects in NetBeans IDE. For some projects that involve console related capabilities, you have to run it from OS console. One example is projects that use the JANSI APIs for colorful console output (see my last post for a sample). If you run the code within IDE, you won’t see the colors as would in a console.
Almost all of the Java console application I had seen were boring black background and white fonts on Windows. This can be changed using a small Java library called Jansi which is open sourced under Apache 2.0. The download link can be found at its project home. The source code is also available on Github here.
If you develop a command line tool, you would probably need to parse options and arguments. In Java, you can use Apache Commons CLI to handle the parsing. Since I don’t write much command line program, I don’t need these tools. While reading vCO API sample, I found one command line tool called args4j which is written by Kohsuke Kawaguchi who had created the famous Hudson/Jenkins server.
While using Netbeans IDE to generate Javadoc for a Maven project, I noticed the generated pages has a default copyright notice at the bottom of every page, say “Copyright 2013. All Rights Reserved.” Because it’s default, it does not show the name of copyright owner. To change it, I found it’s not really straight-forward, therefore it may be worthwhile to share it.
If you implement REST Web Services, you want to secure them. The simplest approach is to use the basic authentication () with user name and password. To protect all the resources behind the REST APIs, you can simply implement filter as introduced in Java Servlet 2.3 ().
Because REST APIs are easy to get started with, I see more products are adopting it for remote management APIs. To implement the REST on the server side, you can use different programming lanaguages and frameworks. In Java, you can use the Jersey framework which is a reference implementation of the JAX-RS (JSR 311 & JSR 339).
Just started to work on hacking the Web application of vCAC and REST APIs in C#. As expected, the XML processing is an indispensable part for that purpose. I have worked on C# on and off in the past, but never as consistently as on Java. To get myself familiar with the related C# APIs for parsing, I coded the following sample code.
Unit testing is an important part of software development because it helps capture bugs before it moves on to QA or even customers. However, it’s not part of the end product therefore whatever you invest in unit testing will not yield any direct result but indirect result in better quality of your product. So at one side, you want to do it more for better quality; on the other side, you want to minimize it for less investment. It’s therefore a tricky trade off for best ROI. For more discussion, see here.
While trying the libvirt Java binding, I came to know Java Native Access (JNA) which is a great alternative to Java Native Interface (JNI). As it’s said, no one can claim to know all about Java after 1.5. It’s now 1.7 (although majority of us are still with 1.6) and it’s even less likely. I am no exception.
While writing technical blogs, it’s always nice to include commands and scripts that readers can try on their own. I find it a bit challenging to accurately document these in steps while intensively testing or debugging something by myself.
There are actually commands that faithfully list all the commands you typed. You can then clean them up for your posts. In the following, I introduce how to do these on Linux, Windows.