添加 X-GB-Ver
This commit is contained in:
parent
b40494f3a7
commit
e559446d08
@ -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.header.impl.XGBVerHeaderImpl;
|
||||||
import cn.skcks.docking.gb28181.sip.utils.SipUtil;
|
import cn.skcks.docking.gb28181.sip.utils.SipUtil;
|
||||||
import gov.nist.javax.sip.message.MessageFactoryImpl;
|
import gov.nist.javax.sip.message.MessageFactoryImpl;
|
||||||
|
import lombok.Setter;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@ -14,6 +15,8 @@ import javax.sip.address.AddressFactory;
|
|||||||
import javax.sip.address.SipURI;
|
import javax.sip.address.SipURI;
|
||||||
import javax.sip.header.*;
|
import javax.sip.header.*;
|
||||||
import javax.sip.message.MessageFactory;
|
import javax.sip.message.MessageFactory;
|
||||||
|
import javax.sip.message.Request;
|
||||||
|
import javax.sip.message.Response;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -21,7 +24,11 @@ import java.util.List;
|
|||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class SipBuilder {
|
public class SipBuilder {
|
||||||
|
@Setter
|
||||||
public static String DEFAULT_CHARSET = StandardCharsets.UTF_8.name();
|
public static String DEFAULT_CHARSET = StandardCharsets.UTF_8.name();
|
||||||
|
@Setter
|
||||||
|
public static XGBVerHeader GB_VERSION = XGBVerHeaderImpl.GB28181_2016;
|
||||||
|
|
||||||
public static SipFactory getSipFactory(){
|
public static SipFactory getSipFactory(){
|
||||||
return SipFactory.getInstance();
|
return SipFactory.getInstance();
|
||||||
}
|
}
|
||||||
@ -158,4 +165,18 @@ public class SipBuilder {
|
|||||||
public static XGBVerHeader createXGBVerHeader(int m,int n){
|
public static XGBVerHeader createXGBVerHeader(int m,int n){
|
||||||
return new XGBVerHeaderImpl(m,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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
package cn.skcks.docking.gb28181.sip.generic;
|
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 lombok.SneakyThrows;
|
||||||
|
|
||||||
import javax.sip.address.SipURI;
|
import javax.sip.address.SipURI;
|
||||||
@ -10,29 +7,39 @@ import javax.sip.header.*;
|
|||||||
import javax.sip.message.Request;
|
import javax.sip.message.Request;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static cn.skcks.docking.gb28181.sip.generic.SipBuilder.GB_VERSION;
|
||||||
|
|
||||||
public class SipRequestBuilder {
|
public class SipRequestBuilder {
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public static Request createRequest(SipURI requestURI, String method, CallIdHeader callId, CSeqHeader cSeq,
|
public static Request createRequest(SipURI requestURI, String method, CallIdHeader callId, CSeqHeader cSeq,
|
||||||
FromHeader from, ToHeader to, List<ViaHeader> via, MaxForwardsHeader maxForwards) {
|
FromHeader from, ToHeader to, List<ViaHeader> via, MaxForwardsHeader maxForwards) {
|
||||||
return SipBuilder.getMessageFactory().createRequest(requestURI, method,callId,cSeq,from,to,via,maxForwards);
|
return SipBuilder.addHeaders(
|
||||||
|
SipBuilder.getMessageFactory().createRequest(requestURI, method, callId, cSeq, from, to, via, maxForwards),
|
||||||
|
GB_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public static <T> Request createRequest(SipURI requestURI, String method, CallIdHeader callId, CSeqHeader cSeq,
|
public static <T> Request createRequest(SipURI requestURI, String method, CallIdHeader callId, CSeqHeader cSeq,
|
||||||
FromHeader from, ToHeader to, List<ViaHeader> via, MaxForwardsHeader maxForwards,
|
FromHeader from, ToHeader to, List<ViaHeader> via, MaxForwardsHeader maxForwards,
|
||||||
ContentTypeHeader contentType, T content) {
|
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
|
@SneakyThrows
|
||||||
public static <T> Request createXmlRequest(SipURI requestURI, String method, CallIdHeader callId, CSeqHeader cSeq,
|
public static <T> Request createXmlRequest(SipURI requestURI, String method, CallIdHeader callId, CSeqHeader cSeq,
|
||||||
FromHeader from, ToHeader to, List<ViaHeader> via, MaxForwardsHeader maxForwards, T content) {
|
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);
|
return SipBuilder.addHeaders(
|
||||||
|
SipBuilder.getMessageFactory().createRequest(requestURI, method, callId, cSeq, from, to, via, maxForwards, SipContentType.XML, content),
|
||||||
|
GB_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public static <T> Request createXmlRequest(SipURI requestURI, String method, CallIdHeader callId, CSeqHeader cSeq,
|
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) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,31 +7,45 @@ import javax.sip.message.Request;
|
|||||||
import javax.sip.message.Response;
|
import javax.sip.message.Response;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static cn.skcks.docking.gb28181.sip.generic.SipBuilder.GB_VERSION;
|
||||||
|
|
||||||
public class SipResponseBuilder {
|
public class SipResponseBuilder {
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public static Response createResponse(int statusCode, Request request) {
|
public static Response createResponse(int statusCode, Request request) {
|
||||||
return SipBuilder.getMessageFactory().createResponse(statusCode, request);
|
return SipBuilder.addHeaders(
|
||||||
|
SipBuilder.getMessageFactory().createResponse(statusCode, request),
|
||||||
|
GB_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public static Response createResponse(int statusCode, CallIdHeader callId, CSeqHeader cSeq,
|
public static Response createResponse(int statusCode, CallIdHeader callId, CSeqHeader cSeq,
|
||||||
FromHeader from, ToHeader to, List<ViaHeader> via, MaxForwardsHeader maxForwards) {
|
FromHeader from, ToHeader to, List<ViaHeader> via, MaxForwardsHeader maxForwards) {
|
||||||
return SipBuilder.getMessageFactory().createResponse(statusCode,callId,cSeq,from,to,via,maxForwards);
|
return SipBuilder.addHeaders(
|
||||||
|
SipBuilder.getMessageFactory().createResponse(statusCode, callId, cSeq, from, to, via, maxForwards),
|
||||||
|
GB_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public static <T> Response createResponse(int statusCode, Request request, ContentTypeHeader contentType, T content) {
|
public static <T> Response createResponse(int statusCode, Request request, ContentTypeHeader contentType, T content) {
|
||||||
return SipBuilder.getMessageFactory().createResponse(statusCode,request,contentType,content);
|
return SipBuilder.addHeaders(
|
||||||
|
SipBuilder.getMessageFactory().createResponse(statusCode, request, contentType, content),
|
||||||
|
GB_VERSION
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public static <T> Response createXmlResponse(int statusCode, Request request, T content) {
|
public static <T> Response createXmlResponse(int statusCode, Request request, T content) {
|
||||||
return SipBuilder.getMessageFactory().createResponse(statusCode,request, SipContentType.XML,content);
|
return SipBuilder.addHeaders(
|
||||||
|
SipBuilder.getMessageFactory().createResponse(statusCode, request, SipContentType.XML, content),
|
||||||
|
GB_VERSION
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public static <T> Response createXmlResponse(int statusCode, Request request, T content, String charset) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user