简单封装 SipBuilder

This commit is contained in:
shikong 2023-09-23 21:26:53 +08:00
parent a15f00cd33
commit 49ea15db92

View File

@ -10,6 +10,7 @@ import javax.sip.address.Address;
import javax.sip.address.AddressFactory; 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 java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -20,12 +21,17 @@ public class SipBuilder {
} }
@SneakyThrows @SneakyThrows
public static AddressFactory createAddressFactory() { public static MessageFactory getMessageFactory(){
return getSipFactory().createMessageFactory();
}
@SneakyThrows
public static AddressFactory getAddressFactory() {
return getSipFactory().createAddressFactory(); return getSipFactory().createAddressFactory();
} }
@SneakyThrows @SneakyThrows
public static HeaderFactory createHeaderFactory() { public static HeaderFactory getHeaderFactory() {
return getSipFactory().createHeaderFactory(); return getSipFactory().createHeaderFactory();
} }
@ -36,38 +42,38 @@ public class SipBuilder {
@SneakyThrows @SneakyThrows
public static SipURI createSipURI(String id, String address) { public static SipURI createSipURI(String id, String address) {
return createAddressFactory().createSipURI(id, address); return getAddressFactory().createSipURI(id, address);
} }
@SneakyThrows @SneakyThrows
public static Address createAddress(SipURI uri) { public static Address createAddress(SipURI uri) {
return createAddressFactory().createAddress(uri); return getAddressFactory().createAddress(uri);
} }
@SneakyThrows @SneakyThrows
public static ToHeader createToHeader(Address toAddress, String toTag) { public static ToHeader createToHeader(Address toAddress, String toTag) {
return createHeaderFactory().createToHeader(toAddress, toTag); return getHeaderFactory().createToHeader(toAddress, toTag);
} }
@SneakyThrows @SneakyThrows
public static FromHeader createFromHeader(Address fromAddress, String fromTag) { public static FromHeader createFromHeader(Address fromAddress, String fromTag) {
return createHeaderFactory().createFromHeader(fromAddress, fromTag); return getHeaderFactory().createFromHeader(fromAddress, fromTag);
} }
@SneakyThrows @SneakyThrows
public static CSeqHeader createCSeqHeader(long cSeq, String method){ public static CSeqHeader createCSeqHeader(long cSeq, String method){
return createHeaderFactory().createCSeqHeader(cSeq, method); return getHeaderFactory().createCSeqHeader(cSeq, method);
} }
@SneakyThrows @SneakyThrows
public static MaxForwardsHeader createMaxForwardsHeader(int maxForwards) { public static MaxForwardsHeader createMaxForwardsHeader(int maxForwards) {
return createHeaderFactory().createMaxForwardsHeader(maxForwards); return getHeaderFactory().createMaxForwardsHeader(maxForwards);
} }
@SneakyThrows @SneakyThrows
public static ViaHeader createViaHeader(String ip, int port, String transport, String viaTag){ public static ViaHeader createViaHeader(String ip, int port, String transport, String viaTag){
ViaHeader viaHeader = createHeaderFactory().createViaHeader(ip, port, transport, viaTag); ViaHeader viaHeader = getHeaderFactory().createViaHeader(ip, port, transport, viaTag);
viaHeader.setRPort(); viaHeader.setRPort();
return viaHeader; return viaHeader;
} }
@ -80,17 +86,17 @@ public class SipBuilder {
@SneakyThrows @SneakyThrows
public static ContactHeader createContactHeader(Address address){ public static ContactHeader createContactHeader(Address address){
return createHeaderFactory().createContactHeader(address); return getHeaderFactory().createContactHeader(address);
}; };
@SneakyThrows @SneakyThrows
public static ContentTypeHeader createContentTypeHeader(String contentType, String subType){ public static ContentTypeHeader createContentTypeHeader(String contentType, String subType){
return createHeaderFactory().createContentTypeHeader(contentType, subType); return getHeaderFactory().createContentTypeHeader(contentType, subType);
} }
@SneakyThrows @SneakyThrows
public static ContentTypeHeader createSDPContentTypeHeader(){ public static ContentTypeHeader createSDPContentTypeHeader(){
return createHeaderFactory().createContentTypeHeader("APPLICATION", "SDP"); return getHeaderFactory().createContentTypeHeader("APPLICATION", "SDP");
} }
public static UserAgentHeader createUserAgentHeader(String userAgent){ public static UserAgentHeader createUserAgentHeader(String userAgent){
@ -99,11 +105,11 @@ public class SipBuilder {
@SneakyThrows @SneakyThrows
public static UserAgentHeader createUserAgentHeader(List<String> product){ public static UserAgentHeader createUserAgentHeader(List<String> product){
return createHeaderFactory().createUserAgentHeader(product); return getHeaderFactory().createUserAgentHeader(product);
} }
@SneakyThrows @SneakyThrows
public static XGBVerHeader createUserAgentHeader(int m,int n){ public static XGBVerHeader createXGBVerHeader(int m,int n){
return new XGBVerHeaderImpl(m,n); return new XGBVerHeaderImpl(m,n);
} }
} }