/** Creates a CANCEL request. */
 public static Message createCancelRequest(Message method, Dialog dialog) {
   ToHeader to = method.getToHeader();
   FromHeader from = method.getFromHeader();
   SipURL request_uri = method.getRequestLine().getAddress();
   NameAddress contact = method.getContactHeader().getNameAddress();
   ViaHeader via = method.getViaHeader();
   String host_addr = via.getHost();
   int host_port = via.getPort();
   boolean rport = via.hasRport();
   String proto = via.getProtocol();
   String branch = method.getViaHeader().getBranch();
   return createRequest(
       SipMethods.CANCEL,
       request_uri,
       to.getNameAddress(),
       from.getNameAddress(),
       contact,
       proto,
       host_addr,
       host_port,
       rport,
       method.getCallIdHeader().getCallId(),
       method.getCSeqHeader().getSequenceNumber(),
       from.getParameter("tag"),
       to.getParameter("tag"),
       branch,
       "",
       null,
       null); // modified by mandrajg
 }
 /**
  * Creates a SIP request message.
  *
  * @param method method name
  * @param request_uri request-uri
  * @param to ToHeader NameAddress
  * @param from FromHeader NameAddress
  * @param contact Contact NameAddress (if null, no ContactHeader is added)
  * @param host_addr Via address
  * @param host_port Via port number
  * @param call_id Call-ID value
  * @param cseq CSeq value
  * @param local_tag tag in FromHeader
  * @param remote_tag tag in ToHeader (if null, no tag is added)
  * @param branch branch value (if null, a random value is picked)
  * @param body body (if null, no body is added)
  * @param qvalue Q value (if ICSI is null, no Q value is added)
  * @param icsi ICSI (if null, no ICSI is added)
  */
 public static Message createRequest(
     String method,
     SipURL request_uri,
     NameAddress to,
     NameAddress from,
     NameAddress contact,
     String proto,
     String via_addr,
     int host_port,
     boolean rport,
     String call_id,
     long cseq,
     String local_tag,
     String remote_tag,
     String branch,
     String body,
     String qvalue,
     String icsi) { // modified by mandrajg
   Message req = new Message();
   // mandatory headers first (To, From, Via, Max-Forwards, Call-ID, CSeq):
   req.setRequestLine(new RequestLine(method, request_uri));
   ViaHeader via = new ViaHeader(proto, via_addr, host_port);
   if (rport) via.setRport();
   if (branch == null) branch = SipProvider.pickBranch();
   via.setBranch(branch);
   req.addViaHeader(via);
   req.setMaxForwardsHeader(new MaxForwardsHeader(70));
   if (remote_tag == null) req.setToHeader(new ToHeader(to));
   else req.setToHeader(new ToHeader(to, remote_tag));
   req.setFromHeader(new FromHeader(from, local_tag));
   req.setCallIdHeader(new CallIdHeader(call_id));
   req.setCSeqHeader(new CSeqHeader(cseq, method));
   // optional headers:
   // start modification by mandrajg
   if (contact != null) {
     if (((method == "REGISTER") || (method == "INVITE")) && (icsi != null)) {
       MultipleHeader contacts = new MultipleHeader(SipHeaders.Contact);
       contacts.addBottom(new ContactHeader(contact, qvalue, icsi));
       req.setContacts(contacts);
     } else {
       MultipleHeader contacts = new MultipleHeader(SipHeaders.Contact);
       contacts.addBottom(new ContactHeader(contact));
       req.setContacts(contacts);
     }
     // System.out.println("DEBUG: Contact: "+contact.toString());
   }
   if ((method == "INVITE") && (icsi != null)) {
     req.setAcceptContactHeader(new AcceptContactHeader(icsi));
   }
   // end modifications by mandrajg
   req.setExpiresHeader(new ExpiresHeader(String.valueOf(SipStack.default_expires)));
   // add User-Agent header field
   if (SipStack.ua_info != null) req.setUserAgentHeader(new UserAgentHeader(SipStack.ua_info));
   // if (body!=null) req.setBody(body); else req.setBody("");
   req.setBody(body);
   // System.out.println("DEBUG: MessageFactory: request:\n"+req);
   return req;
 }