use of javax.sip.header.ExtensionHeader in project load-balancer by RestComm.
the class TestSipListener method processRefer.
public void processRefer(RequestEvent requestEvent, ServerTransaction serverTransactionId) {
try {
SipProvider sipProvider = (SipProvider) requestEvent.getSource();
Request request = requestEvent.getRequest();
logger.info("shootist: got a refer . 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);
Response response = protocolObjects.messageFactory.createResponse(referResponseToSend, request);
sipETag = Integer.toString(new Random().nextInt(10000000));
st.sendResponse(response);
logger.info("shootist: Sending " + referResponseToSend);
List<Header> headers = new ArrayList<Header>();
EventHeader eventHeader = (EventHeader) protocolObjects.headerFactory.createHeader(EventHeader.NAME, "Refer");
headers.add(eventHeader);
if (sendNotifyForRefer) {
if (!referReceived) {
referReceived = true;
SubscriptionStateHeader subscriptionStateHeader = (SubscriptionStateHeader) protocolObjects.headerFactory.createHeader(SubscriptionStateHeader.NAME, "active;expires=3600");
headers.add(subscriptionStateHeader);
allMessagesContent.add("SIP/2.0 100 Trying");
sendInDialogSipRequest(Request.NOTIFY, "SIP/2.0 100 Trying", "message", "sipfrag;version=2.0", headers, null);
Thread.sleep(1000);
headers.remove(subscriptionStateHeader);
subscriptionStateHeader = (SubscriptionStateHeader) protocolObjects.headerFactory.createHeader(SubscriptionStateHeader.NAME, "terminated;reason=noresource");
headers.add(subscriptionStateHeader);
if (inviteRequest == null) {
ExtensionHeader extensionHeader = (ExtensionHeader) protocolObjects.headerFactory.createHeader("Out-Of-Dialog", "true");
headers.add(extensionHeader);
}
allMessagesContent.add("SIP/2.0 200 OK");
sendInDialogSipRequest(Request.NOTIFY, "SIP/2.0 200 OK", "message", "sipfrag;version=2.0", headers, null);
} else {
SubscriptionStateHeader subscriptionStateHeader = (SubscriptionStateHeader) protocolObjects.headerFactory.createHeader(SubscriptionStateHeader.NAME, "active;expires=3600");
headers.add(subscriptionStateHeader);
sendInDialogSipRequest(Request.NOTIFY, "SIP/2.0 100 Subsequent", "message", "sipfrag;version=2.0", headers, null);
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
Aggregations