userAgent.getUac().terminate(sipRequest);
}
}
public void successResponseReceived(SipResponse sipResponse, Transaction transaction) {
SipHeaders responseHeaders = sipResponse.getSipHeaders();
String cseq = responseHeaders.get(
new SipHeaderFieldName(RFC3261.HDR_CSEQ)).getValue();
String method = cseq.substring(cseq.trim().lastIndexOf(' ') + 1);
if (!RFC3261.METHOD_INVITE.equals(method)) {
return;
}
challenged = false;
//13.2.2.4
List<String> peers = userAgent.getPeers();
String responseTo = responseHeaders.get(
new SipHeaderFieldName(RFC3261.HDR_TO)).getValue();
if (!peers.contains(responseTo)) {
peers.add(responseTo);
//timer used to purge dialogs which are not confirmed
//after a given time
ackTimer.schedule(new AckTimerTask(responseTo),
64 * RFC3261.TIMER_T1);
}
Dialog dialog = dialogManager.getDialog(sipResponse);
if (dialog != null) {
//dialog already created with a 180 for example
dialog.setRouteSet(computeRouteSet(sipResponse.getSipHeaders()));
}
dialog = buildOrUpdateDialogForUac(sipResponse, transaction);
SipListener sipListener = userAgent.getSipListener();
if (sipListener != null) {
sipListener.calleePickup(sipResponse);
}
//added for media
SessionDescription sessionDescription =
sdpManager.parse(sipResponse.getBody());
try {
mediaDestination = sdpManager.getMediaDestination(sessionDescription);
} catch (NoCodecException e) {
logger.error(e.getMessage(), e);
}
String remoteAddress = mediaDestination.getDestination();
int remotePort = mediaDestination.getPort();
Codec codec = mediaDestination.getCodec();
String localAddress = userAgent.getConfig()
.getLocalInetAddress().getHostAddress();
userAgent.getMediaManager().successResponseReceived(localAddress,
remoteAddress, remotePort, codec);
//switch to confirmed state
dialog.receivedOrSent2xx();
//generate ack
//p. 82 §3
SipRequest ack = dialog.buildSubsequentRequest(RFC3261.METHOD_ACK);
//update CSeq
SipHeaders ackHeaders = ack.getSipHeaders();
SipHeaderFieldName cseqName = new SipHeaderFieldName(RFC3261.HDR_CSEQ);
SipHeaderFieldValue ackCseq = ackHeaders.get(cseqName);
SipRequest request = transaction.getRequest();
SipHeaders requestHeaders = request.getSipHeaders();
SipHeaderFieldValue requestCseq = requestHeaders.get(cseqName);
ackCseq.setValue(requestCseq.toString().replace(RFC3261.METHOD_INVITE, RFC3261.METHOD_ACK));
//add Via with only the branchid parameter