}
//TODO throw an exception if dialog elements are lacking when dialog is built from 200
protected Dialog buildOrUpdateDialogForUac(SipResponse sipResponse,
Transaction transaction) {
SipHeaders headers = sipResponse.getSipHeaders();
Dialog dialog = dialogManager.getDialog(sipResponse);
if (dialog == null) {
dialog = dialogManager.createDialog(sipResponse);
}
//12.1.2
//TODO if request uri contains sips scheme or if sent over tls => dialog.setSecure(true)
//route set
ArrayList<String> routeSet = computeRouteSet(headers);
if (routeSet != null) {
dialog.setRouteSet(routeSet);
}
//remote target
SipHeaderFieldValue contact = headers.get(new SipHeaderFieldName(RFC3261.HDR_CONTACT));
logger.debug("Contact: " + contact);
if (contact != null) {
String remoteTarget = NameAddress.nameAddressToUri(contact.toString());
dialog.setRemoteTarget(remoteTarget);
}
SipHeaders requestSipHeaders = transaction.getRequest().getSipHeaders();
//local cseq
String requestCSeq = requestSipHeaders.get(
new SipHeaderFieldName(RFC3261.HDR_CSEQ)).toString();
requestCSeq = requestCSeq.substring(0, requestCSeq.indexOf(' '));
dialog.setLocalCSeq(Integer.parseInt(requestCSeq));
//callID
//already done in createDialog()
// String requestCallID = requestSipHeaders.get(
// new SipHeaderFieldName(RFC3261.HDR_CALLID)).toString();
// dialog.setCallId(requestCallID);
//local tag
//already done in createDialog()
// SipHeaderFieldValue requestFrom = requestSipHeaders.get(
// new SipHeaderFieldName(RFC3261.HDR_FROM));
// String requestFromTag =
// requestFrom.getParam(new SipHeaderParamName(RFC3261.PARAM_TAG));
// dialog.setLocalTag(requestFromTag);
//remote tag
//already done in createDialog()
// dialog.setRemoteTag(toTag);
//remote uri
SipHeaderFieldValue to = headers.get(new SipHeaderFieldName(RFC3261.HDR_TO));
if (to != null) {
String remoteUri = to.getValue();
if (remoteUri.indexOf(RFC3261.LEFT_ANGLE_BRACKET) > -1) {
remoteUri = NameAddress.nameAddressToUri(remoteUri);
}
dialog.setRemoteUri(remoteUri);
}
//local uri
SipHeaderFieldValue requestFrom = requestSipHeaders.get(
new SipHeaderFieldName(RFC3261.HDR_FROM));
String localUri = requestFrom.getValue();
if (localUri.indexOf(RFC3261.LEFT_ANGLE_BRACKET) > -1) {
localUri = NameAddress.nameAddressToUri(localUri);
}