Пример #1
0
  /** Process the invite request. */
  public void processInvite(RequestEvent requestEvent, ServerTransaction serverTransaction) {
    SipProvider sipProvider = (SipProvider) requestEvent.getSource();
    Request request = requestEvent.getRequest();
    try {
      System.out.println("shootme: got an Invite sending Trying");
      // System.out.println("shootme: " + request);
      Response response = messageFactory.createResponse(Response.TRYING, request);
      ServerTransaction st = requestEvent.getServerTransaction();

      if (st == null) {
        st = sipProvider.getNewServerTransaction(request);
      }
      dialog = st.getDialog();

      st.sendResponse(response);

      this.okResponse = messageFactory.createResponse(Response.BUSY_HERE, request);

      ToHeader toHeader = (ToHeader) okResponse.getHeader(ToHeader.NAME);
      toHeader.setTag("4321"); // Application is supposed to set.

      this.inviteTid = st;
      // Defer sending the OK to simulate the phone ringing.
      this.inviteRequest = request;

      new Timer().schedule(new MyTimerTask(this), 100);
    } catch (Exception ex) {
      ex.printStackTrace();
      System.exit(0);
    }
  }
Пример #2
0
  /** Process the ACK request. Send the bye and complete the call flow. */
  public void processAck(RequestEvent requestEvent, ServerTransaction serverTransaction) {
    SipProvider sipProvider = (SipProvider) requestEvent.getSource();
    try {
      // System.out.println("*** shootme: got an ACK "
      // + requestEvent.getRequest());
      if (serverTransaction == null) {
        System.out.println("null server transaction -- ignoring the ACK!");
        return;
      }
      Dialog dialog = serverTransaction.getDialog();
      this.createdCount++;
      System.out.println(
          "Dialog Created = "
              + dialog.getDialogId()
              + " createdCount "
              + this.createdCount
              + " Dialog State = "
              + dialog.getState());

      if (this.dialogIds.contains(dialog.getDialogId())) {
        System.out.println("OOPS ! I already saw " + dialog.getDialogId());
      } else {
        this.dialogIds.add(dialog.getDialogId());
      }

      Request byeRequest = dialog.createRequest(Request.BYE);
      ClientTransaction tr = sipProvider.getNewClientTransaction(byeRequest);
      // System.out.println("shootme: got an ACK -- sending bye! ");
      dialog.sendRequest(tr);

    } catch (Exception ex) {
      ex.printStackTrace();
      System.exit(0);
    }
  }
Пример #3
0
  /** Process the invite request. */
  public void processInvite(RequestEvent requestEvent, ServerTransaction serverTransaction) {
    try {
      // System.out.println("ProcessInvite");
      Request request = requestEvent.getRequest();
      SipProvider sipProvider = (SipProvider) requestEvent.getSource();
      // Note you need to create the Server Transaction
      // before the listener returns but you can delay sending the response

      ServerTransaction st = sipProvider.getNewServerTransaction(request);
      if (transactionIDs.containsKey(st.getBranchId())) {
        System.out.println(
            "OOOPS -- seen this guy before!! This must be a late guy "
                + st.getBranchId()
                + " st = "
                + transactionIDs.get(st.getBranchId()));
        return;
      } else {
        transactionIDs.put(st.getBranchId(), st);
      }

      TTask ttask = new TTask(requestEvent, st);
      int ttime;
      if ((numInvite % 4) == 0) ttime = 5000;
      else if ((numInvite % 4) == 1) ttime = 1000;
      else ttime = 300;
      numInvite++;
      new Timer().schedule(ttask, ttime);
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
Пример #4
0
  /** Process the invite request. */
  public void processInvite(RequestEvent requestEvent, ServerTransaction serverTransaction) {
    SipProvider sipProvider = (SipProvider) requestEvent.getSource();
    Request request = requestEvent.getRequest();
    try {
      System.out.println("b2bua: got an Invite sending Trying");
      ServerTransaction st = requestEvent.getServerTransaction();
      if (st == null) {
        st = sipProvider.getNewServerTransaction(request);
      }
      Dialog dialog = st.getDialog();

      ToHeader to = (ToHeader) request.getHeader(ToHeader.NAME);
      SipURI toUri = (SipURI) to.getAddress().getURI();

      SipURI target = registrar.get(toUri.getUser());

      if (target == null) {
        System.out.println("User " + toUri + " is not registered.");
        throw new RuntimeException("User not registered " + toUri);
      } else {
        ClientTransaction otherLeg = call(target);
        otherLeg.setApplicationData(st);
        st.setApplicationData(otherLeg);
        dialog.setApplicationData(otherLeg.getDialog());
        otherLeg.getDialog().setApplicationData(dialog);
      }

    } catch (Exception ex) {
      ex.printStackTrace();
      System.exit(0);
    }
  }
Пример #5
0
  public void processCancel(RequestEvent requestEvent, ServerTransaction serverTransactionId) {
    Request request = requestEvent.getRequest();
    SipProvider sipProvider = (SipProvider) requestEvent.getSource();
    try {
      logger.info("shootme:  got a cancel. ");
      // Because this is not an In-dialog request, you will get a null server Tx id here.
      if (serverTransactionId == null) {
        serverTransactionId = sipProvider.getNewServerTransaction(request);
      }
      Response response = protocolObjects.messageFactory.createResponse(200, request);
      serverTransactionId.sendResponse(response);

      String serverTxId = ((ViaHeader) response.getHeader(ViaHeader.NAME)).getBranch();
      ServerTransaction serverTx = (ServerTransaction) this.serverTxTable.get(serverTxId);
      if (serverTx != null
          && (serverTx.getState().equals(TransactionState.TRYING)
              || serverTx.getState().equals(TransactionState.PROCEEDING))) {
        Request originalRequest = serverTx.getRequest();
        Response resp =
            protocolObjects.messageFactory.createResponse(
                Response.REQUEST_TERMINATED, originalRequest);
        serverTx.sendResponse(resp);
      }

    } catch (Exception ex) {
      ex.printStackTrace();
      System.exit(0);
    }
  }
Пример #6
0
  private void sendInviteOK(RequestEvent requestEvent, ServerTransaction inviteTid) {
    try {
      logger.info("sendInviteOK: " + inviteTid);
      if (inviteTid.getState() != TransactionState.COMPLETED) {
        logger.info("shootme: Dialog state before OK: " + inviteTid.getDialog().getState());

        SipProvider sipProvider = (SipProvider) requestEvent.getSource();
        Request request = requestEvent.getRequest();
        Response okResponse = protocolObjects.messageFactory.createResponse(Response.OK, request);
        ListeningPoint lp = sipProvider.getListeningPoint(protocolObjects.transport);
        int myPort = lp.getPort();

        Address address =
            protocolObjects.addressFactory.createAddress(
                "Shootme <sip:" + myAddress + ":" + myPort + ">");
        ContactHeader contactHeader = protocolObjects.headerFactory.createContactHeader(address);
        okResponse.addHeader(contactHeader);
        inviteTid.sendResponse(okResponse);
        logger.info("shootme: Dialog state after OK: " + inviteTid.getDialog().getState());
        TestHarness.assertEquals(DialogState.CONFIRMED, inviteTid.getDialog().getState());
      } else {
        logger.info("semdInviteOK: inviteTid = " + inviteTid + " state = " + inviteTid.getState());
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
Пример #7
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);
    }
  }
Пример #8
0
  /**
   * Safely returns the transaction from the event if already exists. If not a new transaction is
   * created.
   *
   * @param event the request event
   * @return the server transaction
   * @throws javax.sip.TransactionAlreadyExistsException if transaction exists
   * @throws javax.sip.TransactionUnavailableException if unavailable
   */
  public static ServerTransaction getOrCreateServerTransaction(RequestEvent event)
      throws TransactionAlreadyExistsException, TransactionUnavailableException {
    ServerTransaction serverTransaction = event.getServerTransaction();

    if (serverTransaction == null) {
      SipProvider jainSipProvider = (SipProvider) event.getSource();

      serverTransaction = jainSipProvider.getNewServerTransaction(event.getRequest());
    }
    return serverTransaction;
  }
Пример #9
0
  /** Process the bye request. */
  public void processBye(RequestEvent requestEvent, ServerTransaction serverTransactionId) {
    SipProvider sipProvider = (SipProvider) requestEvent.getSource();
    Request request = requestEvent.getRequest();
    try {
      System.out.println("shootme:  got a bye sending OK.");
      Response response = messageFactory.createResponse(200, request);
      serverTransactionId.sendResponse(response);
      System.out.println("Dialog State is " + serverTransactionId.getDialog().getState());

    } catch (Exception ex) {
      ex.printStackTrace();
      System.exit(0);
    }
  }
Пример #10
0
  public void processCancel(RequestEvent requestEvent, ServerTransaction serverTransactionId) {
    SipProvider sipProvider = (SipProvider) requestEvent.getSource();
    Request request = requestEvent.getRequest();
    try {
      System.out.println("shootme:  got a cancel.");
      if (serverTransactionId == null) {
        System.out.println("shootme:  null tid.");
        return;
      }
      Response response = messageFactory.createResponse(200, request);
      serverTransactionId.sendResponse(response);
      if (dialog.getState() != DialogState.CONFIRMED) {
        response = messageFactory.createResponse(Response.REQUEST_TERMINATED, inviteRequest);
        inviteTid.sendResponse(response);
      }

    } catch (Exception ex) {
      ex.printStackTrace();
      System.exit(0);
    }
  }
Пример #11
0
  /** Process the any in dialog request - MESSAGE, BYE, INFO, UPDATE. */
  public void processInDialogRequest(
      RequestEvent requestEvent, ServerTransaction serverTransactionId) {
    SipProvider sipProvider = (SipProvider) requestEvent.getSource();
    Request request = requestEvent.getRequest();
    Dialog dialog = requestEvent.getDialog();
    System.out.println("local party = " + dialog.getLocalParty());
    try {
      System.out.println("b2bua:  got a bye sending OK.");
      Response response = messageFactory.createResponse(200, request);
      serverTransactionId.sendResponse(response);
      System.out.println("Dialog State is " + serverTransactionId.getDialog().getState());

      Dialog otherLeg = (Dialog) dialog.getApplicationData();
      Request otherBye = otherLeg.createRequest(request.getMethod());
      ClientTransaction clientTransaction = sipProvider.getNewClientTransaction(otherBye);
      clientTransaction.setApplicationData(serverTransactionId);
      serverTransactionId.setApplicationData(clientTransaction);
      otherLeg.sendRequest(clientTransaction);

    } catch (Exception ex) {
      ex.printStackTrace();
      System.exit(0);
    }
  }
Пример #12
0
  /**
   * Dispatches the event received from a JAIN-SIP <tt>SipProvider</tt> to one of our "candidate
   * recipient" listeners.
   *
   * @param event the event received for a <tt>SipProvider</tt>.
   */
  public void processRequest(RequestEvent event) {
    try {
      Request request = event.getRequest();
      if (logger.isTraceEnabled()) logger.trace("received request: " + request.getMethod());

      /*
       * Create the transaction if it doesn't exist yet. If it is a
       * dialog-creating request, the dialog will also be automatically
       * created by the stack.
       */
      if (event.getServerTransaction() == null) {
        try {
          // apply some hacks if needed on incoming request
          // to be compliant with some servers/clients
          // if needed stop further processing.
          if (applyNonConformanceHacks(event)) return;

          SipProvider source = (SipProvider) event.getSource();
          ServerTransaction transaction = source.getNewServerTransaction(request);

          /*
           * Update the event, otherwise getServerTransaction() and
           * getDialog() will still return their previous value.
           */
          event = new RequestEvent(source, transaction, transaction.getDialog(), request);
        } catch (SipException ex) {
          logger.error(
              "couldn't create transaction, please report "
                  + "this to [email protected]",
              ex);
        }
      }

      ProtocolProviderServiceSipImpl service = getServiceData(event.getServerTransaction());
      if (service != null) {
        service.processRequest(event);
      } else {
        service = findTargetFor(request);
        if (service == null) {
          logger.error("couldn't find a ProtocolProviderServiceSipImpl " + "to dispatch to");
          if (event.getServerTransaction() != null) event.getServerTransaction().terminate();
        } else {

          /*
           * Mark the dialog for the dispatching of later in-dialog
           * requests. If there is no dialog, we need to mark the
           * request to dispatch a possible timeout when sending the
           * response.
           */
          Object container = event.getDialog();
          if (container == null) container = request;
          SipApplicationData.setApplicationData(container, SipApplicationData.KEY_SERVICE, service);

          service.processRequest(event);
        }
      }
    } catch (Throwable exc) {

      /*
       * Any exception thrown within our code should be caught here so
       * that we could log it rather than interrupt stack activity with
       * it.
       */
      this.logApplicationException(DialogTerminatedEvent.class, exc);

      // Unfortunately, death can hardly be ignored.
      if (exc instanceof ThreadDeath) throw (ThreadDeath) exc;
    }
  }