<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" version="2.0">

<channel>
	<title>It's not a blog, It's a feature</title>
	
	<link>http://javazquez.com/juan</link>
	<description>Juan A. Vazquez</description>
	<lastBuildDate>Fri, 22 Mar 2013 22:48:33 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/ItsNotABlogItsAFeature" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="itsnotablogitsafeature" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Add Map, Reduce, and Filter to Groovy with an Extension Module</title>
		<link>http://javazquez.com/juan/2013/02/05/add-map-reduce-and-filter-to-groovy-with-groovy-extension-modules/</link>
		<comments>http://javazquez.com/juan/2013/02/05/add-map-reduce-and-filter-to-groovy-with-groovy-extension-modules/#comments</comments>
		<pubDate>Wed, 06 Feb 2013 01:50:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[Gradle]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[jvm]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[functional]]></category>
		<category><![CDATA[Howto]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://javazquez.com/juan/?p=476</guid>
		<description><![CDATA[To solidify my new understanding of Groovy's Extension Modules, I decided that I needed to write some code. The example I came up with was to have the functional names (map, reduce, filter ) that I had come familiar with in using Clojure added to Groovy. These "extended methods" are using Groovy's built-in collect, inject, and grep under the hood.
]]></description>
				<content:encoded><![CDATA[<p>Having just read <a href="http://mally.pl/working-with-legacy-code-is-fun-now/" target="_blank"><span> Michał Mally&#8217;s blog</span></a> that was posted on <a title="Groovy+" href="https://plus.google.com/communities/105160926044623621768" target="_blank">Google+</a>,<br />
I was intrigued with two benefits listed in the blog:</p>
<ul>
<li>The idea of being able to augment Groovy with changes that would behave as &#8220;if they were a part of original GDK&#8221;</li>
<li>support from your IDE like code completion shall be available out-of-the-box</li>
</ul>
<p>In order to get my head around how Extension modules worked, I used the following as references<br />
<a href="http://docs.codehaus.org/display/GROOVY/Creating+an+extension+module" target="_blank">Creating an extension module</a><br />
<a href="http://mrhaki.blogspot.com/2013/01/groovy-goodness-adding-extra-methods.html" target="_blank">Groovy Goodness: Adding Extra Methods Using Extension Modules </a><br />
<a href="http://blog.andresteingress.com/2012/09/07/groovy-extension-modules/" target="_blank">Groovy Extension Modules</a></p>
<p><a href="https://plus.google.com/116089789718222474948/posts" target="_blank">Cédric Champeau </a> had this to say after I asked about the benefits of Extension Modules over using MetaClass/Expando/Category</p>
<blockquote><p>@Juan: extension modules are automatically loaded and made available globally. You don&#8217;t have to bother with metaclasses (and potential issues with external changes). As well, categories are lexically scoped, although extension modules are global (meaning that they can be used anywhere in the code as long as the extension module is found on classpath).</p>
<p>Last but not least, extension modules are compatible with type checking and static compilation <img src='http://javazquez.com/juan/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p></blockquote>
<p>To solidify my new understanding of Groovy&#8217;s Extension Modules, I decided that I needed to write some code. The example I came up with was to have the functional names (map, reduce, filter ) that I had come familiar with in using <a href="http://clojure.org/" target="_blank">Clojure</a> added to Groovy. These &#8220;extended methods&#8221; are using Groovy&#8217;s built-in collect, inject, and grep under the hood.</p>
<p>Source code can be found <a href="https://github.com/javazquez/Groovy/tree/master/FuncProgExtensionModule" target="_blank">here</a></p>
<p>Here is the code for the new aliases found in the <a href="https://github.com/javazquez/Groovy/blob/master/FuncProgExtensionModule/src/main/groovy/com/javazquez/FuncProgUtilExtension.groovy" title="FuncProgExtensionModule" target="_blank"><strong>FuncProgUtilExtension.groovy</strong></a> class</p>
<pre class="brush: groovy; gutter: true">package com.javazquez;

public class FuncProgUtilExtension {
    public static Collection filter(Collection self, Closure clozure) {
	   return self.grep(clozure)
   }
   public static Collection map(Collection self, Closure clozure) {
	   return self.collect(clozure)
   }
   public static Object reduce(Collection self, Closure clozure) {
	   return self.inject(clozure)
   }
   public static Object reduce(Collection self, String operator) {
	   switch(operator){
		   case &#039;+&#039; :
		      self.inject({acc, val -&gt; acc + val})
			  break
		   case &#039;-&#039; :
			   self.inject({acc, val -&gt; acc - val})
			   break
		   case&#039;*&#039; :
			   self.inject({acc, val -&gt; acc * val})
			   break
		   case &#039;/&#039;:
		   	   self.inject({acc, val -&gt; acc / val})
			   break
		   case&#039;**&#039;:
		   	   self.inject({acc, val -&gt; Math.pow(acc, val)})
			   break
		   default:
			   throw new IllegalArgumentException()
			   break
	   }
   }
}</pre>
<p>In a file named &#8216;org.codehaus.groovy.runtime.ExtensionModule&#8217; located in <a href="https://github.com/javazquez/Groovy/blob/master/FuncProgExtensionModule/src/main/resources/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule" target="_blank">&#8216;src/main/resources/META-INF/services/&#8217;</a></p>
<p>I have the following<br />
<code><br />
moduleName=<span>JavazquezFuncProgTest<br />
moduleVersion=1.0<br />
extensionClasses=com.javazquez.FuncProgUtilExtention<br />
</span></code></p>
<p><span>Using <span>spock</span>, I wrote the following </span><a href="https://github.com/javazquez/Groovy/blob/master/FuncProgExtensionModule/src/test/groovy/com/javazquez/FuncProgUtilSpec.groovy" target="_blank">tests</a> :</p>
<pre class="brush: groovy; gutter: true">package com.javazquez

import spock.lang.Specification

class FuncProgUtilSpec extends Specification{

	def &quot;test map&quot;(){
		expect:
			[ 1 ,2 ,3 ,4].map{it*2} == 	[ 1 ,2 ,3 ,4].collect{ it*2 } 	
	}	
	def &quot;test reduce &quot;(){
		expect:
			[ 1 ,2 ,3].reduce(&#039;*&#039;) == 6
			[ 1 ,2 ,3,4].reduce(&#039;+&#039;) == 10
			[ &#039;1&#039; ,&#039;2&#039; ,&#039;3&#039;,&#039;4&#039;].reduce(&#039;+&#039;) == &#039;1234&#039;
			[ 1 ,2 ,3].reduce(&#039;-&#039;) == -4
			[ 2, 2 ,2].reduce(&#039;**&#039;) == 16
			[ 1 ,2 ,3].reduce({acc, val -&gt; acc + val}) ==[ 1 ,2 ,3].inject { acc, val -&gt; acc + val}
	}
	def &quot;test invalid argument&quot;(){
	 	when:
	 		[ 1 ,2 ,3,4].reduce(&#039;%&#039;)
		then:
			thrown(IllegalArgumentException)
	}
	def &quot;test filter&quot;(){
		expect:
			[1,2,3,4,5,6,7,8,9].filter { it % 2 ==0 } == [2,4,6,8]
			[1,2,3,4,5,6,7,8,9].filter { it &gt; 2 } == [3,4,5,6,7,8,9]
			&quot;Juan Vazquez&quot;.toList().filter { it ==~ /[aeiou]/} == [&#039;u&#039;,&#039;a&#039;,&#039;a&#039;,&#039;u&#039;,&#039;e&#039;]
	}
}</pre>
<p>My biggest obstacle was getting the directory structure correct. It is amazing how little code was required to accomplish my goal. I hope my example project and listed references will help in your understanding of this powerful feature. My next step with this project going to be to make evaluation lazy.</p>
<img src="http://feeds.feedburner.com/~r/ItsNotABlogItsAFeature/~4/rfCPjmnS2Xg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://javazquez.com/juan/2013/02/05/add-map-reduce-and-filter-to-groovy-with-groovy-extension-modules/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Groovy Invoke Dynamic Support</title>
		<link>http://javazquez.com/juan/2013/01/26/groovy-invoke-dynamic-support/</link>
		<comments>http://javazquez.com/juan/2013/01/26/groovy-invoke-dynamic-support/#comments</comments>
		<pubDate>Sun, 27 Jan 2013 02:41:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jvm]]></category>
		<category><![CDATA[configuration]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://javazquez.com/juan/?p=463</guid>
		<description><![CDATA[In order to get things working, I read that I needed to get the "indy" jar on my classpath. I added the following to my .bash_profile and restarted my terminal and the error cleared up]]></description>
				<content:encoded><![CDATA[<p>The release of Groovy 2.1 comes with <a title="" href="http://groovy.codehaus.org/Groovy+2.1+release+notes?nc#Groovy21releasenotes-Fullinvokedynamicsupport" target="_blank">full Invoke Dynamic Support</a>. Initially I had issues with trying to get a working example up and running as seen by the following message.</p>
<p><strong>&gt;groovy &#8211;indy mergesort.groovy</strong><br />
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:<br />
General error during class generation: Cannot use invokedynamic, indy module was excluded from this build.</p>
<p>I checked the groovy version to make sure that I had Java 7 loaded as seen here<br />
<strong>groovy -version</strong><br />
Groovy Version: 2.1.0 JVM: 1.7.0_11 Vendor: Oracle Corporation OS: Mac OS X</p>
<p>In order to get things working, I read that <a title="" href="http://derjan.io/blog/2012/08/08/first-steps-with-groovys-invokedynamic-support/" target="_blank">I needed to get the &#8220;indy&#8221; jar on my classpath</a>. I added the following to my .bash_profile and restarted my terminal and the error cleared up</p>
<p><strong>export CLASSPATH=$HOME/.gvm/groovy/current/indy/groovy-2.1.0-indy.jar</strong></p>
<p>Hope this helps and a huge thanks to the Groovy Core Team for this latest update!</p>
<p>-Juan</p>
<img src="http://feeds.feedburner.com/~r/ItsNotABlogItsAFeature/~4/GQ1TuUBYJFE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://javazquez.com/juan/2013/01/26/groovy-invoke-dynamic-support/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using Groovy closures to fake Python generators</title>
		<link>http://javazquez.com/juan/2012/09/08/using-groovy-closures-to-fake-python-generators/</link>
		<comments>http://javazquez.com/juan/2012/09/08/using-groovy-closures-to-fake-python-generators/#comments</comments>
		<pubDate>Sat, 08 Sep 2012 20:10:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Groovy]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[closure]]></category>
		<category><![CDATA[fibonacci]]></category>
		<category><![CDATA[Generator]]></category>

		<guid isPermaLink="false">http://javazquez.com/juan/?p=368</guid>
		<description><![CDATA[Here is a quick example of faking python generators with Groovy. Please update the comments if you have a better approach. def (a,b,sent,acc) = [0,1,null,0] def fib={ (a,b) = [b,a+=b] a } while(true){ currFibValue = fib() if( currFibValue &#62; 4000000) break else if( currFibValue % 2 ==0) acc += currFibValue } println acc]]></description>
				<content:encoded><![CDATA[<p>Here is a quick example of faking python generators with Groovy. Please update the comments if you have a better approach. </p>
<pre class="brush: groovy; gutter: true; first-line: 1; highlight: []; html-script: false">
def (a,b,sent,acc) = [0,1,null,0]
def fib={
    (a,b) = [b,a+=b]
    a
}

while(true){
    currFibValue = fib()
    if( currFibValue &gt; 4000000) break
    else if( currFibValue % 2 ==0) acc += currFibValue
}
println acc
</pre>
<img src="http://feeds.feedburner.com/~r/ItsNotABlogItsAFeature/~4/ZFO5VnumEZY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://javazquez.com/juan/2012/09/08/using-groovy-closures-to-fake-python-generators/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Clojure Soundex</title>
		<link>http://javazquez.com/juan/2012/08/28/clojure-soundex/</link>
		<comments>http://javazquez.com/juan/2012/08/28/clojure-soundex/#comments</comments>
		<pubDate>Wed, 29 Aug 2012 03:57:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Clojure]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[jvm]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[Howto]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[soundex]]></category>

		<guid isPermaLink="false">http://javazquez.com/juan/?p=343</guid>
		<description><![CDATA[In need of a quick program to force myself to dive in to clojure, I chose to implement a soundex program that I at one time had written in C++. It was a fun exercise to step back and look at how my thought process changed based on the language I used. Hope you find [...]]]></description>
				<content:encoded><![CDATA[<p>In need of a quick program to force myself to dive in to clojure, I chose to implement a <a title="Soundex wiki" href="http://en.wikipedia.org/wiki/Soundex" target="_blank">soundex </a>program that I at one time had written in C++. It was a fun exercise to step back and look at how my thought process changed based on the language I used. Hope you find this useful.</p>
<p>&nbsp;</p>
<pre>;steps
;1 keep first letter
;2 replace consonants
;3 remove w and h
;4 two adjacent are same, letters with h or w separating are also the same
;5 remove vowels
;6 continue until 1 letter 3 nums</pre>
<pre class="brush: groovy; gutter: true">(use &#039;clojure.contrib.str-utils)

(defn trnsfrm[ word]
  (-&gt;&gt;
    (re-gsub #&quot;(?i)[fbvp]&quot; &quot;1&quot; word)
    (re-gsub #&quot;(?i)[cgjkqsxz]&quot; &quot;2&quot; ,,) 
    (re-gsub #&quot;(?i)[dt]&quot; &quot;3&quot; ,,) 
    (re-gsub #&quot;(?i)[l]&quot; &quot;4&quot; ,,)
    (re-gsub #&quot;(?i)[mn]&quot; &quot;5&quot; ,,)
    (re-gsub #&quot;(?i)[r]&quot; &quot;6&quot; ,,)))

(defn replace-adjacent [word] 
  (-&gt;&gt; (re-gsub  #&quot;(?i)[wh]&quot; &quot;&quot; word ) 
  	trnsfrm 
  	(re-gsub #&quot;(?i)([a-z0-9])\1+&quot; &quot;$1&quot; )))  	

(defn pad [word](subs (str word &quot;0000&quot;) 0 4))  	

(defn do-soundex [word]
    (pad ( str (first word)(re-gsub #&quot;[aeiouy]&quot;  &quot;&quot; (subs (replace-adjacent word) 1)))))</pre>
<p><strong>Update Refactored version</strong><br />
Not quite happy with the above example, I decided to see if I could refactor my code. Below is what I came up with(4 less lines code).</p>
<pre class="brush: groovy; gutter: true">(use &#039;clojure.contrib.str-utils)

(def re-map{ #&quot;(?i)[fbvp]&quot; &quot;1&quot;,#&quot;(?i)[cgjkqsxz]&quot; &quot;2&quot;,#&quot;(?i)[dt]&quot; &quot;3&quot;,#&quot;(?i)[l]&quot; &quot;4&quot;,#&quot;(?i)[mn]&quot; &quot;5&quot;,#&quot;(?i)[r]&quot; &quot;6&quot; })

(defn trns [word] (map #(re-gsub (key %1) (val %1) word) re-map))

(defn pad [word](subs (str word &quot;0000&quot;) 0 4))

(defn rm1 [word] (apply str(drop 1 word)))

(defn do-soundex [word]
    (pad(str (first word) (-&gt;&gt;
        (re-gsub #&quot;(?i)[^aeiou\d]&quot; &quot;&quot; (apply str (apply interleave (trns word ))))
        (re-gsub #&quot;(?i)([a-z\d])\1+&quot; &quot;$1&quot; )
        rm1
        (re-gsub #&quot;(?i)[a-z]&quot; &quot;&quot; )))))</pre>
<p>&nbsp;</p>
<p><strong>Now for the test cases</strong></p>
<pre class="brush: groovy; gutter: true">;;;Start test
(=(do-soundex  &quot;Ashcroft&quot;) &quot;A261&quot;)
(=(do-soundex  &quot;Ashcraft&quot;) &quot;A261&quot;)
(=(do-soundex  &quot;Tymczak&quot;) &quot;T522&quot;)
(=(do-soundex  &quot;Pfister&quot;) &quot;P236&quot;)
(=(do-soundex&quot;lukaskiewicz&quot;)&quot;l222&quot;)
(=(do-soundex&quot;Rubin&quot;)&quot;R150&quot;)
(=(do-soundex&quot;Rupert&quot;)&quot;R163&quot;)
(=(do-soundex&quot;Robert&quot;)&quot;R163&quot;)
(=(do-soundex &quot;Vazquez&quot;)&quot;V220&quot;)

;;;end test</pre>
<img src="http://feeds.feedburner.com/~r/ItsNotABlogItsAFeature/~4/NZZK_sg9V-A" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://javazquez.com/juan/2012/08/28/clojure-soundex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple Groovy project using Gradle</title>
		<link>http://javazquez.com/juan/2011/11/15/simple-groovy-project-using-gradle/</link>
		<comments>http://javazquez.com/juan/2011/11/15/simple-groovy-project-using-gradle/#comments</comments>
		<pubDate>Wed, 16 Nov 2011 02:40:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[Gradle]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jvm]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[configuration]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[Howto]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://javazquez.com/juan/?p=378</guid>
		<description><![CDATA[Gradle is a fantastic tool and I hope this article helps show the ease of getting a project set up.]]></description>
				<content:encoded><![CDATA[<p>Hello fellow Groovyists <img src='http://javazquez.com/juan/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I have been kicking the tires on using Gradle for my Groovy projects. I had a few stumbles along the way and wanted to share what I came up with for getting a very simple example working.</p>
<p>build.gradle<br />
<code><br />
apply plugin: 'groovy'<br />
version = "1.0-${new Date().format('yyyyMMdd')}"</p>
<p>manifest.mainAttributes("Main-Class" : "com.javazquez.HelloThere")</p>
<p>repositories {<br />
    mavenCentral()<br />
	mavenRepo urls: "http://groovypp.artifactoryonline.com/groovypp/libs-releases-local"<br />
}<br />
dependencies {<br />
	groovy group: 'org.codehaus.groovy', name: 'groovy-all', version: '1.8.4'<br />
	groovy group: 'org.mongodb', name: 'mongo-java-driver', version: '2.6.5'<br />
	groovy group: 'com.gmongo', name: 'gmongo', version: '0.9.1'<br />
	testCompile "org.spockframework:spock-core:0.5-groovy-1.8"<br />
}</p>
<p>jar {<br />
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }<br />
}<br />
</code></p>
<p>below is the the HelloThere.groovy file located src/main/groovy/com/javazquez/HelloThere<br />
<code><br />
package com.javazquez<br />
public class HelloThere {</p>
<p>    public static void main(String []args) {<br />
        println "Hello coders!"</p>
<p>    }    </p>
<p>}<br />
</code></p>
<p>after running <strong>gradle build</strong>, I can navigate to the build/libs directory and run <strong>java -jar HelloThere-1.0-20111115.jar </strong> and get the following ouptut</p>
<p>Hello coders!</p>
<p>Gradle is a fantastic tool and I hope this article helps show the ease of getting a project set up.</p>
<img src="http://feeds.feedburner.com/~r/ItsNotABlogItsAFeature/~4/pZDBsWCbOJE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://javazquez.com/juan/2011/11/15/simple-groovy-project-using-gradle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Activiti GET/POST REST requests with Groovy</title>
		<link>http://javazquez.com/juan/2011/10/12/activiti-getpost-rest-requests-with-groovy/</link>
		<comments>http://javazquez.com/juan/2011/10/12/activiti-getpost-rest-requests-with-groovy/#comments</comments>
		<pubDate>Thu, 13 Oct 2011 00:30:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Groovy]]></category>
		<category><![CDATA[activiti]]></category>
		<category><![CDATA[Authentication]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[GET]]></category>
		<category><![CDATA[Howto]]></category>
		<category><![CDATA[POST]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://javazquez.com/juan/?p=371</guid>
		<description><![CDATA[I have been working with <a href="http://activiti.org/index.html" title="Activiti " target="_blank">Activiti</a> lately and needed to test the Rest API included with the demo. Below are the GET and POST requests I whipped up using Groovy.]]></description>
				<content:encoded><![CDATA[<p>I have been working with <a href="http://activiti.org/index.html" title="Activiti " target="_blank">Activiti</a> lately and needed to test the REST API included with the demo. Below are the GET and POST requests I whipped up using Groovy. Hope you find this useful <img src='http://javazquez.com/juan/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<pre><code>
//---Get Request
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.5.0' )
import groovyx.net.http.RESTClient

def client = new RESTClient('http://localhost:8080/activiti-rest/service/process-engine')
println client.get(headers:[Authorization:"Basic ${'kermit:kermit'.bytes.encodeBase64()}"]).data

// output
[name:default, exception:null, version:5.7, resourceUrl:jar:file:/Users/juanvazquez/Documents/activiti-5.7/apps/apache-tomcat-6.0.32/webapps/activiti-rest/WEB-INF/lib/activiti-cfg.jar!/activiti.cfg.xml]


// POST request
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.5.0' )
import static groovyx.net.http.ContentType.JSON

def jsonObj = new groovy.json.JsonBuilder()
jsonObj{
  userId 'kermit'
  password 'kermit'
}
def client = new groovyx.net.http.RESTClient('http://localhost:8080/activiti-rest/service/login')
def response = client.post(contentType: JSON, body:jsonObj.toString() )

println response.data           

//output
[success:true]
</code></pre>
<img src="http://feeds.feedburner.com/~r/ItsNotABlogItsAFeature/~4/c0q3z_ubhH0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://javazquez.com/juan/2011/10/12/activiti-getpost-rest-requests-with-groovy/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>POP3 Gmail access with Clojure and JavaMail</title>
		<link>http://javazquez.com/juan/2011/05/25/pop3-gmail-access-with-clojure-and-javamail/</link>
		<comments>http://javazquez.com/juan/2011/05/25/pop3-gmail-access-with-clojure-and-javamail/#comments</comments>
		<pubDate>Wed, 25 May 2011 22:44:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Administration]]></category>
		<category><![CDATA[Clojure]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jvm]]></category>
		<category><![CDATA[gmail]]></category>
		<category><![CDATA[google api]]></category>
		<category><![CDATA[Howto]]></category>
		<category><![CDATA[javamail]]></category>
		<category><![CDATA[pop3]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://javazquez.com/juan/?p=357</guid>
		<description><![CDATA[I recently had the need to access gmail using Clojure. I used JavaMail to accomplish this via pop3. Below is some code that I wrote to help me get emails. Hope you find it useful Enjoy (use '[clojure.contrib.duck-streams]) (def props (System/getProperties)) ; Get the default Session object. (def session (javax.mail.Session/getDefaultInstance props)) ; Get a Store [...]]]></description>
				<content:encoded><![CDATA[<p>I recently had the need to access gmail using Clojure. I used JavaMail to accomplish this via pop3. Below is some code that I wrote to help me get emails. Hope you find it useful  Enjoy <img src='http://javazquez.com/juan/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><code><br />
(use '[clojure.contrib.duck-streams])<br />
(def props (System/getProperties))<br />
  ; Get the default Session object.<br />
  (def session (javax.mail.Session/getDefaultInstance props))</p>
<p>  ; Get a Store object that implements the specified protocol.<br />
  (def store (.getStore session "pop3s"))</p>
<p>  ;Connect to the current host using the specified username and password.<br />
  (.connect store "pop.gmail.com" "username@gmail.com" "password")</p>
<p>  ;Create a Folder object corresponding to the given name.<br />
  (def folder (. store getFolder "inbox"))</p>
<p>  ; Open the Folder.<br />
(.open folder (javax.mail.Folder/READ_ONLY ))<br />
  ; Get the messages from the server<br />
  (def messages (.getMessages folder))</p>
<p>   (defn getFrom [message](javax.mail.internet.InternetAddress/toString (.getFrom message)))<br />
   (defn getReplyTo [message] (javax.mail.internet.InternetAddress/toString (.getReplyTo message)) )<br />
   (defn getSubject [message] (.getSubject message))</p>
<p>   ;print out the body of the message<br />
      (for [m messages] (read-lines(.getInputStream m)) )</p>
<p>;;;;;code for sending an email</p>
<p>(def props (System/getProperties))<br />
(. props put "mail.smtp.host", "smtp.gmail.com")<br />
(. props put "mail.smtp.port", "465")<br />
(. props put "mail.smtp.auth", "true")<br />
(. props put "mail.transport.protocol", "smtps")</p>
<p>(def session (javax.mail.Session/getDefaultInstance props nil))<br />
(def msg (javax.mail.internet.MimeMessage. session))<br />
(. msg setFrom (javax.mail.internet.InternetAddress. "sender@gmail.com"))<br />
(. msg addRecipients javax.mail.Message$RecipientType/TO<br />
   "receiver@gmail.com") </p>
<p>(. msg  setSubject "i am the subject")<br />
(. msg setText "I am the body!!!")</p>
<p>(. msg setHeader "X-Mailer", "msgsend")<br />
(. msg setSentDate (java.util.Date.))</p>
<p>    ; send the email<br />
(def transport (. session getTransport))<br />
(. transport connect "smtp.gmail.com" 465 "sender@gmail.com" "password")<br />
(. transport sendMessage msg (. msg getRecipients javax.mail.Message$RecipientType/TO))<br />
(. transport close)<br />
</code></p>
<img src="http://feeds.feedburner.com/~r/ItsNotABlogItsAFeature/~4/1ast98nxLNU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://javazquez.com/juan/2011/05/25/pop3-gmail-access-with-clojure-and-javamail/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Writing a PayPal SOAP client with Java 6</title>
		<link>http://javazquez.com/juan/2011/02/18/writing-a-paypal-soap-client-with-java-6/</link>
		<comments>http://javazquez.com/juan/2011/02/18/writing-a-paypal-soap-client-with-java-6/#comments</comments>
		<pubDate>Sat, 19 Feb 2011 02:50:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jvm]]></category>
		<category><![CDATA[client]]></category>
		<category><![CDATA[consume]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[Howto]]></category>
		<category><![CDATA[jax-ws]]></category>
		<category><![CDATA[PayPal]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[SOAP]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[wsdl]]></category>

		<guid isPermaLink="false">http://javazquez.com/juan/?p=318</guid>
		<description><![CDATA[I have always been mystified on the inner workings of SOAP. That was until I learned about the "wsimport" utility that comes with Java 6. It makes the entire process very easy. Below is an example of writing a SOAP client for PayPal's Sandbox. This code will execute the SetExpressCheckout API call. ]]></description>
				<content:encoded><![CDATA[<p>I have always been mystified on the inner workings of SOAP. That was until I learned about the &#8220;wsimport&#8221; utility that comes with Java 6. It makes the entire process very easy. Below is an example of writing a SOAP client for PayPal&#8217;s Sandbox. This code will execute the SetExpressCheckout API call. </p>
<p>Just enter the following on your command line to generate the com.javazquez package</p>
<p><strong>wsimport -keep -XadditionalHeaders -Xnocompile -p com.javazquez http://www.sandbox.paypal.com/wsdl/PayPalSvc.wsdl</strong></p>
<p>open your favorite java editor(I used eclipse) and add the package(“com.javazquez”..created in the above command) to your new project </p>
<p>next, write some code to test out the APIs<br />
<code><br />
package com.javazquez;</p>
<p>import javax.xml.ws.Holder;<br />
public class TestEC {</p>
<p>	public static void main(String[] args) {<br />
         SetExpressCheckoutReq req = new SetExpressCheckoutReq();<br />
         SetExpressCheckoutRequestType reqType = new SetExpressCheckoutRequestType();<br />
         SetExpressCheckoutRequestDetailsType details = new SetExpressCheckoutRequestDetailsType();<br />
         AddressType addr = new AddressType();<br />
         addr.cityName = "omaha";<br />
         addr.street1 = "123 main";<br />
         addr.country = CountryCodeType.US;<br />
         addr.name = "joe tester";</p>
<p>         details.address = addr;<br />
         details.orderTotal = new BasicAmountType();<br />
         details.orderTotal.currencyID = CurrencyCodeType.USD;<br />
         details.orderTotal.value = "1.00";<br />
         details.cancelURL = "http://javazquez.com/cancel";<br />
         details.returnURL = "http://javazquez.com/return";</p>
<p>         reqType.setVersion("2.10");</p>
<p>         reqType.setExpressCheckoutRequestDetails = details;<br />
         req.setSetExpressCheckoutRequest(reqType);</p>
<p>         UserIdPasswordType user = new UserIdPasswordType();<br />
         user.username = "XXX";<br />
         user.password = "XXXX";<br />
         user.signature = "XXXX";</p>
<p>         PayPalAPIInterfaceService pp = new PayPalAPIInterfaceService();<br />
         PayPalAPIAAInterface pinterface = pp.getPayPalAPIAA();<br />
         Holder<CustomSecurityHeaderType> security = new Holder(new CustomSecurityHeaderType());<br />
         security.value.setCredentials(user);<br />
         try{<br />
               SetExpressCheckoutResponseType resp = pinterface.setExpressCheckout(req, security);<br />
               System.out.println(resp.token);<br />
               System.out.println(resp.correlationID);<br />
               for(ErrorType msg: resp.errors){<br />
                     System.out.println(msg.longMessage);<br />
               }<br />
         }<br />
         catch(Exception ex){<br />
               System.out.println(ex.getMessage());</p>
<p>         }<br />
	}</p>
<p>}</p>
<p></code></p>
<img src="http://feeds.feedburner.com/~r/ItsNotABlogItsAFeature/~4/UdS5ikh0dds" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://javazquez.com/juan/2011/02/18/writing-a-paypal-soap-client-with-java-6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>(def Bonjour-Clojure “Welcome to functional programming”)</title>
		<link>http://javazquez.com/juan/2011/01/01/def-bonjour-clojure-welcome-to-functional-programming/</link>
		<comments>http://javazquez.com/juan/2011/01/01/def-bonjour-clojure-welcome-to-functional-programming/#comments</comments>
		<pubDate>Sat, 01 Jan 2011 20:54:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Clojure]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jvm]]></category>
		<category><![CDATA[functional]]></category>
		<category><![CDATA[Howto]]></category>
		<category><![CDATA[language]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://javazquez.com/juan/?p=285</guid>
		<description><![CDATA[This post will follow my usual getting started with a language snippets.<br/><br/> 

(defn count-consonants [string] (count ( re-seq  #"[^aeiouAEIOU\s]" string )))
<br/> 
(defn count-vowels [string] (count ( re-seq  #"[aeiouAEIOU\s]" string )))
<br/> 
;read a file into a list.. any suggestions on other ways are welcome :)<br/> 
;usage (file-lines "string_path_to_file")<br/> 
(defn file-lines [file] (with-open [rdr (clojure.java.io/reader file)] ( set ( line-seq rdr))))
<br/> ]]></description>
				<content:encoded><![CDATA[<p>After the briefest of introductions to functional programming in college(a la Lisp) and dabbling with Scala, I took the functional plunge and started using Clojure recently. At this point, I have only written a couple of small programs and haven&#8217;t formed much of an opinion on where it stacks against my current favorite language at the moment(Groovy). This post will follow my usual getting started with a language snippets. I plan to write more entries as I get more familiar with the language.  On to the code!</p>
<p>&#8212;<br />
;binding<br />
user=> (def Bonjour-Clojure &#8220;Welcome to functional programming&#8221;)<br />
#&#8217;user/Bonjour-Clojure<br />
user=> Bonjour-Clojure<br />
&#8220;Welcome to functional programming&#8221;</p>
<p>;items in a list can be seperated via a comma or white space..<br />
user=> (= [ 1 2 3] [1,2,3])<br />
true</p>
<p>;count the number of consonants in a string<br />
(defn count-consonants [string] (count ( re-seq  #&#8221;[^aeiouAEIOU\s]&#8221; string )))<br />
user=> (count-consonants &#8220;writing code is fun&#8221;)<br />
10</p>
<p>;count the number of vowels in a string<br />
(defn count-vowels [string] (count ( re-seq  #&#8221;[aeiouAEIOU\s]&#8221; string )))<br />
user=> (count-vowels &#8220;lukaskiewicz&#8221;)<br />
5</p>
<p>;read a file into a list.. any suggestions on other ways are welcome <img src='http://javazquez.com/juan/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
;usage (file-lines &#8220;string_path_to_file&#8221;) or to read a webpage ((file-lines &#8220;http://javazquez.com&#8221;)<br />
(defn file-lines [file] (with-open [rdr (clojure.java.io/reader file)] ( set ( line-seq rdr))))</p>
<p>;view objects class<br />
user=>(class &#8220;Im a string&#8221;)<br />
java.lang.String</p>
<p>;length of string<br />
user=>(count &#8220;I am 18 chars long&#8221;)<br />
18</p>
<p>user=>(range 1 9)<br />
(1 2 3 4 5 6 7 8 )</p>
<p>;repeat a digit<br />
user=>(repeat 4 3)<br />
(3 3 3 3)</p>
<p>;list comprehension<br />
user=>(for [fruit ["apple" "orange" "grape"] ] (str fruit))<br />
(&#8220;apple&#8221; &#8220;orange&#8221; &#8220;grape&#8221;)</p>
<p>;use map to create a new list&#8230; #() is a shortcut for an anonymous<br />
user=>(map #(* 2 %1) [1 2 3 4])<br />
(2 4 6 8 )</p>
<p>; also an anonymous function<br />
user=> (map (fn [item](* 2 item)) [1 2 3 4])<br />
(2 4 6 8 )</p>
<p>;simple fiter example on a list using odd?<br />
user=> (filter odd? [1, 2,3,4,5])<br />
(1 3 5)</p>
<p>;factorial using reduce<br />
user=> (reduce * [1 2 3])<br />
6</p>
<p>;if statement<br />
user=> (if true (str &#8220;i am true&#8221;)(str &#8220;i am false&#8221;))<br />
&#8220;i am true&#8221;</p>
<img src="http://feeds.feedburner.com/~r/ItsNotABlogItsAFeature/~4/mMQ8GkPm84o" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://javazquez.com/juan/2011/01/01/def-bonjour-clojure-welcome-to-functional-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Login with Basic Authentication using Groovy</title>
		<link>http://javazquez.com/juan/2010/11/01/login-with-basic-authentication-using-groovy/</link>
		<comments>http://javazquez.com/juan/2010/11/01/login-with-basic-authentication-using-groovy/#comments</comments>
		<pubDate>Tue, 02 Nov 2010 02:21:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Administration]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[configuration]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://javazquez.com/juan/?p=278</guid>
		<description><![CDATA[Hey there fellow Groovyists! I was recently in need of performing Basic Authentication on Apache using Groovy for a proof of concept. Below is what I was able to quickly put together. //Here is a quick groovy 1.7.4 Basic Auth Example @Grab(group=&#8217;org.codehaus.groovy.modules.http-builder&#8217;, module=&#8217;http-builder&#8217;, version=&#8217;0.5.0&#8242; ) def authSite = new groovyx.net.http.HTTPBuilder( &#8216;http://10.110.201.115/~juanvazquez/basicAuth/&#8217; ) authSite.auth.basic &#8216;user&#8217;, &#8216;pwd&#8217; [...]]]></description>
				<content:encoded><![CDATA[<p>Hey there fellow Groovyists! I was recently in need of performing Basic Authentication on <a href="http://www.webreference.com/programming/apache_authentication/">Apache</a> using Groovy for a proof of concept. Below is what I was able to quickly put together.</p>
<p>//Here is a quick groovy 1.7.4 Basic Auth Example<br />
@Grab(group=&#8217;org.codehaus.groovy.modules.http-builder&#8217;, module=&#8217;http-builder&#8217;, version=&#8217;0.5.0&#8242; )</p>
<p>def authSite = new groovyx.net.http.HTTPBuilder( &#8216;http://10.110.201.115/~juanvazquez/basicAuth/&#8217; )<br />
authSite.auth.basic &#8216;user&#8217;, &#8216;pwd&#8217;<br />
println authSite.get( path:&#8217;testAuth.html&#8217; )</p>
<img src="http://feeds.feedburner.com/~r/ItsNotABlogItsAFeature/~4/GkIXhH7zia0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://javazquez.com/juan/2010/11/01/login-with-basic-authentication-using-groovy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
