* @return true if the message is part of this transaction, false if not.
*/
public boolean isMessagePartOfTransaction(SIPMessage messageToTest) {
// List of Via headers in the message to test
ViaList viaHeaders = messageToTest.getViaHeaders();
// Flags whether the select message is part of this transaction
boolean transactionMatches;
String messageBranch = ((Via) viaHeaders.getFirst()).getBranch();
boolean rfc3261Compliant = getBranch() != null
&& messageBranch != null
&& getBranch().toLowerCase().startsWith(
SIPConstants.BRANCH_MAGIC_COOKIE_LOWER_CASE)
&& messageBranch.toLowerCase().startsWith(
SIPConstants.BRANCH_MAGIC_COOKIE_LOWER_CASE);
transactionMatches = false;
if (TransactionState.COMPLETED == this.getState()) {
if (rfc3261Compliant) {
transactionMatches = getBranch().equalsIgnoreCase(
((Via) viaHeaders.getFirst()).getBranch())
&& getMethod().equals(messageToTest.getCSeq().getMethod());
} else {
transactionMatches = getBranch().equals(messageToTest.getTransactionId());
}
} else if (!isTerminated()) {
if (rfc3261Compliant) {
if (viaHeaders != null) {
// If the branch parameter is the
// same as this transaction and the method is the same,
if (getBranch().equalsIgnoreCase(((Via) viaHeaders.getFirst()).getBranch())) {
transactionMatches = getOriginalRequest().getCSeq().getMethod().equals(
messageToTest.getCSeq().getMethod());
}
}