Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
  * Conditions Of Use
  *
  * This software was developed by employees of the National Institute of
  * Standards and Technology (NIST), an agency of the Federal Government.
  * Pursuant to title 15 Untied States Code Section 105, works of NIST
  * employees are not subject to copyright protection in the United States
  * and are considered to be in the public domain.  As a result, a formal
  * license is not needed to use the software.
 *
 * This software is provided by NIST as a service and is expressly
 * provided "AS IS."  NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
 * OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
 * AND DATA ACCURACY.  NIST does not warrant or make any representations
 * regarding the use of the software or the results thereof, including but
 * not limited to the correctness, accuracy, reliability or usefulness of
 * the software.
 *
 * Permission to use this software is contingent upon your acceptance
 * of the terms of this agreement
 *
 * .
 *
 */
Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * /
 
 package gov.nist.javax.sip.header;
 
 
Via SIPHeader (these are strung together in a ViaList).

Author(s):
M. Ranganathan
Version:
1.2 $Revision: 1.17 $ $Date: 2009/10/18 13:46:33 $
See also:
ViaList
 
 public class Via
     extends ParametersHeader
     implements javax.sip.header.ViaHeaderViaHeaderExt {

    
Comment for serialVersionUID
 
     private static final long serialVersionUID = 5281728373401351378L;

    
The branch parameter is included by every forking proxy.
 
     public static final String BRANCH = .;

    
The "received" parameter is added only for receiver-added Via Fields.
 
     public static final String RECEIVED = .;

    
The "maddr" paramter is designating the multicast address.
 
     public static final String MADDR = .;

    
The "TTL" parameter is designating the time-to-live value.
 
     public static final String TTL = .;

    
The RPORT parameter.
 
     public static final String RPORT = .;

    
sentProtocol field.
 
     protected Protocol sentProtocol;

    
sentBy field.
 
     protected HostPort sentBy;

    
comment field JvB note: RFC3261 does not allow a comment to appear in Via headers, and this is not accessible through the API. Suggest removal
 
     protected String comment;

    
Default constructor
    public Via() {
        super();
         = new Protocol();
    }
    public boolean equals(Object other) {
        if (other==thisreturn true;
        if (other instanceof ViaHeader) {
            final ViaHeader o = (ViaHeaderother;
            return getProtocol().equalsIgnoreCaseo.getProtocol() )
                && getTransport().equalsIgnoreCaseo.getTransport() )
                && getHost().equalsIgnoreCaseo.getHost() )
                && getPort() == o.getPort()
                && equalParameterso );
        }
        return false;
    }


    
get the Protocol Version

Returns:
String
    public String getProtocolVersion() {
        if ( == null)
            return null;
        else
            return .getProtocolVersion();
    }

    
Accessor for the sentProtocol field.

Returns:
Protocol field
    public Protocol getSentProtocol() {
        return ;
    }

    
Accessor for the sentBy field

Returns:
SentBy field
    public HostPort getSentBy() {
        return ;
    }

    
Get the host, port and transport as a Hop. This is useful for the stack to avoid duplication of code.
    public Hop getHop() {
        HopImpl hop = new HopImpl(.getHost().getHostname(),
                .getPort(),.getTransport());
        return hop;
    }

    
Accessor for the parameters field

Returns:
parameters field
    public NameValueList getViaParms() {
        return ;
    }

    
Accessor for the comment field.

Deprecated:
RFC 2543 support feature.
Returns:
comment field.
    public String getComment() {
        return ;
    }



    
port of the Via Header.

Returns:
true if Port exists.
    public boolean hasPort() {
        return (getSentBy()).hasPort();
    }

    
comment of the Via Header.

Returns:
false if comment does not exist and true otherwise.
    public boolean hasComment() {
        return  != null;
    }

    
remove the port.
    public void removePort() {
        .removePort();
    }

    
remove the comment field.
    public void removeComment() {
         = null;
    }

    
set the Protocol Version

Parameters:
protocolVersion String to set
    public void setProtocolVersion(String protocolVersion) {
        if ( == null)
             = new Protocol();
        .setProtocolVersion(protocolVersion);
    }

    
set the Host of the Via Header

Parameters:
host String to set
    public void setHost(Host host) {
        if ( == null) {
             = new HostPort();
        }
        .setHost(host);
    }

    
Set the sentProtocol member

Parameters:
s Protocol to set.
    public void setSentProtocol(Protocol s) {
         = s;
    }

    
Set the sentBy member

Parameters:
s HostPort to set.
    public void setSentBy(HostPort s) {
         = s;
    }

    
Set the comment member

Deprecated:
This is an RFC 2543 feature.
Parameters:
c String to set.
    public void setComment(String c) {
         = c;
    }

    
Encode the body of this header (the stuff that follows headerName). A.K.A headerValue.
    protected String encodeBody() {
        return encodeBody(new StringBuffer()).toString();
    }
    protected StringBuffer encodeBody(StringBuffer buffer) {
        .encode(buffer);
        buffer.append();
        .encode(buffer);
        if (!.isEmpty()) {
            buffer.append();
            .encode(buffer);
        }
        if ( != null) {
            buffer.append().append().append().append();
        }
        return buffer;
    }

    
Set the host part of this ViaHeader to the newly supplied host parameter.

Throws:
java.text.ParseException which signals that an error has been reached unexpectedly while parsing the host value.
    public void setHost(String hostthrows ParseException {
        if ( == null)
             = new HostPort();
        try {
            Host h = new Host(host);
            .setHost(h);
        } catch (Exception e) {
            throw new NullPointerException(" host parameter is null");
        }
    }

    
Returns the host part of this ViaHeader.

Returns:
the string value of the host
    public String getHost() {
        if ( == null)
            return null;
        else {
            Host host = .getHost();
            if (host == null)
                return null;
            else
                return host.getHostname();
        }
    }

    
Set the port part of this ViaHeader to the newly supplied port parameter.

Parameters:
port - the Integer.valueOf value of the port of this ViaHeader
    public void setPort(int portthrows InvalidArgumentException {
        if ( port!=-1 && (port<1 || port>65535)) {
            throw new InvalidArgumentException"Port value out of range -1, [1..65535]" );
        }
        if ( == null)
             = new HostPort();
        .setPort(port);
    }

    
Set the RPort flag parameter
    public void setRPort(){
        try {
            this.setParameter(.,"");
        } catch (ParseException e) {
            e.printStackTrace();    // should not occur
        }
    }

    
Returns the port part of this ViaHeader.

Returns:
the integer value of the port
    public int getPort() {
        if ( == null)
            return -1;
        return .getPort();
    }


    
Return the rport parameter.

Returns:
the rport parameter or -1.
       public int getRPort() {
         String strRport = getParameter(.);
         if (strRport != null && ! strRport.equals(""))
            return Integer.valueOf(strRport).intValue();
         else
            return -1;
         }


    
Returns the value of the transport parameter.

Returns:
the string value of the transport paramter of the ViaHeader
    public String getTransport() {
        if ( == null)
            return null;
        return .getTransport();
    }

    
Sets the value of the transport. This parameter specifies which transport protocol to use for sending requests and responses to this entity. The following values are defined: "udp", "tcp", "sctp", "tls", but other values may be used also.

Parameters:
transport - new value for the transport parameter
Throws:
java.text.ParseException which signals that an error has been reached unexpectedly while parsing the transport value.
    public void setTransport(String transportthrows ParseException {
        if (transport == null)
            throw new NullPointerException(
                "JAIN-SIP Exception, "
                    + "Via, setTransport(), the transport parameter is null.");
        if ( == null)
             = new Protocol();
        .setTransport(transport);
    }

    
Returns the value of the protocol used.

Returns:
the string value of the protocol paramter of the ViaHeader
    public String getProtocol() {
        if ( == null)
            return null;
        return .getProtocol();// JvB: Return name ~and~ version
    }

    
Sets the value of the protocol parameter. This parameter specifies which protocol is used, for example "SIP/2.0".

Parameters:
protocol - new value for the protocol parameter
Throws:
java.text.ParseException which signals that an error has been reached unexpectedly while parsing the protocol value.
    public void setProtocol(String protocolthrows ParseException {
        if (protocol == null)
            throw new NullPointerException(
                "JAIN-SIP Exception, "
                    + "Via, setProtocol(), the protocol parameter is null.");
        if ( == null)
             = new Protocol();
        .setProtocol(protocol);
    }

    
Returns the value of the ttl parameter, or -1 if this is not set.

Returns:
the integer value of the ttl parameter
    public int getTTL() {
        int ttl = getParameterAsInt(.);
        return ttl;
    }

    
Sets the value of the ttl parameter. The ttl parameter specifies the time-to-live value when packets are sent using UDP multicast.

Parameters:
ttl - new value of the ttl parameter
Throws:
javax.sip.InvalidArgumentException if supplied value is less than zero or greater than 255, excluding -1 the default not set value.
    public void setTTL(int ttlthrows InvalidArgumentException {
        if (ttl < 0 && ttl != -1)
            throw new InvalidArgumentException(
                "JAIN-SIP Exception"
                    + ", Via, setTTL(), the ttl parameter is < 0");
        setParameter(new NameValue(., Integer.valueOf(ttl)));
    }

    
Returns the value of the maddr parameter, or null if this is not set.

Returns:
the string value of the maddr parameter
    public String getMAddr() {
        return getParameter(.);
    }

    
Sets the value of the maddr parameter of this ViaHeader. The maddr parameter indicates the server address to be contacted for this user, overriding any address derived from the host field.

Parameters:
mAddr new value of the maddr parameter
Throws:
java.text.ParseException which signals that an error has been reached unexpectedly while parsing the mAddr value.
    public void setMAddr(String mAddrthrows ParseException {
        if (mAddr == null)
            throw new NullPointerException(
                "JAIN-SIP Exception, "
                    + "Via, setMAddr(), the mAddr parameter is null.");
        Host host = new Host();
        host.setAddress(mAddr);
        NameValue nameValue = new NameValue(.host);
        setParameter(nameValue);
    }

    
Gets the received paramater of the ViaHeader. Returns null if received does not exist.

Returns:
the string received value of ViaHeader
    public String getReceived() {
        return getParameter(.);
    }

    
Sets the received parameter of ViaHeader.

Parameters:
received - the newly supplied received parameter.
Throws:
java.text.ParseException which signals that an error has been reached unexpectedly while parsing the received value.
    public void setReceived(String receivedthrows ParseException {
        if (received == null)
            throw new NullPointerException(
                "JAIN-SIP Exception, "
                    + "Via, setReceived(), the received parameter is null.");
        setParameter(.received);
    }

    
Gets the branch paramater of the ViaHeader. Returns null if branch does not exist.

Returns:
the string branch value of ViaHeader
    public String getBranch() {
        return getParameter(.);
    }

    
Sets the branch parameter of the ViaHeader to the newly supplied branch value.

Parameters:
branch - the new string branch parmameter of the ViaHeader.
Throws:
java.text.ParseException which signals that an error has been reached unexpectedly while parsing the branch value.
    public void setBranch(String branchthrows ParseException {
        if (branch == null || branch.length()==0)
            throw new NullPointerException(
                "JAIN-SIP Exception, "
                    + "Via, setBranch(), the branch parameter is null or length 0.");
        setParameter(.branch);
    }
    public Object clone() {
        Via retval = (Viasuper.clone();
        if (this. != null)
            retval.sentProtocol = (Protocolthis..clone();
        if (this. != null)
            retval.sentBy = (HostPortthis..clone();
        if ( this.getRPort() != -1)
            retval.setParameter(,this.getRPort());
        return retval;
    }
    /*
     * (non-Javadoc)
     * @see gov.nist.javax.sip.header.ViaHeaderExt#getSentByField()
     */
    public String getSentByField() {
        if( != null)
            return .encode();
        return null;
    }
    /*
     * (non-Javadoc)
     * @see gov.nist.javax.sip.header.ViaHeaderExt#getSentProtocolField()
     */
    public String getSentProtocolField() {
        if( != null)
            return .encode();
        return null;
    }
New to GrepCode? Check out our FAQ X