//FIXME Contact header should probably added in response here.
SipHeaderFieldName contactName = new SipHeaderFieldName(RFC3261.HDR_CONTACT);
Dialog dialog = dialogManager.createDialog(sipResponse);
//build dialog state
//route set
SipHeaderFieldValue recordRoute =
respHeaders.get(new SipHeaderFieldName(RFC3261.HDR_RECORD_ROUTE));
ArrayList<String> routeSet = new ArrayList<String>();
if (recordRoute != null) {
if (recordRoute instanceof SipHeaderFieldMultiValue) {
SipHeaderFieldMultiValue multiRecordRoute =
(SipHeaderFieldMultiValue) recordRoute;
for (SipHeaderFieldValue routeValue : multiRecordRoute.getValues()) {
routeSet.add(routeValue.getValue());
}
} else {
routeSet.add(recordRoute.getValue());
}
}
dialog.setRouteSet(routeSet);
//remote target
SipHeaderFieldValue reqContact = reqHeaders.get(contactName);
String remoteTarget = reqContact.getValue();
if (remoteTarget.indexOf(RFC3261.LEFT_ANGLE_BRACKET) > -1) {
remoteTarget = NameAddress.nameAddressToUri(remoteTarget);
}
dialog.setRemoteTarget(remoteTarget);
//remote cseq
SipHeaderFieldName cseqName = new SipHeaderFieldName(RFC3261.HDR_CSEQ);
SipHeaderFieldValue cseq = reqHeaders.get(cseqName);
String remoteCseq = cseq.getValue().substring(0, cseq.getValue().indexOf(' '));
dialog.setRemoteCSeq(Integer.parseInt(remoteCseq));
//callid
SipHeaderFieldName callidName = new SipHeaderFieldName(RFC3261.HDR_CALLID);
SipHeaderFieldValue callid = reqHeaders.get(callidName);
dialog.setCallId(callid.getValue());
//local tag
SipHeaderFieldName toName = new SipHeaderFieldName(RFC3261.HDR_TO);
SipHeaderFieldValue to = respHeaders.get(toName);
SipHeaderParamName tagName = new SipHeaderParamName(RFC3261.PARAM_TAG);
String toTag = to.getParam(tagName);
dialog.setLocalTag(toTag);
//remote tag
SipHeaderFieldName fromName = new SipHeaderFieldName(RFC3261.HDR_FROM);
SipHeaderFieldValue from = reqHeaders.get(fromName);
String fromTag = from.getParam(tagName);
dialog.setRemoteTag(fromTag);
//remote uri
String remoteUri = from.getValue();
if (remoteUri.indexOf(RFC3261.LEFT_ANGLE_BRACKET) > -1) {
remoteUri = NameAddress.nameAddressToUri(remoteUri);
}
dialog.setRemoteUri(remoteUri);
//local uri
String localUri = to.getValue();
if (localUri.indexOf(RFC3261.LEFT_ANGLE_BRACKET) > -1) {
localUri = NameAddress.nameAddressToUri(localUri);
}
dialog.setLocalUri(localUri);
return dialog;
}