Package com.opencloud.sentinel.util
Class SIPUtil
- java.lang.Object
-
- com.opencloud.sentinel.util.SIPUtil
-
public class SIPUtil extends java.lang.Object
Utility class for SIP Messages.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
APP_SDP_VALUE
SDP Media type value.static javax.mail.internet.ContentType
APPLICATION_SDP_MIME_TYPE
static java.lang.String
ERROR_CODE_ANNOUNCED_HEADER_NAME
OC-Error-Code-Announced header namestatic java.lang.String
EVENT_HEADER_NAME
Deprecated.static java.lang.String
INITIAL_QOS_REMOTE
static javax.mail.internet.ContentType
MULTIPART_MIXED_MIME_TYPE
static java.lang.String
MULTIPART_MIXED_VALUE
multipart mixedstatic java.lang.String
MULTIPART_VALUE
multipartstatic java.lang.String
RELIABLE_PROVISIONAL_VALUE
Reliable provisional response option tag value.static java.lang.String
SDP_ATTRIBUTE_TYPE_RTPMAP
static java.lang.String
TERMINATING_DOMAIN_HEADER_NAME
SIP OC-Terminating-Domain Header name.static javax.mail.internet.ContentType
TEXT_PLAIN_MIME_TYPE
-
Constructor Summary
Constructors Constructor Description SIPUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addAllowEventsValues(org.jainslee.resources.sip.SipMessage sipMessage, java.lang.String... values)
Make sure SIP message contains Allow-events header with specified valuesstatic void
addAllowHeaderValues(org.jainslee.resources.sip.SipMessage sipMessage, java.lang.String... values)
Make sure SIP message contains Allow header with specified valuesstatic void
addMessageContent(org.jainslee.resources.sip.SipMessage message, MessageBody messageBody, boolean replace, javax.slee.facilities.Tracer tracer)
Sets content in the body of a SIP message.static boolean
checkMediaDescriptionsEqual(javax.sdp.MediaDescription m1, javax.sdp.MediaDescription m2)
Compares two media descriptions. returns true if the are the same.static void
copyListedHeadersToOutgoingMessage(org.jainslee.resources.sip.SipMessage incomingMessage, org.jainslee.resources.sip.SipMessage outgoingMessage, java.util.List<java.lang.String> headersToCopy)
Add specified header value/s to an outgoing message.static void
copySDPSessionVersion(org.jainslee.resources.sip.OutgoingSipRequest outgoingInvite, com.opencloud.sentinel.sdp.SessionDescriptionWrapper latestReceivedSDP, javax.slee.facilities.Tracer tracer)
Copies the SDP session version from the latest received SDP into the outgoing INVITE's SDP.static java.lang.Integer
getMaxExpires(javax.sip.message.Response response)
Gets the maximum expires value (in seconds) found in the global expires header or in any of the contact headers.static java.util.List<MessageBody>
getMessageContent(org.jainslee.resources.sip.SipMessage message, javax.mail.internet.ContentType contentType, javax.slee.facilities.Tracer tracer)
Retrieves message content from a SIP message as a MessageBody.static MessageBody
getSDPMessageBody(org.jainslee.resources.sip.SipMessage message, javax.slee.facilities.Tracer tracer)
Gets the first SDP body in a message; if the message has Content-Type "application/sdp", or a multipart body with an "application/sdp" part.static java.lang.String
getSDPString(org.jainslee.resources.sip.SipMessage sipMessage)
static SubscribedEventID
getSubscribedEventID(org.jainslee.resources.sip.SipMessage message)
Return a subscribed event ID, if present in the message.static boolean
isInitialSipRequest(org.jainslee.resources.sip.SipRequest request)
Returns true if the SipRequest is an initial request.static java.lang.String
makeSIPAddress(java.lang.String user, boolean isSipUri, java.lang.String sipDomain)
It creates a string for the SIP Address user to be used in the SIP Requests.static void
removeMessageContent(org.jainslee.resources.sip.SipMessage message, javax.mail.internet.ContentType contentType, javax.slee.facilities.Tracer tracer)
Removes content with the given content type from a SIP message, or any and all content if no content type is provided.static void
removeSipMessageBody(org.jainslee.resources.sip.SipMessage message)
Removes the message body from a SIP message.static java.lang.String
removeTagsFromURI(java.lang.String uri)
Removes any parameters from the URI Stringstatic void
setSDPBody(org.jainslee.resources.sip.SipMessage message, java.lang.String sdp, javax.slee.facilities.Tracer tracer)
Sets SDP content in a message.static void
updateSDPPreconditions(org.jainslee.resources.sip.OutgoingSipRequest outgoingInvite, com.opencloud.sentinel.sdp.SessionDescriptionWrapper latestReceivedSDP, javax.slee.facilities.Tracer tracer)
Sets SDP qos attributes of an outgoing INVITE based on a provided SDP.
-
-
-
Field Detail
-
EVENT_HEADER_NAME
@Deprecated public static final java.lang.String EVENT_HEADER_NAME
Deprecated.Deprecated. Use javax.sip.header.EventHeader.NAME SIP Event Header name.- See Also:
- Constant Field Values
-
TERMINATING_DOMAIN_HEADER_NAME
public static final java.lang.String TERMINATING_DOMAIN_HEADER_NAME
SIP OC-Terminating-Domain Header name.- See Also:
- Constant Field Values
-
ERROR_CODE_ANNOUNCED_HEADER_NAME
public static final java.lang.String ERROR_CODE_ANNOUNCED_HEADER_NAME
OC-Error-Code-Announced header name- See Also:
- Constant Field Values
-
APP_SDP_VALUE
public static final java.lang.String APP_SDP_VALUE
SDP Media type value.- See Also:
- Constant Field Values
-
MULTIPART_VALUE
public static final java.lang.String MULTIPART_VALUE
multipart- See Also:
- Constant Field Values
-
MULTIPART_MIXED_VALUE
public static final java.lang.String MULTIPART_MIXED_VALUE
multipart mixed- See Also:
- Constant Field Values
-
INITIAL_QOS_REMOTE
public static final java.lang.String INITIAL_QOS_REMOTE
- See Also:
- Constant Field Values
-
RELIABLE_PROVISIONAL_VALUE
public static final java.lang.String RELIABLE_PROVISIONAL_VALUE
Reliable provisional response option tag value.- See Also:
- Constant Field Values
-
APPLICATION_SDP_MIME_TYPE
public static final javax.mail.internet.ContentType APPLICATION_SDP_MIME_TYPE
-
MULTIPART_MIXED_MIME_TYPE
public static final javax.mail.internet.ContentType MULTIPART_MIXED_MIME_TYPE
-
TEXT_PLAIN_MIME_TYPE
public static final javax.mail.internet.ContentType TEXT_PLAIN_MIME_TYPE
-
SDP_ATTRIBUTE_TYPE_RTPMAP
public static final java.lang.String SDP_ATTRIBUTE_TYPE_RTPMAP
- See Also:
- Constant Field Values
-
-
Method Detail
-
removeTagsFromURI
public static java.lang.String removeTagsFromURI(java.lang.String uri)
Removes any parameters from the URI String- Parameters:
uri
- URI String to strip of parameters.- Returns:
- uri URI String without parameters.
-
makeSIPAddress
public static java.lang.String makeSIPAddress(java.lang.String user, boolean isSipUri, java.lang.String sipDomain)
It creates a string for the SIP Address user to be used in the SIP Requests.- Parameters:
user
- the value to use as the user for SIP URI or Tel URIisSipUri
-True
for SIP URIs, otherwiseFalse
sipDomain
- SIP URI domain.- Returns:
- the String used to create a SIP URI or Tel URL
-
isInitialSipRequest
public static boolean isInitialSipRequest(org.jainslee.resources.sip.SipRequest request)
Returns true if the SipRequest is an initial request. This is determined by whether the TO Header has a populated Tag parameter.- Parameters:
request
- SipRequest to query.- Returns:
- true if the given SipRequest is an initial request.
-
addAllowEventsValues
public static void addAllowEventsValues(org.jainslee.resources.sip.SipMessage sipMessage, java.lang.String... values)
Make sure SIP message contains Allow-events header with specified values- Parameters:
sipMessage
- Target SIP messagevalues
- Parameterable value to add/set- Throws:
org.jainslee.resources.sip.SipParseException
-
addAllowHeaderValues
public static void addAllowHeaderValues(org.jainslee.resources.sip.SipMessage sipMessage, java.lang.String... values)
Make sure SIP message contains Allow header with specified values- Parameters:
sipMessage
- Target SIP messagevalues
- Parameterable value to add/set
-
getSubscribedEventID
public static SubscribedEventID getSubscribedEventID(org.jainslee.resources.sip.SipMessage message)
Return a subscribed event ID, if present in the message. Used to distinguish subscriptions on aLeg
. For SUBSCRIBE and NOTIFY requests and responses, use the Event header. REFER requests and responses automatically have the event name "refer", with "id" set to the REFER's sequence number.- Parameters:
message
- a SIP message- Returns:
- a
SubscribedEventID
object, or null if the message did not contain a subscribed event.
-
addMessageContent
public static void addMessageContent(@Nonnull org.jainslee.resources.sip.SipMessage message, @Nonnull MessageBody messageBody, boolean replace, @Nullable javax.slee.facilities.Tracer tracer) throws java.io.IOException
Sets content in the body of a SIP message. Will automatically create/modify/remove multipart bodies as required.- Parameters:
message
- The message to put the content in.messageBody
- The MessageBody object containing the content to add.replace
- if true, if the message already contains a body with the messageBody's content type then the provided content will replace the existing message content of that type.tracer
- Optional tracer for logging debug messages to.- Throws:
java.io.IOException
-
getMessageContent
public static java.util.List<MessageBody> getMessageContent(@Nonnull org.jainslee.resources.sip.SipMessage message, @Nullable javax.mail.internet.ContentType contentType, @Nullable javax.slee.facilities.Tracer tracer)
Retrieves message content from a SIP message as a MessageBody. If a message has multipart content then each individual part will be returned in its own MessageBody object. If the contentType is not null, then only content matching that type (ignoring parameters) will be returned. Note that nested multipart bodies will be returned in a single MessageBody, and providing a multipart contentType parameter will only return matching nested multipart bodies.- Parameters:
message
- The message to retrieve content from.contentType
- The Content-Type of the desired content, or null for any and all content.tracer
- Optional tracer for debug logging.- Returns:
- A list of all content parts with matching Content-Type, empty list if there is no matching content.
-
removeMessageContent
public static void removeMessageContent(@Nonnull org.jainslee.resources.sip.SipMessage message, @Nullable javax.mail.internet.ContentType contentType, @Nullable javax.slee.facilities.Tracer tracer) throws java.io.IOException
Removes content with the given content type from a SIP message, or any and all content if no content type is provided. If the message has a multipart content body, each content part will be handled individually.- Parameters:
message
- The message to strip content from.contentType
- The type of content to strip, or null if all content should be stripped.tracer
- An optional tracer for debug logging.- Throws:
java.io.IOException
- If there is an issue while handling multipart content that prevents content from being stripped.
-
copyListedHeadersToOutgoingMessage
public static void copyListedHeadersToOutgoingMessage(org.jainslee.resources.sip.SipMessage incomingMessage, org.jainslee.resources.sip.SipMessage outgoingMessage, java.util.List<java.lang.String> headersToCopy)
Add specified header value/s to an outgoing message. The method removes any existing header values from the outgoing message before adding the new values. This method can be used in simple cases where all values of the header/s specified are to be copied.- Parameters:
incomingMessage
- the incoming sip message, notnull
.outgoingMessage
- the outgoing sip message, notnull
.headersToCopy
- A list of header/s that need to be copied to the outgoing message
-
removeSipMessageBody
public static void removeSipMessageBody(@Nonnull org.jainslee.resources.sip.SipMessage message)
Removes the message body from a SIP message. Will also strip the following associated headers if they are present: - Content-Type - Content-Disposition - Content-Language - Content-Encoding (The Content-Length header is handled automatically)- Parameters:
message
- The message to remove the body from.
-
getSDPMessageBody
public static MessageBody getSDPMessageBody(@Nonnull org.jainslee.resources.sip.SipMessage message, @Nullable javax.slee.facilities.Tracer tracer)
Gets the first SDP body in a message; if the message has Content-Type "application/sdp", or a multipart body with an "application/sdp" part.- Parameters:
message
- the SIP message to get SDP from.tracer
- Optional tracer for debug logging.- Returns:
- the SDP body as a MessageBody, or null if no SDP could be found.
-
setSDPBody
public static void setSDPBody(@Nonnull org.jainslee.resources.sip.SipMessage message, @Nonnull java.lang.String sdp, @Nullable javax.slee.facilities.Tracer tracer) throws java.io.IOException
Sets SDP content in a message. Will automatically overwrite any existing SDP in the message. Handles SDP inside multipart bodies.- Parameters:
message
- The message to set the SDP in.sdp
- The UTF-8 encoded SDP content to be set.tracer
- Optional tracer for debug logging.- Throws:
java.io.IOException
- If there is an issue reading any existing content body in the message.
-
updateSDPPreconditions
public static void updateSDPPreconditions(org.jainslee.resources.sip.OutgoingSipRequest outgoingInvite, com.opencloud.sentinel.sdp.SessionDescriptionWrapper latestReceivedSDP, javax.slee.facilities.Tracer tracer)
Sets SDP qos attributes of an outgoing INVITE based on a provided SDP. Copies current local qos status from latestReceivedSDP, e.g a=curr:qos local sendrecv Sets current remote qos status to none, e.g a=curr: qos remote none- Parameters:
outgoingInvite
- The INVITE to update.latestReceivedSDP
- the SDP to copy local precondition attributes fromtracer
- Optional tracer for debug logging.
-
copySDPSessionVersion
public static void copySDPSessionVersion(org.jainslee.resources.sip.OutgoingSipRequest outgoingInvite, com.opencloud.sentinel.sdp.SessionDescriptionWrapper latestReceivedSDP, javax.slee.facilities.Tracer tracer)
Copies the SDP session version from the latest received SDP into the outgoing INVITE's SDP. This is required in sequential forking scenarios when retargeting the initial request, so that the called party will sees a valid monotonically increasing sequence of versions in SDP offers it receives from the calling party. Subsequent offers do not need to be updated.- Parameters:
outgoingInvite
- the INVITE request to be forwardedlatestReceivedSDP
- the latest SDP received from the calling party. This SDP's version will be copied into the output requesttracer
- a tracer
-
getSDPString
public static java.lang.String getSDPString(@Nonnull org.jainslee.resources.sip.SipMessage sipMessage) throws java.io.IOException
- Throws:
java.io.IOException
-
checkMediaDescriptionsEqual
public static boolean checkMediaDescriptionsEqual(javax.sdp.MediaDescription m1, javax.sdp.MediaDescription m2)
Compares two media descriptions. returns true if the are the same. Modified from gov.nist.javax.sdp.MediaDescriptionImpl to ensure that rtpmap attributes for matching codes are equivalent if one specifies an explicit channel declaration and the other relies on the implicit value m1 -> rtpmap: 100 AMR/16000/1 m2 -> rtpmap: 100 AMR/16000- Parameters:
m1
- The first media descriptionm2
- The second media description- Returns:
- True if both media descriptions are equivalent
-
getMaxExpires
public static java.lang.Integer getMaxExpires(javax.sip.message.Response response)
Gets the maximum expires value (in seconds) found in the global expires header or in any of the contact headers.- Parameters:
response
- the SIP response- Returns:
- the maximum expires value (in seconds) or null if none is found
-
-