--- layout: post status: PUBLISHED published: true title: Use Apache Ant to post to Apache ESME id: aaf2d338-5b89-45d9-bade-9fa4ba9cb8d1 date: '2011-01-18 11:28:43 -0500' categories: esme tags: - esme - microblogging permalink: esme/entry/use_apache_ant_to_post ---
Apache ESME has an integration with Apache Ant. It is now possible to send messages to Apache ESME that describe the progress of your build steps. This is especially useful when Apache ESME is being used in development projects where individual developers can be made aware of the status of various-build related actions. For example, a development team could be informed that a build is broken or if it is successful.
Here is what the result looks like:
Note: We wrote a version of this blog two years ago on our old blog. I've updated it and added an image plus more details.
"EsmeViaAnt" default="dist" basedir=".">"src" location="src"/>"build" location="build"/>"dist" location="dist"/>"project.class.path" >"./dist/lib/EsmeViaAnt.jar:./lib/esme-rest-api-0.1.jar:./lib/commons-codec-1.4.jar:./lib/commons-logging-1.1.1.jar:./lib/commons-httpclient-3.1.jar" />"init" >"${build}" />"compile" depends="init" description="compile the source " > "${src}" destdir="${build}">"project.class.path" />"dist" depends="compile" description="generate the distribution" > "${dist}/lib" />"${dist}/lib/EsmeViaAnt.jar" basedir="${build}"/>"esme" description="Send Esme" > "true" classname="EsmeAntTask"> "http://esmecloudserverapache.dickhirsch.staxapps.net/api" />"31EL0R0M15NTD2LSOS0BKC5Y0P5JOVAZ6" />"myproxy:81" />"A message from the ant build process" />"./dist/lib/EsmeViaAnt.jar:./lib/esme-rest-api-0.1.jar:./lib/commons-codec-1.4.jar:./lib/commons-logging-1.1.1.jar:./lib/commons-httpclient-3.1.jar" />EsmeAntTask java class
import org.apache.esme.api.EsmeRestApi; import org.apache.esme.model.Message; public class EsmeAntTask { public static void main (String[] args) { String apiUrl; String authToken; String localProxy; String message; EsmeRestApi esme; apiUrl = args[0]; authToken = args[1]; localProxy = args[2]; message = args[3]; try { esme = new EsmeRestApi(apiUrl); if ((localProxy != null) && !("".equals(localProxy))) { // Split proxyHost:port into two parts String[] proxy = localProxy.split(":"); esme.setProxy(proxy[0], Integer.parseInt(proxy[1])); } esme.login(authToken); Message esmeMsg = new Message(); esmeMsg.setBody(message); String[] tags = new String[1]; tags[0] = "Ant Task"; esmeMsg.setTags(tags); esmeMsg.setSource("Ant"); esme.sendMsg(esmeMsg); } catch (Exception e) {} }}