Not logged in. · Lost password · Register
Forum: MatriX RSS
Avatar
andy_steel #1
Member since Mar 2016 · 4 posts
Group memberships: Members
Show profile · Link to this post
Subject: de-serialize Cisco Finesse Messages + access to notification
Hi,

I'm new to xmpp and only have basic workings of .NET. I've just started using this library today and have successfully authenticated against Cisco Finesse server and I'm receiving messages ok.

I'm not sure whether I need to be de-serializing the xml messages myself or whether there's already classes built into Matrix for this.

For example what's the best practice for accessing the "notification" element within the following XML message. If it were java i'd be finding/constructing an XSD and using JAXB to generate the classes and from there de-serializing the string into objects from where I could then access the attributes and elements using a strong typecast method.

Since i'm new to C# i'm not sure whether this is overkill or is there something built into the APIs to allow me to get access to that node?

  1. <message xmlns="jabber:client"
  2.          from="pubsub.XXX.jno.local"
  3.          to="1111126@XXX.jno.local"
  4.          id="/finesse/api/User/1111126__1111126@XXX.jno.local__xDPxe">
  5.    <event xmlns="http://jabber.org/protocol/pubsub#event">
  6.       <items node="/finesse/api/User/1111126">
  7.          <item id="8408e76b-58ca-4e1e-a3cb-9098566186fa140274">
  8.             <notification xmlns="http://jabber.org/protocol/pubsub">
  9. &lt;Update&gt;
  10.  &lt;data&gt;
  11.     &lt;user&gt;
  12.       &lt;dialogs&gt;/finesse/api/User/1111126/Dialogs&lt;/dialogs&gt;
  13.             </notification>
  14.          </item>
  15.       </items>
  16.    </event>
  17. </message>

Thanks
This post was edited on 2016-03-01, 23:49 by Alex.
Avatar
Alex #2
Member since Feb 2003 · 4327 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
here is an example on how you can get and decode the payload.
I don't know why Finesse encodes the Xml in the publus payload.

  1. XNamespace ns = Namespaces.Pubsub;
  2. var notification = message.Descendants(ns + "notification").First();
  3. var payloadXml = System.Uri.UnescapeDataString(notification.Value);

after you have decoded it you can parse it with MatriX or any other Xml parser.

  1. var xmppElement = XmppXElement.LoadXml(payload);

Alex
Avatar
ssteiner #3
Member since Jan 2016 · 26 posts · Location: Switzerland
Group memberships: Members
Show profile · Link to this post
If you're working with javascript, then I presume the finesse javascript lib would come to your help. For other programming languages, 'm afraid you'll have to either parse the XML using an approach like Alex described, or you build your own class representation of the objects you care about (User, Dialog.. perhaps also Teams, Queues and SystemInfo). The payload that you get is in a format that cisco defines, so there's no way Finesse could deserialize this.

Personally, I implemented my own class representation so that I get everything in a proper format. Here's an example for teams extraction

  1. [XmlRoot("Teams")]
  2. public class ListOfTeams
  3. {
  4. [XmlElement("Team")]
  5. //[XmlArray("users")]
  6. //[XmlArrayItem("User", typeof(User))]
  7. public List<BasicTeam> Teams { get; set; }
  8. }
  9.  
  10. //[XmlRoot("Team")]
  11. public class BasicTeam
  12. {
  13. [XmlElement("uri")]
  14. public string uri { get; set; }
  15.  
  16. [XmlElement("id")]
  17. public string Id { get; set; }
  18.  
  19. [XmlElement("name")]
  20. public string Name { get; set; }
  21.  
  22. [XmlElement("useDefault")]
  23. public bool UseDefault { get; set; }
  24.  
  25. [XmlElement("layoutxml")]
  26. public string LayoutXml { get; set; }
  27.  
  28. public override string ToString()
  29. {
  30.     return string.Format("{0} - id {1}", Name, Id);
  31. }

And I then extract the list of teams as follows

  1. public async Task<RestApiOperationResult<Objects.Team.ListOfTeams>> GetTeams(CancellationToken token)
  2. {
  3.     RestApiOperationResult<Objects.Team.ListOfTeams> result = new RestApiOperationResult<Objects.Team.ListOfTeams>();
  4.     HttpResponseMessage response = null;
  5.     try
  6.     {
  7.         string url = CurrentActiveUrl;
  8.         url += string.Format("{0}/Teams", ApiUrl);
  9.         response = await HttpClient.GetAsync(url, token).ConfigureAwait(false);
  10.         if (response.IsSuccessStatusCode)
  11.         {
  12.             result.Result = await response.Content.ReadAsAsync<Objects.Team.ListOfTeams>(MediaFormatters, token).ConfigureAwait(false);
  13.             result.ResultCode = ApiOperationResultCode.Success;
  14.         }
  15.         else
  16.         {
  17.             result.ResultCode = await ProcessNon200HttpResponse(result, response).ConfigureAwait(false);
  18.         }
  19.     }
  20.     catch (Exception e)
  21.     {
  22.         ProcessException(result, e, response);
  23.     }
  24.     return result;
  25. }

Now shown here is error processing, and determination of active url (I poll the systeminfo for both servers, and from that determine which server I should be talking to).

Once you've implemented the object model for the REST API, you can re-use it to handle the notifications as they use the same payload (be mindful of casing.. some objects start their name with an upper case in the REST API and lower case in notifications).
This post was edited on 2016-03-04, 21:57 by Alex.
Avatar
Alex #4
Member since Feb 2003 · 4327 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
MatriX has a build in  Xml parser based on System.Xml.Linq with many custom extensions.
See here for an example:
http://www.ag-software.net/matrix-xmpp-sdk/matrix-develope…

Alex
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Forum: MatriX RSS