Ejemplo n.º 1
0
  /**
   * Sends a request from the TI, generates a response at the RI side, sends it back and checks
   * whether it arrives at the TI.
   */
  public void testReceiveResponse() {
    try {
      // 1. Create and send the original request

      Request invite = createTiInviteRequest(null, null, null);
      RequestEvent receivedRequestEvent = null;
      try {
        // Send using TI and collect using RI
        eventCollector.collectRequestEvent(riSipProvider);
        tiSipProvider.sendRequest(invite);
        waitForMessage();
        receivedRequestEvent = eventCollector.extractCollectedRequestEvent();
        if (receivedRequestEvent == null || receivedRequestEvent.getRequest() == null)
          throw new TckInternalError("The sent request was not received by the RI!");
      } catch (TooManyListenersException ex) {
        throw new TckInternalError(
            "A TooManyListenersException was thrown while trying to add "
                + "a SipListener to an RI SipProvider.",
            ex);
      } catch (SipException ex) {
        throw new TiUnexpectedError("The TI failed to send the request!", ex);
      }
      Request receivedRequest = receivedRequestEvent.getRequest();
      // 2. Create and send the response
      Response ok = null;
      try {
        ok = riMessageFactory.createResponse(Response.OK, receivedRequest);
        addStatus(receivedRequest, ok);
      } catch (ParseException ex) {
        throw new TckInternalError("Failed to create an OK response!", ex);
      }
      // Send the response using the RI and collect using TI
      try {
        eventCollector.collectResponseEvent(tiSipProvider);
      } catch (TooManyListenersException ex) {
        throw new TiUnexpectedError("Error while trying to add riSipProvider");
      }
      try {
        riSipProvider.sendResponse(ok);
      } catch (SipException ex) {
        throw new TckInternalError("Could not send back the response", ex);
      }
      waitForMessage();
      ResponseEvent responseEvent = eventCollector.extractCollectedResponseEvent();
      // 3. Now ... do we like what we got?
      assertNotNull("The TI failed to receive the response!", responseEvent);
      assertNotNull("The TI failed to receive the response!", responseEvent.getResponse());
      assertNull(
          "The TI had implicitly created a client transaction! "
              + "Transactions should only be created explicitly using "
              + "the SipProvider.getNewXxxTransaction() method.",
          responseEvent.getClientTransaction());
    } catch (Throwable exc) {
      exc.printStackTrace();
      fail(exc.getClass().getName() + ": " + exc.getMessage());
    }
    assertTrue(new Exception().getStackTrace()[0].toString(), true);
  }
Ejemplo n.º 2
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);
    }
  }
Ejemplo n.º 3
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("cutme: got an Invite sending Trying");
      // System.out.println("cutme: " + request);
      Response response = messageFactory.createResponse(Response.RINGING, request);
      String toTag = Integer.toString((int) (Math.random() * 10000000));
      ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME);
      toHeader.setTag(toTag); // Application is supposed to set.

      ServerTransaction st = requestEvent.getServerTransaction();

      if (st == null) {
        st = sipProvider.getNewServerTransaction(request);
      }
      inviteTid = st;
      inviteRequest = request;
      dialog = st.getDialog();
      //			inviteRequest = request;
      if (timeToWaitBeforeAnswer > 0) {
        Thread.sleep(timeToWaitBeforeAnswer);
      }

      st.sendResponse(response);
      // If we dont send final response this will receive cancel.
    } catch (Exception ex) {
      ex.printStackTrace();
      System.exit(0);
    }
  }
Ejemplo n.º 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("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);
    }
  }
Ejemplo n.º 5
0
    public void run() {
      Request request = requestEvent.getRequest();
      try {
        // System.out.println("shootme: got an Invite sending OK");
        Response response = messageFactory.createResponse(180, request);
        ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME);
        Address address =
            addressFactory.createAddress("Shootme <sip:" + myAddress + ":" + myPort + ">");
        ContactHeader contactHeader = headerFactory.createContactHeader(address);
        response.addHeader(contactHeader);

        // System.out.println("got a server tranasaction " + st);
        Dialog dialog = st.getDialog();
        /*
         * if (dialog != null) { System.out.println("Dialog " + dialog);
         * System.out.println("Dialog state " + dialog.getState()); }
         */
        st.sendResponse(response); // send 180(RING)
        response = messageFactory.createResponse(200, request);
        toHeader = (ToHeader) response.getHeader(ToHeader.NAME);
        String toTag = new Integer((int) (Math.random() * 1000)).toString();
        toHeader.setTag(toTag); // Application is supposed to set.
        response.addHeader(contactHeader);

        st.sendResponse(response); // send 200(OK)

      } catch (Exception ex) {
        ex.printStackTrace();
        System.exit(0);
      }
    }
Ejemplo n.º 6
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);
    }
  }
Ejemplo n.º 7
0
 /** Sends a single invite request and checks whether it arrives normally at the other end. */
 public void testSendRequest() {
   try {
     // create an empty invite request.
     Request invite = createTiInviteRequest(null, null, null);
     Request receivedRequest = null;
     try {
       // Send using TI and collect using RI
       eventCollector.collectRequestEvent(riSipProvider);
       waitForMessage();
       tiSipProvider.sendRequest(invite);
       waitForMessage();
       RequestEvent receivedRequestEvent = eventCollector.extractCollectedRequestEvent();
       assertNotNull("The sent request was not received at the other end!", receivedRequestEvent);
       assertNotNull(
           "The sent request was not received at the other end!",
           receivedRequestEvent.getRequest());
     } catch (TooManyListenersException ex) {
       throw new TckInternalError(
           "The following exception was thrown while trying to add "
               + "a SipListener to an RI SipProvider",
           ex);
     } catch (SipException ex) {
       ex.printStackTrace();
       fail("A SipException exception was thrown while " + "trying to send a request.");
     }
   } catch (Throwable exc) {
     exc.printStackTrace();
     fail(exc.getClass().getName() + ": " + exc.getMessage());
   }
   assertTrue(new Exception().getStackTrace()[0].toString(), true);
 }
Ejemplo n.º 8
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();
    }
  }
Ejemplo n.º 9
0
  public void processBye(RequestEvent requestEvent, ServerTransaction serverTransaction) {
    try {
      logger.debug("DEBUG: IMByeProcessing, Processing BYE in progress...");

      Request request = requestEvent.getRequest();

      MessageFactory messageFactory = imUA.getMessageFactory();
      InstantMessagingGUI instantMessagingGUI = imUA.getInstantMessagingGUI();
      ListenerInstantMessaging listenerInstantMessaging =
          instantMessagingGUI.getListenerInstantMessaging();
      ChatSessionManager chatSessionManager = listenerInstantMessaging.getChatSessionManager();
      String buddy = IMUtilities.getKey(request, "From");
      if (chatSessionManager.hasAlreadyChatSession(buddy)) {
        chatSessionManager.removeChatSession(buddy);
        // chatSession.setExitedSession(true,"Your contact has exited
        // the session");
      } else {
        logger.debug("DEBUG: IMByeProcessing, processBye(), no active chatSession");
      }

      // Send an OK
      Response response = messageFactory.createResponse(Response.OK, request);
      serverTransaction.sendResponse(response);
      logger.debug("DEBUG: IMByeProcessing, processBye(), OK replied to the BYE");

      logger.debug("DEBUG: IMByeProcessing, Processing BYE completed...");
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
Ejemplo n.º 10
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.RINGING, request);
      ServerTransaction st = requestEvent.getServerTransaction();

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

      st.sendResponse(response);

      this.okResponse = messageFactory.createResponse(Response.OK, request);
      Address address =
          addressFactory.createAddress("Shootme <sip:" + myAddress + ":" + myPort + ">");
      ContactHeader contactHeader = headerFactory.createContactHeader(address);
      response.addHeader(contactHeader);
      ToHeader toHeader = (ToHeader) okResponse.getHeader(ToHeader.NAME);
      toHeader.setTag("4321"); // Application is supposed to set.
      okResponse.addHeader(contactHeader);
      this.inviteTid = st;
      // Defer sending the OK to simulate the phone ringing.
      // Answered in 1 second ( this guy is fast at taking calls)
      this.inviteRequest = request;

      new Timer().schedule(new MyTimerTask(this), 1000);
    } catch (Exception ex) {
      ex.printStackTrace();
      System.exit(0);
    }
  }
Ejemplo n.º 11
0
  /** Tests sending a request from a ClientTransaction. */
  public void testSendRequest() {
    try {
      Request invite = createTiInviteRequest(null, null, null);
      RequestEvent receivedRequestEvent = null;
      ClientTransaction tran = null;
      try {
        tran = tiSipProvider.getNewClientTransaction(invite);
        eventCollector.collectRequestEvent(riSipProvider);
        tran.sendRequest();
        waitForMessage();
        receivedRequestEvent = eventCollector.extractCollectedRequestEvent();
        assertNotNull("The sent request was not received by the RI!", receivedRequestEvent);
        assertNotNull(
            "The sent request was not received by the RI!", receivedRequestEvent.getRequest());
      } catch (TransactionUnavailableException exc) {
        throw new TiUnexpectedError(
            "A TransactionUnavailableException was thrown while trying to "
                + "create a new client transaction",
            exc);
      } catch (SipException exc) {
        exc.printStackTrace();
        fail("The SipException was thrown while trying to send the request.");
      } catch (TooManyListenersException exc) {
        throw new TckInternalError(
            "A  TooManyListenersException was thrown while trying "
                + "to add a SipListener to an RI SipProvider",
            exc);
      }
    } catch (Throwable exc) {
      exc.printStackTrace();
      fail(exc.getClass().getName() + ": " + exc.getMessage());
    }

    assertTrue(new Exception().getStackTrace()[0].toString(), true);
  }
Ejemplo n.º 12
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();
    }
  }
Ejemplo n.º 13
0
  /**
   * Place to put some hacks if needed on incoming requests.
   *
   * @param event the incoming request event.
   * @return status <code>true</code> if we don't need to process this message, just discard it and
   *     <code>false</code> otherwise.
   */
  private boolean applyNonConformanceHacks(RequestEvent event) {
    Request request = event.getRequest();
    try {
      /*
       * Max-Forwards is required, yet there are UAs which do not
       * place it. SipProvider#getNewServerTransaction(Request)
       * will throw an exception in the case of a missing
       * Max-Forwards header and this method will eventually just
       * log it thus ignoring the whole event.
       */
      if (request.getHeader(MaxForwardsHeader.NAME) == null) {
        // it appears that some buggy providers do send requests
        // with no Max-Forwards headers, as we are at application level
        // and we know there will be no endless loops
        // there is no problem of adding headers and process normally
        // this messages
        MaxForwardsHeader maxForwards =
            SipFactory.getInstance().createHeaderFactory().createMaxForwardsHeader(70);
        request.setHeader(maxForwards);
      }
    } catch (Throwable ex) {
      logger.warn("Cannot apply incoming request modification!", ex);
    }

    try {
      // using asterisk voice mail initial notify for messages
      // is ok, but on the fly received messages their notify comes
      // without subscription-state, so we add it in order to be able to
      // process message.
      if (request.getMethod().equals(Request.NOTIFY)
          && request.getHeader(EventHeader.NAME) != null
          && ((EventHeader) request.getHeader(EventHeader.NAME))
              .getEventType()
              .equals(OperationSetMessageWaitingSipImpl.EVENT_PACKAGE)
          && request.getHeader(SubscriptionStateHeader.NAME) == null) {
        request.addHeader(
            new HeaderFactoryImpl().createSubscriptionStateHeader(SubscriptionStateHeader.ACTIVE));
      }
    } catch (Throwable ex) {
      logger.warn("Cannot apply incoming request modification!", ex);
    }

    try {
      // receiving notify message without subscription state
      // used for keep-alive pings, they have done their job
      // and are no more need. Skip processing them to avoid
      // filling logs with unneeded exceptions.
      if (request.getMethod().equals(Request.NOTIFY)
          && request.getHeader(SubscriptionStateHeader.NAME) == null) {
        return true;
      }
    } catch (Throwable ex) {
      logger.warn("Cannot apply incoming request modification!", ex);
    }

    return false;
  }
Ejemplo n.º 14
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);
    }
  }
Ejemplo n.º 15
0
 @Before
 public void setUp() throws Exception {
   when(requestEvent.getRequest()).thenReturn(request);
   when(request.getHeader(ToHeader.NAME)).thenReturn(toHeader);
   when(toHeader.getAddress()).thenReturn(toAddress);
   when(toAddress.getURI()).thenReturn(toAddressURI);
   when(sipUtils.getCanonicalizedURI(toAddressURI)).thenReturn(toAddressURI);
   when(request.getRequestURI()).thenReturn(requestURI);
   when(sipUtils.getCanonicalizedURI(requestURI)).thenReturn(requestURI);
 }
Ejemplo n.º 16
0
  /**
   * Wait for a request.
   *
   * @param method the method expected.
   * @param strict if <code>true</code>, fails if received a request with the wrong method else,
   *     ignore request with wrong method.
   * @param timeout
   * @return
   */
  public synchronized ServerTransaction waitForRequest(
      String method, boolean strict, long timeout) {

    if (!isLastRequestUncommited()) {
      try {
        wait(timeout);
      } catch (Exception e) {
      }
    }
    RequestEvent event = getLastRequest();
    if (event == null) fail("No event received");
    Request request = event.getRequest();

    if (!isLastRequestUncommited())
      fail("Response has been already sent for last request:\n" + event);

    if (strict && !request.getMethod().equals(method))
      fail("Received " + request.getMethod() + " when expected " + method);

    while (!request.getMethod().equals(method)) {
      try {
        wait(timeout);
      } catch (Exception e) {
      }
      event = getLastRequest();
      request = event.getRequest();
    }

    ServerTransaction tx = event.getServerTransaction();

    if (tx == null) {
      if (Request.ACK.equals(method)) return null;

      try {
        tx = _sipPhone.getParent().getSipProvider().getNewServerTransaction(request);
      } catch (Exception ex) {
        throw new RuntimeException(ex);
      }
    }

    return tx;
  }
Ejemplo n.º 17
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;
  }
  public void processRequest(RequestEvent requestReceivedEvent) {
    Request request = requestReceivedEvent.getRequest();
    ServerTransaction serverTransactionId = requestReceivedEvent.getServerTransaction();
    String viaBranch =
        ((ViaHeader) (request.getHeaders(ViaHeader.NAME).next())).getParameter("branch");
    LOG.debug("Request: {}", request.getMethod());
    LOG.debug("Server Transaction Id: {}", serverTransactionId);
    LOG.debug("Received From Branch: {}", viaBranch);

    if (request.getMethod().equals(Request.NOTIFY)) {
      processNotify(requestReceivedEvent, serverTransactionId);
    }
  }
Ejemplo n.º 19
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);
    }
  }
Ejemplo n.º 20
0
  /**
   * Receives options requests and replies with an OK response containing methods that we support.
   *
   * @param requestEvent the incoming options request.
   * @return <tt>true</tt> if request has been successfully processed, <tt>false</tt> otherwise
   */
  @Override
  public boolean processRequest(RequestEvent requestEvent) {
    Response optionsOK = null;
    try {
      optionsOK =
          provider.getMessageFactory().createResponse(Response.OK, requestEvent.getRequest());

      // add to the allows header all methods that we support
      for (String method : provider.getSupportedMethods()) {
        // don't support REGISTERs
        if (!method.equals(Request.REGISTER))
          optionsOK.addHeader(provider.getHeaderFactory().createAllowHeader(method));
      }

      Iterable<String> knownEventsList = provider.getKnownEventsList();

      synchronized (knownEventsList) {
        for (String event : knownEventsList)
          optionsOK.addHeader(provider.getHeaderFactory().createAllowEventsHeader(event));
      }
    } catch (ParseException ex) {
      // What else could we do apart from logging?
      logger.warn("Failed to create an incoming OPTIONS request", ex);
      return false;
    }

    try {
      SipStackSharing.getOrCreateServerTransaction(requestEvent).sendResponse(optionsOK);
    } catch (TransactionUnavailableException ex) {
      // this means that we received an OPTIONS request outside the scope
      // of a transaction which could mean that someone is simply sending
      // us b****hit to keep a NAT connection alive, so let's not get too
      // excited.
      if (logger.isInfoEnabled())
        logger.info("Failed to respond to an incoming " + "transactionless OPTIONS request");
      if (logger.isTraceEnabled()) logger.trace("Exception was:", ex);
      return false;
    } catch (InvalidArgumentException ex) {
      // What else could we do apart from logging?
      logger.warn("Failed to send an incoming OPTIONS request", ex);
      return false;
    } catch (SipException ex) {
      // What else could we do apart from logging?
      logger.warn("Failed to send an incoming OPTIONS request", ex);
      return false;
    }

    return true;
  }
Ejemplo n.º 21
0
  public void processRequest(RequestEvent requestReceivedEvent) {
    Request request = requestReceivedEvent.getRequest();
    ServerTransaction serverTransactionId = requestReceivedEvent.getServerTransaction();

    System.out.println(
        "\n\nRequest "
            + request.getMethod()
            + " received at "
            + sipStack.getStackName()
            + " with server transaction id "
            + serverTransactionId);

    // We are the UAC so the only request we get is the BYE.
    if (request.getMethod().equals(Request.BYE)) processBye(request, serverTransactionId);
  }
Ejemplo n.º 22
0
 public void processRegister(RequestEvent requestEvent, ServerTransaction serverTransactionId) {
   Request request = requestEvent.getRequest();
   ContactHeader contact = (ContactHeader) request.getHeader(ContactHeader.NAME);
   SipURI contactUri = (SipURI) contact.getAddress().getURI();
   FromHeader from = (FromHeader) request.getHeader(FromHeader.NAME);
   SipURI fromUri = (SipURI) from.getAddress().getURI();
   registrar.put(fromUri.getUser(), contactUri);
   try {
     Response response = this.messageFactory.createResponse(200, request);
     ServerTransaction serverTransaction = sipProvider.getNewServerTransaction(request);
     serverTransaction.sendResponse(response);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Ejemplo n.º 23
0
  /** Process the bye request. */
  public void processBye(RequestEvent requestEvent, ServerTransaction serverTransactionId) {
    Request request = requestEvent.getRequest();
    Dialog dialog = requestEvent.getDialog();
    System.out.println("local party = " + dialog.getLocalParty());
    try {
      System.out.println("cutme:  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);
    }
  }
    public void processRequest(RequestEvent requestEvent) {
      Request request = requestEvent.getRequest();
      ServerTransaction serverTransactionId = requestEvent.getServerTransaction();

      System.out.println(
          "\n\nRequest "
              + request.getMethod()
              + " received at "
              + sipStack.getStackName()
              + " with server transaction id "
              + serverTransactionId);

      if (request.getMethod().equals(Request.INVITE)) {
        processInvite(requestEvent, serverTransactionId);
      }
    }
Ejemplo n.º 25
0
  public void processRequest(RequestEvent requestEvent) {
    Request request = requestEvent.getRequest();
    logger.debug("***** Request: " + request.getMethod() + " received by UA *****");
    logger.debug(request);
    logger.debug("***** Request dispatched *****");

    if (request.getMethod().equals("INVITE")) {
      // logger.debug("INVITE Request received");
      sipIC.processRequest(requestEvent);
    } else if (request.getMethod().equals("MESSAGE")) {
      // logger.debug("MESSAGE Request received");
      sipMC.processRequest(requestEvent);
    } else if (request.getMethod().equals("BYE")) {
      // logger.debug("MESSAGE Request received");
      sipMC.processRequest(requestEvent);
    } else {
      logger.info("Not supported yet");
    }
  }
Ejemplo n.º 26
0
 /**
  * Send a simple invite request from the RI and check whether it is properly delivered by the TI
  * SipProvider
  */
 public void testReceiveRequest() {
   try {
     // create an empty invite request.
     Request invite = createRiInviteRequest(null, null, null);
     RequestEvent receivedRequestEvent = null;
     try {
       // Send using RI and collect using TI
       eventCollector.collectRequestEvent(tiSipProvider);
       riSipProvider.sendRequest(invite);
       waitForMessage();
       receivedRequestEvent = eventCollector.extractCollectedRequestEvent();
       assertNotNull("The sent request was not received at the other end!", receivedRequestEvent);
       assertNotNull(
           "The sent request was not received at the other end!",
           receivedRequestEvent.getRequest());
     } catch (TooManyListenersException ex) {
       // This time adding the listener is (sort of) part of the test
       // so we fail instead of just "throwing on" the exc
       ex.printStackTrace();
       fail(
           "A TooManyListenersException was thrown while trying to add "
               + "a SipListener to a TI SipProvider.");
     } catch (SipException ex) {
       throw new TckInternalError("The RI failed to send the request!", ex);
     }
     // question: should we compare sent and received request?
     // my opinion: finding a discrepancy while comparing requests
     // would most probably mean a parse error and parsing is not what
     // we are currently testing
     // Transaction initiating requests should not have a server transaction
     // associated with them as the application might decide to handle the
     // request statelessly
     assertNull(
         "The Tested Implementation has implicitly created a ServerTransaction "
             + "for the received request. Transactions should only be created "
             + "explicitly using the SipProvider.getNewXxxTransaction() method.",
         receivedRequestEvent.getServerTransaction());
   } catch (Throwable exc) {
     exc.printStackTrace();
     fail(exc.getClass().getName() + ": " + exc.getMessage());
   }
   assertTrue(new Exception().getStackTrace()[0].toString(), true);
 }
Ejemplo n.º 27
0
  /** Process the bye request. */
  public void processBye(RequestEvent requestEvent, ServerTransaction serverTransactionId) {
    Request request = requestEvent.getRequest();
    try {
      logger.info("shootme:  got a bye sending OK.");
      logger.info("shootme:  dialog = " + requestEvent.getDialog());
      logger.info("shootme:  dialogState = " + requestEvent.getDialog().getState());
      Response response = protocolObjects.messageFactory.createResponse(200, request);
      if (serverTransactionId != null) {
        serverTransactionId.sendResponse(response);
      }
      logger.info("shootme:  dialogState = " + requestEvent.getDialog().getState());

      this.byeSeen = true;

    } catch (Exception ex) {
      ex.printStackTrace();
      System.exit(0);
    }
  }
Ejemplo n.º 28
0
  public void processCancel(RequestEvent requestEvent, ServerTransaction serverTransactionId) {
    Request request = requestEvent.getRequest();
    try {
      System.out.println("cutme:  got a cancel.");
      if (serverTransactionId == null) {
        System.out.println("cutme:  null tid.");
        return;
      }
      Response responseOK = messageFactory.createResponse(200, request);
      serverTransactionId.sendResponse(responseOK);
      Response response = messageFactory.createResponse(487, inviteRequest);
      inviteTid.sendResponse(response);

      this.canceled = true;

    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
Ejemplo n.º 29
0
  public void processRequest(RequestEvent requestEvent) {
    Request request = requestEvent.getRequest();
    ServerTransaction serverTransactionId = requestEvent.getServerTransaction();

    System.out.println(
        "\n\nRequest "
            + request.getMethod()
            + " received at "
            + sipStack.getStackName()
            + " with server transaction id "
            + serverTransactionId);

    if (request.getMethod().equals(Request.INVITE)) {
      processInvite(requestEvent, serverTransactionId);
    } else if (request.getMethod().equals(Request.ACK)) {
      processAck(requestEvent, serverTransactionId);
    } else if (request.getMethod().equals(Request.BYE)) {
      processBye(requestEvent, serverTransactionId);
    } else if (request.getMethod().equals(Request.CANCEL)) {
      processCancel(requestEvent, serverTransactionId);
    } else {
      try {
        serverTransactionId.sendResponse(messageFactory.createResponse(202, request));

        // send one back
        SipProvider prov = (SipProvider) requestEvent.getSource();
        Request refer = requestEvent.getDialog().createRequest("REFER");
        requestEvent.getDialog().sendRequest(prov.getNewClientTransaction(refer));

      } catch (SipException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (InvalidArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
  }
Ejemplo n.º 30
0
  /**
   * Processes SIP requests. The only request being handled is BYE.
   *
   * @param requestReceivedEvent the event containing the SIP request
   */
  public synchronized void processRequest(RequestEvent requestReceivedEvent) {

    // obtain request and transaction id
    Request request = requestReceivedEvent.getRequest();

    ServerTransaction st = requestReceivedEvent.getServerTransaction();

    if (request.getMethod().equals(Request.BYE)) {
      handleBye(request, st);
    } else if (request.getMethod().equals(Request.INVITE)) {
      /*
       * This is a re-Invite
       */
      handleReInvite(request, st);
    } else if (request.getMethod().equals(Request.ACK)) {
      Logger.println("Call " + cp + " got ACK");
    } else {
      // no other requests should come in other than BYE, INVITE or ACK
      Logger.writeFile("Call " + cp + " ignoring request " + request.getMethod());
    }
  }