Package gov.nist.javax.sip.message

Examples of gov.nist.javax.sip.message.SIPRequest


            /*
             * A refer cannot be processed until previous transaction has been completed.
             */
            SIPTransaction lastTransaction = ((SIPDialog) dialog).getLastTransaction();
            if (lastTransaction != null  && sipProvider.isDialogErrorsAutomaticallyHandled()) {
                SIPRequest lastRequest = (SIPRequest) lastTransaction.getRequest();
                if (lastTransaction instanceof SIPServerTransaction) {
                    if (lastTransaction.getState() == TransactionState.PROCEEDING
                            && lastRequest.getMethod().equals(Request.INVITE)) {
                        this.sendRequestPendingResponse(sipRequest, transaction);
                        return;
                    }
                } else if (lastTransaction != null && lastTransaction instanceof SIPClientTransaction) {
                    long cseqno = lastRequest.getCSeqHeader().getSeqNumber();
                    String method = lastRequest.getMethod();
                    if (method.equals(Request.INVITE) && lastTransaction.getState() != TransactionState.TERMINATED &&
                        lastTransaction.getState() != TransactionState.COMPLETED ) {
                        this.sendRequestPendingResponse(sipRequest, transaction);
                        return;
                    }
View Full Code Here


  /**
   * Hash table for quick lookup of transactions. Here we wait for room if
   * needed.
   */
  private void addTransactionHash(SIPTransaction sipTransaction) {
    SIPRequest sipRequest = sipTransaction.getOriginalRequest();
    if (sipTransaction instanceof SIPClientTransaction) {
      if (!this.unlimitedClientTransactionTableSize) {
        if (this.activeClientTransactionCount.get() > clientTransactionTableHiwaterMark) {
          try {
            synchronized (this.clientTransactionTable) {
              this.clientTransactionTable.wait();
              this.activeClientTransactionCount.incrementAndGet();
            }

          } catch (Exception ex) {
            if (stackLogger.isLoggingEnabled()) {
              stackLogger.logError(
                  "Exception occured while waiting for room",
                  ex);
            }

          }
        }
      } else {
        this.activeClientTransactionCount.incrementAndGet();
      }
      String key = sipRequest.getTransactionId();
      clientTransactionTable.put(key,
          (SIPClientTransaction) sipTransaction);

      if (stackLogger.isLoggingEnabled()) {
        stackLogger
            .logDebug(" putTransactionHash : " + " key = " + key);
      }
    } else {
      String key = sipRequest.getTransactionId();

      if (stackLogger.isLoggingEnabled()) {
        stackLogger
            .logDebug(" putTransactionHash : " + " key = " + key);
      }
View Full Code Here

  /**
   * Remove the transaction from transaction hash.
   */
  protected void removeTransactionHash(SIPTransaction sipTransaction) {
    SIPRequest sipRequest = sipTransaction.getOriginalRequest();
    if (sipRequest == null)
      return;
    if (sipTransaction instanceof SIPClientTransaction) {
      String key = sipTransaction.getTransactionId();
      if (stackLogger.isLoggingEnabled()) {
View Full Code Here

            leakedTransactions++;

            // Generate some report
            TransactionState transactionState = sipTransaction
                .getState();
            SIPRequest origRequest = sipTransaction
                .getOriginalRequest();
            String origRequestMethod = (origRequest != null ? origRequest
                .getMethod()
                : null);
            String transactionReport = sipTransaction.getClass()
                .getName()
                + ", state: "
View Full Code Here

     * @param sipMessage
     */
    public void processMessage(SIPMessage sipMessage) {

        if (sipMessage instanceof SIPRequest) {
            SIPRequest sipRequest = (SIPRequest) sipMessage;

            // This is a request - process it.
            // So far so good -- we will commit this message if
            // all processing is OK.
            if (sipStack.getStackLogger().isLoggingEnabled(ServerLogger.TRACE_MESSAGES)) {

                this.sipStack.serverLogger.logMessage(sipMessage, this
                        .getPeerHostPort().toString(), this.getHost() + ":"
                        + this.myPort, false, receptionTime);

            }
            ServerRequestInterface sipServerRequest = sipStack
                    .newSIPServerRequest(sipRequest, this);
            // Drop it if there is no request returned
            if (sipServerRequest == null) {
                if (sipStack.isLoggingEnabled()) {
                    this.sipStack.getStackLogger()
                            .logWarning("Null request interface returned -- dropping request");
                }


                return;
            }
            if (sipStack.isLoggingEnabled(LogWriter.TRACE_DEBUG))
                this.sipStack.getStackLogger().logDebug("About to process "
                        + sipRequest.getFirstLine() + "/" + sipServerRequest);
            try {
                sipServerRequest.processRequest(sipRequest, this);
            } finally {
                if (sipServerRequest instanceof SIPTransaction) {
                    SIPServerTransaction sipServerTx = (SIPServerTransaction) sipServerRequest;
                    if (!sipServerTx.passToListener()) {
                        ((SIPTransaction) sipServerRequest).releaseSem();
                    }
                }
            }
            if (sipStack.isLoggingEnabled(LogWriter.TRACE_DEBUG))
                this.sipStack.getStackLogger().logDebug("Done processing "
                        + sipRequest.getFirstLine() + "/" + sipServerRequest);

            // So far so good -- we will commit this message if
            // all processing is OK.

        } else {
View Full Code Here

     */
    public void sendMessage(SIPMessage messageToSend) throws IOException {

        try {
            // Message typecast as a request
            SIPRequest transactionRequest;

            transactionRequest = (SIPRequest) messageToSend;

            // Set the branch id for the top via header.
            Via topVia = (Via) transactionRequest.getViaHeaders().getFirst();
            // Tack on a branch identifier to match responses.
            try {
                topVia.setBranch(getBranch());
            } catch (java.text.ParseException ex) {
            }

            if (sipStack.isLoggingEnabled(LogWriter.TRACE_DEBUG)) {
                sipStack.getStackLogger().logDebug("Sending Message " + messageToSend);
                sipStack.getStackLogger().logDebug("TransactionState " + this.getState());
            }
            // If this is the first request for this transaction,
            if (TransactionState.PROCEEDING == getState()
                    || TransactionState.CALLING == getState()) {

                // If this is a TU-generated ACK request,
                if (transactionRequest.getMethod().equals(Request.ACK)) {

                    // Send directly to the underlying
                    // transport and close this transaction
                    if (isReliable()) {
                        this.setState(TransactionState.TERMINATED);
                    } else {
                        this.setState(TransactionState.COMPLETED);
                    }
                    // BUGBUG -- This suppresses sending the ACK uncomment this
                    // to
                    // test 4xx retransmission
                    // if (transactionRequest.getMethod() != Request.ACK)
                    super.sendMessage(transactionRequest);
                    return;

                }

            }
            try {

                // Send the message to the server
                lastRequest = transactionRequest;
                if (getState() == null) {
                    // Save this request as the one this transaction
                    // is handling
                    setOriginalRequest(transactionRequest);
                    // Change to trying/calling state
                    // Set state first to avoid race condition..

                    if (transactionRequest.getMethod().equals(Request.INVITE)) {
                        this.setState(TransactionState.CALLING);
                    } else if (transactionRequest.getMethod().equals(Request.ACK)) {
                        // Acks are never retransmitted.
                        this.setState(TransactionState.TERMINATED);
                    } else {
                        this.setState(TransactionState.TRYING);
                    }
View Full Code Here

     * (non-Javadoc)
     *
     * @see javax.sip.ClientTransaction#sendRequest()
     */
    public void sendRequest() throws SipException {
        SIPRequest sipRequest = this.getOriginalRequest();

        if (this.getState() != null)
            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.getOriginalRequest().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.getState() == null) {
                    throw new SipException(
                            "State is null no provisional response yet -- cannot cancel RFC 3261 9.1");
                } else if (!ct.getMethod().equals(Request.INVITE)) {
                    throw new SipException("Cannot cancel non-invite requests RFC 3261 9.1");
                }
            } else

            if (this.getOriginalRequest().getMethod().equals(Request.BYE)
                    || this.getOriginalRequest().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 (this.getMethod().equals(Request.INVITE)) {
                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;
            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  &&  getMethod().equals(Request.INVITE) &&
View Full Code Here

     * (non-Javadoc)
     *
     * @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

     * (non-Javadoc)
     *
     * @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) {
            // If the record route list is null then we can
            // construct the ACK from the specified contact header.
            // Note the 3xx check here because 3xx is a redirect.
            // The contact header for the 3xx is the redirected
            // location so we cannot use that to construct the
            // request URI.
            if (lastResponse.getContactHeaders() != null
                    && lastResponse.getStatusCode() / 100 != 3) {
                Contact contact = (Contact) lastResponse.getContactHeaders().getFirst();
                javax.sip.address.URI uri = (javax.sip.address.URI) contact.getAddress().getURI()
                        .clone();
                ackRequest.setRequestURI(uri);
            }
            return ackRequest;
        }

        ackRequest.removeHeader(RouteHeader.NAME);
        RouteList routeList = new RouteList();
        // start at the end of the list and walk backwards
        ListIterator<RecordRoute> li = recordRouteList.listIterator(recordRouteList.size());
        while (li.hasPrevious()) {
            RecordRoute rr = (RecordRoute) li.previous();

            Route route = new Route();
            route.setAddress((AddressImpl) ((AddressImpl) rr.getAddress()).clone());
            route.setParameters((NameValueList) rr.getParameters().clone());
            routeList.add(route);
        }

        Contact contact = null;
        if (lastResponse.getContactHeaders() != null) {
            contact = (Contact) lastResponse.getContactHeaders().getFirst();
        }

        if (!((SipURI) ((Route) routeList.getFirst()).getAddress().getURI()).hasLrParam()) {

            // Contact may not yet be there (bug reported by Andreas B).

            Route route = null;
            if (contact != null) {
                route = new Route();
                route.setAddress((AddressImpl) ((AddressImpl) (contact.getAddress())).clone());
            }

            Route firstRoute = (Route) routeList.getFirst();
            routeList.removeFirst();
            javax.sip.address.URI uri = firstRoute.getAddress().getURI();
            ackRequest.setRequestURI(uri);

            if (route != null)
                routeList.add(route);

            ackRequest.addHeader(routeList);
        } else {
            if (contact != null) {
                javax.sip.address.URI uri = (javax.sip.address.URI) contact.getAddress().getURI()
                        .clone();
                ackRequest.setRequestURI(uri);
                ackRequest.addHeader(routeList);
            }
        }
        return ackRequest;

    }
View Full Code Here

     * Creates an ACK for an error response, according to RFC3261 section 17.1.1.3
     *
     * 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 (!getMethod().equals(Request.INVITE)) {
            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

TOP

Related Classes of gov.nist.javax.sip.message.SIPRequest

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.