NIST-SIP: The Reference Implementation for JAIN-SIP 1.2

gov.nist.javax.sip.message
Class MessageFactoryImpl

java.lang.Object
  extended by gov.nist.javax.sip.message.MessageFactoryImpl
All Implemented Interfaces:
MessageFactoryExt, MessageFactory

public class MessageFactoryImpl
extends Object
implements MessageFactory, MessageFactoryExt

Message Factory implementation

Since:
1.1
Version:
1.2 $Revision: 1.21 $ $Date: 2009/08/20 19:01:21 $
Author:
M. Ranganathan
, Olivier Deruelle

Constructor Summary
MessageFactoryImpl()
          Creates a new instance of MessageFactoryImpl
 
Method Summary
 MultipartMimeContent createMultipartMimeContent(ContentTypeHeader multipartMimeCth, String[] contentType, String[] contentSubtype, String[] contentBody)
          Create a MultipartMime attachment from a list of content type, subtype and content.
 Request createRequest(String requestString)
          Create a request from a string.
 Request createRequest(URI requestURI, String method, CallIdHeader callId, CSeqHeader cSeq, FromHeader from, ToHeader to, List via, MaxForwardsHeader maxForwards)
          Creates a new Request message of type specified by the method paramater, containing the URI of the Request, the mandatory headers of the message.
 Request createRequest(URI requestURI, String method, CallIdHeader callId, CSeqHeader cSeq, FromHeader from, ToHeader to, List via, MaxForwardsHeader maxForwards, byte[] content, ContentTypeHeader contentType)
          Creates a new Request message of type specified by the method paramater, containing the URI of the Request, the mandatory headers of the message with a body in the form of a byte array and body content type.
 Request createRequest(URI requestURI, String method, CallIdHeader callId, CSeqHeader cSeq, FromHeader from, ToHeader to, List via, MaxForwardsHeader maxForwards, ContentTypeHeader contentType, byte[] content)
          Creates a new Request message of type specified by the method paramater, containing the URI of the Request, the mandatory headers of the message with a body in the form of a byte array and body content type.
 Request createRequest(URI requestURI, String method, CallIdHeader callId, CSeqHeader cSeq, FromHeader from, ToHeader to, List via, MaxForwardsHeader maxForwards, ContentTypeHeader contentType, Object content)
          Creates a new Request message of type specified by the method paramater, containing the URI of the Request, the mandatory headers of the message with a body in the form of a Java object and the body content type.
 Response createResponse(int statusCode, CallIdHeader callId, CSeqHeader cSeq, FromHeader from, ToHeader to, List via, MaxForwardsHeader maxForwards)
          Creates a new Response message of type specified by the statusCode paramater, containing the mandatory headers of the message.
 Response createResponse(int statusCode, CallIdHeader callId, CSeqHeader cSeq, FromHeader from, ToHeader to, List via, MaxForwardsHeader maxForwards, byte[] content, ContentTypeHeader contentType)
          Creates a new Response message of type specified by the statusCode paramater, containing the mandatory headers of the message with a body in the form of a byte array and the body content type.
 Response createResponse(int statusCode, CallIdHeader callId, CSeqHeader cSeq, FromHeader from, ToHeader to, List via, MaxForwardsHeader maxForwards, ContentTypeHeader contentType, byte[] content)
          Creates a new Response message of type specified by the statusCode paramater, containing the mandatory headers of the message with a body in the form of a byte array and the body content type.
 Response createResponse(int statusCode, CallIdHeader callId, CSeqHeader cSeq, FromHeader from, ToHeader to, List via, MaxForwardsHeader maxForwards, ContentTypeHeader contentType, Object content)
          Creates a new Response message of type specified by the statusCode paramater, containing the mandatory headers of the message with a body in the form of a Java object and the body content type.
 Response createResponse(int statusCode, CallIdHeader callId, CSeqHeader cSeq, FromHeader from, ToHeader to, List via, MaxForwardsHeader maxForwards, Object content, ContentTypeHeader contentType)
          Creates a new Response message of type specified by the statusCode paramater, containing the mandatory headers of the message with a body in the form of a Java object and the body content type.
 Response createResponse(int statusCode, Request request)
          Creates a new Response message of type specified by the statusCode paramater, based on a specific Request message.
 Response createResponse(int statusCode, Request request, ContentTypeHeader contentType, byte[] content)
          Creates a new Response message of type specified by the statusCode paramater, based on a specific Request with a new body in the form of a byte array and the body content type.
 Response createResponse(int statusCode, Request request, ContentTypeHeader contentType, Object content)
          Creates a new Response message of type specified by the statusCode paramater, based on a specific Request with a new body in the form of a Java object and the body content type.
 Response createResponse(String responseString)
          Create a response from a string
static String getDefaultContentEncodingCharset()
           
static ServerHeader getDefaultServerHeader()
          Get the default common server header.
static UserAgentHeader getDefaultUserAgentHeader()
          Get the default common UserAgentHeader.
 void setDefaultContentEncodingCharset(String charset)
          Set default charset used for encoding String content.
 void setDefaultServerHeader(ServerHeader server)
          Set the common Server header for all responses created from this message factory.
 void setDefaultUserAgentHeader(UserAgentHeader userAgent)
          Set the common UserAgent header for all requests created from this message factory.
 void setTest(boolean flag)
          This is for testing -- allows you to generate invalid requests
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MessageFactoryImpl

public MessageFactoryImpl()
Creates a new instance of MessageFactoryImpl

Method Detail

setTest

public void setTest(boolean flag)
This is for testing -- allows you to generate invalid requests


createRequest

public Request createRequest(URI requestURI,
                             String method,
                             CallIdHeader callId,
                             CSeqHeader cSeq,
                             FromHeader from,
                             ToHeader to,
                             List via,
                             MaxForwardsHeader maxForwards,
                             ContentTypeHeader contentType,
                             Object content)
                      throws ParseException
Creates a new Request message of type specified by the method paramater, containing the URI of the Request, the mandatory headers of the message with a body in the form of a Java object and the body content type.

Specified by:
createRequest in interface MessageFactory
Parameters:
requestURI - - the new URI object of the requestURI value of this Message.
method - - the new string of the method value of this Message.
callId - - the new CallIdHeader object of the callId value of this Message.
cSeq - - the new CSeqHeader object of the cSeq value of this Message.
from - - the new FromHeader object of the from value of this Message.
to - - the new ToHeader object of the to value of this Message.
via - - the new List object of the ViaHeaders of this Message.
content - - the new Object of the body content value of this Message.
contentType - - the new ContentTypeHeader object of the content type value of this Message.
Returns:
the newly created Request object.
Throws:
ParseException - which signals that an error has been reached unexpectedly while parsing the method or the body.

createRequest

public Request createRequest(URI requestURI,
                             String method,
                             CallIdHeader callId,
                             CSeqHeader cSeq,
                             FromHeader from,
                             ToHeader to,
                             List via,
                             MaxForwardsHeader maxForwards,
                             byte[] content,
                             ContentTypeHeader contentType)
                      throws ParseException
Creates a new Request message of type specified by the method paramater, containing the URI of the Request, the mandatory headers of the message with a body in the form of a byte array and body content type.

Parameters:
requestURI - - the new URI object of the requestURI value of this Message.
method - - the new string of the method value of this Message.
callId - - the new CallIdHeader object of the callId value of this Message.
cSeq - - the new CSeqHeader object of the cSeq value of this Message.
from - - the new FromHeader object of the from value of this Message.
to - - the new ToHeader object of the to value of this Message.
via - - the new List object of the ViaHeaders of this Message.
content - - the new byte array of the body content value of this Message.
contentType - - the new ContentTypeHeader object of the content type value of this Message.
Throws:
ParseException - which signals that an error has been reached unexpectedly while parsing the method or the body.

createRequest

public Request createRequest(URI requestURI,
                             String method,
                             CallIdHeader callId,
                             CSeqHeader cSeq,
                             FromHeader from,
                             ToHeader to,
                             List via,
                             MaxForwardsHeader maxForwards)
                      throws ParseException
Creates a new Request message of type specified by the method paramater, containing the URI of the Request, the mandatory headers of the message. This new Request does not contain a body.

Specified by:
createRequest in interface MessageFactory
Parameters:
requestURI - - the new URI object of the requestURI value of this Message.
method - - the new string of the method value of this Message.
callId - - the new CallIdHeader object of the callId value of this Message.
cSeq - - the new CSeqHeader object of the cSeq value of this Message.
from - - the new FromHeader object of the from value of this Message.
to - - the new ToHeader object of the to value of this Message.
via - - the new List object of the ViaHeaders of this Message.
Returns:
the newly created Request object.
Throws:
ParseException - which signals that an error has been reached unexpectedly while parsing the method.

createResponse

public Response createResponse(int statusCode,
                               CallIdHeader callId,
                               CSeqHeader cSeq,
                               FromHeader from,
                               ToHeader to,
                               List via,
                               MaxForwardsHeader maxForwards,
                               Object content,
                               ContentTypeHeader contentType)
                        throws ParseException
Creates a new Response message of type specified by the statusCode paramater, containing the mandatory headers of the message with a body in the form of a Java object and the body content type.

Parameters:
statusCode - - the new integer of the statusCode value of this Message.
callId - - the new CallIdHeader object of the callId value of this Message.
cSeq - - the new CSeqHeader object of the cSeq value of this Message.
from - - the new FromHeader object of the from value of this Message.
to - - the new ToHeader object of the to value of this Message.
via - - the new List object of the ViaHeaders of this Message.
content - - the new Object of the body content value of this Message.
contentType - - the new ContentTypeHeader object of the content type value of this Message.
Throws:
ParseException - which signals that an error has been reached unexpectedly while parsing the statusCode or the body.

createResponse

public Response createResponse(int statusCode,
                               CallIdHeader callId,
                               CSeqHeader cSeq,
                               FromHeader from,
                               ToHeader to,
                               List via,
                               MaxForwardsHeader maxForwards,
                               byte[] content,
                               ContentTypeHeader contentType)
                        throws ParseException
Creates a new Response message of type specified by the statusCode paramater, containing the mandatory headers of the message with a body in the form of a byte array and the body content type.

Parameters:
statusCode - - the new integer of the statusCode value of this Message.
callId - - the new CallIdHeader object of the callId value of this Message.
cSeq - - the new CSeqHeader object of the cSeq value of this Message.
from - - the new FromHeader object of the from value of this Message.
to - - the new ToHeader object of the to value of this Message.
via - - the new List object of the ViaHeaders of this Message.
content - - the new byte array of the body content value of this Message.
contentType - - the new ContentTypeHeader object of the content type value of this Message.
Throws:
ParseException - which signals that an error has been reached unexpectedly while parsing the statusCode or the body.

createResponse

public Response createResponse(int statusCode,
                               CallIdHeader callId,
                               CSeqHeader cSeq,
                               FromHeader from,
                               ToHeader to,
                               List via,
                               MaxForwardsHeader maxForwards)
                        throws ParseException
Creates a new Response message of type specified by the statusCode paramater, containing the mandatory headers of the message. This new Response does not contain a body.

Specified by:
createResponse in interface MessageFactory
Parameters:
statusCode - - the new integer of the statusCode value of this Message.
callId - - the new CallIdHeader object of the callId value of this Message.
cSeq - - the new CSeqHeader object of the cSeq value of this Message.
from - - the new FromHeader object of the from value of this Message.
to - - the new ToHeader object of the to value of this Message.
via - - the new List object of the ViaHeaders of this Message.
Returns:
the newly created Response object.
Throws:
ParseException - which signals that an error has been reached unexpectedly while parsing the statusCode.

createResponse

public Response createResponse(int statusCode,
                               Request request,
                               ContentTypeHeader contentType,
                               Object content)
                        throws ParseException
Creates a new Response message of type specified by the statusCode paramater, based on a specific Request with a new body in the form of a Java object and the body content type.

Specified by:
createResponse in interface MessageFactory
Parameters:
statusCode - - the new integer of the statusCode value of this Message.
request - - the received Reqest object upon which to base the Response.
content - - the new Object of the body content value of this Message.
contentType - - the new ContentTypeHeader object of the content type value of this Message.
Returns:
the newly created Response object.
Throws:
ParseException - which signals that an error has been reached unexpectedly while parsing the statusCode or the body.

createResponse

public Response createResponse(int statusCode,
                               Request request,
                               ContentTypeHeader contentType,
                               byte[] content)
                        throws ParseException
Creates a new Response message of type specified by the statusCode paramater, based on a specific Request with a new body in the form of a byte array and the body content type.

Specified by:
createResponse in interface MessageFactory
Parameters:
statusCode - - the new integer of the statusCode value of this Message.
request - - the received Reqest object upon which to base the Response.
content - - the new byte array of the body content value of this Message.
contentType - - the new ContentTypeHeader object of the content type value of this Message.
Returns:
the newly created Response object.
Throws:
ParseException - which signals that an error has been reached unexpectedly while parsing the statusCode or the body.

createResponse

public Response createResponse(int statusCode,
                               Request request)
                        throws ParseException
Creates a new Response message of type specified by the statusCode paramater, based on a specific Request message. This new Response does not contain a body.

Specified by:
createResponse in interface MessageFactory
Parameters:
statusCode - - the new integer of the statusCode value of this Message.
request - - the received Reqest object upon which to base the Response.
Returns:
the newly created Response object.
Throws:
ParseException - which signals that an error has been reached unexpectedly while parsing the statusCode.

createRequest

public Request createRequest(URI requestURI,
                             String method,
                             CallIdHeader callId,
                             CSeqHeader cSeq,
                             FromHeader from,
                             ToHeader to,
                             List via,
                             MaxForwardsHeader maxForwards,
                             ContentTypeHeader contentType,
                             byte[] content)
                      throws ParseException
Creates a new Request message of type specified by the method paramater, containing the URI of the Request, the mandatory headers of the message with a body in the form of a byte array and body content type.

Specified by:
createRequest in interface MessageFactory
Parameters:
requestURI - - the new URI object of the requestURI value of this Message.
method - - the new string of the method value of this Message.
callId - - the new CallIdHeader object of the callId value of this Message.
cSeq - - the new CSeqHeader object of the cSeq value of this Message.
from - - the new FromHeader object of the from value of this Message.
to - - the new ToHeader object of the to value of this Message.
via - - the new List object of the ViaHeaders of this Message.
contentType - - the new ContentTypeHeader object of the content type value of this Message.
content - - the new byte array of the body content value of this Message.
Returns:
the newly created Request object.
Throws:
ParseException - which signals that an error has been reached unexpectedly while parsing the method or the body.

createResponse

public Response createResponse(int statusCode,
                               CallIdHeader callId,
                               CSeqHeader cSeq,
                               FromHeader from,
                               ToHeader to,
                               List via,
                               MaxForwardsHeader maxForwards,
                               ContentTypeHeader contentType,
                               Object content)
                        throws ParseException
Creates a new Response message of type specified by the statusCode paramater, containing the mandatory headers of the message with a body in the form of a Java object and the body content type.

Specified by:
createResponse in interface MessageFactory
Parameters:
statusCode - the new integer of the statusCode value of this Message.
callId - the new CallIdHeader object of the callId value of this Message.
cSeq - the new CSeqHeader object of the cSeq value of this Message.
from - the new FromHeader object of the from value of this Message.
to - the new ToHeader object of the to value of this Message.
via - the new List object of the ViaHeaders of this Message.
contentType - the new ContentTypeHeader object of the content type value of this Message.
content - the new Object of the body content value of this Message.
Returns:
the newly created Response object.
Throws:
ParseException - which signals that an error has been reached unexpectedly while parsing the statusCode or the body.

createResponse

public Response createResponse(int statusCode,
                               CallIdHeader callId,
                               CSeqHeader cSeq,
                               FromHeader from,
                               ToHeader to,
                               List via,
                               MaxForwardsHeader maxForwards,
                               ContentTypeHeader contentType,
                               byte[] content)
                        throws ParseException
Creates a new Response message of type specified by the statusCode paramater, containing the mandatory headers of the message with a body in the form of a byte array and the body content type.

Specified by:
createResponse in interface MessageFactory
Parameters:
statusCode - the new integer of the statusCode value of this Message.
callId - the new CallIdHeader object of the callId value of this Message.
cSeq - the new CSeqHeader object of the cSeq value of this Message.
from - the new FromHeader object of the from value of this Message.
to - the new ToHeader object of the to value of this Message.
via - the new List object of the ViaHeaders of this Message.
contentType - the new ContentTypeHeader object of the content type value of this Message.
content - the new byte array of the body content value of this Message.
Returns:
the newly created Response object.
Throws:
ParseException - which signals that an error has been reached unexpectedly while parsing the statusCode or the body.

createRequest

public Request createRequest(String requestString)
                      throws ParseException
Create a request from a string. Conveniance method for UACs that want to create an outgoing request from a string. Only the headers of the request should be included in the String that is supplied to this method.

Specified by:
createRequest in interface MessageFactory
Parameters:
requestString - -- string from which to create the message null string returns an empty message.
Returns:
the newly created Request object.
Throws:
ParseException - which signals that an error has been reached unexpectedly while parsing the request.

createResponse

public Response createResponse(String responseString)
                        throws ParseException
Create a response from a string

Specified by:
createResponse in interface MessageFactory
Parameters:
responseString - -- string from which to create the message null string returns an empty message.
Throws:
ParseException - which signals an error has been reached unexpectedly while parsing the response.

setDefaultUserAgentHeader

public void setDefaultUserAgentHeader(UserAgentHeader userAgent)
Set the common UserAgent header for all requests created from this message factory. This header is applied to all Messages created from this Factory object except those that take String for an argument and create Message from the given String.

Specified by:
setDefaultUserAgentHeader in interface MessageFactoryExt
Parameters:
userAgent - -- the user agent header to set.
Since:
2.0

setDefaultServerHeader

public void setDefaultServerHeader(ServerHeader server)
Set the common Server header for all responses created from this message factory. This header is applied to all Messages created from this Factory object except those that take String for an argument and create Message from the given String.

Specified by:
setDefaultServerHeader in interface MessageFactoryExt
Parameters:
userAgent - -- the user agent header to set.
Since:
2.0

getDefaultUserAgentHeader

public static UserAgentHeader getDefaultUserAgentHeader()
Get the default common UserAgentHeader.

Returns:
the user agent header.
Since:
2.0

getDefaultServerHeader

public static ServerHeader getDefaultServerHeader()
Get the default common server header.

Returns:
the server header.

setDefaultContentEncodingCharset

public void setDefaultContentEncodingCharset(String charset)
                                      throws NullPointerException,
                                             IllegalArgumentException
Set default charset used for encoding String content.

Specified by:
setDefaultContentEncodingCharset in interface MessageFactoryExt
Parameters:
charset -
Throws:
NullPointerException - if null arg
IllegalArgumentException - if Charset is not a known charset.

getDefaultContentEncodingCharset

public static String getDefaultContentEncodingCharset()

createMultipartMimeContent

public MultipartMimeContent createMultipartMimeContent(ContentTypeHeader multipartMimeCth,
                                                       String[] contentType,
                                                       String[] contentSubtype,
                                                       String[] contentBody)
Description copied from interface: MessageFactoryExt
Create a MultipartMime attachment from a list of content type, subtype and content.

Specified by:
createMultipartMimeContent in interface MessageFactoryExt

NIST-SIP: The Reference Implementation for JAIN-SIP 1.2

A product of the NIST/ITL Advanced Networking Technologies Division.
See conditions of use.
Submit a bug report or feature request.