Beispiel #1
0
  /** Process the ACK request. Send the bye and complete the call flow. */
  public void processAck(RequestEvent requestEvent, ServerTransaction serverTransaction) {
    logger.info("shootme: got an ACK! ");
    logger.info("Dialog = " + requestEvent.getDialog());
    logger.info("Dialog State = " + requestEvent.getDialog().getState());

    this.ackSeen = true;
  }
 public synchronized void processEvent(EventObject event) {
   if (event instanceof RequestEvent) {
     RequestEvent requestEvent = (RequestEvent) event;
     if (requestEvent.getDialog() == _dialog || _dialog == null) {
       _receivedRequests.add(requestEvent);
       notifyAll();
     }
   }
 }
Beispiel #3
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);
    }
  }
  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();
      }
    }
  }
Beispiel #5
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);
    }
  }
Beispiel #6
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);
    }
  }
  /**
   * 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;
    }
  }
  /**
   * Starts the process of handling a new sip subscription
   *
   * @param event
   * @param aci
   * @param eventPackage
   * @param eventId
   * @param expires
   * @param entityManager
   * @param childSbb
   */
  public void newSipSubscription(
      RequestEvent event,
      ActivityContextInterface aci,
      String eventPackage,
      String eventId,
      int expires,
      SubscriptionControlDataSource dataSource,
      ImplementedSubscriptionControlSbbLocalObject childSbb) {

    // get subscription data from request
    Address fromAddress = ((FromHeader) event.getRequest().getHeader(FromHeader.NAME)).getAddress();
    String subscriber = fromAddress.getURI().toString();
    String subscriberDisplayName = fromAddress.getDisplayName();

    Notifier notifier = new Notifier(event.getRequest().getRequestURI().toString());

    // get content
    String content = null;
    String contentType = null;
    String contentSubtype = null;
    ContentTypeHeader contentTypeHeader =
        (ContentTypeHeader) event.getRequest().getHeader(ContentTypeHeader.NAME);
    if (contentTypeHeader != null) {
      contentType = contentTypeHeader.getContentType();
      contentSubtype = contentTypeHeader.getContentSubType();
      content = new String(event.getRequest().getRawContent());
    }

    // create dialog if does not exists
    Dialog dialog = event.getDialog();
    if (dialog == null) {
      try {
        dialog =
            sipSubscriptionHandler.sbb.getSipProvider().getNewDialog(event.getServerTransaction());
      } catch (Exception e) {
        tracer.severe("Can't create dialog", e);
        // cleanup
        try {
          Response response =
              sipSubscriptionHandler
                  .sbb
                  .getMessageFactory()
                  .createResponse(Response.SERVER_INTERNAL_ERROR, event.getRequest());
          response = sipSubscriptionHandler.addContactHeader(response);
          event.getServerTransaction().sendResponse(response);
        } catch (Exception f) {
          tracer.severe("Can't send RESPONSE", f);
        }
        return;
      }
    }

    // if dialog id is null (cause it's a new dialog and no response was sent yet) then build it
    // manually
    String dialogId =
        dialog.getDialogId() != null
            ? dialog.getDialogId()
            : ((SIPRequest) event.getRequest()).getDialogId(true, dialog.getLocalTag());
    SubscriptionKey key = new SubscriptionKey(dialogId, eventPackage, eventId);

    if (sipSubscriptionHandler.sbb.getConfiguration().getEventListSupportOn()) {
      // we need to find out if the notifier is a resource list
      int rlsResponse =
          sipSubscriptionHandler
              .sbb
              .getEventListSubscriptionHandler()
              .validateSubscribeRequest(subscriber, notifier, eventPackage, event);

      switch (rlsResponse) {
        case Response.NOT_FOUND:
          // the notifier is not a resource list, proceed with normal authorization means
          authorizeNewSipSubscription(
              event,
              aci,
              subscriber,
              subscriberDisplayName,
              notifier,
              key,
              expires,
              content,
              contentType,
              contentSubtype,
              false,
              dataSource,
              childSbb);
          break;
        case Response.OK:
          // the notifier is a resource list
          authorizeNewSipSubscription(
              event,
              aci,
              subscriber,
              subscriberDisplayName,
              notifier,
              key,
              expires,
              content,
              contentType,
              contentSubtype,
              true,
              dataSource,
              childSbb);
          break;
        default:
          // the rls request validation returned an error
          try {
            Response response =
                sipSubscriptionHandler
                    .sbb
                    .getMessageFactory()
                    .createResponse(rlsResponse, event.getRequest());
            response = sipSubscriptionHandler.addContactHeader(response);
            response.addHeader(
                sipSubscriptionHandler.sbb.getHeaderFactory().createRequireHeader("eventlist"));
            event.getServerTransaction().sendResponse(response);
          } catch (Exception f) {
            tracer.severe("Can't send RESPONSE", f);
          }
          return;
      }
    } else {
      authorizeNewSipSubscription(
          event,
          aci,
          subscriber,
          subscriberDisplayName,
          notifier,
          key,
          expires,
          content,
          contentType,
          contentSubtype,
          false,
          dataSource,
          childSbb);
    }
  }