Package gov.nist.javax.sip.header

Examples of gov.nist.javax.sip.header.Via


     * underlying message channel, and adds a branch parameter to it for this
     * transaction.
     */
    public Via getViaHeader() {
        // Via header of the encapulated channel
        Via channelViaHeader;

        // Add the branch parameter to the underlying
        // channel's Via header
        channelViaHeader = super.getViaHeader();
        try {
            channelViaHeader.setBranch(branch);
        } catch (java.text.ParseException ex) {
        }
        return channelViaHeader;

    }
View Full Code Here


    public boolean doesCancelMatchTransaction(SIPRequest requestToTest) {

        // List of Via headers in the message to test
//        ViaList viaHeaders;
        // Topmost Via header in the list
        Via topViaHeader;
        // Branch code in the topmost Via header
        String messageBranch;
        // Flags whether the select message is part of this transaction
        boolean transactionMatches;

        transactionMatches = false;

        if (this.getOriginalRequest() == null
                || this.getMethod().equals(Request.CANCEL))
            return false;
        // Get the topmost Via header and its branch parameter
        topViaHeader = requestToTest.getTopmostVia();
        if (topViaHeader != null) {

//            topViaHeader = (Via) viaHeaders.getFirst();
            messageBranch = topViaHeader.getBranch();
            if (messageBranch != null) {

                // If the branch parameter exists but
                // does not start with the magic cookie,
                if (!messageBranch.toLowerCase().startsWith(SIPConstants.BRANCH_MAGIC_COOKIE_LOWER_CASE)) {

                    // Flags this as old
                    // (RFC2543-compatible) client
                    // version
                    messageBranch = null;

                }

            }

            // If a new branch parameter exists,
            if (messageBranch != null && this.getBranch() != null) {

                // If the branch equals the branch in
                // this message,
                if (getBranch().equalsIgnoreCase(messageBranch)
                        && topViaHeader.getSentBy().equals(
                                getOriginalRequest().getTopmostVia().getSentBy())) {
                    transactionMatches = true;
                    if (sipStack.isLoggingEnabled(LogWriter.TRACE_DEBUG))
                        sipStack.getStackLogger().logDebug("returning  true");
                }

            } else {
                // If this is an RFC2543-compliant message,
                // If RequestURI, To tag, From tag,
                // CallID, CSeq number, and top Via
                // headers are the same,
                if (sipStack.isLoggingEnabled(LogWriter.TRACE_DEBUG))
                    sipStack.getStackLogger().logDebug("testing against "
                            + getOriginalRequest());

                if (getOriginalRequest().getRequestURI().equals(
                        requestToTest.getRequestURI())
                        && getOriginalRequest().getTo().equals(
                                requestToTest.getTo())
                        && getOriginalRequest().getFrom().equals(
                                requestToTest.getFrom())
                        && getOriginalRequest().getCallId().getCallId().equals(
                                requestToTest.getCallId().getCallId())
                        && getOriginalRequest().getCSeq().getSeqNumber() == requestToTest
                                .getCSeq().getSeqNumber()
                        && topViaHeader.equals(getOriginalRequest().getTopmostVia())) {

                    transactionMatches = true;
                }

            }
View Full Code Here

     * @return true if the message is part of this transaction, false if not.
     */
    public boolean isMessagePartOfTransaction(SIPMessage messageToTest) {

        // List of Via headers in the message to test
        Via topMostViaHeader = messageToTest.getTopmostVia();
        // Flags whether the select message is part of this transaction
        boolean transactionMatches;
        String messageBranch = topMostViaHeader.getBranch();
        boolean rfc3261Compliant = getBranch() != null
                && messageBranch != null
                && getBranch().toLowerCase().startsWith(
                        SIPConstants.BRANCH_MAGIC_COOKIE_LOWER_CASE)
                && messageBranch.toLowerCase().startsWith(
                        SIPConstants.BRANCH_MAGIC_COOKIE_LOWER_CASE);

        transactionMatches = false;
        if (TransactionState._COMPLETED == this.getInternalState()) {
            if (rfc3261Compliant) {
                transactionMatches = getBranch().equalsIgnoreCase(
                    topMostViaHeader.getBranch())
                        && getMethod().equals(messageToTest.getCSeq().getMethod());
            } else {
                transactionMatches = getBranch().equals(messageToTest.getTransactionId());
            }
        } else if (!isTerminated()) {
            if (rfc3261Compliant) {
                if (topMostViaHeader != null) {
                    // If the branch parameter is the
                    // same as this transaction and the method is the same,
                    if (getBranch().equalsIgnoreCase(topMostViaHeader.getBranch())) {
                        transactionMatches = getMethod().equals(
                                messageToTest.getCSeq().getMethod());

                    }
                }
View Full Code Here

            SIPRequest transactionRequest;

            transactionRequest = (SIPRequest) messageToSend;

            // Set the branch id for the top via header.
            Via topVia = (Via) transactionRequest.getTopmostVia();
            // 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);
View Full Code Here

   *         message. This can be used for matching responses and requests
   *         (i.e. an outgoing request and its matching response have the same
   *         computed transaction identifier).
   */
  public String getTransactionId() {
    Via topVia = null;
    if (!this.getViaHeaders().isEmpty()) {
      topVia = (Via) this.getViaHeaders().getFirst();
    }
    // Have specified a branch Identifier so we can use it to identify
    // the transaction. BranchId is not case sensitive.
    // Branch Id prefix is not case sensitive.
    if (topVia != null && topVia.getBranch() != null
        && topVia.getBranch().toUpperCase().startsWith(
            SIPConstants.BRANCH_MAGIC_COOKIE_UPPER_CASE)) {
      // Bis 09 compatible branch assignment algorithm.
      // implies that the branch id can be used as a transaction
      // identifier.
      if (this.getCSeq().getMethod().equals(Request.CANCEL))
        return (topVia.getBranch() + ":" + this.getCSeq().getMethod())
            .toLowerCase();
      else
        return topVia.getBranch().toLowerCase();
    } else {
      // Old style client so construct the transaction identifier
      // from various fields of the request.
      StringBuffer retval = new StringBuffer();
      From from = (From) this.getFrom();
      To to = (To) this.getTo();
      // String hpFrom = from.getUserAtHostPort();
      // retval.append(hpFrom).append(":");
      if (from.hasTag())
        retval.append(from.getTag()).append("-");
      // String hpTo = to.getUserAtHostPort();
      // retval.append(hpTo).append(":");
      String cid = this.callIdHeader.getCallId();
      retval.append(cid).append("-");
      retval.append(this.cSeqHeader.getSequenceNumber()).append("-")
          .append(this.cSeqHeader.getMethod());
      if (topVia != null) {
        retval.append("-").append(topVia.getSentBy().encode());
        if (!topVia.getSentBy().hasPort()) {
          retval.append("-").append(5060);
        }
      }
      if (this.getCSeq().getMethod().equals(Request.CANCEL))
        retval.append(Request.CANCEL);
View Full Code Here

   */
  public void setVia(java.util.List viaList) {
    ViaList vList = new ViaList();
    ListIterator it = viaList.listIterator();
    while (it.hasNext()) {
      Via via = (Via) it.next();
      vList.add(via);
    }
    this.setHeader(vList);
  }
View Full Code Here

    // Be kind and assign a via header for this provider if the user is
    // sloppy
    if (sipRequest.getTopmostVia() == null) {
      ListeningPointImpl lp = (ListeningPointImpl) this
          .getListeningPoint("udp");
      Via via = lp.getViaHeader();
      request.setHeader(via);
    }
    // Give the request a quick check to see if all headers are assigned.
    try {
      sipRequest.checkHeaders();
    } catch (ParseException ex) {
      throw new TransactionUnavailableException(ex.getMessage(), ex);
    }

    /*
     * User decided to give us his own via header branch. Lets see if it
     * results in a clash. If so reject the request.
     */
    if (sipRequest.getTopmostVia().getBranch() != null
        && sipRequest.getTopmostVia().getBranch().startsWith(
            SIPConstants.BRANCH_MAGIC_COOKIE)
        && sipStack.findTransaction((SIPRequest) request, false) != null) {
      throw new TransactionUnavailableException(
          "Transaction already exists!");
    }

   
   

    if (request.getMethod().equalsIgnoreCase(Request.CANCEL)) {
      SIPClientTransaction ct = (SIPClientTransaction) sipStack
          .findCancelTransaction((SIPRequest) request, false);
      if (ct != null) {
        ClientTransaction retval = sipStack.createClientTransaction(
            (SIPRequest) request, ct.getMessageChannel());

        ((SIPTransaction) retval).addEventListener(this);
        sipStack.addTransaction((SIPClientTransaction) retval);
        if (ct.getDialog() != null) {
          ((SIPClientTransaction) retval).setDialog((SIPDialog) ct
              .getDialog(), sipRequest.getDialogId(false));

        }
        return retval;
      }

    }
    if (sipStack.isLoggingEnabled())
      sipStack.getLogWriter().logDebug(
          "could not find existing transaction for "
              + ((SIPRequest) request).getFirstLine()
              + " creating a new one ");

    // Could not find a dialog or the route is not set in dialog.

    Hop hop = null;
    try {
      hop = sipStack.getNextHop((SIPRequest) request);
      if (hop == null)
        throw new TransactionUnavailableException(
            "Cannot resolve next hop -- transaction unavailable");
    } catch (SipException ex) {
      throw new TransactionUnavailableException(
          "Cannot resolve next hop -- transaction unavailable", ex);
    }
    String transport = hop.getTransport();
        ListeningPointImpl listeningPoint = (ListeningPointImpl) this
                .getListeningPoint(transport);
       
    String dialogId = sipRequest.getDialogId(false);
    SIPDialog dialog = sipStack.getDialog(dialogId);
    if (dialog != null && dialog.getState() == DialogState.TERMINATED) {

      // throw new TransactionUnavailableException
      // ("Found a terminated dialog -- possible re-use of old tag
      // parameters");
      sipStack.removeDialog(dialog);

    }

    // An out of dialog route was found. Assign this to the
    // client transaction.

    try {
      // Set the brannch id before you ask for a tx.
      // If the user has set his own branch Id and the
      // branch id starts with a valid prefix, then take it.
      // otherwise, generate one.
      String branchId = null;
      if (sipRequest.getTopmostVia().getBranch() == null
          || !sipRequest.getTopmostVia().getBranch().startsWith(
              SIPConstants.BRANCH_MAGIC_COOKIE)) {
        branchId = Utils.getInstance().generateBranchId();

        sipRequest.getTopmostVia().setBranch(branchId);
      }
      Via topmostVia = sipRequest.getTopmostVia();
          topmostVia.setTransport(transport);
          topmostVia.setPort(listeningPoint.getPort());
      branchId = sipRequest.getTopmostVia().getBranch();
     
      SIPClientTransaction ct = (SIPClientTransaction) sipStack
          .createMessageChannel(sipRequest, listeningPoint
              .getMessageProcessor(), hop);
View Full Code Here

       * 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()))
View Full Code Here

     * Get the Via header for this transport. Note that this does not set a branch identifier.
     *
     * @return a via header for outgoing messages sent from this channel.
     */
    public Via getViaHeader() {
        Via channelViaHeader;

        channelViaHeader = new Via();
        try {
            channelViaHeader.setTransport(getTransport());
        } catch (ParseException ex) {
        }
        channelViaHeader.setSentBy(getHostPort());
        return channelViaHeader;
    }
View Full Code Here

   */
  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;
View Full Code Here

TOP

Related Classes of gov.nist.javax.sip.header.Via

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.