添加 X-GB-Ver

This commit is contained in:
shikong 2023-09-26 15:06:30 +08:00
parent b40494f3a7
commit e559446d08
3 changed files with 60 additions and 18 deletions

View File

@ -4,6 +4,7 @@ import cn.skcks.docking.gb28181.sip.header.XGBVerHeader;
import cn.skcks.docking.gb28181.sip.header.impl.XGBVerHeaderImpl;
import cn.skcks.docking.gb28181.sip.utils.SipUtil;
import gov.nist.javax.sip.message.MessageFactoryImpl;
import lombok.Setter;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
@ -14,6 +15,8 @@ import javax.sip.address.AddressFactory;
import javax.sip.address.SipURI;
import javax.sip.header.*;
import javax.sip.message.MessageFactory;
import javax.sip.message.Request;
import javax.sip.message.Response;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collections;
@ -21,7 +24,11 @@ import java.util.List;
@Slf4j
public class SipBuilder {
@Setter
public static String DEFAULT_CHARSET = StandardCharsets.UTF_8.name();
@Setter
public static XGBVerHeader GB_VERSION = XGBVerHeaderImpl.GB28181_2016;
public static SipFactory getSipFactory(){
return SipFactory.getInstance();
}
@ -158,4 +165,18 @@ public class SipBuilder {
public static XGBVerHeader createXGBVerHeader(int m,int n){
return new XGBVerHeaderImpl(m,n);
}
public static Response addHeaders(Response response,Header ...headers){
for (Header header : headers) {
response.addHeader(header);
}
return response;
}
public static Request addHeaders(Request request, Header ...headers){
for (Header header : headers) {
request.addHeader(header);
}
return request;
}
}

View File

@ -1,8 +1,5 @@
package cn.skcks.docking.gb28181.sip.generic;
import cn.skcks.docking.gb28181.sip.generic.SipBuilder;
import cn.skcks.docking.gb28181.sip.generic.SipContentType;
import cn.skcks.docking.gb28181.sip.utils.SipUtil;
import lombok.SneakyThrows;
import javax.sip.address.SipURI;
@ -10,29 +7,39 @@ import javax.sip.header.*;
import javax.sip.message.Request;
import java.util.List;
import static cn.skcks.docking.gb28181.sip.generic.SipBuilder.GB_VERSION;
public class SipRequestBuilder {
@SneakyThrows
public static Request createRequest(SipURI requestURI, String method, CallIdHeader callId, CSeqHeader cSeq,
FromHeader from, ToHeader to, List<ViaHeader> via, MaxForwardsHeader maxForwards){
return SipBuilder.getMessageFactory().createRequest(requestURI, method,callId,cSeq,from,to,via,maxForwards);
FromHeader from, ToHeader to, List<ViaHeader> via, MaxForwardsHeader maxForwards) {
return SipBuilder.addHeaders(
SipBuilder.getMessageFactory().createRequest(requestURI, method, callId, cSeq, from, to, via, maxForwards),
GB_VERSION);
}
@SneakyThrows
public static <T> Request createRequest(SipURI requestURI, String method, CallIdHeader callId, CSeqHeader cSeq,
FromHeader from, ToHeader to, List<ViaHeader> via, MaxForwardsHeader maxForwards,
ContentTypeHeader contentType, T content) {
return SipBuilder.getMessageFactory().createRequest(requestURI, method, callId, cSeq, from, to, via, maxForwards, contentType, content);
return SipBuilder.addHeaders(
SipBuilder.getMessageFactory().createRequest(requestURI, method, callId, cSeq, from, to, via, maxForwards, contentType, content),
GB_VERSION);
}
@SneakyThrows
public static <T> Request createXmlRequest(SipURI requestURI, String method, CallIdHeader callId, CSeqHeader cSeq,
FromHeader from, ToHeader to, List<ViaHeader> via, MaxForwardsHeader maxForwards, T content) {
return SipBuilder.getMessageFactory().createRequest(requestURI, method, callId, cSeq, from, to, via, maxForwards, SipContentType.XML, content);
FromHeader from, ToHeader to, List<ViaHeader> via, MaxForwardsHeader maxForwards, T content) {
return SipBuilder.addHeaders(
SipBuilder.getMessageFactory().createRequest(requestURI, method, callId, cSeq, from, to, via, maxForwards, SipContentType.XML, content),
GB_VERSION);
}
@SneakyThrows
public static <T> Request createXmlRequest(SipURI requestURI, String method, CallIdHeader callId, CSeqHeader cSeq,
FromHeader from, ToHeader to, List<ViaHeader> via, MaxForwardsHeader maxForwards, T content, String charset) {
return SipBuilder.getMessageFactory(charset).createRequest(requestURI, method, callId, cSeq, from, to, via, maxForwards, SipContentType.XML, content);
return SipBuilder.addHeaders(
SipBuilder.getMessageFactory(charset).createRequest(requestURI, method, callId, cSeq, from, to, via, maxForwards, SipContentType.XML, content),
GB_VERSION);
}
}

View File

@ -7,31 +7,45 @@ import javax.sip.message.Request;
import javax.sip.message.Response;
import java.util.List;
import static cn.skcks.docking.gb28181.sip.generic.SipBuilder.GB_VERSION;
public class SipResponseBuilder {
@SneakyThrows
public static Response createResponse(int statusCode, Request request){
return SipBuilder.getMessageFactory().createResponse(statusCode, request);
public static Response createResponse(int statusCode, Request request) {
return SipBuilder.addHeaders(
SipBuilder.getMessageFactory().createResponse(statusCode, request),
GB_VERSION);
}
@SneakyThrows
public static Response createResponse(int statusCode, CallIdHeader callId, CSeqHeader cSeq,
FromHeader from, ToHeader to, List<ViaHeader> via, MaxForwardsHeader maxForwards){
return SipBuilder.getMessageFactory().createResponse(statusCode,callId,cSeq,from,to,via,maxForwards);
FromHeader from, ToHeader to, List<ViaHeader> via, MaxForwardsHeader maxForwards) {
return SipBuilder.addHeaders(
SipBuilder.getMessageFactory().createResponse(statusCode, callId, cSeq, from, to, via, maxForwards),
GB_VERSION);
}
@SneakyThrows
public static <T> Response createResponse(int statusCode, Request request, ContentTypeHeader contentType, T content){
return SipBuilder.getMessageFactory().createResponse(statusCode,request,contentType,content);
public static <T> Response createResponse(int statusCode, Request request, ContentTypeHeader contentType, T content) {
return SipBuilder.addHeaders(
SipBuilder.getMessageFactory().createResponse(statusCode, request, contentType, content),
GB_VERSION
);
}
@SneakyThrows
public static <T> Response createXmlResponse(int statusCode, Request request, T content){
return SipBuilder.getMessageFactory().createResponse(statusCode,request, SipContentType.XML,content);
public static <T> Response createXmlResponse(int statusCode, Request request, T content) {
return SipBuilder.addHeaders(
SipBuilder.getMessageFactory().createResponse(statusCode, request, SipContentType.XML, content),
GB_VERSION
);
}
@SneakyThrows
public static <T> Response createXmlResponse(int statusCode, Request request, T content, String charset) {
return SipBuilder.getMessageFactory(charset).createResponse(statusCode, request, SipContentType.XML, content);
return SipBuilder.addHeaders(
SipBuilder.getMessageFactory(charset).createResponse(statusCode, request, SipContentType.XML, content),
GB_VERSION);
}
}