In the previous post we used the Groovy XML-RPC library, in this snippet we will use the Apache XML-RPC library. Why ? There is no basic security implemented in the Groovy XML-RPC to access for example a
The prerequisites are still the same, just we change the library:
- Download the Apache library from here. You should download a file from the binaries folder (apache-xmlrpc-3.1.2-bin.zip), inside you will find a lib subfolder with a couple of jars we need to add to the classpath.
(commons-logging-1.1.jar, xmlrpc-client-3.1.2.jar, xmlrpc-server-3.1.2.jar, ws-commons-util-1.0.2.jar, xmlrpc-common-3.1.2.jar)
Snippet:
Remark: You can add more parameters for the server with
- config.setEncoding(“UTF-8″)
config.setBasicUserName(“[username]“);
config.setBasicPassword(“[password]“);
Comments Off
It is straight forward to access Snipplr via XML-RPC with Groovy. In this tutorial we use the Groovy Console to play with Snipplr snippets.
Requirements:
Tutorial:
The MarkupBuilder is lacking of xml declaration features, so I ported the previous sample to StreamingMarkupBuilder. Unfortunately it throws the complete XML content into 1 line without CR, to make it again human-readable, aka pretty-print it, we use the XmlUtil.serialize method.
.
.
Note: mkp is part of the XML helperclass (link)
.
Comments Off
Please note the difference between MarkupBuilder and StramingMarkupBuilder. More information about XML processing at groovy.codehaus.org
MarkupBuilder is not very flexible, but simple to use for some basic task. If you require comments, XML declarations and more, your rather use the StreamingMarkupBuilder.
Comments Off
At my main blog (javadude.wordpress.com) i use the sourcecode tag to display code nicely formatted. Unfortunately you cant maintain this code other than editing the post itself. I choose to work with a (public) code snippet repository, SNIPPLR. There is a wordpress plugin available, so I can embed my code snippets from my Snipplr account and maintain it there (and also use it for different purpose as well, more on that later).
The Snipplr plugin is straight forward to install (link) and even easier to use. Just place the snipplr tag [snippet=id] and the code snippet is placed in your post.
Comments Off
Decided to move this blog to my own server, giving me more flexibility to add plugins. This page will serves as a repository for Groovy Code Snippets, Tips and Tricks. Also lists news, books and websites from the Groovy and Grails ecosystem. Enjoy reading and any feedback is highly appreciated.
The old blog is still available at groovydude.wordpress.com
Comments Off