Re: Implemeting an ExtensionHeader
"M. Ranganathan" <[email protected]>
| Newsgroups | gmane.comp.voip.nist-sip |
|---|---|
| Message-ID | <[email protected]> |
Hello! [email protected] wrote: > On Fri, 17 Nov 2006 at 13:49, M. Rangnathan wrote: > >> There is no Java trick involved. You implement ExtensionHeader just >> the same way as you implement any interface. However, what you are >> attempting to do will not work. >> >> Yes you will get a ClassCastException and thats because the stack >> keeps a NAME to Class mapping for the Factory and expects an header >> of NAME "Contact" to be of a type that implements >> javax.sip.header.ContactHeader and of type >> gov.nist.javax.sip.header.Contact > > > Um, OK. So what you are saying is that Headers are only conformant to > the interface specification if they are obtained from the HeaderFactory? No that is not what I (or anybody else) is saying. You can supply your own implementation of ContactHeader but the stack may cast it to gov.nist.javax.sip.Contact (and create a class cast if it is not sublcassed from gov.nist.javax.sip.Contact) and besides, the HeaderFactory will create objects of type gov.nist.javax.sip.Contact and hence your sublcass will be ignored. > It doesn't actually say that anywhere in the spec that I could find. > Perhaps it would be obvious to an experienced Java programmer. The only way to explicitly create headers is through the header factory. Upon examination of the specification one might learn that there is no other way to create headers than explictly though the header factory and implicitly via the MessageFactory.Therefore it is unambiguous. Now it is possible that if I switched to using the Interfaces internally rather than the implementation classes everywhere in the RI you could supply your own implementation of the classes (although the HeaderFactory would still create problems). However the changes required to support that are too pervasive and difficult. Besides, there is hardly much of use case for such a feature. In any case, I have neither the time nor inclination to attempt it nor is it required to be supported by the spec. The JAIN-SIP contract is this: as far as any external application goes, any header coming out of the JAIN-SIP implementation is supposed to comply with the Interfaces defined by the spec. So long as a JAIN-SIP implementation does that, it is compliant to the spec. A given JAIN-SIP implementation is NOT required to deal with headers coming out of another JAIN-SIP implementation. To give you a concrete example of what may not work in this case -- if you had a Listener registered with two stacks (from two different vendors), then if you took the header coming out of one of the stacks (via the common Listener) and tried sending it through the second vendor's provider, then it is quite legal for that vendor's provider to throw a class cast exception. ( You can of course go to String and back to Request and make this work but that is not the point. ) > > I must say that I'm disappointed by the high degree of coupling > demonstrated by this interface and code. So sorry to hear that. > As my case demonstrates, > this makes code reuse difficult. The code is all there for you to do what you want with. Nothing stops you from editing the java file and redistributing it with your product or project. You are basically asking for a way to deal with a stack that is not standards compliant ( Asterisk in this case). Please do edit the source code that is provided to you for exactly that purpose and make it deviate as much from RFC 3261 as you wish. > I wonder if this stems from a > kind of culture clash between the proprietary world and the open > source world I'm more familiar with. Ah nothing quite so deep. There is no conspiracy here. > > Anyway, I'll go hack the source. > > --David > _______________________________________________ > nist-sip mailing list > [email protected] > http://www-x.antd.nist.gov/mailman/listinfo/nist-sip > -- M. Ranganathan Advanced Networking Technologies Division, National Institute of Standards and Technology (NIST), 100 Bureau Drive, Stop 8920, Gaithersburg, MD 20899. tel:301 975 3664 , fax:301 590 0932 http://w3.antd.nist.gov/ Advanced Networking Technologies For the People!