Package javax.sip

Examples of javax.sip.SipException


     * @see javax.sip.ServerTransaction#enableRetransmissionAlerts()
     */

    public void enableRetransmissionAlerts() throws SipException {
        if (this.getDialog() != null)
            throw new SipException("Dialog associated with tx");

        else if (!isInviteTransaction())
            throw new SipException("Request Method must be INVITE");

        this.retransmissionAlertEnabled = true;

    }
View Full Code Here


     */
    public void sendRequest() throws SipException {
        SIPRequest sipRequest = this.getOriginalRequest();

        if (this.getInternalState() >= 0)
            throw new SipException("Request already sent");

        if (sipStack.isLoggingEnabled(LogWriter.TRACE_DEBUG)) {
            sipStack.getStackLogger().logDebug("sendRequest() " + sipRequest);
        }

        try {
            sipRequest.checkHeaders();
        } catch (ParseException ex) {
          if (sipStack.isLoggingEnabled())
            sipStack.getStackLogger().logError("missing required header");
            throw new SipException(ex.getMessage());
        }

        if (getMethod().equals(Request.SUBSCRIBE)
                && sipRequest.getHeader(ExpiresHeader.NAME) == null) {
            /*
             * If no "Expires" header is present in a SUBSCRIBE request, the implied default is
             * defined by the event package being used.
             *
             */
          if (sipStack.isLoggingEnabled())
            sipStack.getStackLogger().logWarning(
                    "Expires header missing in outgoing subscribe --"
                            + " Notifier will assume implied value on event package");
        }
        try {
            /*
             * This check is removed because it causes problems for load balancers ( See issue
             * 136) reported by Raghav Ramesh ( BT )
             *
             */
            if (this.getMethod().equals(Request.CANCEL)
                    && sipStack.isCancelClientTransactionChecked()) {
                SIPClientTransaction ct = (SIPClientTransaction) sipStack.findCancelTransaction(
                        this.getOriginalRequest(), false);
                if (ct == null) {
                    /*
                     * If the original request has generated a final response, the CANCEL SHOULD
                     * NOT be sent, as it is an effective no-op, since CANCEL has no effect on
                     * requests that have already generated a final response.
                     */
                    throw new SipException("Could not find original tx to cancel. RFC 3261 9.1");
                } else if (ct.getInternalState() < 0) {
                    throw new SipException(
                            "State is null no provisional response yet -- cannot cancel RFC 3261 9.1");
                } else if (!ct.isInviteTransaction()) {
                    throw new SipException("Cannot cancel non-invite requests RFC 3261 9.1");
                }
            } else if (this.getMethod().equals(Request.BYE)
                    || this.getMethod().equals(Request.NOTIFY)) {
                SIPDialog dialog = sipStack.getDialog(this.getOriginalRequest()
                        .getDialogId(false));
                // I want to behave like a user agent so send the BYE using the
                // Dialog
                if (this.getSipProvider().isAutomaticDialogSupportEnabled() && dialog != null) {
                    throw new SipException(
                            "Dialog is present and AutomaticDialogSupport is enabled for "
                                    + " the provider -- Send the Request using the Dialog.sendRequest(transaction)");
                }
            }
            // Only map this after the fist request is sent out.
            if (isInviteTransaction()) {
                SIPDialog dialog = this.getDefaultDialog();

                if (dialog != null && dialog.isBackToBackUserAgent()) {
                    // Block sending re-INVITE till we see the ACK.
                    if ( ! dialog.takeAckSem() ) {
                        throw new SipException ("Failed to take ACK semaphore");
                    }

                }
            }
            this.isMapped = true;
         // Time extracted from the Expires header.
            int expiresTime = -1;

           if ( sipRequest.getHeader(ExpiresHeader.NAME) != null ) {
                Expires expires = (Expires) sipRequest.getHeader(ExpiresHeader.NAME);
                expiresTime = expires.getExpires();
            }
            // This is a User Agent. The user has specified an Expires time. Start a timer
            // which will check if the tx is terminated by that time.
            if ( this.getDefaultDialog() != null  &&  isInviteTransaction() &&
                    expiresTime != -1 && expiresTimerTask == null ) {
                this.expiresTimerTask = new ExpiresTimerTask();
                sipStack.getTimer().schedule(expiresTimerTask, expiresTime * 1000);
               
            }
            this.sendMessage(sipRequest);
           

        } catch (IOException ex) {
            this.setState(TransactionState._TERMINATED);
            if ( this.expiresTimerTask != null ) {
                sipStack.getTimer().cancel(this.expiresTimerTask);
            }
            throw new SipException(
                    ex.getMessage() == null ? "IO Error sending request" : ex.getMessage(),
                    ex);
        }

    }
View Full Code Here

     * @see javax.sip.ClientTransaction#createCancel()
     */
    public Request createCancel() throws SipException {
        SIPRequest originalRequest = this.getOriginalRequest();
        if (originalRequest == null)
            throw new SipException("Bad state " + getState());
        if (!originalRequest.getMethod().equals(Request.INVITE))
            throw new SipException("Only INIVTE may be cancelled");

        if (originalRequest.getMethod().equalsIgnoreCase(Request.ACK))
            throw new SipException("Cannot Cancel ACK!");
        else {
            SIPRequest cancelRequest = originalRequest.createCancelRequest();
            cancelRequest.setInviteTransaction(this);
            return cancelRequest;
        }
View Full Code Here

     * @see javax.sip.ClientTransaction#createAck()
     */
    public Request createAck() throws SipException {
        SIPRequest originalRequest = this.getOriginalRequest();
        if (originalRequest == null)
            throw new SipException("bad state " + getState());
        if (getMethod().equalsIgnoreCase(Request.ACK)) {
            throw new SipException("Cannot ACK an ACK!");
        } else if (lastResponse == null) {
            throw new SipException("bad Transaction state");
        } else if (lastResponse.getStatusCode() < 200) {
            if (sipStack.isLoggingEnabled(LogWriter.TRACE_DEBUG)) {
                sipStack.getStackLogger().logDebug("lastResponse = " + lastResponse);
            }
            throw new SipException("Cannot ACK a provisional response!");
        }
        SIPRequest ackRequest = originalRequest.createAckRequest((To) lastResponse.getTo());
        // Pull the record route headers from the last reesponse.
        RecordRouteList recordRouteList = lastResponse.getRecordRouteHeaders();
        if (recordRouteList == null) {
View Full Code Here

     * Note that this is different from an ACK for 2xx
     */
    private final Request createErrorAck() throws SipException, ParseException {
        SIPRequest originalRequest = this.getOriginalRequest();
        if (originalRequest == null)
            throw new SipException("bad state " + getState());
        if (!isInviteTransaction()) {
            throw new SipException("Can only ACK an INVITE!");
        } else if (lastResponse == null) {
            throw new SipException("bad Transaction state");
        } else if (lastResponse.getStatusCode() < 200) {
            if (sipStack.isLoggingEnabled(LogWriter.TRACE_DEBUG)) {
                sipStack.getStackLogger().logDebug("lastResponse = " + lastResponse);
            }
            throw new SipException("Cannot ACK a provisional response!");
        }
        return originalRequest.createErrorAck((To) lastResponse.getTo());
    }
View Full Code Here

      throw new NullPointerException("null arg!");

    try {
      this.attachHeader((SIPHeader) header, false, false);
    } catch (SIPDuplicateHeaderException ex) {
      throw new SipException("Cannot add header - header already exists");
    }

  }
View Full Code Here

      throw new NullPointerException("null arg!");

    try {
      this.attachHeader((SIPHeader) header, false, true);
    } catch (SIPDuplicateHeaderException ex) {
      throw new SipException("Cannot add header - header already exists");
    }

  }
View Full Code Here

   *
   * @see javax.sip.SipProvider#sendRequest(javax.sip.message.Request)
   */
  public void sendRequest(Request request) throws SipException {
    if (!sipStack.isAlive())
      throw new SipException("Stack is stopped.");

    // mranga: added check to ensure we are not sending empty (keepalive)
    // message.
    if (((SIPRequest) request).getRequestLine() != null
        && request.getMethod().equals(Request.ACK)) {
      Dialog dialog = sipStack.getDialog(((SIPRequest) request)
          .getDialogId(false));
      if (dialog != null && dialog.getState() != null) {
        sipStack.getLogWriter().logWarning(
            "Dialog exists -- you may want to use Dialog.sendAck() "
                + dialog.getState());
      }
    }
    Hop hop = sipStack.getRouter((SIPRequest) request).getNextHop(request);
    if (hop == null)
      throw new SipException("could not determine next hop!");
    SIPRequest sipRequest = (SIPRequest) request;
    // Check if we have a valid via.
    // Null request is used to send default proxy keepalive messages.
    if ((!sipRequest.isNullRequest()) && sipRequest.getTopmostVia() == null)
      throw new SipException("Invalid SipRequest -- no via header!");

    try {
      /*
       * JvB: Via branch should already be OK, dont touch it here? Some
       * apps forward statelessly, and then it's not set. So set only when
       * not set already, dont overwrite CANCEL branch here..
       */
      if (!sipRequest.isNullRequest()) {
        Via via = sipRequest.getTopmostVia();
        String branch = via.getBranch();
        if (branch == null || branch.length() == 0) {
          via.setBranch(sipRequest.getTransactionId());
        }
      }
      MessageChannel messageChannel = null;
      if (this.listeningPoints.containsKey(hop.getTransport()
          .toUpperCase()))
        messageChannel = sipStack.createRawMessageChannel(
            this.getListeningPoint(hop.getTransport()).getIPAddress(),
            this.getListeningPoint(hop.getTransport()).getPort(), hop);
      if (messageChannel != null) {
        messageChannel.sendMessage((SIPMessage) sipRequest,hop);
      } else {
        throw new SipException(
            "Could not create a message channel for "
                + hop.toString());
      }
    } catch (IOException ex) {
      if (sipStack.isLoggingEnabled()) {
        sipStack.getLogWriter().logException(ex);
      }

      throw new SipException(
          "IO Exception occured while Sending Request", ex);

    } catch (ParseException ex1) {
      InternalErrorHandler.handleException(ex1);
    } finally {
View Full Code Here

   *
   * @see javax.sip.SipProvider#sendResponse(javax.sip.message.Response)
   */
  public void sendResponse(Response response) throws SipException {
    if (!sipStack.isAlive())
      throw new SipException("Stack is stopped");
    SIPResponse sipResponse = (SIPResponse) response;
    Via via = sipResponse.getTopmostVia();
    if (via == null)
      throw new SipException("No via header in response!");
    SIPServerTransaction st = (SIPServerTransaction) sipStack.findTransaction((SIPMessage)response, true);
    if ( st != null   && st.getState() != TransactionState.TERMINATED && this.isAutomaticDialogSupportEnabled()) {
      throw new SipException("Transaction exists -- cannot send response statelessly");
    }
    String transport = via.getTransport();

    // check to see if Via has "received paramaeter". If so
    // set the host to the via parameter. Else set it to the
    // Via host.
    String host = via.getReceived();

    if (host == null)
      host = via.getHost();

    // Symmetric nat support
    int port = via.getRPort();
    if (port == -1) {
      port = via.getPort();
      if (port == -1) {
        if (transport.equalsIgnoreCase("TLS"))
          port = 5061;
        else
          port = 5060;
      }
    }

    // for correct management of IPv6 addresses.
    if (host.indexOf(":") > 0)
      if (host.indexOf("[") < 0)
        host = "[" + host + "]";

    Hop hop = sipStack.getAddressResolver().resolveAddress(
        new HopImpl(host, port, transport));

    try {
      ListeningPointImpl listeningPoint = (ListeningPointImpl) this
          .getListeningPoint(transport);
      if (listeningPoint == null)
        throw new SipException(
            "whoopsa daisy! no listening point found for transport "
                + transport);
      MessageChannel messageChannel = sipStack.createRawMessageChannel(
          this.getListeningPoint(hop.getTransport()).getIPAddress(),
          listeningPoint.port, hop);
      messageChannel.sendMessage(sipResponse);
    } catch (IOException ex) {
      throw new SipException(ex.getMessage());
    }
  }
View Full Code Here

  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 (sipStack.isDialogCreated(sipRequest.getMethod())) {
        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!");
      }
    }
    return dialog;
View Full Code Here

TOP

Related Classes of javax.sip.SipException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.