Package gov.nist.javax.sip.header

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


   */
  public LinkedList<String> getMessageAsEncodedStrings() {
    LinkedList<String> retval = new LinkedList<String>();
    Iterator<SIPHeader> li = headers.iterator();
    while (li.hasNext()) {
      SIPHeader sipHeader = (SIPHeader) li.next();
      if (sipHeader instanceof SIPHeaderList) {
        SIPHeaderList<?> shl = (SIPHeaderList<?>) sipHeader;
        retval.addAll(shl.getHeadersAsEncodedStrings());
      } else {
        retval.add(sipHeader.encode());
      }
    }

    return retval;
  }
View Full Code Here


  protected String encodeSIPHeaders() {
    StringBuffer encoding = new StringBuffer();
    Iterator<SIPHeader> it = this.headers.iterator();

    while (it.hasNext()) {
      SIPHeader siphdr = (SIPHeader) it.next();
      if (!(siphdr instanceof ContentLength))
        siphdr.encode(encoding);
    }

    return contentLengthHeader.encode(encoding).append(NEWLINE).toString();
  }
View Full Code Here

    if (!other.getClass().equals(this.getClass()))
      return false;
    SIPMessage matchObj = (SIPMessage) other;
    Iterator<SIPHeader> li = matchObj.getHeaders();
    while (li.hasNext()) {
      SIPHeader hisHeaders = (SIPHeader) li.next();
      List<SIPHeader> myHeaders = this.getHeaderList(hisHeaders
          .getHeaderName());

      // Could not find a header to match his header.
      if (myHeaders == null || myHeaders.size() == 0)
        return false;

      if (hisHeaders instanceof SIPHeaderList) {
        ListIterator<?> outerIterator = ((SIPHeaderList<?>) hisHeaders)
            .listIterator();
        while (outerIterator.hasNext()) {
          SIPHeader hisHeader = (SIPHeader) outerIterator.next();
          if (hisHeader instanceof ContentLength)
            continue;
          ListIterator<?> innerIterator = myHeaders.listIterator();
          boolean found = false;
          while (innerIterator.hasNext()) {
            SIPHeader myHeader = (SIPHeader) innerIterator.next();
            if (myHeader.match(hisHeader)) {
              found = true;
              break;
            }
          }
          if (!found)
            return false;
        }
      } else {
        SIPHeader hisHeader = hisHeaders;
        ListIterator<SIPHeader> innerIterator = myHeaders.listIterator();
        boolean found = false;
        while (innerIterator.hasNext()) {
          SIPHeader myHeader = (SIPHeader) innerIterator.next();
          if (myHeader.match(hisHeader)) {
            found = true;
            break;
          }
        }
        if (!found)
View Full Code Here

      throw new IllegalArgumentException("Bad class "
          + template.getClass());
    SIPMessage templateMessage = (SIPMessage) template;
    Object[] templateHeaders = templateMessage.headers.toArray();
    for (int i = 0; i < templateHeaders.length; i++) {
      SIPHeader hdr = (SIPHeader) templateHeaders[i];
      String hdrName = hdr.getHeaderName();
      List<SIPHeader> myHdrs = this.getHeaderList(hdrName);
      if (myHdrs == null) {
        this.attachHeader(hdr);
      } else {
        ListIterator<SIPHeader> it = myHdrs.listIterator();
        while (it.hasNext()) {
          SIPHeader sipHdr = (SIPHeader) it.next();
          sipHdr.merge(hdr);
        }
      }
    }

  }
View Full Code Here

  public String encode() {
    StringBuffer encoding = new StringBuffer();
    Iterator<SIPHeader> it = this.headers.iterator();

    while (it.hasNext()) {
      SIPHeader siphdr = (SIPHeader) it.next();
      if (!(siphdr instanceof ContentLength))
        encoding.append(siphdr.encode());
    }
    // Append the unrecognized headers. Headers that are not
    // recognized are passed through unchanged.
    for ( String unrecognized : this.unrecognizedHeaders) {
      encoding.append(unrecognized).append(NEWLINE);
View Full Code Here

    StringBuffer encoding = new StringBuffer();
    synchronized (this.headers) {
      Iterator<SIPHeader> it = this.headers.iterator();

      while (it.hasNext()) {
        SIPHeader siphdr = (SIPHeader) it.next();
        if (!(siphdr instanceof ContentLength))
          siphdr.encode(encoding);

      }
    }
    contentLengthHeader.encode(encoding);
    encoding.append(NEWLINE);
View Full Code Here

    retval.contentLengthHeader = null;
    retval.maxForwardsHeader = null;
    if (this.headers != null) {
        retval.headers = new ConcurrentLinkedQueue<SIPHeader>();
      for (Iterator<SIPHeader> iter = headers.iterator(); iter.hasNext();) {
        SIPHeader hdr = (SIPHeader) iter.next();
        retval.attachHeader((SIPHeader) hdr.clone());
      }

    }
    if (this.messageContentBytes != null)
      retval.messageContentBytes = (byte[]) this.messageContentBytes
View Full Code Here

   *
   * @param sipHeader
   *            SIPHeader that replaces a header of the same type.
   */
  public void setHeader(Header sipHeader) {
    SIPHeader header = (SIPHeader) sipHeader;
    if (header == null)
      throw new IllegalArgumentException("null header!");
    try {
      if (header instanceof SIPHeaderList) {
        SIPHeaderList<?> hl = (SIPHeaderList<?>) header;
        // Ignore empty lists.
        if (hl.isEmpty())
          return;
      }
      this.removeHeader(header.getHeaderName());
      attachHeader(header, true, false);
    } catch (SIPDuplicateHeaderException ex) {
      InternalErrorHandler.handleException(ex);
    }
  }
View Full Code Here

   *            a list of headers to set.
   */
  public void setHeaders(java.util.List<SIPHeader> headers) {
    ListIterator<SIPHeader> listIterator = headers.listIterator();
    while (listIterator.hasNext()) {
      SIPHeader sipHeader = (SIPHeader) listIterator.next();
      try {
        this.attachHeader(sipHeader, false);
      } catch (SIPDuplicateHeaderException ex) {
      }
    }
View Full Code Here

      throws SIPDuplicateHeaderException {
    if (header == null) {
      throw new NullPointerException("null header");
    }

    SIPHeader h;

    if (ListMap.hasList(header)
        && !SIPHeaderList.class.isAssignableFrom(header.getClass())) {
      SIPHeaderList<SIPHeader> hdrList = ListMap.getList(header);
      hdrList.add(header);
      h = hdrList;
    } else {
      h = header;
    }

    String headerNameLowerCase = SIPHeaderNamesCache.toLowerCase(h
        .getName());
    if (replaceFlag) {
      nameTable.remove(headerNameLowerCase);
    } else if (nameTable.containsKey(headerNameLowerCase)
        && !(h instanceof SIPHeaderList)) {
      if (h instanceof ContentLength) {
        try {
          ContentLength cl = (ContentLength) h;
          contentLengthHeader.setContentLength(cl.getContentLength());
        } catch (InvalidArgumentException e) {
        }
      }
      // Just ignore duplicate header.
      return;
    }

    SIPHeader originalHeader = (SIPHeader) getHeader(header.getName());

    // Delete the original header from our list structure.
    if (originalHeader != null) {
      Iterator<SIPHeader> li = headers.iterator();
      while (li.hasNext()) {
        SIPHeader next = (SIPHeader) li.next();
        if (next.equals(originalHeader)) {
          li.remove();
        }
      }
    }
View Full Code Here

TOP

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

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.