我正在尝试创建转发请求以转发呼叫,我已创建了引荐和已转发的标头,并且对于联系人标头,它是作为follos SipURI myURI = address.createSipURI(contactNew, realm);
Address contactAddress = addressFactory.createAddress(myURI);
contactAddress.setDisplayName(contactNew);
ContactHeader contactHeader = headerFactory.createContactHeader(contactAddress);
(contactNew是联系人价值,领域是我的域名) 当我发送REFER请求时,我得到了响应“400缺少联系人”,并且我的请求中没有显示联系人标题!我没找到问题出在哪里! 谁能帮我 ?提前谢谢
答案 0 :(得分:0)
我没有看到您将该联系人标题添加到您要发送的请求中。你这样做:
referRequest.addHeader(contactHeader);
您必须在发送请求之前执行此操作。否则,您只有一个未使用的独立联系人标题。如果那不是问题那么你应该附上调试日志。
答案 1 :(得分:0)
private void refer(Request request, String referTo, String referredBy, String contactNew) throws Exception {
try{
AddressFactory address = SipFactory.getInstance().createAddressFactory();
FromHeader fromheader = (FromHeader)request.getHeader(FromHeader.NAME);
String tagfrom=fromheader.getTag();
// System.out.println(((FromHeader)request.getHeader(FromHeader.NAME)).getAddress().toString());
//from
SipURI myRealmURI = addressFactory.createSipURI(username, realm);
Address fromAddress = addressFactory.createAddress(myRealmURI);
fromAddress.setDisplayName(username);
FromHeader fromHeader = headerFactory.createFromHeader(fromAddress, new BigInteger(130, tag).toString(32));
//to
//ki nous a appelé!?????
String appelant=((FromHeader)request.getHeader(FromHeader.NAME)).getAddress().toString();
int index=appelant.indexOf("@");
int index1=appelant.indexOf(":");
SipURI myRealmURII = addressFactory.createSipURI(appelant.substring(index1+1, (index)), realm);
Address toAddress = addressFactory.createAddress(myRealmURII);
toAddress.setDisplayName(appelant.substring(index1+1, (index)));
ToHeader toHeader = headerFactory.createToHeader(toAddress,tagfrom);
//refer-to:à saisir
String ref="sip:"+referTo + "@"+realm;
ReferToHeader referto = headerFactory.createReferToHeader(
addressFactory.createAddress( ref )
);
//contactHeader
//referred-by
Header referredby = headerFactory.createHeader("Referred-By","sip:"+referredBy+"@"+realm);
URI requestURI =addressFactory.createURI("sip:sip.ooredoo.tn"+":"+distantPort);
List<ViaHeader> viaHeaders = new ArrayList<>();
CallIdHeader callIdHeader = sipProvider.getNewCallId();
long seq = 1;
CSeqHeader cSeqHeader = headerFactory.createCSeqHeader(seq++, Request.REFER);
int max=70;
MaxForwardsHeader maxForwards = headerFactory.createMaxForwardsHeader(max);
Request reques = messageFactory.createRequest(requestURI, Request.REFER, callIdHeader,
cSeqHeader, fromHeader, toHeader, viaHeaders, maxForwards);
SipURI myURI = address.createSipURI(contactNew, realm);
Address contactAddress = addressFactory.createAddress(myURI);
contactAddress.setDisplayName(contactNew);
ContactHeader contactHeader = headerFactory.createContactHeader(contactAddress);
request.addHeader(contactHeader);
reques.addHeader(referto);
reques.addHeader(referredby);
System.out.println(contactHeader.toString());
ClientTransaction transaction = sipProvider.getNewClientTransaction(reques);
transaction.sendRequest();
System.out.println(reques.toString());
CallID callidres = (CallID)reques.getHeader(CallID.NAME);
((DefaultTableModel)jTable3.getModel()).addRow(new Object[]{new date().date(),username,appelant.substring(index1+1, (index)) ,contactNew,password,localPort,distantPort,protocol,proxy,ipSRC,callidres.getValue(),"REGISTERED","REFER"});
} catch (Throwable e) {
e.printStackTrace();
System.out.println("Can't send REFER reply.");
} }
PS:这是&#34;参考&#34;
的方法