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.message;
 
 
SIP Response structure.

Author(s):
M. Ranganathan
Version:
1.2 $Revision: 1.35 $ $Date: 2010-09-14 14:39:39 $
Since:
1.1
 
 public class SIPResponse
     extends SIPMessage
     implements javax.sip.message.ResponseResponseExt {
     protected StatusLine statusLine;
     private boolean isRetransmission = true;
    
     public static String getReasonPhrase(int rc) {
         String retval = null;
         switch (rc) {
 
             case  :
                 retval = "Trying";
                 break;
 
             case  :
                 retval = "Ringing";
                 break;
 
             case  :
                 retval = "Call is being forwarded";
                 break;
 
             case  :
                 retval = "Queued";
                 break;
 
             case  :
                 retval = "Session progress";
                 break;
 
             case  :
                 retval = "OK";
                 break;
 
             case  :
                 retval = "Accepted";
                 break;
 
             case  :
                 retval = "Multiple choices";
                 break;
 
             case  :
                 retval = "Moved permanently";
                 break;
 
            case  :
                retval = "Moved Temporarily";
                break;
            case  :
                retval = "Use proxy";
                break;
            case  :
                retval = "Alternative service";
                break;
            case  :
                retval = "Bad request";
                break;
            case  :
                retval = "Unauthorized";
                break;
            case  :
                retval = "Payment required";
                break;
            case  :
                retval = "Forbidden";
                break;
            case  :
                retval = "Not found";
                break;
            case  :
                retval = "Method not allowed";
                break;
            case  :
                retval = "Not acceptable";
                break;
            case  :
                retval = "Proxy Authentication required";
                break;
            case  :
                retval = "Request timeout";
                break;
            case  :
                retval = "Gone";
                break;
            case  :
                retval = "Temporarily Unavailable";
                break;
            case  :
                retval = "Request entity too large";
                break;
            case  :
                retval = "Request-URI too large";
                break;
            case  :
                retval = "Unsupported media type";
                break;
            case  :
                retval = "Unsupported URI Scheme";
                break;
            case  :
                retval = "Bad extension";
                break;
            case  :
                retval = "Etension Required";
                break;
            case  :
                retval = "Interval too brief";
                break;
            case  :
                retval = "Call leg/Transaction does not exist";
                break;
            case  :
                retval = "Loop detected";
                break;
            case  :
                retval = "Too many hops";
                break;
            case  :
                retval = "Address incomplete";
                break;
            case  :
                retval = "Ambiguous";
                break;
            case  :
                retval = "Busy here";
                break;
            case  :
                retval = "Request Terminated";
                break;
            //Issue 168, Typo fix reported by fre on the retval
            case  :
                retval = "Not Acceptable here";
                break;
            case  :
                retval = "Bad Event";
                break;
            case  :
                retval = "Request Pending";
                break;
            case  :
                retval = "Server Internal Error";
                break;
            case  :
                retval = "Undecipherable";
                break;
            case  :
                retval = "Not implemented";
                break;
            case  :
                retval = "Bad gateway";
                break;
            case  :
                retval = "Service unavailable";
                break;
            case  :
                retval = "Gateway timeout";
                break;
            case  :
                retval = "SIP version not supported";
                break;
            case  :
                retval = "Message Too Large";
                break;
            case  :
                retval = "Busy everywhere";
                break;
            case  :
                retval = "Decline";
                break;
            case  :
                retval = "Does not exist anywhere";
                break;
            case  :
                retval = "Session Not acceptable";
                break;
            case :
                retval = "Conditional request failed";
                break;
            default :
                retval = "Unknown Status";
        }
        return retval;
    }

    
set the status code.

Parameters:
statusCode is the status code to set.
Throws:
IlegalArgumentException if invalid status code.
    public void setStatusCode(int statusCodethrows ParseException {
      // RFC3261 defines statuscode as 3DIGIT, 606 is the highest officially
      // defined code but extensions may add others (in theory up to 999,
      // but in practice up to 699 since the 6xx range is defined as 'final error')
        if (statusCode < 100 || statusCode > 699)
            throw new ParseException("bad status code", 0);
        if (this. == null)
            this. = new StatusLine();
        this..setStatusCode(statusCode);
    }

    
Get the status line of the response.

Returns:
StatusLine
    public StatusLine getStatusLine() {
        return ;
    }

    
Get the staus code (conveniance function).

Returns:
the status code of the status line.
    public int getStatusCode() {
        return .getStatusCode();
    }

    
Set the reason phrase.

Parameters:
reasonPhrase the reason phrase.
Throws:
java.lang.IllegalArgumentException if null string
    public void setReasonPhrase(String reasonPhrase) {
        if (reasonPhrase == null)
            throw new IllegalArgumentException("Bad reason phrase");
        if (this. == null)
            this. = new StatusLine();
        this..setReasonPhrase(reasonPhrase);
    }

    
Get the reason phrase.

Returns:
the reason phrase.
    public String getReasonPhrase() {
        if ( == null || .getReasonPhrase() == null)
            return "";
        else
            return .getReasonPhrase();
    }

    
Return true if the response is a final response.

Parameters:
rc is the return code.
Returns:
true if the parameter is between the range 200 and 700.
    public static boolean isFinalResponse(int rc) {
        return rc >= 200 && rc < 700;
    }

    
Is this a final response?

Returns:
true if this is a final response.
    public boolean isFinalResponse() {
        return isFinalResponse(.getStatusCode());
    }

    
Set the status line field.

Parameters:
sl Status line to set.
    public void setStatusLine(StatusLine sl) {
         = sl;
    }

    
Constructor.
    public SIPResponse() {
        super();
    }
    
Print formatting function. Indent and parenthesize for pretty printing. Note -- use the encode method for formatting the message. Hack here to XMLize.

Returns:
a string for pretty printing.
    public String debugDump() {
        String superstring = super.debugDump();
         = "";
        sprint(SIPResponse.class.getCanonicalName());
        sprint("{");
        if ( != null) {
            sprint(.debugDump());
        }
        sprint(superstring);
        sprint("}");
        return ;
    }

    
Check the response structure. Must have from, to CSEQ and VIA headers.
    public void checkHeaders() throws ParseException {
        if (getCSeq() == null) {
            throw new ParseException(." Is missing ", 0);
        }
        if (getTo() == null) {
            throw new ParseException(." Is missing ", 0);
        }
        if (getFrom() == null) {
            throw new ParseException(." Is missing ", 0);
        }
        if (getViaHeaders() == null) {
            throw new ParseException(." Is missing ", 0);
        }
        if (getCallId() == null) {
            throw new ParseException(. + " Is missing ", 0);
        }
        if (getStatusCode() > 699) {
            throw new ParseException("Unknown error code!" + getStatusCode(), 0);
        }
    }

    
Encode the SIP Request as a string.

Returns:
The string encoded canonical form of the message.
    public String encode() {
        String retval;
        if ( != null)
            retval = .encode() + super.encode();
        else
            retval = super.encode();
        return retval ;
    }

    
Encode the message except for the body.

Returns:
The string except for the body.
    public StringBuilder encodeMessage(StringBuilder retval) {
//        String retval;
        if ( != null) {
            .encode(retval);
            super.encodeSIPHeaders(retval);
        } else {
            retval = super.encodeSIPHeaders(retval);
        }
        return retval;
    }



    
Get this message as a list of encoded strings.

Returns:
LinkedList containing encoded strings for each header in the message.
        LinkedList retval = super.getMessageAsEncodedStrings();
        if ( != null)
            retval.addFirst(.encode());
        return retval;
    }

    
Make a clone (deep copy) of this object.

Returns:
a deep copy of this object.
    public Object clone() {
        SIPResponse retval = (SIPResponsesuper.clone();
        if (this. != null)
            retval.statusLine = (StatusLinethis..clone();
        return retval;
    }


    
Compare for equality.

Parameters:
other other object to compare with.
    public boolean equals(Object other) {
        if (!this.getClass().equals(other.getClass()))
            return false;
        SIPResponse that = (SIPResponseother;
        return .equals(that.statusLine) && super.equals(other);
    }

    
Match with a template.

Parameters:
matchObj template object to match ourselves with (null in any position in the template object matches wildcard)
    public boolean match(Object matchObj) {
        if (matchObj == null)
            return true;
        else if (!matchObj.getClass().equals(this.getClass())) {
            return false;
        } else if (matchObj == this)
            return true;
        SIPResponse that = (SIPResponsematchObj;
        StatusLine rline = that.statusLine;
        if (this. == null && rline != null)
            return false;
        else if (this. == rline)
            return super.match(matchObj);
        else {
            return .match(that.statusLine) && super.match(matchObj);
        }
    }

    
Encode this into a byte array. This is used when the body has been set as a binary array and you want to encode the body as a byte array for transmission.

Returns:
a byte array containing the SIPRequest encoded as a byte array.
    public byte[] encodeAsBytesString transport ) {
        byte[] slbytes = null;
        if ( != null) {
            try {
                slbytes = .encode().getBytes("UTF-8");
            } catch (UnsupportedEncodingException ex) {
                InternalErrorHandler.handleException(ex);
            }
        }
        byte[] superbytes = super.encodeAsBytestransport );
        byte[] retval = new byte[slbytes.length + superbytes.length];
        System.arraycopy(slbytes, 0, retval, 0, slbytes.length);
        System.arraycopy(superbytes, 0, retvalslbytes.length,
                superbytes.length);
        return retval;
    }

    
Get the encoded first line.

Returns:
the status line encoded.
    public String getFirstLine() {
        if (this. == null)
            return null;
        else
            return this..encode();
    }
    public void setSIPVersion(String sipVersion) {
        this..setSipVersion(sipVersion);
    }
    public String getSIPVersion() {
        return this..getSipVersion();
    }
    public String toString() {
        if ( == nullreturn  "";
        else return .encode() + super.encode();
    }
    
    @Override
    public void cleanUp() {
//    	statusLine = null;
    	super.cleanUp();
    }

    

Parameters:
isRetransmission the isRetransmission to set
    public void setRetransmission(boolean isRetransmission) {
        
        this. = isRetransmission;
    }

    

Returns:
the isRetransmission
    public boolean isRetransmission() {
        return ;
    }
New to GrepCode? Check out our FAQ X