コード例 #1
0
 /** 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
 }
コード例 #2
0
 /**
  * Creates a SIP response message.
  *
  * @param req the request message
  * @param code the response code
  * @param reason the response reason
  * @param contact the contact address
  * @param local_tag the local tag in the 'To' header
  * @param body the message body
  */
 public static Message createResponse(
     Message req,
     int code,
     String reason,
     String local_tag,
     NameAddress contact,
     String content_type,
     String body) {
   Message resp = new Message();
   resp.setStatusLine(new StatusLine(code, reason));
   resp.setVias(req.getVias());
   if (code >= 180 && code < 300 && req.hasRecordRouteHeader())
     resp.setRecordRoutes(req.getRecordRoutes());
   ToHeader toh = req.getToHeader();
   if (local_tag != null) toh.setParameter("tag", local_tag);
   resp.setToHeader(toh);
   resp.setFromHeader(req.getFromHeader());
   resp.setCallIdHeader(req.getCallIdHeader());
   resp.setCSeqHeader(req.getCSeqHeader());
   if (contact != null) resp.setContactHeader(new ContactHeader(contact));
   // add Server header field
   if (SipStack.server_info != null) resp.setServerHeader(new ServerHeader(SipStack.server_info));
   // if (body!=null) resp.setBody(body); else resp.setBody("");
   if (content_type == null) resp.setBody(body);
   else resp.setBody(content_type, body);
   // System.out.println("DEBUG: MessageFactory:
   // response:\n"+resp.toString());
   return resp;
 }
コード例 #3
0
 /** Creates an ACK request for a non-2xx response */
 public static Message createNon2xxAckRequest(
     SipProvider sip_provider, Message method, Message resp) {
   SipURL request_uri = method.getRequestLine().getAddress();
   FromHeader from = method.getFromHeader();
   ToHeader to = resp.getToHeader();
   String via_addr = sip_provider.getViaAddress();
   int host_port = sip_provider.getPort();
   boolean rport = sip_provider.isRportSet();
   String proto;
   if (request_uri.hasTransport()) proto = request_uri.getTransport();
   else proto = sip_provider.getDefaultTransport();
   String branch = method.getViaHeader().getBranch();
   NameAddress contact = null;
   Message ack =
       createRequest(
           SipMethods.ACK,
           request_uri,
           to.getNameAddress(),
           from.getNameAddress(),
           contact,
           proto,
           via_addr,
           host_port,
           rport,
           method.getCallIdHeader().getCallId(),
           method.getCSeqHeader().getSequenceNumber(),
           from.getParameter("tag"),
           to.getParameter("tag"),
           branch,
           null,
           null,
           null); // modified by mandrajg
   ack.removeExpiresHeader();
   if (method.hasRouteHeader()) ack.setRoutes(method.getRoutes());
   return ack;
 }