Example #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("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);
    }
  }
Example #2
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);
    }
  }