Not logged in. · Lost password · Register
Forum: agsXMPP RSS
Avatar
BringerOD #1
Member since Dec 2005 · 12 posts
Group memberships: Members
Show profile · Link to this post
Subject: Custom IQ packets  <service-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
I followed the instructions in the documentation that describes creating a custom iq packet.

I get the following error when sending the packet. 

  1. <prime xmlns="primeCRM:packets"><MessageData /><MessageType>Ping</MessageType><FromJabberId>test2@xmpp.prime.web.local/agsXMPP</FromJabberId><ToJabberId>Test1@xmpp.prime.web.local</ToJabberId><AgentId /><ClientInstanceId /><SentDateTime>12/03/2011 11:39:13</SentDateTime></prime><error xmlns="jabber:client" type="cancel" code="503"><service-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" /></error>


Here is the code.

Any ideas?


  1. namespace Prime.Messenger.BaseClientAGS
  2. {
  3.    using System;
  4.    using System.Globalization;
  5.    using BaseClient;
  6.    using BayTech.Common.Data;
  7.    using agsXMPP.Xml.Dom;
  8.  
  9.    public class PrimePacket : Element
  10.    {
  11.       public PrimePacket()
  12.       {
  13.          TagName = ConnectionCache.TagName;
  14.          Namespace = ConnectionCache.Namespace;
  15.          
  16.       }
  17.       public MessageActionType MessageType
  18.       {
  19.          get
  20.          {
  21.             var value = GetTag("MessageType");
  22.             MessageActionType returnValue;
  23.             if (Enum.IsDefined(typeof (MessageActionType), value))
  24.                returnValue = (MessageActionType) Enum.Parse(typeof (MessageActionType), value, true);
  25.             else
  26.                returnValue = MessageActionType.Unknown;
  27.             return returnValue;
  28.          }
  29.          set { SetTag("MessageType", value.ToString()); }
  30.       }
  31.  
  32.       public DateTime SentDateTime
  33.       {
  34.          get { return ConvertSafe.ToDateTime(GetTag("SentDateTime")); }
  35.          set { SetTag("SentDateTime", value.ToString(CultureInfo.InvariantCulture)); }
  36.       }
  37.  
  38.       public DateTime ReceivedDateTime
  39.       {
  40.          get { return ConvertSafe.ToDateTime(GetTag("ReceivedDateTime")); }
  41.          set { SetTag("ReceivedDateTime", value.ToString(CultureInfo.InvariantCulture)); }
  42.       }
  43.  
  44.       public DateTime ReturnedDateTime
  45.       {
  46.          get { return ConvertSafe.ToDateTime(GetTag("ReturnedDateTime")); }
  47.          set { SetTag("ReturnedDateTime", value.ToString(CultureInfo.InvariantCulture)); }
  48.       }
  49.  
  50.       public int RoundTripMilliSeconds
  51.       {
  52.          get { return GetTagInt("RoundTripMilliSeconds"); }
  53.          set { SetTag("RoundTripMilliSeconds", value); }
  54.       }
  55.  
  56.       public string FromJabberId
  57.       {
  58.          get { return GetTag("FromJabberId"); }
  59.          set { SetTag("FromJabberId", value); }
  60.       }
  61.  
  62.       public string ToJabberId
  63.       {
  64.          get { return GetTag("ToJabberId"); }
  65.          set { SetTag("ToJabberId", value); }
  66.       }
  67.  
  68.  
  69.       public Guid? AgentId
  70.       {
  71.          get { return GetTag("AgentId").ToGuid(); }
  72.          set { SetTag("AgentId", value.ToString()); }
  73.       }
  74.  
  75.  
  76.       public Guid? ClientInstanceId
  77.       {
  78.          get { return GetTag("ClientInstanceId").ToGuid(); }
  79.          set { SetTag("ClientInstanceId", value.ToString()); }
  80.       }
  81.  
  82.  
  83.       public string MessageData
  84.       {
  85.          get { return GetTag("MessageData"); }
  86.          set { SetTag("MessageData", value); }
  87.       }
  88.  
  89. //      private List<string> _ipAddress;
  90. //      public List<string> IPAddress
  91. //      {
  92. //         get { return _ipAddress; }
  93. //         set { _ipAddress = value; }
  94. //      }
  95.    }
  96. }

  1. namespace Prime.Messenger.BaseClientAGS
  2. {
  3.    using agsXMPP;
  4.    using agsXMPP.protocol.client;
  5.  
  6.    public class PrimePacketIq : IQ
  7.    {
  8.       private readonly PrimePacket _primePacket = new PrimePacket();
  9.  
  10.       public PrimePacketIq()
  11.       {
  12.          base.Query = _primePacket;
  13.          GenerateId();
  14.       }
  15.  
  16.       public PrimePacketIq(IqType type)
  17.          : this()
  18.       {
  19.          Type = type;
  20.       }
  21.  
  22.       public PrimePacketIq(IqType type, Jid to)
  23.          : this(type)
  24.       {
  25.          To = to;
  26.       }
  27.  
  28.       public PrimePacketIq(IqType type, Jid to, Jid from)
  29.          : this(type, to)
  30.       {
  31.          From = from;
  32.       }
  33.  
  34.       public new PrimePacket Query
  35.       {
  36.          get { return _primePacket; }
  37.       }
  38.    }
  39. }

  1. ElementFactory.AddElementType(ConnectionCache.TagName, ConnectionCache.Namespace, typeof(PrimePacket));


  1.  private void _clientConnection_OnIq(object sender, IQ e)
  2.       {
  3.  
  4.          var iq = e;
  5.          var query = iq.Query;
  6.  
  7.          if (query != null)
  8.          {
  9.             if (query.GetType() == typeof (PrimePacket))
  10.             {
  11.                var primePacket = query as PrimePacket;
  12.                if (iq.Type == IqType.get && primePacket != null)
  13.                {
  14.                   iq.SwitchDirection();
  15.                   iq.Type = IqType.result;
  16.                   primePacket.ReceivedDateTime = DateTime.Now;
  17.                   _clientConnection.Send(iq);
  18.                }
  19.             }
  20.          }
  21.       }
Avatar
Alex #2
Member since Feb 2003 · 4307 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Please post the complete xml log.
Are you sending to a full jid when including your custom stuff to an iq?

Alex
Avatar
BringerOD #3
Member since Dec 2005 · 12 posts
Group memberships: Members
Show profile · Link to this post
Yes
Avatar
BringerOD #4
Member since Dec 2005 · 12 posts
Group memberships: Members
Show profile · Link to this post
In reply to post #2
BTW, thanks for your help.

I was able to get a little farther along.   From you statement I thought about full jib.  So I put in the resource.  I hadn't had it in there before.  Did not think it was needed.  I put it in and the error went away. 

Now a different problem has arisen.  The IQ packet is successfully received on TEST1 from TEST2, but the query object is set to null. What is weird is the packet is in the xml when I debug it.  Not sure what is going on now.

Skips over my code to send the response because the query object is null.

  1.       private void _clientConnection_OnIq(object sender, IQ e)
  2.       {
  3.          var iq = e;
  4.          var query = iq.Query;
  5.  
  6.          if (query != null)
  7.          {
  8.             if (query.GetType() == typeof (PrimePacket))
  9.             {
  10.                var primePacket = query as PrimePacket;
  11.                if (iq.Type == IqType.get && primePacket != null)
  12.                {
  13.                   iq.SwitchDirection();
  14.                   iq.Type = IqType.result;
  15.                   primePacket.ReceivedDateTime = DateTime.Now;
  16.                   ClientConnection.Send(iq);
  17.                }
  18.             }
  19.          }
  20.       }

Client XML LOG

  1. WRITE:<iq id="agsXMPP_9" type="get" to="Test1@xmpp.prime.web.local/agsXMPP" from="test2@xmpp.prime.web.local/agsXMPP"><primepacket xmlns="primeCRM:primepacket"><MessageData /><MessageType>Ping</MessageType><FromJabberId>test2@xmpp.prime.web.local/agsXMPP</FromJabberId><ToJabberId>Test1@xmpp.prime.web.local/agsXMPP</ToJabberId><AgentId /><ClientInstanceId /><SentDateTime>12/04/2011 12:14:43</SentDateTime></primepacket></iq>

SERVER LOG

  1. READ:<iq xmlns="jabber:client" to="test1@xmpp.prime.web.local/agsXMPP" id="agsXMPP_9" type="get" from="test2@xmpp.prime.web.local/agsXMPP"><primepacket xmlns="primeCRM:primepacket"><MessageData /><MessageType>Ping</MessageType><FromJabberId>test2@xmpp.prime.web.local/agsXMPP</FromJabberId><ToJabberId>Test1@xmpp.prime.web.local/agsXMPP</ToJabberId><AgentId /><ClientInstanceId /><SentDateTime>12/04/2011 12:14:43</SentDateTime></primepacket></iq>
This post was edited on 2016-11-06, 12:18 by Alex.
Avatar
Alex #5
Member since Feb 2003 · 4307 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Quote by BringerOD:
Now a different problem has arisen.  The IQ packet is successfully received on TEST1 from TEST2, but the query object is set to null. What is weird is the packet is in the xml when I debug it.  Not sure what is going on now.

Skips over my code to send the response because the query object is null.

this is the code of the Query member:

  1. public Element Query
  2. {
  3.     get
  4.     {        
  5.         return this.SelectSingleElement("query");
  6.     }
  7.     set
  8.     {
  9.         if (value != null)
  10.             ReplaceChild(value);
  11.         else
  12.             RemoveTag("query");    
  13.     }
  14. }

as you can see it finds only tags with the tagname query.
Use either FirstNode or similar members, or change the tagname of your custom element.

Alex
Avatar
BringerOD #6
Member since Dec 2005 · 12 posts
Group memberships: Members
Show profile · Link to this post
Hmm . .

Ok, well I was attempting to follow the instructions in the "creating_own_packet_types.pdf" file.

Maybe that file needs to be updated. 

Still not quite sure what I need to do.

I basically copied the WeatherIq in the document, where it replaces the query function.

using System;
using agsXMPP;
using agsXMPP.protocol.client;
public class WeatherIq : IQ
{
private Weather m_Weather = new Weather();
public WeatherIq()
{
base.Query = m_Weather;
this.GenerateId();
}
public WeatherIq(IqType type)
: this()
{
this.Type = type;
}
public WeatherIq(IqType type, Jid to)
: this(type)
{
this.To = to;
}
public WeatherIq(IqType type, Jid to, Jid from)
: this(type, to)
{
this.From = from;
}
public new Weather Query
{
get
{
return m_Weather;
}
}
}
Avatar
Alex #7
Member since Feb 2003 · 4307 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Quote by BringerOD:
Ok, well I was attempting to follow the instructions in the "creating_own_packet_types.pdf" file.

Maybe that file needs to be updated. 

no its correct. The Iq example of this document build the following xml:

  1. <iq to=’romeo@montagne.net’ from=’weather.mortagne.net’ type=’result’ id=’agsXMPP_1’>
  2.  <query xmlns=’agsoftware:weather’>
  3.     <humidity>90</humidity >
  4.     <temperature>57</temperature>
  5.     <zip>74080</zip>
  6.  </query>
  7. </iq>

as you can see the custom stuff is contained in a query tag with a custom namespace. So the Query member can retrieve this element.

Alex
Avatar
BringerOD #8
Member since Dec 2005 · 12 posts
Group memberships: Members
Show profile · Link to this post
I am sure you are right.  I still don't seem to get it.  You can see in the code I posted it's almost exactly what is in the pdf document.

I appreciate the help.  I can imagine it's a pain.

Bryan
Avatar
Alex #9
Member since Feb 2003 · 4307 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
As I said before the Query member finds only children with the tagname query

your packet:
  1. <iq id="agsXMPP_9" type="get" to="Test1@xmpp.prime.web.local/agsXMPP" from="test2@xmpp.prime.web.local/agsXMPP">
  2.    <!-- tagname = primepacket -->
  3.    <primepacket xmlns="primeCRM:primepacket">
  4.       <MessageData />
  5.       <MessageType>Ping</MessageType>
  6.       <FromJabberId>test2@xmpp.prime.web.local/agsXMPP</FromJabberId>
  7.       <ToJabberId>Test1@xmpp.prime.web.local/agsXMPP</ToJabberId>
  8.       <AgentId />
  9.       <ClientInstanceId />
  10.       <SentDateTime>12/04/2011 12:14:43</SentDateTime>
  11.    </primepacket>
  12. </iq>

packet of the tutorial:
  1. <iq to=’romeo@montagne.net’ from=’weather.mortagne.net’ type=’result’ id=’agsXMPP_1’>
  2.    <!-- tagname = query -->
  3.    <query xmlns=’agsoftware:weather’>
  4.       <humidity>90</humidity >
  5.       <temperature>57</temperature>
  6.       <zip>74080</zip>
  7.    </query>
  8. </iq>

My custom Element has the tagname query, yours has the tagname primepacket.

If you want to use the Query member you have to rename your custom element.
if not, then just use this code:

  1. if (iq.HasTag<PrimePacket>())
  2. {
  3.    var pp = iq.SelectSingleElement<PrimePacket>();
  4. }

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: agsXMPP RSS