예제 #1
0
  @Before
  public void before() throws Exception {
    bobSipStack =
        tool1.initializeSipStack(SipStack.PROTOCOL_UDP, "127.0.0.1", "5090", "127.0.0.1:5080");
    bobPhone = bobSipStack.createSipPhone("127.0.0.1", SipStack.PROTOCOL_UDP, 5080, bobContact);

    aliceSipStack =
        tool2.initializeSipStack(SipStack.PROTOCOL_UDP, "127.0.0.1", "5091", "127.0.0.1:5080");
    alicePhone =
        aliceSipStack.createSipPhone("127.0.0.1", SipStack.PROTOCOL_UDP, 5080, aliceContact);
  }
  /** Initialize the sipStack 1 & 2 and a user agent for the test. */
  @Before
  public void setUp() throws Exception {
    sipStack1 = new SipStack(PROXY_PROTO, 5061, properties1);
    sipStack2 = new SipStack(PROXY_PROTO, 5090, properties2);

    ua = sipStack1.createSipPhone(PROXY_HOST, PROXY_PROTO, PROXY_PORT, "sip:[email protected]");
  }
예제 #3
0
  @Test // For github issue #600, At the DB the IncomingPhoneNumber is '+2222' and we dial '2222',
        // Restcomm should find this number even without the '+'
  public synchronized void testDialClientAliceWithoutPlusSign()
      throws InterruptedException, ParseException {
    stubFor(
        get(urlPathEqualTo("/1111"))
            .willReturn(
                aResponse()
                    .withStatus(200)
                    .withHeader("Content-Type", "text/xml")
                    .withBody(dialClientRcml)));

    // Phone2 register as alice
    SipURI uri = aliceSipStack.getAddressFactory().createSipURI(null, "127.0.0.1:5080");
    assertTrue(alicePhone.register(uri, "alice", "1234", aliceContact, 3600, 3600));

    // Prepare second phone to receive call
    SipCall aliceCall = alicePhone.createSipCall();
    aliceCall.listenForIncomingCall();

    // Create outgoing call with first phone
    final SipCall bobCall = bobPhone.createSipCall();
    bobCall.initiateOutgoingCall(
        bobContact, "sip:[email protected]:5080", null, body, "application", "sdp", null, null);
    assertLastOperationSuccess(bobCall);
    assertTrue(bobCall.waitOutgoingCallResponse(5 * 1000));
    final int response = bobCall.getLastReceivedResponse().getStatusCode();
    assertTrue(response == Response.TRYING || response == Response.RINGING);

    if (response == Response.TRYING) {
      assertTrue(bobCall.waitOutgoingCallResponse(5 * 1000));
      assertEquals(Response.RINGING, bobCall.getLastReceivedResponse().getStatusCode());
    }

    assertTrue(bobCall.waitOutgoingCallResponse(5 * 1000));
    assertEquals(Response.OK, bobCall.getLastReceivedResponse().getStatusCode());

    bobCall.sendInviteOkAck();
    assertTrue(!(bobCall.getLastReceivedResponse().getStatusCode() >= 400));

    assertTrue(aliceCall.waitForIncomingCall(30 * 1000));
    assertTrue(aliceCall.sendIncomingCallResponse(Response.RINGING, "Ringing-Alice", 3600));
    String receivedBody = new String(aliceCall.getLastReceivedRequest().getRawContent());
    assertTrue(
        aliceCall.sendIncomingCallResponse(
            Response.OK, "OK-Alice", 3600, receivedBody, "application", "sdp", null, null));
    assertTrue(aliceCall.waitForAck(50 * 1000));

    Thread.sleep(3000);

    // hangup.
    bobCall.disconnect();

    aliceCall.listenForDisconnect();
    assertTrue(aliceCall.waitForDisconnect(30 * 1000));
    assertTrue(aliceCall.respondToDisconnect());
  }
예제 #4
0
  @After
  public void after() throws Exception {
    if (bobPhone != null) {
      bobPhone.dispose();
    }
    if (bobSipStack != null) {
      bobSipStack.dispose();
    }

    if (aliceSipStack != null) {
      aliceSipStack.dispose();
    }
    if (alicePhone != null) {
      alicePhone.dispose();
    }
    Thread.sleep(3000);
    wireMockRule.resetRequests();
    Thread.sleep(2000);
  }
예제 #5
0
  @Test
  // Non regression test for
  // https://bitbucket.org/telestax/telscale-restcomm/issue/132/implement-twilio-sip-out
  // with Dial Action screening
  public synchronized void testDialSipDialTagScreening180Decline()
      throws InterruptedException, ParseException {
    stubFor(
        get(urlPathEqualTo("/1111"))
            .willReturn(
                aResponse()
                    .withStatus(200)
                    .withHeader("Content-Type", "text/xml")
                    .withBody(dialSipDialScreeningRcml)));

    stubFor(
        get(urlPathEqualTo("/screening"))
            .willReturn(
                aResponse()
                    .withStatus(200)
                    .withHeader("Content-Type", "text/xml")
                    .withBody(screeningRcml)));

    stubFor(
        get(urlPathEqualTo("/action"))
            .willReturn(
                aResponse()
                    .withStatus(200)
                    .withHeader("Content-Type", "text/xml")
                    .withBody(sipDialUrlActionRcml)));

    // Phone2 register as alice
    SipURI uri = aliceSipStack.getAddressFactory().createSipURI(null, "127.0.0.1:5080");
    assertTrue(alicePhone.register(uri, "alice", "1234", aliceContact, 3600, 3600));

    // Prepare second phone to receive call
    SipCall aliceCall = alicePhone.createSipCall();
    aliceCall.listenForIncomingCall();

    // Create outgoing call with first phone
    final SipCall bobCall = bobPhone.createSipCall();
    bobCall.initiateOutgoingCall(
        bobContact, dialRestcomm, null, body, "application", "sdp", null, null);
    assertLastOperationSuccess(bobCall);
    assertTrue(bobCall.waitOutgoingCallResponse(5 * 1000));
    final int response = bobCall.getLastReceivedResponse().getStatusCode();
    assertTrue(response == Response.TRYING || response == Response.RINGING);

    if (response == Response.TRYING) {
      assertTrue(bobCall.waitOutgoingCallResponse(5 * 1000));
      assertEquals(Response.RINGING, bobCall.getLastReceivedResponse().getStatusCode());
    }

    assertTrue(bobCall.waitOutgoingCallResponse(5 * 1000));
    assertEquals(Response.OK, bobCall.getLastReceivedResponse().getStatusCode());

    bobCall.sendInviteOkAck();
    assertTrue(!(bobCall.getLastReceivedResponse().getStatusCode() >= 400));

    bobCall.listenForDisconnect();

    assertTrue(aliceCall.waitForIncomingCall(30 * 1000));
    MessageExt invite = (MessageExt) aliceCall.getLastReceivedRequest().getMessage();
    assertNotNull(invite);
    assertEquals(Request.INVITE, invite.getCSeqHeader().getMethod());
    Header mycustomheader = invite.getHeader("X-mycustomheader");
    Header myotherheader = invite.getHeader("X-myotherheader");
    assertNotNull(mycustomheader);
    assertNotNull(myotherheader);

    String receivedBody = new String(aliceCall.getLastReceivedRequest().getRawContent());

    assertTrue(
        aliceCall.sendIncomingCallResponse(
            Response.RINGING, "Ringing", 3600, receivedBody, "application", "sdp", null, null));

    ArrayList<String> headers = new ArrayList<String>();
    Header customHeader =
        aliceSipStack.getHeaderFactory().createHeader("X-mycustomheader", "customValue");
    Header otherHeader =
        aliceSipStack.getHeaderFactory().createHeader("X-myothereader", "customOtherValue");
    headers.add(customHeader.toString());
    headers.add(otherHeader.toString());
    assertTrue(
        aliceCall.sendIncomingCallResponse(
            Response.DECLINE, "Declined", 3600, receivedBody, "application", "sdp", headers, null));
    assertTrue(aliceCall.waitForAck(50 * 1000));

    assertTrue(bobCall.waitForDisconnect(5000));
    assertTrue(bobCall.respondToDisconnect());
  }
예제 #6
0
  //    @Ignore
  @Test
  // Non regression test for
  // https://bitbucket.org/telestax/telscale-restcomm/issue/132/implement-twilio-sip-out
  // in auth manner
  public synchronized void testDialSipAuth() throws InterruptedException, ParseException {
    stubFor(
        get(urlPathEqualTo("/1111"))
            .willReturn(
                aResponse()
                    .withStatus(200)
                    .withHeader("Content-Type", "text/xml")
                    .withBody(dialSipAuthRcml)));

    // Phone2 register as alice
    SipURI uri = aliceSipStack.getAddressFactory().createSipURI(null, "127.0.0.1:5080");
    assertTrue(alicePhone.register(uri, "alice", "1234", aliceContact, 3600, 3600));

    // Prepare second phone to receive call
    SipCall aliceCall = alicePhone.createSipCall();
    aliceCall.listenForIncomingCall();

    // Create outgoing call with first phone
    final SipCall bobCall = bobPhone.createSipCall();
    bobCall.initiateOutgoingCall(
        bobContact, dialRestcomm, null, body, "application", "sdp", null, null);
    assertLastOperationSuccess(bobCall);
    assertTrue(bobCall.waitOutgoingCallResponse(5 * 1000));
    final int response = bobCall.getLastReceivedResponse().getStatusCode();
    assertTrue(response == Response.TRYING || response == Response.RINGING);

    if (response == Response.TRYING) {
      assertTrue(bobCall.waitOutgoingCallResponse(5 * 1000));
      assertEquals(Response.RINGING, bobCall.getLastReceivedResponse().getStatusCode());
    }

    assertTrue(bobCall.waitOutgoingCallResponse(5 * 1000));
    assertEquals(Response.OK, bobCall.getLastReceivedResponse().getStatusCode());

    bobCall.sendInviteOkAck();
    assertTrue(!(bobCall.getLastReceivedResponse().getStatusCode() >= 400));

    assertTrue(aliceCall.waitForIncomingCall(30 * 1000));
    MessageExt invite = (MessageExt) aliceCall.getLastReceivedRequest().getMessage();
    assertNotNull(invite);
    assertEquals(Request.INVITE, invite.getCSeqHeader().getMethod());
    Header mycustomheader = invite.getHeader("X-mycustomheader");
    Header myotherheader = invite.getHeader("X-myotherheader");
    assertNotNull(mycustomheader);
    assertNotNull(myotherheader);

    DigestServerAuthenticationMethod dsam = new DigestServerAuthenticationMethod();
    dsam.initialize(); // it should read values from file, now all static

    ProxyAuthenticateHeader proxyAuthenticate =
        aliceSipStack.getHeaderFactory().createProxyAuthenticateHeader(dsam.getScheme());
    proxyAuthenticate.setParameter("realm", dsam.getRealm(null));
    proxyAuthenticate.setParameter("nonce", dsam.generateNonce());
    // proxyAuthenticateImpl.setParameter("domain",authenticationMethod.getDomain());
    proxyAuthenticate.setParameter("opaque", "");

    proxyAuthenticate.setParameter("algorithm", dsam.getAlgorithm());
    ArrayList<Header> headers = new ArrayList<Header>();
    headers.add(proxyAuthenticate);
    assertTrue(
        aliceCall.sendIncomingCallResponse(
            Response.PROXY_AUTHENTICATION_REQUIRED, "Non authorized", 3600, headers, null, null));

    assertTrue(aliceCall.waitForIncomingCall(30 * 1000));
    invite = (MessageExt) aliceCall.getLastReceivedRequest().getMessage();
    assertNotNull(invite.getHeader(ProxyAuthorizationHeader.NAME));

    ProxyAuthorizationHeader proxyAuthorization =
        (ProxyAuthorizationHeader) invite.getHeader(ProxyAuthorizationHeader.NAME);

    boolean res = dsam.doAuthenticate("alice", "1234", proxyAuthorization, (Request) invite);
    assertTrue(res);

    assertTrue(aliceCall.sendIncomingCallResponse(Response.RINGING, "Ringing-Alice", 3600));
    String receivedBody = new String(aliceCall.getLastReceivedRequest().getRawContent());
    assertTrue(
        aliceCall.sendIncomingCallResponse(
            Response.OK, "OK-Alice", 3600, receivedBody, "application", "sdp", null, null));
    assertTrue(aliceCall.waitForAck(50 * 1000));
    aliceCall.listenForDisconnect();

    Thread.sleep(3000);

    // hangup.
    bobCall.disconnect();

    assertTrue(aliceCall.waitForDisconnect(30 * 1000));
  }
  @Test
  public void testBothSides() throws Exception {
    assertTrue(ua.register("amit", "a1b2c3d4", null, 600, 5000));

    SipPhone ub =
        sipStack2.createSipPhone(PROXY_HOST, PROXY_PROTO, PROXY_PORT, "sip:[email protected]");
    assertTrue(ub.register("becky", "a1b2c3d4", null, 600, 5000));

    SipCall callA = ua.createSipCall();
    SipCall callB = ub.createSipCall();

    callB.listenForIncomingCall();
    Thread.sleep(100);

    callA.initiateOutgoingCall("sip:[email protected]", null); // "127.0.0.1:4000/UDP"
    assertLastOperationSuccess("a initiate call - " + callA.format(), callA);

    callB.waitForIncomingCall(3000);
    assertLastOperationSuccess("b wait incoming call - " + callB.format(), callB);

    callB.sendIncomingCallResponse(Response.RINGING, null, -1);
    assertLastOperationSuccess("b send RINGING - " + callB.format(), callB);

    Thread.sleep(1000);

    callB.sendIncomingCallResponse(Response.OK, "Answer - Hello world", 0);
    assertLastOperationSuccess("b send OK - " + callB.format(), callB);

    callA.waitOutgoingCallResponse(10000);
    assertLastOperationSuccess("a wait 1st response - " + callA.format(), callA);
    assertTrue(
        "Unexpected 1st response received",
        (callA.getReturnCode() == Response.RINGING || callA.getReturnCode() == Response.TRYING));
    if (callA.getLastReceivedResponse().getStatusCode() == Response.RINGING) {
      assertNotNull(
          "Default response reason not sent", callA.getLastReceivedResponse().getReasonPhrase());
      assertEquals(
          "Unexpected default reason",
          "Ringing",
          callA.getLastReceivedResponse().getReasonPhrase());
    }

    callA.waitOutgoingCallResponse(5000);
    assertLastOperationSuccess("a wait 2nd response - " + callA.format(), callA);
    callA.waitOutgoingCallResponse(2000);

    assertEquals(
        "Unexpected final response received",
        Response.OK,
        callA.getLastReceivedResponse().getStatusCode());

    callA.sendInviteOkAck();
    assertLastOperationSuccess("Failure sending ACK - " + callA.format(), callA);

    Thread.sleep(1000);

    callA.listenForDisconnect();
    assertLastOperationSuccess("a listen disc - " + callA.format(), callA);

    callB.disconnect();
    assertLastOperationSuccess("b disc - " + callB.format(), callB);

    callA.waitForDisconnect(5000);
    assertLastOperationSuccess("a wait disc - " + callA.format(), callA);

    callA.respondToDisconnect();
    assertLastOperationSuccess("a respond to disc - " + callA.format(), callA);

    Thread.sleep(1000);
    ub.dispose();
  }