use of javax.sip.TransactionUnavailableException in project load-balancer by RestComm.
the class Shootist method processRequest.
public void processRequest(RequestEvent requestReceivedEvent) {
Request request = requestReceivedEvent.getRequest();
ServerTransaction serverTransactionId = requestReceivedEvent.getServerTransaction();
if (serverTransactionId == null) {
try {
serverTransactionId = sipProvider.getNewServerTransaction(request);
} catch (TransactionAlreadyExistsException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TransactionUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
System.out.println("\n\nRequest " + request.getMethod() + " received at " + sipStack.getStackName() + " with server transaction id " + serverTransactionId);
if (request.getMethod().equals(Request.INVITE)) {
processInvite(request, serverTransactionId);
} else if (request.getMethod().equals(Request.BYE)) {
processBye(request, serverTransactionId);
} else if (request.getMethod().equals(Request.ACK)) {
processAck(request, serverTransactionId);
} else {
try {
serverTransactionId.sendResponse(messageFactory.createResponse(200, request));
} catch (Exception e) {
e.printStackTrace();
fail("Unxepcted exception ");
}
}
}
use of javax.sip.TransactionUnavailableException in project XobotOS by xamarin.
the class SipProviderImpl method getNewServerTransaction.
/*
* (non-Javadoc)
*
* @see javax.sip.SipProvider#getNewServerTransaction(javax.sip.message.Request)
*/
public ServerTransaction getNewServerTransaction(Request request) throws TransactionAlreadyExistsException, TransactionUnavailableException {
if (!sipStack.isAlive())
throw new TransactionUnavailableException("Stack is stopped");
SIPServerTransaction transaction = null;
SIPRequest sipRequest = (SIPRequest) request;
try {
sipRequest.checkHeaders();
} catch (ParseException ex) {
throw new TransactionUnavailableException(ex.getMessage(), ex);
}
if (request.getMethod().equals(Request.ACK)) {
if (sipStack.isLoggingEnabled())
sipStack.getStackLogger().logError("Creating server transaction for ACK -- makes no sense!");
throw new TransactionUnavailableException("Cannot create Server transaction for ACK ");
}
/*
* Got a notify.
*/
if (sipRequest.getMethod().equals(Request.NOTIFY) && sipRequest.getFromTag() != null && sipRequest.getToTag() == null) {
SIPClientTransaction ct = sipStack.findSubscribeTransaction(sipRequest, (ListeningPointImpl) this.getListeningPoint());
/* Issue 104 */
if (ct == null && !sipStack.deliverUnsolicitedNotify) {
throw new TransactionUnavailableException("Cannot find matching Subscription (and gov.nist.javax.sip.DELIVER_UNSOLICITED_NOTIFY not set)");
}
}
if (!sipStack.acquireSem()) {
throw new TransactionUnavailableException("Transaction not available -- could not acquire stack lock");
}
try {
if (sipStack.isDialogCreated(sipRequest.getMethod())) {
if (sipStack.findTransaction((SIPRequest) request, true) != null)
throw new TransactionAlreadyExistsException("server transaction already exists!");
transaction = (SIPServerTransaction) ((SIPRequest) request).getTransaction();
if (transaction == null)
throw new TransactionUnavailableException("Transaction not available");
if (transaction.getOriginalRequest() == null)
transaction.setOriginalRequest(sipRequest);
try {
sipStack.addTransaction(transaction);
} catch (IOException ex) {
throw new TransactionUnavailableException("Error sending provisional response");
}
// So I can handle timeouts.
transaction.addEventListener(this);
if (isAutomaticDialogSupportEnabled()) {
// If automatic dialog support is enabled then
// this tx gets his own dialog.
String dialogId = sipRequest.getDialogId(true);
SIPDialog dialog = sipStack.getDialog(dialogId);
if (dialog == null) {
dialog = sipStack.createDialog(transaction);
}
transaction.setDialog(dialog, sipRequest.getDialogId(true));
if (sipRequest.getMethod().equals(Request.INVITE) && this.isDialogErrorsAutomaticallyHandled()) {
sipStack.putInMergeTable(transaction, sipRequest);
}
dialog.addRoute(sipRequest);
if (dialog.getRemoteTag() != null && dialog.getLocalTag() != null) {
this.sipStack.putDialog(dialog);
}
}
} else {
if (isAutomaticDialogSupportEnabled()) {
/*
* Under automatic dialog support, dialog is tied into a transaction. You cannot
* create a server tx except for dialog creating transactions. After that, all
* subsequent transactions are created for you by the stack.
*/
transaction = (SIPServerTransaction) sipStack.findTransaction((SIPRequest) request, true);
if (transaction != null)
throw new TransactionAlreadyExistsException("Transaction exists! ");
transaction = (SIPServerTransaction) ((SIPRequest) request).getTransaction();
if (transaction == null)
throw new TransactionUnavailableException("Transaction not available!");
if (transaction.getOriginalRequest() == null)
transaction.setOriginalRequest(sipRequest);
// Map the transaction.
try {
sipStack.addTransaction(transaction);
} catch (IOException ex) {
throw new TransactionUnavailableException("Could not send back provisional response!");
}
// If there is a dialog already assigned then just update the
// dialog state.
String dialogId = sipRequest.getDialogId(true);
SIPDialog dialog = sipStack.getDialog(dialogId);
if (dialog != null) {
dialog.addTransaction(transaction);
dialog.addRoute(sipRequest);
transaction.setDialog(dialog, sipRequest.getDialogId(true));
}
} else {
transaction = (SIPServerTransaction) sipStack.findTransaction((SIPRequest) request, true);
if (transaction != null)
throw new TransactionAlreadyExistsException("Transaction exists! ");
transaction = (SIPServerTransaction) ((SIPRequest) request).getTransaction();
if (transaction != null) {
if (transaction.getOriginalRequest() == null)
transaction.setOriginalRequest(sipRequest);
// Map the transaction.
sipStack.mapTransaction(transaction);
// If there is a dialog already assigned then just
// assign the dialog to the transaction.
String dialogId = sipRequest.getDialogId(true);
SIPDialog dialog = sipStack.getDialog(dialogId);
if (dialog != null) {
dialog.addTransaction(transaction);
dialog.addRoute(sipRequest);
transaction.setDialog(dialog, sipRequest.getDialogId(true));
}
return transaction;
} else {
// tx does not exist so create the tx.
MessageChannel mc = (MessageChannel) sipRequest.getMessageChannel();
transaction = sipStack.createServerTransaction(mc);
if (transaction == null)
throw new TransactionUnavailableException("Transaction unavailable -- too many servrer transactions");
transaction.setOriginalRequest(sipRequest);
sipStack.mapTransaction(transaction);
// If there is a dialog already assigned then just
// assign the dialog to the transaction.
String dialogId = sipRequest.getDialogId(true);
SIPDialog dialog = sipStack.getDialog(dialogId);
if (dialog != null) {
dialog.addTransaction(transaction);
dialog.addRoute(sipRequest);
transaction.setDialog(dialog, sipRequest.getDialogId(true));
}
return transaction;
}
}
}
return transaction;
} finally {
sipStack.releaseSem();
}
}
use of javax.sip.TransactionUnavailableException in project Spark by igniterealtime.
the class CallProcessing method sayBye.
// send message
// private void sendInfoMessage(Dialog dialog, String body)
// throws CommunicationsException {
// Request request = dialog.getFirstTransaction().getRequest();
// Request info = null;
// String contentType = "application/dtmd-relay";
// String[] contentTypeTab = contentType.split("/");
// ContentTypeHeader contentTypeHeader = null;
// try {
// info = dialog.createRequest(Request.INFO);
// try {
// contentTypeHeader = sipManCallback.headerFactory
// .createContentTypeHeader(contentTypeTab[0],
// contentTypeTab[1]);
// info.setContent(body, contentTypeHeader);
// }
// catch (ParseException ex) {
//
// throw new CommunicationsException(
// "ContentType Header must look like type/subtype!",
// ex);
// }
// }
// catch (SipException ex) {
//
// throw new CommunicationsException(
// "Failed to create bye request!", ex);
// }
// ClientTransaction clientTransaction = null;
// try {
// clientTransaction = sipManCallback.sipProvider
// .getNewClientTransaction(info);
// }
// catch (TransactionUnavailableException ex) {
//
// throw new CommunicationsException(
// "Failed to construct a client transaction from the INFO request",
// ex);
// }
// try {
// dialog.sendRequest(clientTransaction);
// }
// catch (SipException ex1) {
// throw new CommunicationsException(
// "Failed to send the INFO request");
// }
//
// } // send message
// Bye
private void sayBye(Dialog dialog) throws CommunicationsException {
Request bye = null;
bye = dialog.getFirstTransaction().getRequest();
try {
bye = dialog.createRequest(Request.BYE);
} catch (SipException e) {
Log.error("bye", e);
}
long cseq = ((CSeq) (bye.getHeader(CSeq.NAME))).getSequenceNumber() + 1;
bye.removeHeader(CSeq.NAME);
try {
bye.addHeader(sipManCallback.headerFactory.createCSeqHeader(cseq, Request.BYE));
} catch (Exception e) {
Log.error("bye", e);
}
bye.removeHeader(ViaHeader.NAME);
for (ViaHeader via : sipManCallback.getLocalViaHeaders()) bye.addHeader(via);
ContactHeader contactHeader = sipManCallback.getContactHeader();
bye.addHeader(contactHeader);
AllowHeader allow = null;
try {
allow = sipManCallback.headerFactory.createAllowHeader("INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO");
bye.addHeader(allow);
} catch (ParseException e) {
Log.error(e);
}
// Transaction
ClientTransaction inviteTransaction;
try {
inviteTransaction = sipManCallback.sipProvider.getNewClientTransaction(bye);
dialog.sendRequest(inviteTransaction);
} catch (SipException ee) {
Log.error("bye", ee);
}
return;
}
use of javax.sip.TransactionUnavailableException in project Spark by igniterealtime.
the class CallProcessing method invite.
// -------------------------------- User Initiated processing
// ---------------------------------
Call invite(String callee, String sdpContent) throws CommunicationsException {
callee = callee.trim();
// Remove excessive characters from phone numbers such as '
// ','(',')','-'
String excessiveChars = SIPConfig.getExcessiveURIChar();
if (excessiveChars != null) {
StringBuffer calleeBuff = new StringBuffer(callee);
for (int i = 0; i < excessiveChars.length(); i++) {
String charToDeleteStr = excessiveChars.substring(i, i + 1);
int charIndex = -1;
while ((charIndex = calleeBuff.indexOf(charToDeleteStr)) != -1) calleeBuff.delete(charIndex, charIndex + 1);
}
callee = calleeBuff.toString();
}
// Handle default domain name (i.e. transform 1234 -> 1234@sip.com
String defaultDomainName = SIPConfig.getDefaultDomain();
if (// no sip scheme
defaultDomainName != null && !callee.trim().startsWith("tel:") && // most probably a sip uri
callee.indexOf('@') == -1) {
callee = callee + "@" + defaultDomainName;
}
// Let's be uri fault tolerant
if (// no sip scheme
callee.toLowerCase().indexOf("sip:") == -1 && // most probably a sip uri
callee.indexOf('@') != -1) {
callee = "sip:" + callee;
}
// Request URI
URI requestURI;
try {
requestURI = sipManCallback.addressFactory.createURI(callee);
} catch (ParseException ex) {
throw new CommunicationsException(callee + " is not a legal SIP uri!", ex);
}
// Call ID
CallIdHeader callIdHeader = sipManCallback.sipProvider.getNewCallId();
// CSeq
CSeqHeader cSeqHeader;
try {
cSeqHeader = sipManCallback.headerFactory.createCSeqHeader(1L, Request.INVITE);
} catch (ParseException ex) {
throw new CommunicationsException("An unexpected erro occurred while" + "constructing the CSeqHeadder", ex);
} catch (InvalidArgumentException ex) {
// Shouldn't happen
throw new CommunicationsException("An unexpected erro occurred while" + "constructing the CSeqHeadder", ex);
}
// FromHeader
FromHeader fromHeader = sipManCallback.getFromHeader();
// ToHeader
Address toAddress = sipManCallback.addressFactory.createAddress(requestURI);
ToHeader toHeader;
try {
toHeader = sipManCallback.headerFactory.createToHeader(toAddress, null);
} catch (ParseException ex) {
// Shouldn't happen
throw new CommunicationsException("Null is not an allowed tag for the to header!", ex);
}
// ViaHeaders
ArrayList<ViaHeader> viaHeaders = sipManCallback.getLocalViaHeaders();
// MaxForwards
MaxForwardsHeader maxForwards = sipManCallback.getMaxForwardsHeader();
// Contact
ContactHeader contactHeader = sipManCallback.getContactHeader();
Request invite = null;
try {
invite = sipManCallback.messageFactory.createRequest(requestURI, Request.INVITE, callIdHeader, cSeqHeader, fromHeader, toHeader, viaHeaders, maxForwards);
} catch (ParseException ex) {
throw new CommunicationsException("Failed to create invite Request!", ex);
}
//
invite.addHeader(contactHeader);
AllowHeader allow = null;
try {
allow = sipManCallback.headerFactory.createAllowHeader("INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO");
invite.addHeader(allow);
} catch (ParseException e) {
Log.error(e);
}
// Content
ContentTypeHeader contentTypeHeader = null;
try {
// content type should be application/sdp (not applications)
// reported by Oleg Shevchenko (Miratech)
contentTypeHeader = sipManCallback.headerFactory.createContentTypeHeader("application", "sdp");
} catch (ParseException ex) {
// Shouldn't happen
throw new CommunicationsException("Failed to create a content type header for the INVITE request", ex);
}
try {
invite.setContent(sdpContent, contentTypeHeader);
} catch (ParseException ex) {
throw new CommunicationsException("Failed to parse sdp data while creating invite request!", ex);
}
// Transaction
ClientTransaction inviteTransaction;
try {
inviteTransaction = sipManCallback.sipProvider.getNewClientTransaction(invite);
} catch (TransactionUnavailableException ex) {
throw new CommunicationsException("Failed to create inviteTransaction.\n" + "This is most probably a network connection error.", ex);
}
try {
inviteTransaction.sendRequest();
} catch (SipException ex) {
throw new CommunicationsException("An error occurred while sending invite request", ex);
}
Call call = callDispatcher.createCall(inviteTransaction.getDialog(), invite);
call.setState(Call.DIALING);
return call;
}
use of javax.sip.TransactionUnavailableException in project Spark by igniterealtime.
the class RegisterProcessing method register.
synchronized void register(String registrarAddress, int registrarPort, String registrarTransport, int expires) throws CommunicationsException {
try {
isUnregistering = false;
// From
FromHeader fromHeader = sipManCallback.getFromHeader(true);
Address fromAddress = fromHeader.getAddress();
sipManCallback.fireRegistering(fromAddress.toString());
// Request URI
SipURI requestURI = null;
try {
requestURI = sipManCallback.addressFactory.createSipURI(null, registrarAddress);
} catch (ParseException ex) {
throw new CommunicationsException("Bad registrar address:" + registrarAddress, ex);
} catch (NullPointerException ex) {
// Do not throw an exc, we should rather silently notify the
// user
// throw new CommunicationsException("A registrar address was
// not specified!", ex);
sipManCallback.fireUnregistered(fromAddress.getURI().toString() + " (registrar not specified)");
return;
}
/*
requestURI.setPort(registrarPort);
try {
requestURI.setTransportParam(registrarTransport);
}
catch (ParseException ex) {
throw new CommunicationsException(registrarTransport
+ " is not a valid transport!", ex);
}
*/
// Call ID Header
CallIdHeader callIdHeader = sipManCallback.sipProvider.getNewCallId();
// CSeq Header
CSeqHeader cSeqHeader = null;
try {
cSeqHeader = sipManCallback.headerFactory.createCSeqHeader((long) 1, Request.REGISTER);
} catch (ParseException ex) {
// Should never happen
Log.error("register", ex);
} catch (InvalidArgumentException ex) {
// Should never happen
Log.error("register", ex);
}
// To Header
ToHeader toHeader = null;
try {
toHeader = sipManCallback.headerFactory.createToHeader(fromAddress, null);
} catch (ParseException ex) {
// throw was missing - reported by Eero Vaarnas
throw new CommunicationsException("Could not create a To header " + "for address:" + fromHeader.getAddress(), ex);
}
// User Agent Header
UserAgentHeader uaHeader = null;
ArrayList<String> userAgentList = new ArrayList<String>();
userAgentList.add(SoftPhoneManager.userAgent);
try {
uaHeader = sipManCallback.headerFactory.createUserAgentHeader(userAgentList);
} catch (ParseException ex) {
// throw was missing - reported by Eero Vaarnas
throw new CommunicationsException("Could not create a To header " + "for address:" + fromHeader.getAddress(), ex);
}
// Via Headers
ArrayList<ViaHeader> viaHeaders = sipManCallback.getLocalViaHeaders();
// MaxForwardsHeader
MaxForwardsHeader maxForwardsHeader = sipManCallback.getMaxForwardsHeader();
// Request
Request request = null;
try {
request = sipManCallback.messageFactory.createRequest(requestURI, Request.REGISTER, callIdHeader, cSeqHeader, fromHeader, toHeader, viaHeaders, maxForwardsHeader);
request.setHeader(uaHeader);
} catch (ParseException ex) {
// throw was missing - reported by Eero Vaarnas
throw new CommunicationsException("Could not create the register request!", ex);
}
// Expires Header
ExpiresHeader expHeader = null;
for (int retry = 0; retry < 2; retry++) {
try {
expHeader = sipManCallback.headerFactory.createExpiresHeader(expires);
} catch (InvalidArgumentException ex) {
if (retry == 0) {
expires = 3600;
continue;
}
throw new CommunicationsException("Invalid registrations expiration parameter - " + expires, ex);
}
}
request.addHeader(expHeader);
// Contact Header should contain IP - bug report - Eero Vaarnas
ContactHeader contactHeader = sipManCallback.getRegistrationContactHeader();
request.addHeader(contactHeader);
AllowHeader allow = sipManCallback.headerFactory.createAllowHeader("INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO");
request.addHeader(allow);
// Transaction
ClientTransaction regTrans = null;
try {
regTrans = sipManCallback.sipProvider.getNewClientTransaction(request);
} catch (TransactionUnavailableException ex) {
throw new CommunicationsException("Could not create a register transaction!\n" + "Check that the Registrar address is correct!");
}
try {
regTrans.sendRequest();
}// we sometimes get a null pointer exception here so catch them all
catch (Exception ex) {
// throw was missing - reported by Eero Vaarnas
throw new CommunicationsException("Could not send out the register request!", ex);
}
this.registerRequest = request;
} catch (Exception e) {
Log.error("register", e);
sipManCallback.fireRegistrationFailed(registrarAddress == null ? "" : registrarAddress, RegistrationEvent.Type.TimeOut);
}
}
Aggregations