示例#1
0
  /** Default constructor. */
  protected SIPTransactionStack() {
    super();
    this.transactionTableSize = -1;
    // a set of methods that result in dialog creation.
    this.dialogCreatingMethods = new HashSet<String>();
    // Standard set of methods that create dialogs.
    this.dialogCreatingMethods.add(Request.REFER);
    this.dialogCreatingMethods.add(Request.INVITE);
    this.dialogCreatingMethods.add(Request.SUBSCRIBE);
    // Notify may or may not create a dialog. This is handled in
    // the code.
    // Create the transaction collections

    clientTransactions = Collections.synchronizedList(new ArrayList<SIPClientTransaction>());
    serverTransactions = Collections.synchronizedList(new ArrayList<SIPServerTransaction>());
    // Dialog dable.
    this.dialogTable = new Hashtable<String, SIPDialog>();

    clientTransactionTable = new Hashtable<String, SIPTransaction>();
    serverTransactionTable = new Hashtable<String, SIPTransaction>();

    // Start the timer event thread.

    this.timer = new Timer();
    this.pendingRecordScanner = new Thread(new PendingRecordScanner(this));
    this.pendingRecordScanner.setDaemon(true);
    this.pendingTransactions = new HashSet<SIPServerTransaction>();
    pendingRecords = Collections.synchronizedList(new ArrayList<PendingRecord>());
    pendingRecordScanner.setName("PendingRecordScanner");
    pendingRecordScanner.start();
    // endif
    //

  }
示例#2
0
    public void run() {
      try {
        for (int i = 0; i < 1; i++) {

          Thread.sleep(1000);
          Request request = this.notifier.dialog.createRequest(Request.NOTIFY);
          SubscriptionStateHeader subscriptionState =
              headerFactory.createSubscriptionStateHeader(SubscriptionStateHeader.ACTIVE);
          request.addHeader(subscriptionState);
          request.addHeader(eventHeader);
          ClientTransaction ct = udpProvider.getNewClientTransaction(request);
          this.notifier.dialog.sendRequest(ct);
        }
        Request request = this.notifier.dialog.createRequest(Request.NOTIFY);
        SubscriptionStateHeader subscriptionState =
            headerFactory.createSubscriptionStateHeader(SubscriptionStateHeader.TERMINATED);
        request.addHeader(eventHeader);
        request.addHeader(subscriptionState);
        ClientTransaction ct = udpProvider.getNewClientTransaction(request);
        this.notifier.dialog.sendRequest(ct);
      } catch (Exception ex) {
        ex.printStackTrace();
        System.exit(0);
      }
    }
示例#3
0
  /** Re Initialize the stack instance. */
  protected void reInit() {
    super.reInit();
    clientTransactions = Collections.synchronizedList(new ArrayList<SIPClientTransaction>());
    serverTransactions = Collections.synchronizedList(new ArrayList<SIPServerTransaction>());
    pendingTransactions = new HashSet<SIPServerTransaction>();
    pendingRecords = Collections.synchronizedList(new ArrayList<PendingRecord>());
    clientTransactionTable = new Hashtable<String, SIPTransaction>();
    serverTransactionTable = new Hashtable<String, SIPTransaction>();
    // Dialog dable.
    this.dialogTable = new Hashtable<String, SIPDialog>();

    this.timer = new Timer();
    pendingRecordScanner = new Thread(new PendingRecordScanner(this));
    pendingRecordScanner.setDaemon(true);
    pendingRecordScanner.setName("PendingRecordScanner");
    pendingRecordScanner.start();
  }
示例#4
0
  /** Process the invite request. */
  public void processInvite(RequestEvent requestEvent, ServerTransaction serverTransaction) {
    SipProvider sipProvider = (SipProvider) requestEvent.getSource();
    Request request = requestEvent.getRequest();
    try {
      logger.info("shootme: got an Invite sending Trying");
      // logger.info("shootme: " + request);

      ServerTransaction st = requestEvent.getServerTransaction();

      if (st == null) {
        logger.info("null server tx -- getting a new one");
        st = sipProvider.getNewServerTransaction(request);
      }

      logger.info("getNewServerTransaction : " + st);

      String txId = ((ViaHeader) request.getHeader(ViaHeader.NAME)).getBranch();
      this.serverTxTable.put(txId, st);

      // Create the 100 Trying response.
      Response response = protocolObjects.messageFactory.createResponse(Response.TRYING, request);
      ListeningPoint lp = sipProvider.getListeningPoint(protocolObjects.transport);
      int myPort = lp.getPort();

      Address address =
          protocolObjects.addressFactory.createAddress(
              "Shootme <sip:" + myAddress + ":" + myPort + ">");

      // Add a random sleep to stagger the two OK's for the benifit of implementations
      // that may not be too good about handling re-entrancy.
      int timeToSleep = (int) (Math.random() * 1000);

      Thread.sleep(timeToSleep);

      st.sendResponse(response);

      Response ringingResponse =
          protocolObjects.messageFactory.createResponse(Response.RINGING, request);
      ContactHeader contactHeader = protocolObjects.headerFactory.createContactHeader(address);
      response.addHeader(contactHeader);
      ToHeader toHeader = (ToHeader) ringingResponse.getHeader(ToHeader.NAME);
      String toTag =
          actAsNonRFC3261UAS ? null : new Integer((int) (Math.random() * 10000)).toString();
      if (!actAsNonRFC3261UAS) toHeader.setTag(toTag); // Application is supposed to set.
      ringingResponse.addHeader(contactHeader);
      st.sendResponse(ringingResponse);
      Dialog dialog = st.getDialog();
      dialog.setApplicationData(st);

      this.inviteSeen = true;

      new Timer().schedule(new MyTimerTask(requestEvent, st /*,toTag*/), 1000);
    } catch (Exception ex) {
      ex.printStackTrace();
      System.exit(0);
    }
  }
示例#5
0
 private void shutDown() {
   try {
     try {
       Thread.sleep(2000);
     } catch (InterruptedException e) {
     }
     System.out.println("nulling reference");
     sipStack.deleteListeningPoint(tcpListeningPoint);
     sipStack.deleteListeningPoint(udpListeningPoint);
     // This will close down the stack and exit all threads
     tcpProvider.removeSipListener(this);
     udpProvider.removeSipListener(this);
     while (true) {
       try {
         sipStack.deleteSipProvider(udpProvider);
         sipStack.deleteSipProvider(tcpProvider);
         break;
       } catch (ObjectInUseException ex) {
         try {
           Thread.sleep(2000);
         } catch (InterruptedException e) {
           continue;
         }
       }
     }
     sipStack = null;
     tcpProvider = null;
     udpProvider = null;
     this.contactHeader = null;
     addressFactory = null;
     headerFactory = null;
     messageFactory = null;
     this.udpListeningPoint = null;
     this.tcpListeningPoint = null;
     this.reInviteCount = 0;
     System.gc();
     // Redo this from the start.
     if (counter < 10) this.init();
     else counter++;
   } catch (Exception ex) {
     ex.printStackTrace();
   }
 }
示例#6
0
  public void processResponse(ResponseEvent responseReceivedEvent) {
    System.out.println("Got a response");
    Response response = (Response) responseReceivedEvent.getResponse();
    Transaction tid = responseReceivedEvent.getClientTransaction();

    System.out.println(
        "Response received with client transaction id " + tid + ":\n" + response.getStatusCode());
    if (tid == null) {
      System.out.println("Stray response -- dropping ");
      return;
    }
    System.out.println("transaction state is " + tid.getState());
    System.out.println("Dialog = " + tid.getDialog());
    System.out.println("Dialog State is " + tid.getDialog().getState());

    try {
      if (response.getStatusCode() == Response.OK
          && ((CSeqHeader) response.getHeader(CSeqHeader.NAME))
              .getMethod()
              .equals(Request.INVITE)) {
        // Request cancel = inviteTid.createCancel();
        // ClientTransaction ct =
        //  sipProvider.getNewClientTransaction(cancel);
        // ct.sendRequest();
        Dialog dialog = tid.getDialog();
        CSeqHeader cseq = (CSeqHeader) response.getHeader(CSeqHeader.NAME);
        Request ackRequest = dialog.createAck(cseq.getSeqNumber());
        System.out.println("Sending ACK");
        dialog.sendAck(ackRequest);

        // Send a Re INVITE but this time force it
        // to use UDP as the transport. Else, it will
        // Use whatever transport was used to create
        // the dialog.
        if (reInviteCount == 0) {
          Request inviteRequest = dialog.createRequest(Request.INVITE);
          ((SipURI) inviteRequest.getRequestURI()).removeParameter("transport");
          ((ViaHeader) inviteRequest.getHeader(ViaHeader.NAME)).setTransport("udp");
          inviteRequest.addHeader(contactHeader);
          try {
            Thread.sleep(100);
          } catch (Exception ex) {
          }
          ClientTransaction ct = udpProvider.getNewClientTransaction(inviteRequest);
          dialog.sendRequest(ct);
          reInviteCount++;
        }
      }
    } catch (Exception ex) {
      ex.printStackTrace();
      System.exit(0);
    }
  }