public void testCallForwardingCallerSendBye() throws Exception {
    sender = new TestSipListener(5080, 5070, senderProtocolObjects, false);
    SipProvider senderProvider = sender.createProvider();

    receiver = new TestSipListener(5090, 5070, receiverProtocolObjects, false);
    receiver.setSendReinvite(true);
    SipProvider receiverProvider = receiver.createProvider();

    receiverProvider.addSipListener(receiver);
    senderProvider.addSipListener(sender);

    senderProtocolObjects.start();
    receiverProtocolObjects.start();

    String fromName = "forward-sender";
    String fromSipAddress = "sip-servlets.com";
    SipURI fromAddress =
        senderProtocolObjects.addressFactory.createSipURI(fromName, fromSipAddress);

    String toSipAddress = "sip-servlets.com";
    String toUser = "******";
    SipURI toAddress = senderProtocolObjects.addressFactory.createSipURI(toUser, toSipAddress);

    sender.sendSipRequest("INVITE", fromAddress, toAddress, null, null, false);
    Thread.sleep(TIMEOUT);
    assertTrue(sender.isInviteReceived());
    assertTrue(sender.isAckReceived());
    assertNotNull(sender.getInviteRequest().getHeader("ReInvite"));
    MaxForwardsHeader maxForwardsHeader =
        (MaxForwardsHeader) receiver.getInviteRequest().getHeader(MaxForwardsHeader.NAME);
    assertNotNull(maxForwardsHeader);
    // Non Regression test for http://code.google.com/p/mobicents/issues/detail?id=1490
    // B2buaHelper.createRequest does not decrement Max-forwards
    assertEquals(69, maxForwardsHeader.getMaxForwards());
    sender.sendInDialogSipRequest("BYE", null, null, null, null, null);
    Thread.sleep(TIMEOUT);
    assertTrue(receiver.getByeReceived());
    assertTrue(sender.getOkToByeReceived());
    assertEquals(1, sender.bindings); // http://code.google.com/p/mobicents/issues/detail?id=2100
    maxForwardsHeader =
        (MaxForwardsHeader) receiver.getByeRequestReceived().getHeader(MaxForwardsHeader.NAME);
    assertNotNull(maxForwardsHeader);
    // Non Regression test for http://code.google.com/p/mobicents/issues/detail?id=1490
    // B2buaHelper.createRequest does not decrement Max-forwards
    assertEquals(69, maxForwardsHeader.getMaxForwards());
  }
Пример #2
0
 public boolean equals(Object other) {
   if (this == other) return true;
   if (other instanceof MaxForwardsHeader) {
     final MaxForwardsHeader o = (MaxForwardsHeader) other;
     return this.getMaxForwards() == o.getMaxForwards();
   }
   return false;
 }
  // Issue 2500 http://code.google.com/p/mobicents/issues/detail?id=2500
  // B2buaHelper.createRequest() throws a NullPointerException if the request contains an empty
  // header
  public void testCallForwardingCallerSendReInviteSendBye() throws Exception {
    sender = new TestSipListener(5080, 5070, senderProtocolObjects, false);
    SipProvider senderProvider = sender.createProvider();

    receiver = new TestSipListener(5090, 5070, receiverProtocolObjects, false);
    SipProvider receiverProvider = receiver.createProvider();

    receiverProvider.addSipListener(receiver);
    senderProvider.addSipListener(sender);

    senderProtocolObjects.start();
    receiverProtocolObjects.start();

    String fromName = "forward-sender";
    String fromSipAddress = "sip-servlets.com";
    SipURI fromAddress =
        senderProtocolObjects.addressFactory.createSipURI(fromName, fromSipAddress);

    String toSipAddress = "sip-servlets.com";
    String toUser = "******";
    SipURI toAddress = senderProtocolObjects.addressFactory.createSipURI(toUser, toSipAddress);

    sender.sendSipRequest(
        "INVITE",
        fromAddress,
        toAddress,
        null,
        null,
        false,
        new String[] {AllowHeader.NAME},
        new String[] {"INVITE, CANCEL, BYE, ACK, OPTIONS"},
        true);
    Thread.sleep(TIMEOUT);
    assertTrue(receiver.isInviteReceived());
    assertTrue(receiver.isAckReceived());
    MaxForwardsHeader maxForwardsHeader =
        (MaxForwardsHeader) receiver.getInviteRequest().getHeader(MaxForwardsHeader.NAME);
    assertNotNull(maxForwardsHeader);
    // Non Regression test for http://code.google.com/p/mobicents/issues/detail?id=1490
    // B2buaHelper.createRequest does not decrement Max-forwards
    assertEquals(69, maxForwardsHeader.getMaxForwards());

    ListIterator<AllowHeader> allowHeaderIt =
        receiver.getInviteRequest().getHeaders(AllowHeader.NAME);
    int i = 0;
    while (allowHeaderIt.hasNext()) {
      allowHeaderIt.next();
      i++;
    }
    assertEquals(5, i);

    Header methodHeader = receiverProtocolObjects.headerFactory.createHeader("Supported", "");
    // Non Regression for Issue 184 http://code.google.com/p/sipservlets/issues/detail?id=184
    Header allowHeader =
        receiverProtocolObjects.headerFactory.createAllowHeader(
            "INVITE, CANCEL, BYE, ACK, OPTIONS");
    List<Header> headers = new ArrayList<Header>();
    headers.add(methodHeader);
    headers.add(allowHeader);

    sender.sendInDialogSipRequest("INVITE", null, null, null, headers, null);
    receiver.setInviteReceived(false);
    receiver.setAckReceived(false);
    Thread.sleep(TIMEOUT);
    assertTrue(receiver.isInviteReceived());
    assertTrue(receiver.isAckReceived());
    allowHeaderIt = receiver.getInviteRequest().getHeaders(AllowHeader.NAME);
    i = 0;
    while (allowHeaderIt.hasNext()) {
      allowHeaderIt.next();
      i++;
    }
    assertEquals(5, i);
    sender.sendInDialogSipRequest("BYE", null, null, null, null, null);
    Thread.sleep(TIMEOUT);
    assertTrue(receiver.getByeReceived());
    assertTrue(sender.getOkToByeReceived());
  }
    public void processRequest(RequestEvent requestEvent) {
      try {
        Request request = requestEvent.getRequest();

        ViaHeader viaHeader =
            headerFactory.createViaHeader(
                this.myHost,
                this.myPort,
                ListeningPoint.UDP,
                "z9hG4bK" + Math.random() * 31 + "" + System.currentTimeMillis());
        // Decreasing the Max Forward Header
        MaxForwardsHeader maxForwardsHeader =
            (MaxForwardsHeader) request.getHeader(MaxForwardsHeader.NAME);
        if (maxForwardsHeader == null) {
          maxForwardsHeader = headerFactory.createMaxForwardsHeader(70);
          request.addHeader(maxForwardsHeader);
        } else {
          maxForwardsHeader.setMaxForwards(maxForwardsHeader.getMaxForwards() - 1);
        }
        // Add the via header to the top of the header list.
        request.addHeader(viaHeader);
        // Removing first routeHeader if it is for us
        RouteHeader routeHeader = (RouteHeader) request.getHeader(RouteHeader.NAME);
        if (routeHeader != null) {
          SipURI routeUri = (SipURI) routeHeader.getAddress().getURI();
          if (routeUri.getHost().equalsIgnoreCase(myHost) && routeUri.getPort() == myPort) {
            request.removeFirst(RouteHeader.NAME);
          }
        }

        // Record route the invite so the bye comes to me.
        if (request.getMethod().equals(Request.INVITE)
            || request.getMethod().equals(Request.SUBSCRIBE)) {
          SipURI sipUri =
              addressFactory.createSipURI(
                  null, sipProvider.getListeningPoint(ListeningPoint.UDP).getIPAddress());
          sipUri.setPort(sipProvider.getListeningPoint(ListeningPoint.UDP).getPort());
          // See RFC 3261 19.1.1 for lr parameter
          sipUri.setLrParam();
          Address address = addressFactory.createAddress(sipUri);
          address.setURI(sipUri);
          RecordRouteHeader recordRoute = headerFactory.createRecordRouteHeader(address);
          request.addHeader(recordRoute);

          // Adding Route Header
          SipURI routeSipUri = addressFactory.createSipURI(null, IP_ADDRESS);
          routeSipUri.setPort(5070);
          routeSipUri.setLrParam();
          RouteHeader route =
              headerFactory.createRouteHeader(addressFactory.createAddress(routeSipUri));
          request.addFirst(route);
        } else if (!Request.ACK.equals(request.getMethod())) {
          // Adding Route Header
          if (((SipURI) request.getRequestURI()).getPort() == 5070) {
            SipURI routeSipUri = addressFactory.createSipURI(null, IP_ADDRESS);
            routeSipUri.setPort(5080);
            routeSipUri.setLrParam();
            RouteHeader route =
                headerFactory.createRouteHeader(addressFactory.createAddress(routeSipUri));
            request.addFirst(route);
          }
        }
        // sending request
        sipProvider.sendRequest(request);
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    }