use of javax.sip.header.SIPIfMatchHeader in project load-balancer by RestComm.
the class TestSipListener method processPublish.
private void processPublish(RequestEvent requestEvent, ServerTransaction serverTransactionId) {
try {
SipProvider sipProvider = (SipProvider) requestEvent.getSource();
Request request = requestEvent.getRequest();
logger.info("shootist: got a publish . ServerTxId = " + serverTransactionId);
ServerTransaction st = requestEvent.getServerTransaction();
if (st == null) {
st = sipProvider.getNewServerTransaction(request);
}
inviteServerTid = st;
Dialog dialog = st.getDialog();
this.dialogCount++;
this.dialog = dialog;
logger.info("Shootme: dialog = " + dialog);
if (request.getRawContent() != null) {
this.lastMessageContent = new String(request.getRawContent());
allMessagesContent.add(new String(lastMessageContent));
}
SIPIfMatchHeader sipIfMatchHeader = (SIPIfMatchHeader) request.getHeader(SIPIfMatchHeader.NAME);
boolean sipIfMatchFound = true;
if (sipIfMatchHeader != null && sipIfMatchHeader.getETag() != null && !sipIfMatchHeader.getETag().equals(sipETag)) {
sipIfMatchFound = false;
}
if (sipIfMatchFound) {
Response response = protocolObjects.messageFactory.createResponse(200, request);
sipETag = Integer.toString(new Random().nextInt(10000000));
SIPETagHeader sipTagHeader = protocolObjects.headerFactory.createSIPETagHeader(sipETag);
response.addHeader(sipTagHeader);
response.addHeader(request.getHeader(ExpiresHeader.NAME));
st.sendResponse(response);
logger.info("shootist: Sending OK.");
} else {
Response response = protocolObjects.messageFactory.createResponse(500, request);
serverTransactionId.sendResponse(response);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of javax.sip.header.SIPIfMatchHeader in project load-balancer by RestComm.
the class TestSipListener method addSpecificHeaders.
private void addSpecificHeaders(String method, Request request) throws ParseException, InvalidArgumentException {
if (Request.SUBSCRIBE.equals(method) || Request.PUBLISH.equals(method)) {
// Create an event header for the subscription.
EventHeader eventHeader = protocolObjects.headerFactory.createEventHeader(publishEvent);
request.addHeader(eventHeader);
ExpiresHeader expires = protocolObjects.headerFactory.createExpiresHeader(200);
request.addHeader(expires);
}
if (Request.PUBLISH.equals(method)) {
if (sipETag != null) {
SIPIfMatchHeader sipIfMatchHeader = protocolObjects.headerFactory.createSIPIfMatchHeader(sipETag);
request.addHeader(sipIfMatchHeader);
}
if (publishContentMessage != null) {
ContentLengthHeader contentLengthHeader = protocolObjects.headerFactory.createContentLengthHeader(publishContentMessage.length());
ContentTypeHeader contentTypeHeader = protocolObjects.headerFactory.createContentTypeHeader(APPLICATION_CONTENT_TYPE, PIDF_XML_SUBTYPE);
request.setContentLength(contentLengthHeader);
request.setContent(publishContentMessage, contentTypeHeader);
}
}
if (Request.REFER.equals(method)) {
ReferToHeader referToHeader = (ReferToHeader) protocolObjects.headerFactory.createHeader(ReferToHeader.NAME, "sip:refer-to@nist.gov");
request.addHeader(referToHeader);
}
}
Aggregations