use of javax.sip.SipException in project XobotOS by xamarin.
the class SipProviderImpl method getNewDialog.
/*
* (non-Javadoc)
*
* @see javax.sip.SipProvider#getNewDialog(javax.sip.Transaction)
*/
public Dialog getNewDialog(Transaction transaction) throws SipException {
if (transaction == null)
throw new NullPointerException("Null transaction!");
if (!sipStack.isAlive())
throw new SipException("Stack is stopped.");
if (isAutomaticDialogSupportEnabled())
throw new SipException(" Error - AUTOMATIC_DIALOG_SUPPORT is on");
if (!sipStack.isDialogCreated(transaction.getRequest().getMethod()))
throw new SipException("Dialog cannot be created for this method " + transaction.getRequest().getMethod());
SIPDialog dialog = null;
SIPTransaction sipTransaction = (SIPTransaction) transaction;
if (transaction instanceof ServerTransaction) {
SIPServerTransaction st = (SIPServerTransaction) transaction;
Response response = st.getLastResponse();
if (response != null) {
if (response.getStatusCode() != 100)
throw new SipException("Cannot set dialog after response has been sent");
}
SIPRequest sipRequest = (SIPRequest) transaction.getRequest();
String dialogId = sipRequest.getDialogId(true);
dialog = sipStack.getDialog(dialogId);
if (dialog == null) {
dialog = sipStack.createDialog((SIPTransaction) transaction);
// create and register the dialog and add the inital route set.
dialog.addTransaction(sipTransaction);
dialog.addRoute(sipRequest);
sipTransaction.setDialog(dialog, null);
} else {
sipTransaction.setDialog(dialog, sipRequest.getDialogId(true));
}
if (sipRequest.getMethod().equals(Request.INVITE) && this.isDialogErrorsAutomaticallyHandled()) {
sipStack.putInMergeTable(st, sipRequest);
}
} else {
SIPClientTransaction sipClientTx = (SIPClientTransaction) transaction;
SIPResponse response = sipClientTx.getLastResponse();
if (response == null) {
// A response has not yet been received, then set this up as the
// default dialog.
SIPRequest request = (SIPRequest) sipClientTx.getRequest();
String dialogId = request.getDialogId(false);
dialog = sipStack.getDialog(dialogId);
if (dialog != null) {
throw new SipException("Dialog already exists!");
} else {
dialog = sipStack.createDialog(sipTransaction);
}
sipClientTx.setDialog(dialog, null);
} else {
throw new SipException("Cannot call this method after response is received!");
}
}
dialog.addEventListener(this);
return dialog;
}
use of javax.sip.SipException in project XobotOS by xamarin.
the class SIPServerTransaction method sendReliableProvisionalResponse.
protected void sendReliableProvisionalResponse(Response relResponse) throws SipException {
/*
* After the first reliable provisional response for a request has been acknowledged, the
* UAS MAY send additional reliable provisional responses. The UAS MUST NOT send a second
* reliable provisional response until the first is acknowledged.
*/
if (this.pendingReliableResponse != null) {
throw new SipException("Unacknowledged response");
} else
this.pendingReliableResponse = (SIPResponse) relResponse;
/*
* In addition, it MUST contain a Require header field containing the option tag 100rel,
* and MUST include an RSeq header field.
*/
RSeq rseq = (RSeq) relResponse.getHeader(RSeqHeader.NAME);
if (relResponse.getHeader(RSeqHeader.NAME) == null) {
rseq = new RSeq();
relResponse.setHeader(rseq);
}
try {
this.rseqNumber++;
rseq.setSeqNumber(this.rseqNumber);
// start the timer task which will retransmit the reliable response
// until the PRACK is received
this.lastResponse = (SIPResponse) relResponse;
if (this.getDialog() != null) {
boolean acquired = this.provisionalResponseSem.tryAcquire(1, TimeUnit.SECONDS);
if (!acquired) {
throw new SipException("Unacknowledged response");
}
}
this.sendMessage((SIPMessage) relResponse);
this.provisionalResponseTask = new ProvisionalResponseTask();
this.sipStack.getTimer().schedule(provisionalResponseTask, 0, SIPTransactionStack.BASE_TIMER_INTERVAL);
} catch (Exception ex) {
InternalErrorHandler.handleException(ex);
}
}
use of javax.sip.SipException in project XobotOS by xamarin.
the class SIPDialog method createAck.
/*
* (non-Javadoc) The UAC core MUST generate an ACK request for each 2xx received from the
* transaction layer. The header fields of the ACK are constructed in the same way as for any
* request sent within a dialog (see Section 12) with the exception of the CSeq and the header
* fields related to authentication. The sequence number of the CSeq header field MUST be the
* same as the INVITE being acknowledged, but the CSeq method MUST be ACK. The ACK MUST
* contain the same credentials as the INVITE. If the 2xx contains an offer (based on the
* rules above), the ACK MUST carry an answer in its body. If the offer in the 2xx response is
* not acceptable, the UAC core MUST generate a valid answer in the ACK and then send a BYE
* immediately.
*
* Note that for the case of forked requests, you can create multiple outgoing invites each
* with a different cseq and hence you need to supply the invite.
*
* @see javax.sip.Dialog#createAck(long)
*/
public Request createAck(long cseqno) throws InvalidArgumentException, SipException {
// then send INVITE+ACK later on
if (!method.equals(Request.INVITE))
throw new SipException("Dialog was not created with an INVITE" + method);
if (cseqno <= 0)
throw new InvalidArgumentException("bad cseq <= 0 ");
else if (cseqno > ((((long) 1) << 32) - 1))
throw new InvalidArgumentException("bad cseq > " + ((((long) 1) << 32) - 1));
if (this.remoteTarget == null) {
throw new SipException("Cannot create ACK - no remote Target!");
}
if (this.sipStack.isLoggingEnabled()) {
this.sipStack.getStackLogger().logDebug("createAck " + this + " cseqno " + cseqno);
}
// out of order ACK sending. Old ACKs seqno's can always be ACKed.
if (lastInviteOkReceived < cseqno) {
if (sipStack.isLoggingEnabled()) {
this.sipStack.getStackLogger().logDebug("WARNING : Attempt to crete ACK without OK " + this);
this.sipStack.getStackLogger().logDebug("LAST RESPONSE = " + this.lastResponse);
}
throw new SipException("Dialog not yet established -- no OK response!");
}
try {
// JvB: Transport from first entry in route set, or remote Contact
// if none
// Only used to find correct LP & create correct Via
SipURI uri4transport = null;
if (this.routeList != null && !this.routeList.isEmpty()) {
Route r = (Route) this.routeList.getFirst();
uri4transport = ((SipURI) r.getAddress().getURI());
} else {
// should be !=null, checked above
uri4transport = ((SipURI) this.remoteTarget.getURI());
}
String transport = uri4transport.getTransportParam();
if (transport == null) {
// JvB fix: also support TLS
transport = uri4transport.isSecure() ? ListeningPoint.TLS : ListeningPoint.UDP;
}
ListeningPointImpl lp = (ListeningPointImpl) sipProvider.getListeningPoint(transport);
if (lp == null) {
if (sipStack.isLoggingEnabled()) {
sipStack.getStackLogger().logError("remoteTargetURI " + this.remoteTarget.getURI());
sipStack.getStackLogger().logError("uri4transport = " + uri4transport);
sipStack.getStackLogger().logError("No LP found for transport=" + transport);
}
throw new SipException("Cannot create ACK - no ListeningPoint for transport towards next hop found:" + transport);
}
SIPRequest sipRequest = new SIPRequest();
sipRequest.setMethod(Request.ACK);
sipRequest.setRequestURI((SipUri) getRemoteTarget().getURI().clone());
sipRequest.setCallId(this.callIdHeader);
sipRequest.setCSeq(new CSeq(cseqno, Request.ACK));
List<Via> vias = new ArrayList<Via>();
// Via via = lp.getViaHeader();
// The user may have touched the sentby for the response.
// so use the via header extracted from the response for the ACK =>
// https://jain-sip.dev.java.net/issues/show_bug.cgi?id=205
// strip the params from the via of the response and use the params from the
// original request
Via via = this.lastResponse.getTopmostVia();
via.removeParameters();
if (originalRequest != null && originalRequest.getTopmostVia() != null) {
NameValueList originalRequestParameters = originalRequest.getTopmostVia().getParameters();
if (originalRequestParameters != null && originalRequestParameters.size() > 0) {
via.setParameters((NameValueList) originalRequestParameters.clone());
}
}
// new branch
via.setBranch(Utils.getInstance().generateBranchId());
vias.add(via);
sipRequest.setVia(vias);
From from = new From();
from.setAddress(this.localParty);
from.setTag(this.myTag);
sipRequest.setFrom(from);
To to = new To();
to.setAddress(this.remoteParty);
if (hisTag != null)
to.setTag(this.hisTag);
sipRequest.setTo(to);
sipRequest.setMaxForwards(new MaxForwards(70));
if (this.originalRequest != null) {
Authorization authorization = this.originalRequest.getAuthorization();
if (authorization != null)
sipRequest.setHeader(authorization);
}
// ACKs for 2xx responses
// use the Route values learned from the Record-Route of the 2xx
// responses.
this.updateRequest(sipRequest);
return sipRequest;
} catch (Exception ex) {
InternalErrorHandler.handleException(ex);
throw new SipException("unexpected exception ", ex);
}
}
use of javax.sip.SipException in project XobotOS by xamarin.
the class SIPDialog method sendAck.
/**
* Sends ACK Request to the remote party of this Dialogue.
*
*
* @param request the new ACK Request message to send.
* @param throwIOExceptionAsSipException - throws SipException if IOEx encountered. Otherwise,
* no exception is propagated.
* @param releaseAckSem - release ack semaphore.
* @throws SipException if implementation cannot send the ACK Request for any other reason
*
*/
private void sendAck(Request request, boolean throwIOExceptionAsSipException) throws SipException {
SIPRequest ackRequest = (SIPRequest) request;
if (sipStack.isLoggingEnabled())
sipStack.getStackLogger().logDebug("sendAck" + this);
if (!ackRequest.getMethod().equals(Request.ACK))
throw new SipException("Bad request method -- should be ACK");
if (this.getState() == null || this.getState().getValue() == EARLY_STATE) {
if (sipStack.isLoggingEnabled()) {
sipStack.getStackLogger().logError("Bad Dialog State for " + this + " dialogID = " + this.getDialogId());
}
throw new SipException("Bad dialog state " + this.getState());
}
if (!this.getCallId().getCallId().equals(((SIPRequest) request).getCallId().getCallId())) {
if (sipStack.isLoggingEnabled()) {
sipStack.getStackLogger().logError("CallID " + this.getCallId());
sipStack.getStackLogger().logError("RequestCallID = " + ackRequest.getCallId().getCallId());
sipStack.getStackLogger().logError("dialog = " + this);
}
throw new SipException("Bad call ID in request");
}
try {
if (sipStack.isLoggingEnabled()) {
sipStack.getStackLogger().logDebug("setting from tag For outgoing ACK= " + this.getLocalTag());
sipStack.getStackLogger().logDebug("setting To tag for outgoing ACK = " + this.getRemoteTag());
sipStack.getStackLogger().logDebug("ack = " + ackRequest);
}
if (this.getLocalTag() != null)
ackRequest.getFrom().setTag(this.getLocalTag());
if (this.getRemoteTag() != null)
ackRequest.getTo().setTag(this.getRemoteTag());
} catch (ParseException ex) {
throw new SipException(ex.getMessage());
}
Hop hop = sipStack.getNextHop(ackRequest);
// Hop hop = defaultRouter.getNextHop(ackRequest);
if (hop == null)
throw new SipException("No route!");
try {
if (sipStack.isLoggingEnabled())
sipStack.getStackLogger().logDebug("hop = " + hop);
ListeningPointImpl lp = (ListeningPointImpl) this.sipProvider.getListeningPoint(hop.getTransport());
if (lp == null)
throw new SipException("No listening point for this provider registered at " + hop);
InetAddress inetAddress = InetAddress.getByName(hop.getHost());
MessageChannel messageChannel = lp.getMessageProcessor().createMessageChannel(inetAddress, hop.getPort());
boolean releaseAckSem = false;
long cseqNo = ((SIPRequest) request).getCSeq().getSeqNumber();
if (!this.isAckSent(cseqNo)) {
releaseAckSem = true;
}
this.setLastAckSent(ackRequest);
messageChannel.sendMessage(ackRequest);
// Sent atleast one ACK.
this.isAcknowledged = true;
this.highestSequenceNumberAcknowledged = Math.max(this.highestSequenceNumberAcknowledged, ((SIPRequest) ackRequest).getCSeq().getSeqNumber());
if (releaseAckSem && this.isBackToBackUserAgent) {
this.releaseAckSem();
} else {
if (sipStack.isLoggingEnabled()) {
sipStack.getStackLogger().logDebug("Not releasing ack sem for " + this + " isAckSent " + releaseAckSem);
}
}
} catch (IOException ex) {
if (throwIOExceptionAsSipException)
throw new SipException("Could not send ack", ex);
this.raiseIOException(hop.getHost(), hop.getPort(), hop.getTransport());
} catch (SipException ex) {
if (sipStack.isLoggingEnabled())
sipStack.getStackLogger().logException(ex);
throw ex;
} catch (Exception ex) {
if (sipStack.isLoggingEnabled())
sipStack.getStackLogger().logException(ex);
throw new SipException("Could not create message channel", ex);
}
if (this.dialogDeleteTask != null) {
this.dialogDeleteTask.cancel();
this.dialogDeleteTask = null;
}
this.ackSeen = true;
}
use of javax.sip.SipException in project XobotOS by xamarin.
the class SIPDialog method sendReliableProvisionalResponse.
/*
* (non-Javadoc)
*
* @see javax.sip.Dialog#sendReliableProvisionalResponse(javax.sip.message.Response)
*/
public void sendReliableProvisionalResponse(Response relResponse) throws SipException {
if (!this.isServer()) {
throw new SipException("Not a Server Dialog");
}
SIPResponse sipResponse = (SIPResponse) relResponse;
if (relResponse.getStatusCode() == 100)
throw new SipException("Cannot send 100 as a reliable provisional response");
if (relResponse.getStatusCode() / 100 > 2)
throw new SipException("Response code is not a 1xx response - should be in the range 101 to 199 ");
/*
* Do a little checking on the outgoing response.
*/
if (sipResponse.getToTag() == null) {
throw new SipException("Badly formatted response -- To tag mandatory for Reliable Provisional Response");
}
ListIterator requireList = (ListIterator) relResponse.getHeaders(RequireHeader.NAME);
boolean found = false;
if (requireList != null) {
while (requireList.hasNext() && !found) {
RequireHeader rh = (RequireHeader) requireList.next();
if (rh.getOptionTag().equalsIgnoreCase("100rel")) {
found = true;
}
}
}
if (!found) {
Require require = new Require("100rel");
relResponse.addHeader(require);
if (sipStack.isLoggingEnabled()) {
sipStack.getStackLogger().logDebug("Require header with optionTag 100rel is needed -- adding one");
}
}
SIPServerTransaction serverTransaction = (SIPServerTransaction) this.getFirstTransaction();
/*
* put into the dialog table before sending the response so as to avoid race condition
* with PRACK
*/
this.setLastResponse(serverTransaction, sipResponse);
this.setDialogId(sipResponse.getDialogId(true));
serverTransaction.sendReliableProvisionalResponse(relResponse);
this.startRetransmitTimer(serverTransaction, relResponse);
}
Aggregations