public interface SipHeader extends Cloneable
Represents any header in SIP.
All SipHeader
s in this API are created through a set of factory methods as well as
through builders. Any header that is simple in nature, as in it only contains a single value,
such as the MaxForwardsHeader
, can be created directly through a create
method on the the corresponding interface of that header. Headers that are constructed through
many arguments, or have ambiguous arguments, are created through builders. Finally, all headers
have a frame
method that takes a Buffer
and will attempt to frame the
content into a specific header. Note it frames the header and as such does not verify
every aspect of the header since speed is important.
Example: create a simple header directly, such as the MaxForwardsHeader
.
MaxForwardsHeader header = MaxForwardsHeader.create(20);
Example: create a header using the builder-pattern, such as a ToHeader
.
ToHeader header = ToHeader.with().user("alice").host("example.com").build();
Note, by default most things are done lazily in order to speed things up. As such, you may
successfully construct a header but it may in fact miss important information. If you are
building an io.sipstack.application.application where you want to be 100% sure that a header is correct according to the
BNF in rfc 3261 then call verify()
.
Modifier and Type | Interface and Description |
---|---|
static interface |
SipHeader.Builder<H extends SipHeader> |
Modifier and Type | Field and Description |
---|---|
static String |
CANNOT_CAST_HEADER_OF_TYPE |
static String |
UNABLE_TO_PARSE_OUT_THE_HEADER_NAME_DUE_TO_UNDERLYING_IO_EXCEPTION |
Modifier and Type | Method and Description |
---|---|
SipHeader |
clone() |
SipHeader.Builder |
copy()
Everything within the pkts.io SIP module are immutable so if you actually want
to change anything you have to create a copy, which will return a specific Builder
for that header.
|
static SipHeader |
create(String name,
String value) |
SipHeader |
ensure()
As most things in this library are done lazily, such as framing headers, you can make sure
that a particular header has indeed been parsed to the more specific header type by calling
this method.
|
static SipHeader |
frame(Buffer value)
Create a new
SipHeader based on the buffer. |
static SipHeader |
frame(String value) |
default int |
getBufferSize() |
void |
getBytes(Buffer dst) |
Buffer |
getName()
Get the name of the header
|
default String |
getNameStr()
Get the name as a string.
|
Buffer |
getValue()
Get the value of the buffer
|
default boolean |
is(Buffer name) |
default boolean |
is(String name)
Convenience method for checking the name of this header.
|
default boolean |
isAddressParametersHeader()
If you use the
ensure() method then, if possible, the header will
be parsed to a more specific header type but you may not know exactly which type
but you can use the various isXXX methods to find out. |
default boolean |
isCallIdHeader() |
default boolean |
isContactHeader()
Check whether this is a contact header.
|
default boolean |
isContentLengthHeader() |
default boolean |
isContentTypeHeader() |
default boolean |
isCSeqHeader() |
default boolean |
isExpiresHeader() |
default boolean |
isFromHeader() |
default boolean |
isMaxForwardsHeader() |
default boolean |
isRecordRouteHeader() |
default boolean |
isRouteHeader() |
default boolean |
isSubjectHeader() |
default boolean |
isSystemHeader() |
default boolean |
isToHeader() |
default boolean |
isViaHeader() |
default AddressParametersHeader |
toAddressParametersHeader() |
default CallIdHeader |
toCallIdHeader() |
default ContactHeader |
toContactHeader() |
default ContentLengthHeader |
toContentLengthHeader() |
default ContentTypeHeader |
toContentTypeHeader() |
default CSeqHeader |
toCSeqHeader() |
default ExpiresHeader |
toExpiresHeader() |
default FromHeader |
toFromHeader() |
default MaxForwardsHeader |
toMaxForwardsHeader() |
default RecordRouteHeader |
toRecordRouteHeader() |
default RouteHeader |
toRouteHeader() |
default ToHeader |
toToHeader() |
default ViaHeader |
toViaHeader() |
void |
verify() |
static final String CANNOT_CAST_HEADER_OF_TYPE
static final String UNABLE_TO_PARSE_OUT_THE_HEADER_NAME_DUE_TO_UNDERLYING_IO_EXCEPTION
Buffer getName()
default String getNameStr()
default boolean is(String name)
name
- default boolean is(Buffer name)
Buffer getValue()
void verify() throws SipParseException
SipParseException
void getBytes(Buffer dst)
default int getBufferSize()
SipHeader clone()
static SipHeader frame(Buffer value) throws SipParseException
SipHeader
based on the buffer. Each SipHeader
will override this
factory method to parse the header into a more specialized header.
Note, the header returned really is a SipHeader
and is NOT e.g. a ToHeader
.
If you really need to parse it as a ToHeader
you should use theheader
- the raw headerSipHeader
.SipParseException
- in case the header is not a correct formatted header.static SipHeader frame(String value) throws SipParseException
SipParseException
SipHeader ensure()
ContactHeader
but it is still in its "raw" form and therefore represented as a
SipHeader
as opposed to an actual ContactHeader
but by calling this method
you will force the library to actually fully frame it.
Note, if the header is successfully parsed into a more explicit header type you may
still not really know what to cast it so in order to make life somewhat easier you can
use the isXXXHeader methods (such as isAddressParametersHeader()
to
check what type it possible can be and then use the corresponding toXXXHeader to
"cast" it.default boolean isAddressParametersHeader()
ensure()
method then, if possible, the header will
be parsed to a more specific header type but you may not know exactly which type
but you can use the various isXXX methods to find out.default boolean isSystemHeader()
default boolean isFromHeader()
default FromHeader toFromHeader()
default boolean isToHeader()
default ToHeader toToHeader()
default boolean isContactHeader()
ensure()
.toContactHeader()
because the way this method works is that if the header hasn't been fully framed
then the default method, which is on the SipHeader
itself, will check the method name
if it "spells" "Contact". However, if the header you have really has been parsed into a
ContactHeader
then this method will be overridden to return true right away
but since you cannot know that you must force it to be framed (if you actually want to
work with the ContactHeader
interface i.e.), which is done by calling
ensure()
.default ContactHeader toContactHeader()
default boolean isSubjectHeader()
default boolean isCallIdHeader()
default CallIdHeader toCallIdHeader()
default boolean isRouteHeader()
default boolean isRecordRouteHeader()
default RecordRouteHeader toRecordRouteHeader()
default RouteHeader toRouteHeader()
default boolean isContentLengthHeader()
default ContentLengthHeader toContentLengthHeader()
default boolean isContentTypeHeader()
default ContentTypeHeader toContentTypeHeader()
default boolean isExpiresHeader()
default ExpiresHeader toExpiresHeader()
default boolean isCSeqHeader()
default CSeqHeader toCSeqHeader()
default boolean isMaxForwardsHeader()
default ViaHeader toViaHeader()
default boolean isViaHeader()
default MaxForwardsHeader toMaxForwardsHeader()
default AddressParametersHeader toAddressParametersHeader() throws ClassCastException
ClassCastException
SipHeader.Builder copy()
Copyright © 2016. All Rights Reserved.