mardi 4 août 2015

Add Action Rule Axis Camera

I am trying to use the vapix API for Axis cameras to make a new action rule. The responses for this API are hilariously unhelpful. My error is : "The requested SOAP action failed" . I am using SOAPUI 5.2.0. Here is my code which is supposed to make a new action rule:

<soap:Envelope xmlns:soap="http://ift.tt/18hkEkn" xmlns:SOAP-ENC="http://ift.tt/1cvL1jU" xmlns:xsi="http://ift.tt/ra1lAU" xmlns:xsd="http://ift.tt/tphNwY" xmlns:c14n="http://ift.tt/11kTCUR" xmlns:wsu="http://ift.tt/Hm2joJ" xmlns:ds="http://ift.tt/uq6naF" xmlns:wsse="http://ift.tt/LRW8Ij" xmlns:wsa5="http://ift.tt/HKXHai" xmlns:xmime="http://ift.tt/1LP4jbf" xmlns:xop="http://ift.tt/1euX8oV" xmlns:wsrfbf="http://ift.tt/1cvL1Ai" xmlns:wstop="http://ift.tt/1cvL3s5" xmlns:tt="http://ift.tt/1cvL1Ag" xmlns:acert="http://ift.tt/1DWHUkg" xmlns:wsrfr="http://ift.tt/1leiF5D" xmlns:aa="http://ift.tt/1LP4jbj" xmlns:acertificates="http://ift.tt/1IzbYrz" xmlns:aev="http://ift.tt/1LP4iUP" xmlns:ali1="http://ift.tt/1LP4jrz" xmlns:ali2="http://ift.tt/1MSjz49" xmlns:ali3="http://ift.tt/1LP4jrB" xmlns:ali4="http://ift.tt/1LP4lQh" xmlns:ali="http://ift.tt/1LP4lQk" xmlns:apc="http://ift.tt/1DWHWsr" xmlns:arth="http://ift.tt/1IzbWA7" xmlns:aweb="http://ift.tt/1DWHUAE" xmlns:tan1="http://ift.tt/1MSjz4d" xmlns:tan2="http://ift.tt/1LP4jrG" xmlns:tan="http://ift.tt/1leiDe2" xmlns:tds="http://ift.tt/1leiEPp" xmlns:tev1="http://ift.tt/1cvL1Au" xmlns:tev2="http://ift.tt/1cvL3Ix" xmlns:tev3="http://ift.tt/1leiF5N" xmlns:wsnt="http://ift.tt/1leiEPh" xmlns:tev4="http://ift.tt/1leiDuF" xmlns:tev="http://ift.tt/1cvL3Ik" xmlns:timg="http://ift.tt/1sSAh9q" xmlns:tptz="http://ift.tt/1cvL3Is" xmlns:trt="http://ift.tt/1cvL0wr" xmlns:ter="http://ift.tt/1leiEyG" xmlns:tns1="http://ift.tt/1cvL3rY" xmlns:tnsaxis="http://ift.tt/1MSjxcw">
  <soap:Header/>
  <soap:Body>
    <act:AddActionRule>
    <act:NewActionRule>
      <!--Optional:-->
      <act:Name>AHHHHH</act:Name>
      <act:Enabled>true</act:Enabled>
      <!--Optional:-->
      <!--<act:StartEvent>-->
      <!--You may enter ANY elements at this point-->
      <!--</act:StartEvent>-->
      <!--Optional:-->
      <act:Conditions>
        <!--1 or more repetitions:-->
        <act:Condition>
          <wsnt:TopicExpression Dialect="http://ift.tt/1IzbWQp">tns1:Device/ tnsaxis:IO/Port//.</wsnt:TopicExpression>
          <wsnt:MessageContent Dialect="http://ift.tt/1DWHWIR">boolean(//SimpleItem[@Name="state" and @Value="1"]) and boolean(//SimpleItem[@Name="port" and @Value="0"])</wsnt:MessageContent>
        </act:Condition>
      </act:Conditions>
      <!--Optional:-->
      <!--act:ActivationTimeout>?</act:ActivationTimeout-->
      <act:PrimaryAction>16</act:PrimaryAction>
      <!--Optional:-->
      <!--act:FailoverAction>?</act:FailoverAction-->
    </act:NewActionRule>
  </act:AddActionRule>
</soap:Body>

To be honest I am not sure what the things inside the condition are doing. I went into the camera setup and added the action rule through the setup, then used another soap command "GetActionRules" to see how to format it. The GeActionRules command is

<soap:Envelope xmlns:soap="http://ift.tt/18hkEkn" xmlns:act="http://ift.tt/1LP4jbj">
   <soap:Header/>
   <soap:Body>
      <act:GetActionRules/>
   </soap:Body>
</soap:Envelope>

And the response is

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://ift.tt/18hkEkn" xmlns:SOAP-ENC="http://ift.tt/1cvL1jU" xmlns:xsi="http://ift.tt/ra1lAU" xmlns:xsd="http://ift.tt/tphNwY" xmlns:c14n="http://ift.tt/11kTCUR" xmlns:wsu="http://ift.tt/Hm2joJ" xmlns:ds="http://ift.tt/uq6naF" xmlns:wsse="http://ift.tt/LRW8Ij" xmlns:wsa5="http://ift.tt/HKXHai" xmlns:xmime="http://ift.tt/1LP4jbf" xmlns:xop="http://ift.tt/1euX8oV" xmlns:wsrfbf="http://ift.tt/1cvL1Ai" xmlns:wstop="http://ift.tt/1cvL3s5" xmlns:tt="http://ift.tt/1cvL1Ag" xmlns:acert="http://ift.tt/1DWHUkg" xmlns:wsrfr="http://ift.tt/1leiF5D" xmlns:aa="http://ift.tt/1LP4jbj" xmlns:acertificates="http://ift.tt/1IzbYrz" xmlns:aev="http://ift.tt/1LP4iUP" xmlns:ali1="http://ift.tt/1LP4jrz" xmlns:ali2="http://ift.tt/1MSjz49" xmlns:ali3="http://ift.tt/1LP4jrB" xmlns:ali4="http://ift.tt/1LP4lQh" xmlns:ali="http://ift.tt/1LP4lQk" xmlns:apc="http://ift.tt/1DWHWsr" xmlns:arth="http://ift.tt/1IzbWA7" xmlns:aweb="http://ift.tt/1DWHUAE" xmlns:tan1="http://ift.tt/1MSjz4d" xmlns:tan2="http://ift.tt/1LP4jrG" xmlns:tan="http://ift.tt/1leiDe2" xmlns:tds="http://ift.tt/1leiEPp" xmlns:tev1="http://ift.tt/1cvL1Au" xmlns:tev2="http://ift.tt/1cvL3Ix" xmlns:tev3="http://ift.tt/1leiF5N" xmlns:wsnt="http://ift.tt/1leiEPh" xmlns:tev4="http://ift.tt/1leiDuF" xmlns:tev="http://ift.tt/1cvL3Ik" xmlns:timg="http://ift.tt/1sSAh9q" xmlns:tptz="http://ift.tt/1cvL3Is" xmlns:trt="http://ift.tt/1cvL0wr" xmlns:ter="http://ift.tt/1leiEyG" xmlns:tns1="http://ift.tt/1cvL3rY" xmlns:tnsaxis="http://ift.tt/1MSjxcw">
   <SOAP-ENV:Header/>
   <SOAP-ENV:Body>
      <aa:GetActionRulesResponse>
         <aa:ActionRules>
            <aa:ActionRule>
               <aa:RuleID>8</aa:RuleID>
               <aa:Name>FTP</aa:Name>
               <aa:Enabled>true</aa:Enabled>
               <aa:Conditions>
                  <aa:Condition>
                     <wsnt:TopicExpression Dialect="http://ift.tt/1IzbWQp">tns1:Device/tnsaxis:IO/Port//.</wsnt:TopicExpression>
                     <wsnt:MessageContent Dialect="http://ift.tt/1DWHWIR">boolean(//SimpleItem[@Name="port" and @Value="0"]) and boolean(//SimpleItem[@Name="state" and @Value="1"])</wsnt:MessageContent>
                  </aa:Condition>
               </aa:Conditions>
               <aa:PrimaryAction>13</aa:PrimaryAction>
           </aa:ActionRule>
            <aa:ActionRule>
               <aa:RuleID>9</aa:RuleID>
               <aa:Name>noobbbb</aa:Name>
               <aa:Enabled>true</aa:Enabled>
               <aa:Conditions>
                  <aa:Condition>
                     <wsnt:TopicExpression Dialect="http://ift.tt/1IzbWQp">tns1:Device/tnsaxis:IO/Port//.</wsnt:TopicExpression>
                     <wsnt:MessageContent Dialect="http://ift.tt/1DWHWIR">boolean(//SimpleItem[@Name="port" and @Value="0"]) and boolean(//SimpleItem[@Name="state" and @Value="1"])</wsnt:MessageContent>
                  </aa:Condition>
               </aa:Conditions>
               <aa:PrimaryAction>14</aa:PrimaryAction>
            </aa:ActionRule>
         </aa:ActionRules>
      </aa:GetActionRulesResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

How to get the XML of a Batik SVGOMSymbolElement

I want to isolate an element from a svg file and get the code of this element (<svg><path/>...</svg>). I try with Batik, but I don't find how to transform a SVGOMSymbolElement into String.

String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
Document doc = f.createDocument("file.svg");
Element element = doc.getElementById("my-id");

Max size of xml for Dom parser

I´m making android app. As ussual i´m storing my data in xml file(i´m used to do that), I have DOM parser to get these data into my app. Now i have this problem, i was working only with partial xml and everything was fine. When i filled my xml completely (its about 6000 rows and 375kb size, i will probably need even more) i´m getting this error:

08-03 17:01:36.429    3866-3866/com.example.blackess.smstestas E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NullPointerException
        at android.app.ActivityThread.handleStopActivity(ActivityThread.java:2476)
        at android.app.ActivityThread.access$1800(ActivityThread.java:117)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:952)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:130)
        at android.app.ActivityThread.main(ActivityThread.java:3687)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:507)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
        at dalvik.system.NativeStart.main(Native Method)

I thought that i have some bad value or something wrong in my xml, but after i searched for that problem i find out that when i have xml under 5000 rows my program is working but if i add more even tested data my program will crash.

What could be that problem or how can i fix it?

Edit: Was reading this Maximum size when parsing XML with DOM too, thought with my 375kb i ´m in limit.

How to handle collection of object in apapche digester?

i'm using apache digester-2.0 to convert XML to java beans and it's works fine. But now i've an evolution to do and the structure of the file is a bit more complex. Indeed now , my XML is like that :

<main>
*some properties here*
 <objectCollection>
    <object>
      <id>foo</id>
      <string>bar</string>
    </object>
    <object>
      <id>foo</id>
      <string>bar</string>
    </object>
  </objectCollection>
</main>

So , since now i've handled simple lines like

<title>foo</title>

But i don't find how to handle correctly the collection. Is there some good practice ? i guess i can do a loop on xml objectCollection node, but it seems very weird for me. Isn't a better method ?

Thx

Using a CheckedListBox as a filter for a DataGridView with an XML file as a datasource

I'm using an XML file loaded into a datagridview, but I want to be able to filter the data based on variable name. Here's an example of the XML:

    <Variable>
    <Name>Logic1</Name>
    <Description/>
    <Values>
        <Value>
            <isstring>FALSE</isstring>
            <value>0.0</value>
            <unit/>
            <date>7/17/2015</date>
            <time>11:16:00 AM,000</time>
            <status>INVALID</status>
        </Value>
        <Value>
            <isstring>FALSE</isstring>
            <value>0.0</value>
            <unit/>
            <date>7/17/2015</date>
            <time>11:17:00 AM,000</time>
            <status>INVALID</status>
        </Value>
        <Value>
            <isstring>FALSE</isstring>
            <value>468.6</value>
            <unit/>
            <date>7/17/2015</date>
            <time>11:18:00 AM,000</time>
            <status>SPONT</status>
        </Value>
        <Value>
            <isstring>FALSE</isstring>
            <value>434.3</value>
            <unit/>
            <date>7/17/2015</date>
            <time>11:19:00 AM,000</time>
            <status>SPONT</status>
        </Value>
        <Value>
            <isstring>FALSE</isstring>
            <value>557.1</value>
            <unit/>
            <date>7/17/2015</date>
            <time>11:20:00 AM,000</time>
            <status>SPONT</status>
        </Value>
    </Values>
</Variable>

And here is my code to populate the datagridview and checkedlistbox with the loaded XML file.

    private void btnLoadXML_Click(object sender, EventArgs e)
    {

        Stream input = null;
        OpenFileDialog loadXML = new OpenFileDialog();
        loadXML.Filter = "XML Files(.*xml)|*.xml";
        loadXML.FilterIndex = 0;
        loadXML.RestoreDirectory = true;

        if(loadXML.ShowDialog() == DialogResult.OK)
        {
            try
            {
                if((input = loadXML.OpenFile()) != null)
                {
                    using(input)
                    {
                        XmlReader xmlFile = XmlReader.Create(input, new XmlReaderSettings());
                        DataSet dgvData = new DataSet();
                        dgvData.ReadXml(xmlFile);
                        dgvZenonXML.DataSource = dgvData.Tables[2];
                        this.checkedListBox1.DataSource = dgvData.Tables[0];
                        this.checkedListBox1.DisplayMember = "Name";
                        this.checkedListBox1.ValueMember = "Name";
                        xmlFile.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
    }

At this point, I'm fairly stumped, as there isn't always a defined number of variables and data points available in each XML.

Puppet Augeas - cannot update value in xml node containing CDATA

I have an xml document similar to this:

<?xml version="1.0" encoding="UTF-8"?>
<example>
    <member name="dbsettings">
        <node name="username"><![CDATA[someusername]]></node>
        <node name="password"><![CDATA[mypassword]]></node>
    </member>
    <member name="sitesettings">
        <node name="title"><![CDATA[just a title]]></node>
    </member>
</example>

And I'm trying to update these settings in puppet using the following augeas command:

set example/member[#attributes/name='dbsettings']/node[#attributes/name='username']/#text anotherusername

What I expect it to do is to replace the entire contents of the node by "anotherusername" instead it just appends it resulting in:

<node name="username"><![CDATA[someusername]]>anotherusername</node>

How can I select and update the contents of the CDATA element using augeas or remove it without removing the actual node itself? (the real node contains more attributes which I don't want to hard-code in)

Read and write XML file in Python / Flask

I have a bunch of XML configuration files that looks like this

 <list>
        <flip ip="x.x.x.x" port="30016" />
        <geo ip="x.x.x.x" port="11111" />
        <shake ip="x.x.x.x" port="30006" />
            <ip2location ip="x.x.x.x" port="30006" />
        <radar ip="x.x.x.x" port="11111" />
        <fb ip="x.x.x.x" port="22001" />
        <sms ip="x.x.x.x" port="22222" />
        <pn ip="x.x.x.x" port="30001" />
            <db ip="x.x.x.x" pool="300" port="18000" />
        <cache ip="x.x.x.x" pool="100" port="11213" />
        <session ip="x.x.x.x" pool="100" port="11212" />
    </list>

I am writing a flask web-app that can load up these XMLs and display as an HTML web-page, and it also allow the user to edit any field of the XML and then save to the file

What I have done is to parse these XML using xmltodict, so I will get a nested dictionary object, then recursively display them using the flask jinja2 template like this

Simple Form

But there are several problems to it:

1.These XMLs may contain totally different field, so it is not possible to do traditional POST such as in flask request.form[] to update any of the field

2.The parsed dict object is a mixed nested dictionary and list, it is very hard to access and change any value inside

because of these, I don't know how to update the dict object once a user entered a value into the HTML form

Please help if you have some good idea , or any other solution to the requirement

Thanks !