Re: any JSR that describe on presence's PIDF ?

Man-Chi Leung <[email protected]>
Newsgroups gmane.comp.voip.nist-sip
Message-ID <[email protected]>
hi Becky,

thanks so much for your advice. i was looking at sipunit too :-D

btw, I also managed to find some ideas from sip-communicator(old source 
tree) 's package /net/java/sip/communicator/sip/simple for PIDF 
pasrsing.

~manchi


On 2006-07-19 19:10:49 +0800, Becky McElroy <[email protected]> said:

> Man-Chi,
> 
> I don't know about a JSR, but for SipUnit I used JAXB which was 
> probably overkill and isn't completely perfect, yet anyway. But simple 
> - given an XMLSchema definition and a jaxb compiler, Java classes are 
> autogenerated that you can then use to parse and validate a received 
> XML doc. You can look at the SipUnit project source dir (download from 
> cafesip.org), the parts of interest are the build.xml (for jaxb 
> compiling), conf/presence-pidf.xsd, and the app code that uses it 
> (org.cafesip.sipunit.Subscription) - method below, called after 
> validating the NOTIFY headers. The classes you see like 'Tuple' are the 
> autogenerated ones.
> 
> Becky
> 
>     private void updatePresenceInfo(Request request) throws StatusReport
>     {
>         // parse the presence info contained in the message, if any
> 
>         byte[] body_bytes = request.getRawContent();
>         if (body_bytes == null)
>         {
>             return;
>         }
> 
>         // check for supported content type, currently supporting only the
>         // package default
> 
>         ContentTypeHeader ct = (ContentTypeHeader) request
>                 .getHeader(ContentTypeHeader.NAME);
> 
>         if (ct == null)
>         {
>             throw new StatusReport(SipResponse.BAD_REQUEST,
>                     "NOTIFY body has bytes but no content type header 
> was received");
>         }
> 
>         if (ct.getContentType().equals("application") == false)
>         {
>             throw new StatusReport(SipResponse.UNSUPPORTED_MEDIA_TYPE,
>                     "received NOTIFY body with unsupported content type = "
>                             + ct.getContentType());
>         }
>         else if (ct.getContentSubType().equals("pidf+xml") == false)
>         {
>             throw new StatusReport(SipResponse.UNSUPPORTED_MEDIA_TYPE,
>                     "received NOTIFY body with unsupported content subtype = "
>                             + ct.getContentSubType());
>         }
> 
>         // parse and get info from the xml body
> 
>         try
>         {
>             Presence doc = (Presence) JAXBContext.newInstance(
>                     "org.cafesip.sipunit.presenceparser.pidf")
>                     .createUnmarshaller().unmarshal(
>                             new ByteArrayInputStream(body_bytes));
> 
>             // is it the correct presentity?
> 
>             if (!buddyUri.equals(doc.getEntity()))
>             {
>                 throw new StatusReport(SipResponse.BAD_REQUEST,
>                         "received NOTIFY body with wrong presentity = "
>                                 + doc.getEntity());
>             }
> 
>             // finally, update our presence information
> 
>             devices.clear();
>             if (doc.getTuple() != null)
>             {
>                 Iterator i = doc.getTuple().iterator();
>                 while (i.hasNext())
>                 {
>                     Tuple t = (Tuple) i.next();
> 
>                     PresenceDeviceInfo dev = new PresenceDeviceInfo();
>                     dev.setBasicStatus(t.getStatus().getBasic());
> 
>                     Contact contact = t.getContact();
>                     if (contact != null)
>                     {
>                         if (contact.getPriority() != null)
>                         {
>                             dev.setContactPriority(contact.getPriority()
>                                     .doubleValue());
>                         }
>                         dev.setContactValue(contact.getValue());
>                     }
> 
>                     dev.setDeviceExtensions(t.getAny());
>                     dev.setId(t.getId());
>                     dev.setStatusExtensions(t.getStatus().getAny());
>                     dev.setTimestamp(t.getTimestamp());
> 
>                     ArrayList notes = new ArrayList();
>                     if (t.getNote() != null)
>                     {
>                         Iterator j = t.getNote().iterator();
>                         while (j.hasNext())
>                         {
>                             Note n = (Note) j.next();
>                             notes.add(new PresenceNote(n.getLang(), n
>                                     .getValue()));
>                         }
>                     }
>                     dev.setDeviceNotes(notes);
> 
>                     devices.put(t.getId(), dev);
>                 }
>             }
> 
>             presenceNotes.clear();
>             if (doc.getNote() != null)
>             {
>                 Iterator i = doc.getNote().iterator();
>                 while (i.hasNext())
>                 {
>                     Note n = (Note) i.next();
>                     presenceNotes.add(new PresenceNote(n.getLang(), n
>                             .getValue()));
>                 }
>             }
> 
>             presenceExtensions.clear();
>             if (doc.getAny() != null)
>             {
>                 presenceExtensions.addAll(doc.getAny());
>             }
> 
>             SipStack
>                     .trace("Successfully processed NOTIFY message body 
> for Subscription to "
>                             + buddyUri);
>         }
>         catch (Exception e)
>         {
>             throw new StatusReport(SipResponse.BAD_REQUEST,
>                     "NOTIFY body parsing error : " + e.getMessage());
>         }
> 
>         return;
>     }
> 
> 
> 
> Man-Chi Leung wrote:
> 
>> hi,
>> 
>> I am looking an implemenation to parse out a PIDF xml message contained 
>> in for notify request.
>> 
>> just quick check, is PIDF supported in any JSR?
>> 
>> any existing PIDF parse is available? pls advise.
>> 
>> thanks,
>> ~manchi
>> 
>> 
>> _______________________________________________
>> nist-sip mailing list
>> [email protected]
>> http://www-x.antd.nist.gov/mailman/listinfo/nist-sip
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.