|
@ -7,8 +7,11 @@ import javax.sip.Dialog; |
|
|
import javax.sip.InvalidArgumentException; |
|
|
import javax.sip.InvalidArgumentException; |
|
|
import javax.sip.ResponseEvent; |
|
|
import javax.sip.ResponseEvent; |
|
|
import javax.sip.SipException; |
|
|
import javax.sip.SipException; |
|
|
|
|
|
import javax.sip.address.Address; |
|
|
import javax.sip.address.SipURI; |
|
|
import javax.sip.address.SipURI; |
|
|
import javax.sip.header.CSeqHeader; |
|
|
import javax.sip.header.CSeqHeader; |
|
|
|
|
|
import javax.sip.header.ContactHeader; |
|
|
|
|
|
import javax.sip.header.FromHeader; |
|
|
import javax.sip.header.ViaHeader; |
|
|
import javax.sip.header.ViaHeader; |
|
|
import javax.sip.message.Request; |
|
|
import javax.sip.message.Request; |
|
|
import javax.sip.message.Response; |
|
|
import javax.sip.message.Response; |
|
@ -22,6 +25,9 @@ import com.genersoft.iot.vmp.gb28181.SipLayer; |
|
|
import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorFactory; |
|
|
import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorFactory; |
|
|
import com.genersoft.iot.vmp.gb28181.transmit.response.ISIPResponseProcessor; |
|
|
import com.genersoft.iot.vmp.gb28181.transmit.response.ISIPResponseProcessor; |
|
|
|
|
|
|
|
|
|
|
|
// import java.util.regex.Pattern;
|
|
|
|
|
|
// import java.util.regex.Matcher;
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @Description:处理INVITE响应 |
|
|
* @Description:处理INVITE响应 |
|
|
* @author: songww |
|
|
* @author: songww |
|
@ -35,17 +41,16 @@ public class InviteResponseProcessor implements ISIPResponseProcessor { |
|
|
/** |
|
|
/** |
|
|
* 处理invite响应 |
|
|
* 处理invite响应 |
|
|
* |
|
|
* |
|
|
* @param evt |
|
|
* @param evt 响应消息 |
|
|
* 响应消息 |
|
|
* @throws ParseException |
|
|
*/ |
|
|
*/ |
|
|
@Override |
|
|
@Override |
|
|
public void process(ResponseEvent evt, SipLayer layer, SipConfig config) { |
|
|
public void process(ResponseEvent evt, SipLayer layer, SipConfig config) throws ParseException { |
|
|
try { |
|
|
try { |
|
|
Response response = evt.getResponse(); |
|
|
Response response = evt.getResponse(); |
|
|
int statusCode = response.getStatusCode(); |
|
|
int statusCode = response.getStatusCode(); |
|
|
// trying不会回复
|
|
|
// trying不会回复
|
|
|
if (statusCode == Response.TRYING) { |
|
|
if (statusCode == Response.TRYING) { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
// 成功响应
|
|
|
// 成功响应
|
|
|
// 下发ack
|
|
|
// 下发ack
|
|
@ -56,8 +61,9 @@ public class InviteResponseProcessor implements ISIPResponseProcessor { |
|
|
// return;
|
|
|
// return;
|
|
|
// }
|
|
|
// }
|
|
|
// Dialog clientDialog = clientTransaction.getDialog();
|
|
|
// Dialog clientDialog = clientTransaction.getDialog();
|
|
|
//
|
|
|
|
|
|
// CSeqHeader clientCSeqHeader = (CSeqHeader) response.getHeader(CSeqHeader.NAME);
|
|
|
// CSeqHeader clientCSeqHeader = (CSeqHeader)
|
|
|
|
|
|
// response.getHeader(CSeqHeader.NAME);
|
|
|
// long cseqId = clientCSeqHeader.getSeqNumber();
|
|
|
// long cseqId = clientCSeqHeader.getSeqNumber();
|
|
|
// /*
|
|
|
// /*
|
|
|
// createAck函数,创建的ackRequest,会采用Invite响应的200OK,中的contact字段中的地址,作为目标地址。
|
|
|
// createAck函数,创建的ackRequest,会采用Invite响应的200OK,中的contact字段中的地址,作为目标地址。
|
|
@ -67,12 +73,30 @@ public class InviteResponseProcessor implements ISIPResponseProcessor { |
|
|
// Request ackRequest = clientDialog.createAck(cseqId);
|
|
|
// Request ackRequest = clientDialog.createAck(cseqId);
|
|
|
// SipURI requestURI = (SipURI) ackRequest.getRequestURI();
|
|
|
// SipURI requestURI = (SipURI) ackRequest.getRequestURI();
|
|
|
// ViaHeader viaHeader = (ViaHeader) response.getHeader(ViaHeader.NAME);
|
|
|
// ViaHeader viaHeader = (ViaHeader) response.getHeader(ViaHeader.NAME);
|
|
|
|
|
|
// try {
|
|
|
// requestURI.setHost(viaHeader.getHost());
|
|
|
// requestURI.setHost(viaHeader.getHost());
|
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
|
// }
|
|
|
// requestURI.setPort(viaHeader.getPort());
|
|
|
// requestURI.setPort(viaHeader.getPort());
|
|
|
// clientDialog.sendAck(ackRequest);
|
|
|
// clientDialog.sendAck(ackRequest);
|
|
|
|
|
|
|
|
|
Dialog dialog = evt.getDialog(); |
|
|
Dialog dialog = evt.getDialog(); |
|
|
Request reqAck =dialog.createAck(1L); |
|
|
CSeqHeader cseq = (CSeqHeader) response.getHeader(CSeqHeader.NAME); |
|
|
|
|
|
Request reqAck = dialog.createAck(cseq.getSeqNumber()); |
|
|
|
|
|
|
|
|
|
|
|
SipURI requestURI = (SipURI) reqAck.getRequestURI(); |
|
|
|
|
|
ViaHeader viaHeader = (ViaHeader) response.getHeader(ViaHeader.NAME); |
|
|
|
|
|
// String viaHost =viaHeader.getHost();
|
|
|
|
|
|
//getHost()函数取回的IP地址是“[xxx.xxx.xxx.xxx:yyyy]”的格式,需用正则表达式截取为“xxx.xxx.xxx.xxx"格式
|
|
|
|
|
|
// Pattern p = Pattern.compile("(?<=//|)((\\w)+\\.)+\\w+");
|
|
|
|
|
|
// Matcher matcher = p.matcher(viaHeader.getHost());
|
|
|
|
|
|
// if (matcher.find()) {
|
|
|
|
|
|
// requestURI.setHost(matcher.group());
|
|
|
|
|
|
// }
|
|
|
|
|
|
requestURI.setHost(viaHeader.getHost()); |
|
|
|
|
|
requestURI.setPort(viaHeader.getPort()); |
|
|
|
|
|
reqAck.setRequestURI(requestURI); |
|
|
dialog.sendAck(reqAck); |
|
|
dialog.sendAck(reqAck); |
|
|
} |
|
|
} |
|
|
} catch (InvalidArgumentException | SipException e) { |
|
|
} catch (InvalidArgumentException | SipException e) { |
|
|