Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.impl.protocol.sip
Class SipMessageFactory

java.lang.Object
  extended by net.java.sip.communicator.impl.protocol.sip.SipMessageFactory
All Implemented Interfaces:
javax.sip.message.MessageFactory

public class SipMessageFactory
extends Object
implements javax.sip.message.MessageFactory

This MessageFactory is just a wrapper around a "real" Messagefactory, which will be passed to the constructor. Its only purpose is to mark every created message with its ProtocolProviderServiceSipImpl, so that the generated Message-s will be easy to route or dispatch.

Author:
Sebastien Mazy, Emil Ivov

Field Summary
static Logger logger
          The logger for this class
 
Constructor Summary
SipMessageFactory(ProtocolProviderServiceSipImpl service, javax.sip.message.MessageFactory wrappedFactory)
          The constructor for this class.
 
Method Summary
 javax.sip.message.Request createAck(javax.sip.ClientTransaction clientTransaction)
          Creates an ACK request that can be sent in the context of clientTransaction's Dialog.
 javax.sip.message.Request createInviteRequest(javax.sip.address.Address toAddress)
          Creates an invite request destined for callee.
 javax.sip.message.Request createInviteRequest(javax.sip.address.Address toAddress, javax.sip.message.Message cause)
          Creates an invite request destined for callee and reflects any possible non-null cause (e.g.
 javax.sip.message.Request createRegisterRequest(javax.sip.address.Address addressOfRecord, int registrationsExpiration, javax.sip.header.CallIdHeader callIdHeader, long cSeqValue)
          Creates a REGISTER Request as per the specified parameters.
 javax.sip.message.Request createRequest(javax.sip.Dialog dialog, String method)
          Creates a new Request of a specific method which is to be sent in a specific Dialog and populates its generally-necessary headers such as the Authorization header.
 javax.sip.message.Request createRequest(String requestParam)
          Calls the same method in the internal wrapped factory and returns a Request marked with its service.
 javax.sip.message.Request createRequest(javax.sip.address.URI requestURI, String method, javax.sip.header.CallIdHeader callId, javax.sip.header.CSeqHeader cSeq, javax.sip.header.FromHeader from, javax.sip.header.ToHeader to, List via, javax.sip.header.MaxForwardsHeader maxForwards)
          Calls the same method in the internal wrapped factory and returns a Request marked with its service.
 javax.sip.message.Request createRequest(javax.sip.address.URI requestURI, String method, javax.sip.header.CallIdHeader callId, javax.sip.header.CSeqHeader cSeq, javax.sip.header.FromHeader from, javax.sip.header.ToHeader to, List via, javax.sip.header.MaxForwardsHeader maxForwards, javax.sip.header.ContentTypeHeader contentType, byte[] content)
          Calls the same method in the internal wrapped factory and returns a Request marked with its service.
 javax.sip.message.Request createRequest(javax.sip.address.URI requestURI, String method, javax.sip.header.CallIdHeader callId, javax.sip.header.CSeqHeader cSeq, javax.sip.header.FromHeader from, javax.sip.header.ToHeader to, List via, javax.sip.header.MaxForwardsHeader maxForwards, javax.sip.header.ContentTypeHeader contentType, Object content)
          Calls the same method in the internal wrapped factory and returns a Request marked with its service.
 javax.sip.message.Response createResponse(int statusCode, javax.sip.header.CallIdHeader callId, javax.sip.header.CSeqHeader cSeq, javax.sip.header.FromHeader from, javax.sip.header.ToHeader to, List via, javax.sip.header.MaxForwardsHeader maxForwards)
          Calls the same method in the internal wrapped factory and returns a Response marked with its service.
 javax.sip.message.Response createResponse(int statusCode, javax.sip.header.CallIdHeader callId, javax.sip.header.CSeqHeader cSeq, javax.sip.header.FromHeader from, javax.sip.header.ToHeader to, List via, javax.sip.header.MaxForwardsHeader maxForwards, javax.sip.header.ContentTypeHeader contentType, byte[] content)
          Calls the same method in the internal wrapped factory and returns a Response marked with its service.
 javax.sip.message.Response createResponse(int statusCode, javax.sip.header.CallIdHeader callId, javax.sip.header.CSeqHeader cSeq, javax.sip.header.FromHeader from, javax.sip.header.ToHeader to, List via, javax.sip.header.MaxForwardsHeader maxForwards, javax.sip.header.ContentTypeHeader contentType, Object content)
          Calls the same method in the internal wrapped factory and returns a Response marked with its service.
 javax.sip.message.Response createResponse(int statusCode, javax.sip.message.Request request)
          Calls the same method in the internal wrapped factory and returns a Response marked with its service.
 javax.sip.message.Response createResponse(int statusCode, javax.sip.message.Request request, javax.sip.header.ContentTypeHeader contentType, byte[] content)
          Calls the same method in the internal wrapped factory and returns a Response marked with its service.
 javax.sip.message.Response createResponse(int statusCode, javax.sip.message.Request request, javax.sip.header.ContentTypeHeader contentType, Object content)
          Calls the same method in the internal wrapped factory and returns a Response marked with its service.
 javax.sip.message.Response createResponse(String responseParam)
          Calls the same method in the internal wrapped factory and returns a Response marked with its service.
 javax.sip.message.Request createUnRegisterRequest(javax.sip.message.Request registerRequest, long cSeqValue)
          Creates a request that would end a registration established with registerRequest
static String generateLocalTag()
          Generate a tag for a FROM header or TO header.
 void preAuthenticateRequest(javax.sip.message.Request request)
          Verifies wither we have already authenticated requests with the same Call-ID as request and attaches the corresponding credentials in an effort to avoid receiving an authentication challenge from the server and having to re-send the request.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

public static final Logger logger
The logger for this class

Constructor Detail

SipMessageFactory

public SipMessageFactory(ProtocolProviderServiceSipImpl service,
                         javax.sip.message.MessageFactory wrappedFactory)
The constructor for this class.

Parameters:
service - the service this MessageFactory belongs to.
wrappedFactory - the MessageFactory which will really create messages.
Method Detail

createRequest

public javax.sip.message.Request createRequest(javax.sip.address.URI requestURI,
                                               String method,
                                               javax.sip.header.CallIdHeader callId,
                                               javax.sip.header.CSeqHeader cSeq,
                                               javax.sip.header.FromHeader from,
                                               javax.sip.header.ToHeader to,
                                               List via,
                                               javax.sip.header.MaxForwardsHeader maxForwards,
                                               javax.sip.header.ContentTypeHeader contentType,
                                               Object content)
                                        throws ParseException
Calls the same method in the internal wrapped factory and returns a Request marked with its service.

Specified by:
createRequest in interface javax.sip.message.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.
maxForwards - the Max-Forwards header for the new Request.
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:
a Request marked with its service
Throws:
ParseException - which signals that an error has been reached unexpectedly while parsing the method or the body.

createRequest

public javax.sip.message.Request createRequest(javax.sip.address.URI requestURI,
                                               String method,
                                               javax.sip.header.CallIdHeader callId,
                                               javax.sip.header.CSeqHeader cSeq,
                                               javax.sip.header.FromHeader from,
                                               javax.sip.header.ToHeader to,
                                               List via,
                                               javax.sip.header.MaxForwardsHeader maxForwards,
                                               javax.sip.header.ContentTypeHeader contentType,
                                               byte[] content)
                                        throws ParseException
Calls the same method in the internal wrapped factory and returns a Request marked with its service.

Specified by:
createRequest in interface javax.sip.message.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.
maxForwards - the Max-Forwards header for the new Request.
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:
a Request marked with its service
Throws:
ParseException - which signals that an error has been reached unexpectedly while parsing the method or the body.

createRequest

public javax.sip.message.Request createRequest(javax.sip.address.URI requestURI,
                                               String method,
                                               javax.sip.header.CallIdHeader callId,
                                               javax.sip.header.CSeqHeader cSeq,
                                               javax.sip.header.FromHeader from,
                                               javax.sip.header.ToHeader to,
                                               List via,
                                               javax.sip.header.MaxForwardsHeader maxForwards)
                                        throws ParseException
Calls the same method in the internal wrapped factory and returns a Request marked with its service.

Specified by:
createRequest in interface javax.sip.message.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.
maxForwards - the Max-Forwards header for the new Request.
Returns:
a Request marked with its service
Throws:
ParseException - which signals that an error has been reached unexpectedly while parsing the method or the body.

createRequest

public javax.sip.message.Request createRequest(String requestParam)
                                        throws ParseException
Calls the same method in the internal wrapped factory and returns a Request marked with its service.

Specified by:
createRequest in interface javax.sip.message.MessageFactory
Parameters:
requestParam - the new string value of the Request.
Returns:
a Request marked with its service
Throws:
ParseException - which signals that an error has been reached unexpectedly while parsing the request.

createResponse

public javax.sip.message.Response createResponse(int statusCode,
                                                 javax.sip.header.CallIdHeader callId,
                                                 javax.sip.header.CSeqHeader cSeq,
                                                 javax.sip.header.FromHeader from,
                                                 javax.sip.header.ToHeader to,
                                                 List via,
                                                 javax.sip.header.MaxForwardsHeader maxForwards,
                                                 javax.sip.header.ContentTypeHeader contentType,
                                                 Object content)
                                          throws ParseException
Calls the same method in the internal wrapped factory and returns a Response marked with its service.

Specified by:
createResponse in interface javax.sip.message.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.
maxForwards - the Max-Forwards header for the new Response.
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:
a Response marked with its service
Throws:
ParseException - which signals that an error has been reached unexpectedly while parsing the statusCode or the body.

createResponse

public javax.sip.message.Response createResponse(int statusCode,
                                                 javax.sip.header.CallIdHeader callId,
                                                 javax.sip.header.CSeqHeader cSeq,
                                                 javax.sip.header.FromHeader from,
                                                 javax.sip.header.ToHeader to,
                                                 List via,
                                                 javax.sip.header.MaxForwardsHeader maxForwards,
                                                 javax.sip.header.ContentTypeHeader contentType,
                                                 byte[] content)
                                          throws ParseException
Calls the same method in the internal wrapped factory and returns a Response marked with its service.

Specified by:
createResponse in interface javax.sip.message.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.
maxForwards - the Max-Forwards header for the new Response.
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:
a Response marked with its service
Throws:
ParseException - which signals that an error has been reached unexpectedly while parsing the statusCode or the body.

createResponse

public javax.sip.message.Response createResponse(int statusCode,
                                                 javax.sip.header.CallIdHeader callId,
                                                 javax.sip.header.CSeqHeader cSeq,
                                                 javax.sip.header.FromHeader from,
                                                 javax.sip.header.ToHeader to,
                                                 List via,
                                                 javax.sip.header.MaxForwardsHeader maxForwards)
                                          throws ParseException
Calls the same method in the internal wrapped factory and returns a Response marked with its service.

Specified by:
createResponse in interface javax.sip.message.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.
maxForwards - the Max-Forwards header for the new Response.
Returns:
a Response marked with its service
Throws:
ParseException - which signals that an error has been reached unexpectedly while parsing the statusCode or the body.

createResponse

public javax.sip.message.Response createResponse(int statusCode,
                                                 javax.sip.message.Request request,
                                                 javax.sip.header.ContentTypeHeader contentType,
                                                 Object content)
                                          throws ParseException
Calls the same method in the internal wrapped factory and returns a Response marked with its service.

Specified by:
createResponse in interface javax.sip.message.MessageFactory
Parameters:
statusCode - the new integer of the statusCode value of this Message.
request - the received Request object upon which to base the Response.
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:
a Response marked with its service
Throws:
ParseException - which signals that an error has been reached unexpectedly while parsing the statusCode or the body.

createResponse

public javax.sip.message.Response createResponse(int statusCode,
                                                 javax.sip.message.Request request,
                                                 javax.sip.header.ContentTypeHeader contentType,
                                                 byte[] content)
                                          throws ParseException
Calls the same method in the internal wrapped factory and returns a Response marked with its service.

Specified by:
createResponse in interface javax.sip.message.MessageFactory
Parameters:
statusCode - the new integer of the statusCode value of this Message.
request - the received Request object upon which to base the Response.
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:
a Response marked with its service
Throws:
ParseException - which signals that an error has been reached unexpectedly while parsing the statusCode or the body.

createResponse

public javax.sip.message.Response createResponse(int statusCode,
                                                 javax.sip.message.Request request)
                                          throws ParseException
Calls the same method in the internal wrapped factory and returns a Response marked with its service.

Specified by:
createResponse in interface javax.sip.message.MessageFactory
Parameters:
statusCode - the new integer of the statusCode value of this Message.
request - the received Request object upon which to base the Response.
Returns:
a Response marked with its service
Throws:
ParseException - which signals that an error has been reached unexpectedly while parsing the statusCode or the body.

createResponse

public javax.sip.message.Response createResponse(String responseParam)
                                          throws ParseException
Calls the same method in the internal wrapped factory and returns a Response marked with its service.

Specified by:
createResponse in interface javax.sip.message.MessageFactory
Parameters:
responseParam - is a string representing the response. The argument should only contain the Sip Headers and not the body of the response.
Returns:
a Response marked with its service
Throws:
ParseException - which signals an error has been reached unexpectedly while parsing the response.

generateLocalTag

public static String generateLocalTag()
Generate a tag for a FROM header or TO header. Just return a random 4 digit integer (should be enough to avoid any clashes!) Tags only need to be unique within a call.

Returns:
a string that can be used as a tag parameter. synchronized: needed for access to 'rand', else risk to generate same tag twice

createRequest

public javax.sip.message.Request createRequest(javax.sip.Dialog dialog,
                                               String method)
                                        throws OperationFailedException
Creates a new Request of a specific method which is to be sent in a specific Dialog and populates its generally-necessary headers such as the Authorization header.

Parameters:
dialog - the Dialog to create the new Request in
method - the method of the newly-created Request
Returns:
a new Request of the specified method which is to be sent in the specified dialog and populated with its generally-necessary headers such as the Authorization header
Throws:
OperationFailedException - if we get a SipException while creating the new request from dialog.

createInviteRequest

public javax.sip.message.Request createInviteRequest(javax.sip.address.Address toAddress)
                                              throws OperationFailedException,
                                                     IllegalArgumentException
Creates an invite request destined for callee.

Parameters:
toAddress - the sip address of the callee that the request is meant for.
Returns:
a newly created sip Request destined for callee.
Throws:
OperationFailedException - with the corresponding code if creating the request fails.
IllegalArgumentException - if toAddress does not appear to be a valid destination.

createInviteRequest

public javax.sip.message.Request createInviteRequest(javax.sip.address.Address toAddress,
                                                     javax.sip.message.Message cause)
                                              throws OperationFailedException,
                                                     IllegalArgumentException
Creates an invite request destined for callee and reflects any possible non-null cause (e.g. a Refer request causing a transfer) on the newly created request.

Parameters:
toAddress - the sip address of the callee that the request is meant for.
cause - the SIP Message from which the information is to be copied or null if there is no cause to be reflected ( e.g. a refer request).
Returns:
a newly created sip Request destined for callee.
Throws:
OperationFailedException - with the corresponding code if creating the request fails.
IllegalArgumentException - if toAddress does not appear to be a valid destination.

createAck

public javax.sip.message.Request createAck(javax.sip.ClientTransaction clientTransaction)
                                    throws javax.sip.InvalidArgumentException,
                                           javax.sip.SipException
Creates an ACK request that can be sent in the context of clientTransaction's Dialog.

Parameters:
clientTransaction - the transaction that caused us to send an Ack.
Returns:
the newly created ACK Request.
Throws:
javax.sip.InvalidArgumentException - if there is a problem with the supplied CSeq ( for example <= 0 ).
javax.sip.SipException - if the CSeq does not relate to a previously sent INVITE or if the Method that created the Dialog is not an INVITE ( for example SUBSCRIBE)

preAuthenticateRequest

public void preAuthenticateRequest(javax.sip.message.Request request)
Verifies wither we have already authenticated requests with the same Call-ID as request and attaches the corresponding credentials in an effort to avoid receiving an authentication challenge from the server and having to re-send the request. This method has no effect if the Call-ID has not been seen by our security manager.

Parameters:
request - the request that we'd like to try pre-authenticating.

createRegisterRequest

public javax.sip.message.Request createRegisterRequest(javax.sip.address.Address addressOfRecord,
                                                       int registrationsExpiration,
                                                       javax.sip.header.CallIdHeader callIdHeader,
                                                       long cSeqValue)
                                                throws javax.sip.InvalidArgumentException,
                                                       ParseException,
                                                       OperationFailedException
Creates a REGISTER Request as per the specified parameters.

Parameters:
addressOfRecord - the address that we shall be registering
registrationsExpiration - the expiration interval for the AOR
callIdHeader - the Call-ID header for our new Request.
cSeqValue - the sequence number of the new request.
Returns:
the newly created REGISTER Request
Throws:
javax.sip.InvalidArgumentException - in case there's a problem with any of the arguments that we received for this request.
ParseException - in case there's a problem with any of the arguments that we received for this request.
OperationFailedException - if we have a problem with the MaxForwardsHeader.

createUnRegisterRequest

public javax.sip.message.Request createUnRegisterRequest(javax.sip.message.Request registerRequest,
                                                         long cSeqValue)
                                                  throws javax.sip.InvalidArgumentException
Creates a request that would end a registration established with registerRequest

Parameters:
registerRequest - the request that established the registration we are now about to terminate.
cSeqValue - the value of the sequence number that the new Request should list in its CSeq header.
Returns:
a Request built to terminate the registration established with registerRequest .
Throws:
javax.sip.InvalidArgumentException - if we fail constructing the request for some reason.

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

Jitsi, the OpenSource Java VoIP and Instant Messaging client.
Distributable under LGPL license.