Read data to XML using apache ant

Here we have explained a few steps how to integrate Procesy5 with apache ant framework.

This example also shows some extra informations that may be very helpful to extend your current knowledge.

During our system integrations and development, we achieved many problems which were mainly related to different Java Runtime Environment .

We noticed the following problems:

  1. SSL certificates were not correctly identificated as valid
  2. Systems have multiple versions of JRE , with also different place of their keystore.

To solve this issues and also to show useful scenario prepared the following reciept:

  1. We created an Ant Build.xml with several Tasks to achieve SSL problems
    1. Verify if we are sure that we have correct SSL certificates downloaded to keystore. The target name import_ssl_certificates_to_system_check
      Note: This task is intend to be executed by another by task dependency and conditions tracking
      <?xml version="1.0" encoding="UTF-8"?>
      <project
          xmlns:bp="https://procesy5.pl/biale_plamy-schema.xsd"
          xmlns:ogc="http://www.opengis.net/ogc"
          basedir="." name="download_data_from_procesy5_API" default="download_data">
      
          <property name="API_address" value="biuro.biall-net.pl"/>
          <property name="API_wfst_url" value="https://${API_address}/SE/version-git/wfs-data.php/default_db/"/>
              <property name="API_address_cert.txt" value="${API_address}_cert.txt"/>
              <property name="API_address_cert.cert" value="${API_address}_cert.cert"/>
              <property name="API_address_cert.installed" value="${API_address}_cert.installed"/>
          <property name="cacert_dir" value="${java.home}/lib/security/cacerts"/>
          <property name="gnutls-cli" value="/opt/local/bin/gnutls-cli"/>
      <target name="import_ssl_certificates_to_system_check" description="Veryfing to be sure if we have already a certificate. Else we should add it ">
              <!-- This is example by Arkadiusz Binder with Procesy5 system workaround example -->
              <echo>We check if we have already this SSL certificate -  </echo>
              <!--<property name="API_address" value="biuro.biall-net.pl"/>-->
              <exec command="keytool" output="${API_address_cert.installed}">
                  <arg value="-list"/>
                  <arg value="-alias"/>
                  <arg value="${API_address}"/>
                  <arg value="-keystore"/>
                  <arg value="${cacert_dir}"/>
                  <arg value="-storepass"/>
                  <arg value="${Password_for_cacerts}"/>
                  <arg value="-noprompt"/>
              </exec>
              <loadfile property="API_address_cert.installed_contents" srcfile="${API_address_cert.installed}" />
              <condition  property="API_address_cert.installed_exists_ok"  taskname="import_ssl_certificates_to_system"  else="NotInstalled"  >
                  <!--<available file="${API_address_cert.installed}" filepath="."/>-->
                  <contains string="${API_address_cert.installed_contents}" substring="${API_address}"/>
              </condition>
              <echo message="API_address_cert.installed_exists_ok ${API_address_cert.installed_exists_ok}  .  "/>
          </target>
    2. If not, download new certificates to keystore and by using keytool utility to add it to there:
      <target name="import_ssl_certificates_to_system" depends="import_ssl_certificates_to_system_check"  unless="${API_address_cert.installed_exists_ok}" description="It is good to be sure if we are correct keys to ">
              <echo>  We will upload certificate to ${cacert_dir}/   </echo>
              <!--<property name="cacert_dir" value="${java.home}/lib/security/cacerts"/>-->
              <delete file="${API_address_cert.txt}"/>
              <delete file="${API_address_cert.cert}"/>
              <delete file="${API_address_cert.installed}"/>
              <exec output="${API_address_cert.txt}"  executable="${gnutls-cli}" >
              </exec>
              <exec  input="${API_address_cert.txt}" output="${API_address_cert.cert}" executable="openssl">
                  <arg line="x509"/>
              </exec>
              <exec executable="keytool">
                  <arg line="-import -v -trustcacerts -alias ${API_address} -file ${API_address}.cert -keystore ${cacert_dir} -storepass ${Password_for_cacerts} -noprompt"/>
              </exec>
      </target>
    3. And there is download_data task which is called as default from Project directive.
      <target name="download_data"   description="Get data from API with XML - this example shows how easy is to use Procesy5 framework/system!" depends="import_ssl_certificates_to_system">
              <property name="WFS_VERSION" value="&amp;VERSION=1.0.0"/>
              <property name="TYPENAME" value="&amp;TYPENAME=p5_default_db:Rozdzielcza_test_bzyk_PE"/>  
              <property name="PE_fixings.xml" value="PE_fixings.xml"/>
              <delete file="${PE_fixings.xml}"></delete>
              <property name="OGC_Filter">&amp;Filter=&quot;&lt;ogc:Filter&gt;&lt;ogc:Or&gt;&lt;ogc:Not&gt;&lt;ogc:PropertyIsNull&gt;&lt;ogc:PropertyName&gt;the_geom&lt;/ogc:PropertyName&gt;&lt;/ogc:PropertyIsNull&gt;&lt;/ogc:Not&gt;&lt;ogc:PropertyIsEqualTo&gt;&lt;ogc:PropertyName&gt;ID&lt;/ogc:PropertyName&gt;&lt;ogc:Literal&gt;2&lt;/ogc:Literal&gt;&lt;/ogc:PropertyIsEqualTo&gt;&lt;/ogc:Or&gt;&lt;/ogc:Filter&gt;&quot;</property>
              <property name="URL_get_PE_fixings_from_db" value="${API_wfst_url}?SERVICE=WFS${WFS_VERSION}&amp;${TYPENAME}&amp;REQUEST=GetFeature&amp;SRSNAME=EPSG:3003${OGC_Filter}"/>
              <echo message="we get data from URL: ${URL_get_PE_fixings_from_db}"></echo>
              <get dest="${PE_fixings.xml}"  username="${username}" password="${pass}" verbose="true" >
                  <url  url="${URL_get_PE_fixings_from_db}"/>
              </get>
      </target>
      In this example we used the same ogc:filter which was escaped from XML This was the origin filter in XML
      <ogc:Filter>
          <ogc:Or>
              <ogc:Not>
                  <ogc:PropertyIsNull>
                      <ogc:PropertyName>the_geom</ogc:PropertyName>
                  </ogc:PropertyIsNull>
              </ogc:Not>
              <ogc:PropertyIsEqualTo>
                  <ogc:PropertyName>ID</ogc:PropertyName>
                  <ogc:Literal>2</ogc:Literal>
              </ogc:PropertyIsEqualTo>
          </ogc:Or>
      </ogc:Filter>
    4. And the end of this Build XML
      </project>
  2. Then we make another steps:
    1. executed the build file on Unix with the following command:
      prezes.procesy5.pl:php-cli a.binder$ ant -f build.xml get_PE_fixings_from_db -Dusernamea.binder -Dpass=XXXXXXX
    2. and there were shown such output on console:
      Buildfile: /Users/a.binder/Documents/biuro.biall-net.pl-gitlab-se-2015-02-16.git/SE/dev/php-cli/build.xml
      
      import_ssl_certificates_to_system_check:
           [echo] We check if we have already this SSL certificate -  
           [exec] The command attribute is deprecated.
           [exec] Please use the executable attribute and nested arg elements.
           [exec] Result: 1
           [echo] API_address_cert.installed_exists_ok true  .  
      
      import_ssl_certificates_to_system:
      
      get_PE_fixings_from_db:
           [echo] we get data from URL: https://biuro.biall-net.pl/SE/version-git/wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&&TYPENAME=p5_default_db:Rozdzielcza_test_bzyk_PE&REQUEST=GetFeature&SRSNAME=EPSG:3003&Filter="<ogc:Filter><ogc:Or><ogc:Not><ogc:PropertyIsNull><ogc:PropertyName>the_geom</ogc:PropertyName></ogc:PropertyIsNull></ogc:Not><ogc:PropertyIsEqualTo><ogc:PropertyName>ID</ogc:PropertyName><ogc:Literal>2</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Or></ogc:Filter>"
            [get] Getting: https://biuro.biall-net.pl/SE/version-git/wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&&TYPENAME=p5_default_db:Rozdzielcza_test_bzyk_PE&REQUEST=GetFeature&SRSNAME=EPSG:3003&Filter="<ogc:Filter><ogc:Or><ogc:Not><ogc:PropertyIsNull><ogc:PropertyName>the_geom</ogc:PropertyName></ogc:PropertyIsNull></ogc:Not><ogc:PropertyIsEqualTo><ogc:PropertyName>ID</ogc:PropertyName><ogc:Literal>2</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Or></ogc:Filter>"
            [get] To: /Users/a.binder/Documents/biuro.biall-net.pl-gitlab-se-2015-02-16.git/SE/dev/php-cli/PE_fixings.xml
      
      BUILD FAILED
      /Users/a.binder/Documents/biuro.biall-net.pl-gitlab-se-2015-02-16.git/SE/dev/php-cli/build.xml:613: HTTP Authorization failure
      
      Total time: 1 second
      prezes.procesy5.pl:php-cli a.binder$ ant -f build.xml get_PE_fixings_from_db -Dusername=a.binder -Dpass=Vis11on69X
      Buildfile: /Users/a.binder/Documents/biuro.biall-net.pl-gitlab-se-2015-02-16.git/SE/dev/php-cli/build.xml
      
      import_ssl_certificates_to_system_check:
           [echo] We check if we have already this SSL certificate -  
           [exec] The command attribute is deprecated.
           [exec] Please use the executable attribute and nested arg elements.
           [exec] Result: 1
           [echo] API_address_cert.installed_exists_ok true  .  
      
      import_ssl_certificates_to_system:
      
      get_PE_fixings_from_db:
           [echo] we get data from URL: https://biuro.biall-net.pl/SE/version-git/wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&&TYPENAME=p5_default_db:Rozdzielcza_test_bzyk_PE&REQUEST=GetFeature&SRSNAME=EPSG:3003&Filter="<ogc:Filter><ogc:Or><ogc:Not><ogc:PropertyIsNull><ogc:PropertyName>the_geom</ogc:PropertyName></ogc:PropertyIsNull></ogc:Not><ogc:PropertyIsEqualTo><ogc:PropertyName>ID</ogc:PropertyName><ogc:Literal>2</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Or></ogc:Filter>"
            [get] Getting: https://biuro.biall-net.pl/SE/version-git/wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&&TYPENAME=p5_default_db:Rozdzielcza_test_bzyk_PE&REQUEST=GetFeature&SRSNAME=EPSG:3003&Filter="<ogc:Filter><ogc:Or><ogc:Not><ogc:PropertyIsNull><ogc:PropertyName>the_geom</ogc:PropertyName></ogc:PropertyIsNull></ogc:Not><ogc:PropertyIsEqualTo><ogc:PropertyName>ID</ogc:PropertyName><ogc:Literal>2</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Or></ogc:Filter>"
            [get] To: /Users/a.binder/Documents/biuro.biall-net.pl-gitlab-se-2015-02-16.git/SE/dev/php-cli/PE_fixings.xml
            [get] ....................................................
            [get] ....................................................
            [get] ....................................................
            [get] ....................................................
            [get] ....................................................
            [get] ....................................................
            [get] ....................................................
            [get] ....................................................
            [get] ....................................................
            [get] ....................................................
            [get] ....................................................
            [get] ....................................................
            [get] ....................................................
            [get] ...........................................
      
      BUILD SUCCESSFUL
      Total time: 4 seconds
  3. Now we look at the downloaded PE_fixings.xml file:
    prezes.procesy5.pl:php-cli a.binder$ cat PE_fixings.xml |head -n 40
    <?xml version="1.0" encoding="UTF-8"?>
    <wfs:FeatureCollection xmlns:wfs="http://www.opengis.net/wfs" xmlns="http://www.opengis.net/wfs" xmlns:gml="http://www.opengis.net/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:p5_default_db="https://biuro.biall-net.pl/wfs/default_db" xsi:schemaLocation="https://biuro.biall-net.pl/wfs/default_db https://biuro.biall-net.pl/SE/version-git/wfs-data.php/default_db/?SERVICE=WFS&amp;VERSION=1.0.0&amp;TYPENAME=p5_default_db:Rozdzielcza_test_bzyk_PE&amp;REQUEST=DescribeFeatureType">
     <gml:featureMember>
      <p5_default_db:Rozdzielcza_test_bzyk_PE fid="Rozdzielcza_test_bzyk_PE.3657">
       <p5_default_db:ID>3657</p5_default_db:ID>
       <p5_default_db:ID_way>2962</p5_default_db:ID_way>
       <p5_default_db:the_geom>
        <gml:Point srsName="http://www.opengis.net/gml/srs/epsg.xml#4326" xmlns:gml="http://www.opengis.net/gml">
         <gml:coordinates>18.3095622,51.187241499079</gml:coordinates>
        </gml:Point>
       </p5_default_db:the_geom>
      </p5_default_db:Rozdzielcza_test_bzyk_PE>
     </gml:featureMember>
     <gml:featureMember>
      <p5_default_db:Rozdzielcza_test_bzyk_PE fid="Rozdzielcza_test_bzyk_PE.3656">
       <p5_default_db:ID>3656</p5_default_db:ID>
       <p5_default_db:ID_way>2963</p5_default_db:ID_way>
       <p5_default_db:the_geom>
        <gml:Point srsName="http://www.opengis.net/gml/srs/epsg.xml#4326" xmlns:gml="http://www.opengis.net/gml">
         <gml:coordinates>18.308112234546,51.187209944258</gml:coordinates>
        </gml:Point>
       </p5_default_db:the_geom>
      </p5_default_db:Rozdzielcza_test_bzyk_PE>
     </gml:featureMember>
     <gml:featureMember>
      <p5_default_db:Rozdzielcza_test_bzyk_PE fid="Rozdzielcza_test_bzyk_PE.3655">
       <p5_default_db:ID>3655</p5_default_db:ID>
       <p5_default_db:ID_way>2960</p5_default_db:ID_way>
       <p5_default_db:the_geom>
        <gml:Point srsName="http://www.opengis.net/gml/srs/epsg.xml#4326" xmlns:gml="http://www.opengis.net/gml">
         <gml:coordinates>18.301921711891,51.187623744197</gml:coordinates>
        </gml:Point>
       </p5_default_db:the_geom>
      </p5_default_db:Rozdzielcza_test_bzyk_PE>
     </gml:featureMember>
     <gml:featureMember>
      <p5_default_db:Rozdzielcza_test_bzyk_PE fid="Rozdzielcza_test_bzyk_PE.3654">
       <p5_default_db:ID>3654</p5_default_db:ID>
       <p5_default_db:ID_way>2958</p5_default_db:ID_way>
       <p5_default_db:the_geom>
Note: This shows complete integration with Procesy5 API with also solving some problems natured with technlogy. As You see You can easily integrate any environment with Procesy5 engine. Also remember that this system is still application itselfs!
Note: To enable access to data remember to use Process/Acl and Data managing utilities