String branchId = topVia.getParam(new SipHeaderParamName(
RFC3261.PARAM_BRANCH));
InviteServerTransaction inviteServerTransaction =
(InviteServerTransaction)transactionManager
.getServerTransaction(branchId,RFC3261.METHOD_INVITE);
SipResponse cancelResponse;
if (inviteServerTransaction == null) {
//TODO generate CANCEL 481 Call Leg/Transaction Does Not Exist
cancelResponse = buildGenericResponse(sipRequest,
RFC3261.CODE_481_CALL_TRANSACTION_DOES_NOT_EXIST,
RFC3261.REASON_481_CALL_TRANSACTION_DOES_NOT_EXIST);
} else {
cancelResponse = buildGenericResponse(sipRequest,
RFC3261.CODE_200_OK, RFC3261.REASON_200_OK);
}
ServerTransaction cancelServerTransaction = transactionManager
.createServerTransaction(cancelResponse,
userAgent.getSipPort(),
RFC3261.TRANSPORT_UDP, this, sipRequest);
cancelServerTransaction.start();
cancelServerTransaction.receivedRequest(sipRequest);
cancelServerTransaction.sendReponse(cancelResponse);
if (cancelResponse.getStatusCode() != RFC3261.CODE_200_OK) {
return;
}
SipResponse lastResponse = inviteServerTransaction.getLastResponse();
if (lastResponse != null &&
lastResponse.getStatusCode() >= RFC3261.CODE_200_OK) {
return;
}
SipResponse inviteResponse = buildGenericResponse(
inviteServerTransaction.getRequest(),
RFC3261.CODE_487_REQUEST_TERMINATED,
RFC3261.REASON_487_REQUEST_TERMINATED);
inviteServerTransaction.sendReponse(inviteResponse);