MessageBuilder
This commit is contained in:
parent
bb0bdcb397
commit
89225fa9c3
@ -0,0 +1,7 @@
|
||||
package cn.skcks.docking.gb28181.sip.method.message;
|
||||
|
||||
import javax.sip.message.Request;
|
||||
|
||||
public interface MessageBuilder {
|
||||
String METHOD = Request.MESSAGE;
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package cn.skcks.docking.gb28181.sip.method.message.request;
|
||||
|
||||
import cn.skcks.docking.gb28181.sip.generic.SipBuilder;
|
||||
import cn.skcks.docking.gb28181.sip.method.RequestBuilder;
|
||||
import cn.skcks.docking.gb28181.sip.method.message.MessageBuilder;
|
||||
import gov.nist.javax.sip.message.SIPRequest;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.sip.message.Request;
|
||||
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class MessageRequestBuilder extends RequestBuilder implements MessageBuilder {
|
||||
public Request createMessageRequest(String callId, long cSeq, byte[] content) {
|
||||
return createMessageRequest(callId, cSeq, content, "");
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public Request createMessageRequest(String callId, long cSeq, byte[] content, String toTag) {
|
||||
SIPRequest request = (SIPRequest) createRequest(METHOD, callId, cSeq, content);
|
||||
if (StringUtils.isNotBlank(toTag)) {
|
||||
request.getToHeader().setTag(toTag);
|
||||
}
|
||||
return SipBuilder.addHeaders(request);
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package cn.skcks.docking.gb28181.sip.method.message.response;
|
||||
|
||||
import cn.skcks.docking.gb28181.sip.generic.SipBuilder;
|
||||
import cn.skcks.docking.gb28181.sip.generic.SipContentType;
|
||||
import cn.skcks.docking.gb28181.sip.generic.SipResponseBuilder;
|
||||
import cn.skcks.docking.gb28181.sip.method.message.MessageBuilder;
|
||||
import gov.nist.javax.sip.message.SIPResponse;
|
||||
import lombok.Data;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.sip.message.Request;
|
||||
import javax.sip.message.Response;
|
||||
|
||||
@Slf4j
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@ToString(callSuper = true)
|
||||
public class MessageResponseBuilder implements MessageBuilder {
|
||||
@SneakyThrows
|
||||
public Response createMessageResponse(Request request,byte[] content){
|
||||
return createMessageResponse(request, content, null);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public Response createMessageResponse(Request request,byte[] content, String toTag) {
|
||||
Response response = SipResponseBuilder.createResponse(Response.OK, request, SipContentType.XML, content);
|
||||
SIPResponse sipResponse = (SIPResponse) response;
|
||||
if (StringUtils.isNotBlank(toTag)) {
|
||||
sipResponse.getToHeader().setTag(toTag);
|
||||
}
|
||||
return SipBuilder.addHeaders(response);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user