...
- Install Apache Ant
- Install Apache Maven
- Download the Apache Commons packages "Codec" and Logger. We also need Apache "Httpclient" and . Please note that we are currently using the legacy 3.1 version of the HTTP Client.
- Check-out the ESME java client: _https://svn.apache.org/repos/asf/esme/trunk/esme-java-client_
- Perform a maven build in this directory with the following command "mvn compile package -Dmaven.test.skip=true" . This will create a jar file "esme-rest-api-0.1.jar" in the target directory.
- Create _lib _directory and copy "rest-api-0.1-SNAPSHOT.jar", "commons-codec-1.2.jar", "commons-httpclient-3.1.jar" into this directory.
- Create src directory and copy the "EsmeAntTask.java" file to this directory
- Change the build.xml file to point to the appropriate directories
- Change the token in the "esme" target in the build.xml file to a correct token.
- Change the proxy in the "esme" target in the build.xml file to a correct proxy.
- call ant dist esme to test the application
Build.xml
Code Block | ||
---|---|---|
| ||
<project name="EsmeViaAnt" default="dist" basedir="."> <!-- set global properties for this build --> <property name="src" location="src"/> <property name="build" location="build"/> <property name="dist" location="dist"/> <path id="project.class.path"> <pathelement path="./dist/lib/EsmeViaAnt.jar:./lib/esme-rest-api-0.1-SNAPSHOT.jar:./lib/commons-codec-1.24.jar:./lib/commons-logging-1.01.41.jar:./lib/commons-httpclient-3.1.jar/"/> </path> <target name="init"> <!-- Create the time stamp --> <tstamp/> <!-- Create the build directory structure used by compile --> <mkdir dir="${build}"/> </target> <target name="compile" depends="init" description="compile the source " > <!-- Compile the java code from ${src} into ${build} --> <javac srcdir="${src}" destdir="${build}"> <classpath refid="project.class.path"/> </javac> </target> <target name="dist" depends="compile" description="generate the distribution" > <!-- Create the distribution directory --> <mkdir dir="${dist}/lib"/> <!-- Put everything in ${build} into the jar file --> <jar jarfile="${dist}/lib/EsmeViaAnt.jar" basedir="${build}"/> </target> <target name="esme" description="Send Esme" > <java fork="true" classname="EsmeAntTask"> <arg value="http://apiesmecloudserverapache.dickhirsch.esmestaxapps.usnet/esme/api"/> <arg value="IFDHJ2RNDECAT84ZJZUKDE59TVOIVTXL31EL0R0M15NTD2LSOS0BKC5Y0P5JOVAC"/> <arg value="proxymyproxy:81"/> <arg value="A message from the ant build process"/> <classpath> <pathelement path="./dist/lib/EsmeViaAnt.jar:./lib/esme-rest-api-0.1-SNAPSHOT.jar:./lib/commons-codec-1.24.jar:./lib/commons-logging-1.01.41.jar:./lib/commons-httpclient-3.1.jar/"/> </classpath> </java> </target> </project> |
EsmeAntTask java class
Code Block |
---|
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.setTextsetBody(message); String[] tags = new String[1]; tags[0] = "Ant Task"; esmeMsg.setTags(tags); esmeMsg.setViasetSource("Ant"); esme.sendMsg(esmeMsg); } catch (Exception e) {} } } |