<project name="orchestra-producer" default="usage">

  <description>Orchestra Producer Consumer example</description>

  <!-- properties files -->
  <property file="../../conf/orchestra.properties" />

  <path id="base.classpath">
    <pathelement location="../../conf"/>
    <fileset dir="../../lib">
      <include name="orchestra-jmxclient*.jar" />
    </fileset>
  </path>

  <target name="usage">
    <echo>Producer example</echo>
    <echo>To deploy the process: ant deploy</echo>
    <echo>To invoke the process as a consumer: ant launch-consumer</echo>
    <echo>To invoke the process as a producer: ant launch-producer</echo>
    <echo>To undeploy the process: ant undeploy</echo>
    <echo>Please make sure Orchestra is started before executing this example.</echo>
  </target>

  <target name="createBar">
    <propertyfile file="bar.properties">
      <entry key="bpel" value="consumerProducer.bpel"/>
      <entry key="wsdl" value="consumerProducer.wsdl"/>
    </propertyfile>
    <zip destfile="producer.bar">
      <fileset dir="." includes="*.bpel"/>
      <fileset dir="." includes="*.wsdl"/>
      <fileset dir="." includes="bar.properties"/>
    </zip>
  </target>


  <target name="deploy">
    <java classpathref="base.classpath" classname="org.ow2.orchestra.jmxclient.JMXClient" fork="yes" failonerror="true">
      <arg value="--deploy" />
      <arg value="--bpel" />
      <arg value="${basedir}/consumerProducer.bpel" />
      <arg value="--wsdls" />
      <arg value="${basedir}/consumerProducer.wsdl" />
    </java>
  </target>

  <target name="undeploy">
    <java classpathref="base.classpath" classname="org.ow2.orchestra.jmxclient.JMXClient" fork="yes" failonerror="true">
      <arg value="--undeploy" />
      <arg value="--process" />
      <arg value="{http://orchestra.ow2.org/demos/producerConsumer}producerConsumer" />
    </java>
  </target>

  <target name="launch-consumer">
    <input message="Consumer name" addproperty="consumer.name" defaultvalue="Me" />

    <java classpathref="base.classpath" classname="org.ow2.orchestra.jmxclient.JMXClient" fork="yes" failonerror="true">
      <arg value="--call" />
      <arg value="--endpoint" />
      <arg value="http://${orchestra.servlet.host}:${orchestra.servlet.port}/${orchestra.servlet.path}/consumerPort"/>
      <arg value="--soapAction" />
      <arg value="http://orchestra.ow2.org/demos/producerConsumer/request" />
      <arg value="--soapMessage" />
      <arg value="
        &lt;request xmlns='http://orchestra.ow2.org/demos/producerConsumer'&gt;
          &lt;input&gt;${consumer.name}&lt;/input&gt;
        &lt;/request&gt;
      "/>
    </java>
  </target>

  <target name="launch-producer">
    <input message="Product name :" addproperty="product.name" defaultvalue="Orchestra" />

    <java classpathref="base.classpath" classname="org.ow2.orchestra.jmxclient.JMXClient" fork="yes" failonerror="true">
      <arg value="--call" />
      <arg value="--endpoint" />
      <arg value="http://${orchestra.servlet.host}:${orchestra.servlet.port}/${orchestra.servlet.path}/producerPort"/>
      <arg value="--soapAction" />
      <arg value="http://orchestra.ow2.org/demos/producerConsumer/produce" />
      <arg value="--soapMessage" />
      <arg value="
              &lt;request xmlns='http://orchestra.ow2.org/demos/producerConsumer'&gt;
                &lt;input&gt;${product.name}&lt;/input&gt;
              &lt;/request&gt;
            "/>
    </java>
  </target>
</project>