use of javax.sip.message.Response in project load-balancer by RestComm.
the class TestSipListener method processCancel.
private void processCancel(RequestEvent requestEvent, ServerTransaction serverTransactionId) {
try {
cancelReceived = true;
SipProvider sipProvider = (SipProvider) requestEvent.getSource();
Request request = requestEvent.getRequest();
Response response = protocolObjects.messageFactory.createResponse(Response.OK, request);
ServerTransaction st = requestEvent.getServerTransaction();
if (st == null) {
st = sipProvider.getNewServerTransaction(request);
}
Dialog dialog = st.getDialog();
logger.info("Shootme: dialog = " + dialog);
st.sendResponse(response);
response = protocolObjects.messageFactory.createResponse(Response.REQUEST_TERMINATED, inviteRequest);
inviteServerTid.sendResponse(response);
} catch (Exception ex) {
ex.printStackTrace();
logger.error("error sending CANCEL responses", ex);
}
}
use of javax.sip.message.Response in project load-balancer by RestComm.
the class TestSipListener method processNotify.
public void processNotify(RequestEvent requestEvent, ServerTransaction serverTransactionId) {
SipProvider provider = (SipProvider) requestEvent.getSource();
Request notify = requestEvent.getRequest();
try {
logger.info("subscriber: got a notify count " + this.notifyCount++);
if (serverTransactionId == null) {
logger.info("subscriber: null TID.");
serverTransactionId = provider.getNewServerTransaction(notify);
}
Dialog dialog = serverTransactionId.getDialog();
// if ( dialog != subscriberDialog ) {
// if (forkedDialog == null) {
// forkedDialog = dialog;
// } else {
// AbstractSubsnotifyTestCase.assertTrue("Dialog should be either the subscriber dialog ",
// forkedDialog == dialog);
// }
// }
//
// this.dialogs.add(dialog);
logger.info("Dialog State = " + dialog.getState());
Response response = protocolObjects.messageFactory.createResponse(200, notify);
// SHOULD add a Contact
ContactHeader contact = (ContactHeader) contactHeader.clone();
((SipURI) contact.getAddress().getURI()).setParameter("id", "sub");
response.addHeader(contact);
logger.info("Transaction State = " + serverTransactionId.getState());
serverTransactionId.sendResponse(response);
logger.info("Dialog State = " + dialog.getState());
SubscriptionStateHeader subscriptionState = (SubscriptionStateHeader) notify.getHeader(SubscriptionStateHeader.NAME);
// Subscription is terminated?
String state = subscriptionState.getState();
allSubscriptionStates.add(state.toLowerCase());
if (notify.getRawContent() != null) {
this.lastMessageContent = new String(notify.getRawContent());
allMessagesContent.add(new String(lastMessageContent));
}
if (state.equalsIgnoreCase(SubscriptionStateHeader.TERMINATED)) {
if (subscriptionState.getReasonCode() == null) {
dialog.delete();
}
} else if (state.equalsIgnoreCase(SubscriptionStateHeader.ACTIVE)) {
if ("reg".equalsIgnoreCase(((EventHeader) notify.getHeader(EventHeader.NAME)).getEventType())) {
if (sendByeBeforeTerminatingNotify) {
dialog.terminateOnBye(false);
sendBye();
Thread.sleep(1000);
}
logger.info("Subscriber: sending unSUBSCRIBE");
// Else we end it ourselves
Request unsubscribe = dialog.createRequest(Request.SUBSCRIBE);
logger.info("dialog created:" + unsubscribe);
// SHOULD add a Contact (done by dialog), lets mark it to test updates
// ((SipURI) dialog.getLocalParty().getURI()).setParameter( "id", "unsub" );
ExpiresHeader expires = protocolObjects.headerFactory.createExpiresHeader(0);
unsubscribe.addHeader(expires);
// JvB note : stack should do this!
// copy
unsubscribe.addHeader(notify.getHeader(EventHeader.NAME));
// event
// header
logger.info("Sending Unsubscribe : " + unsubscribe);
logger.info("unsubscribe dialog " + dialog);
ClientTransaction ct = sipProvider.getNewClientTransaction(unsubscribe);
dialog.sendRequest(ct);
if (sendByeAfterTerminatingNotify) {
Thread.sleep(1000);
sendBye();
}
} else if (sendByeBeforeTerminatingNotify) {
sendBye();
}
} else {
// pending
logger.info("Subscriber: state now " + state);
}
} catch (Exception ex) {
logger.error("Unexpected exception", ex);
}
}
use of javax.sip.message.Response in project load-balancer by RestComm.
the class TestSipListener method processPrack.
private void processPrack(Request request, ServerTransaction serverTransactionId) {
try {
prackReceived = true;
prackRequestReceived = request;
ServerTransaction st = serverTransactionId;
if (st == null) {
st = sipProvider.getNewServerTransaction(request);
}
Response response = protocolObjects.messageFactory.createResponse(200, request);
st.sendResponse(response);
Thread.sleep(200);
inviteServerTid.sendResponse(getFinalResponse());
} catch (Exception e) {
logger.error("Unexpected exception while trying to send the 200 to PRACK " + request, e);
}
}
use of javax.sip.message.Response in project load-balancer by RestComm.
the class TestSipListener method processInvite.
/**
* Process the invite request.
*/
public void processInvite(RequestEvent requestEvent, ServerTransaction serverTransaction) {
inviteReceived = true;
SipProvider sipProvider = (SipProvider) requestEvent.getSource();
Request request = requestEvent.getRequest();
inviteRequest = request;
logger.info("shootme: got an Invite " + request);
try {
ServerTransaction st = requestEvent.getServerTransaction();
if (st == null) {
st = sipProvider.getNewServerTransaction(request);
}
inviteServerTid = st;
Dialog dialog = st.getDialog();
if (request.getHeader(JoinHeader.NAME) != null) {
setJoinRequestReceived(true);
this.joinDialog = dialog;
} else if (request.getHeader(ReplacesHeader.NAME) != null) {
setReplacesRequestReceived(true);
this.replacesDialog = dialog;
} else {
this.dialogCount++;
this.dialog = dialog;
}
logger.info("Shootme: dialog = " + dialog);
this.inviteRequest = request;
boolean sendReliably = false;
RequireHeader requireHeader = (RequireHeader) request.getHeader(RequireHeader.NAME);
if (requireHeader != null && "100rel".equalsIgnoreCase(requireHeader.getOptionTag().trim())) {
sendReliably = true;
}
if (respondWithError == null)
for (int provisionalResponseToSend : provisionalResponsesToSend) {
Thread.sleep(getTimeToWaitBetweenProvisionnalResponse());
Response response = protocolObjects.messageFactory.createResponse(provisionalResponseToSend, request);
if (provisionalResponseToSend >= Response.TRYING && provisionalResponseToSend < Response.OK) {
ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME);
if (provisionalResponseToSend != Response.TRYING && toHeader.getTag() == null) {
// Application is supposed to set.
toHeader.setTag(TO_TAG);
}
if (sendReliably && provisionalResponseToSend != Response.TRYING) {
requireHeader = protocolObjects.headerFactory.createRequireHeader("100rel");
response.addHeader(requireHeader);
Header rseqHeader = protocolObjects.headerFactory.createRSeqHeader(rseqNumber.getAndIncrement());
response.addHeader(rseqHeader);
dialog.sendReliableProvisionalResponse(response);
} else {
st.sendResponse(response);
eventListener.uasAfterResponse(response.getStatusCode(), appServer);
}
}
}
if (respondWithError != null && !sendReliably) {
Response response = protocolObjects.messageFactory.createResponse(respondWithError, request);
response.setReasonPhrase("Unable to setup media services");
st.sendResponse(response);
eventListener.uasAfterResponse(response.getStatusCode(), appServer);
return;
}
ContactHeader contactHeader = (ContactHeader) request.getHeader(ContactHeader.NAME);
if (contactHeader != null && "0.0.0.0".equals(((SipURI) contactHeader.getAddress().getURI()).getHost())) {
abortProcessing = true;
throw new IllegalArgumentException("we received a contact header with 0.0.0.0 in an INVITE !");
}
if (!waitForCancel) {
Address address = null;
if (!isIpv6)
address = protocolObjects.addressFactory.createAddress("Shootme <sip:127.0.0.1:" + myPort + ";transport=" + protocolObjects.transport + ">");
else
address = protocolObjects.addressFactory.createAddress("Shootme <sip:[::1]:" + myPort + ";transport=" + protocolObjects.transport + ">");
contactHeader = protocolObjects.headerFactory.createContactHeader(address);
setFinalResponse(protocolObjects.messageFactory.createResponse(finalResponseToSend, request));
if (testAckViaParam) {
ViaHeader viaHeader = (ViaHeader) getFinalResponse().getHeader(ViaHeader.NAME);
viaHeader.setParameter("testAckViaParam", "true");
}
ToHeader toHeader = (ToHeader) getFinalResponse().getHeader(ToHeader.NAME);
if (toHeader.getTag() == null) {
// Application is supposed to set.
toHeader.setTag(TO_TAG);
}
getFinalResponse().addHeader(contactHeader);
if (!sendReliably) {
Thread.sleep(2000);
st.sendResponse(getFinalResponse());
eventListener.uasAfterResponse(getFinalResponse().getStatusCode(), appServer);
}
} else {
logger.info("Waiting for CANCEL, stopping the INVITE processing ");
return;
}
if (("join").equalsIgnoreCase(((SipUri) request.getRequestURI()).getUser())) {
sendJoinMessage = true;
}
if (("replaces").equalsIgnoreCase(((SipUri) request.getRequestURI()).getUser())) {
sendReplacesMessage = true;
}
} catch (Exception ex) {
logger.error("unexpected exception", ex);
throw new RuntimeException(ex);
}
}
use of javax.sip.message.Response in project load-balancer by RestComm.
the class Shootist method processInvite.
public void processInvite(Request request, ServerTransaction stx) {
try {
inviteRequest = request;
Response response = messageFactory.createResponse(180, request);
contactHeader = headerFactory.createContactHeader(addressFactory.createAddress("sip:here@" + localIPAddress + ":" + localPort));
response.addHeader(contactHeader);
dialog = stx.getDialog();
// check removing incorrect patching last via https://github.com/RestComm/load-balancer/issues/97
FromHeader fromHeader = (FromHeader) response.getHeader(From.NAME);
URI currUri = fromHeader.getAddress().getURI();
String fromUser = null;
if (currUri.isSipURI()) {
fromUser = ((SipURI) currUri).getUser();
if (fromUser.equals("senderToNexmo")) {
ViaHeader lastViaHeader = null;
ListIterator<ViaHeader> it = response.getHeaders(ViaHeader.NAME);
while (it.hasNext()) lastViaHeader = it.next();
lastViaHeader.setReceived("127.0.0.2");
lastViaHeader.setParameter("rport", "1111");
}
}
stx.sendResponse(response);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
response = messageFactory.createResponse(200, request);
contactHeader = headerFactory.createContactHeader(addressFactory.createAddress("sip:here@" + localIPAddress + ":" + localPort));
response.addHeader(contactHeader);
dialog = stx.getDialog();
stx.sendResponse(response);
} catch (SipException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Aggregations