/*******************************************************************************
* Product of NIST/ITL Advanced Networking Technologies Division (ANTD). *
*******************************************************************************/
package gov.nist.javax.sip.message;
import java.text.ParseException;
import javax.sip.header.*;
import java.util.LinkedList;
import java.util.List;
import gov.nist.javax.sip.header.*;
import javax.sip.message.*;
import javax.sip.address.*;
import gov.nist.javax.sip.parser.*;
/**
* Message Factory implementation
*
* @version 1.2 $Revision: 1.23 $ $Date: 2009/09/08 01:58:40 $
* @since 1.1
*
* @author M. Ranganathan <br/>
* @author Olivier Deruelle <br/>
*
*/
@SuppressWarnings("unchecked")
public class MessageFactoryImpl implements MessageFactory, MessageFactoryExt {
private boolean testing = false;
private boolean strict = true;
private static String defaultContentEncodingCharset = "UTF-8";
/*
* The UserAgent header to include for all requests created from this message factory.
*/
private static UserAgentHeader userAgent;
/*
* The Server header to include
*/
private static ServerHeader server;
public void setStrict(boolean strict) {
this.strict = strict;
}
/**
* This is for testing -- allows you to generate invalid requests
*/
public void setTest(boolean flag) {
this.testing = flag;
}
/**
* Creates a new instance of MessageFactoryImpl
*/
public MessageFactoryImpl() {
}
/**
* 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.
*
* @param requestURI -
* the new URI object of the requestURI value of this Message.
* @param method -
* the new string of the method value of this Message.
* @param callId -
* the new CallIdHeader object of the callId value of this
* Message.
* @param cSeq -
* the new CSeqHeader object of the cSeq value of this Message.
* @param from -
* the new FromHeader object of the from value of this Message.
* @param to -
* the new ToHeader object of the to value of this Message.
* @param via -
* the new List object of the ViaHeaders of this Message.
* @param content -
* the new Object of the body content value of this Message.
* @param 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.
*/
public Request createRequest(javax.sip.address.URI requestURI,
String method, CallIdHeader callId, CSeqHeader cSeq,
FromHeader from, ToHeader to, List via,
MaxForwardsHeader maxForwards, ContentTypeHeader contentType,
Object content) throws ParseException {
if (requestURI == null || method == null || callId == null
|| cSeq == null || from == null || to == null || via == null
|| maxForwards == null || content == null
|| contentType == null)
throw new NullPointerException("Null parameters");
SIPRequest sipRequest = new SIPRequest();
sipRequest.setRequestURI(requestURI);
sipRequest.setMethod(method);
sipRequest.setCallId(callId);
sipRequest.setCSeq(cSeq);
sipRequest.setFrom(from);
sipRequest.setTo(to);
sipRequest.setVia(via);
sipRequest.setMaxForwards(maxForwards);
sipRequest.setContent(content, contentType);
if ( userAgent != null ) {
sipRequest.setHeader(userAgent);
}
return sipRequest;
}
/**
* 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.
*
* @param requestURI -
* the new URI object of the requestURI value of this Message.
* @param method -
* the new string of the method value of this Message.
* @param callId -
* the new CallIdHeader object of the callId value of this
* Message.
* @param cSeq -
* the new CSeqHeader object of the cSeq value of this Message.
* @param from -
* the new FromHeader object of the from value of this Message.
* @param to -
* the new ToHeader object of the to value of this Message.
* @param via -
* the new List object of the ViaHeaders of this Message.
* @param content -
* the new byte array of the body content value of this Message.
* @param 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.
*/
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 {
if (requestURI == null || method == null || callId == null
|| cSeq == null || from == null || to == null || via == null
|| maxForwards == null || content == null
|| contentType == null)
throw new ParseException(
"JAIN-SIP Exception, some parameters are missing"
+ ", unable to create the request", 0);
SIPRequest sipRequest = new SIPRequest();
sipRequest.setRequestURI(requestURI);
sipRequest.setMethod(method);
sipRequest.setCallId(callId);
sipRequest.setCSeq(cSeq);
sipRequest.setFrom(from);
sipRequest.setTo(to);
sipRequest.setVia(via);
sipRequest.setMaxForwards(maxForwards);
sipRequest.setHeader((ContentType) contentType);
sipRequest.setMessageContent(content);
if ( userAgent != null ) {
sipRequest.setHeader(userAgent);
}
return sipRequest;
}
/**
* 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.
*
* @param requestURI -
* the new URI object of the requestURI value of this Message.
* @param method -
* the new string of the method value of this Message.
* @param callId -
* the new CallIdHeader object of the callId value of this
* Message.
* @param cSeq -
* the new CSeqHeader object of the cSeq value of this Message.
* @param from -
* the new FromHeader object of the from value of this Message.
* @param to -
* the new ToHeader object of the to value of this Message.
* @param via -
* the new List object of the ViaHeaders of this Message.
* @throws ParseException
* which signals that an error has been reached unexpectedly
* while parsing the method.
*/
public Request createRequest(URI requestURI, String method,
CallIdHeader callId, CSeqHeader cSeq, FromHeader from, ToHeader to,
List
MessageFactoryImpl.rar_factory
版权申诉
14 浏览量
2022-09-23
00:12:52
上传
评论
收藏 3KB RAR 举报
御道御小黑
- 粉丝: 61
- 资源: 1万+