Пример #1
0
  @Override
  public synchronized void forwardTo(final Call call, final Map<String, String> headers)
      throws SignalException {
    if (!(call instanceof SIPCall)) {
      throw new UnsupportedOperationException("Cannot forward to non-SIPCall.");
    }
    if (_req.isInitial()) {
      throw new IllegalArgumentException("Cannot forward initial SIP request.");
    }
    final SIPCallImpl scall = (SIPCallImpl) call;
    if (!scall.isAnswered()) {
      throw new IllegalStateException("Cannot forward to no-answered call.");
    }
    this.checkState();

    _forwarded = true;
    final SipSession session = scall.getSipSession();
    final SipServletRequest req = session.createRequest(_req.getMethod());
    SIPHelper.addHeaders(req, headers);
    SIPHelper.copyContent(_req, req);
    SIPHelper.linkSIPMessage(_req, req);
    try {
      req.send();
    } catch (final IOException e) {
      throw new SignalException(e);
    }
  }
  public void connectionOpenRequest(MsConnectionEvent event, SipServletRequest inviteRequest) {
    logger.info("connection opened " + event);

    String sdp = event.getConnection().getLocalDescriptor();
    SipServletResponse sipServletResponse = inviteRequest.createResponse(SipServletResponse.SC_OK);

    try {
      sipServletResponse.setContent(sdp, "application/sdp");
      sipServletResponse.send();
    } catch (Exception e) {
      logger.error(e);
    }
    provider = ConferenceCenter.getInstance().getProvider();
    MsConnection connection = event.getConnection();
    MsEndpoint endpoint = connection.getEndpoint();
    MsSession session = connection.getSession();
    String callerName = inviteRequest.getFrom().getURI().toString();

    ConferenceParticipant participant =
        new EndpointConferenceParticipant(callerName, endpoint, session, inviteRequest, connection);

    String key = ((SipURI) inviteRequest.getTo().getURI()).getUser();

    ConferenceCenter.getInstance().getConference(key).joinParticipant(participant);
  }
Пример #3
0
  /**
   *
   *
   * <pre>
   *  Alice        Proxy       Bob        Bob(2)       HSS
   * 1  | INVITE     |          |           |           |
   *    |----------->|          |           |           |
   * 2  |            | INVITE   |           |           |
   *    |            |--------->|           |           |
   * 3  |            |      404 |           |           |
   *    |            |<---------|           |           |
   * 4  |            | ACK      |           |           |
   *    |            |--------->|           |           |
   * 5  |            | UDR      |           |           |
   *    |            |--------------------------------->|
   * 6  |            |          |           |       UDA |
   *    |            |<---------------------------------|
   * 7  |            | INVITE   |           |           |
   *    |            |--------------------->|           |
   * 8  |            |          |       200 |           |
   *    |            |<---------------------|           |
   * 9  |        200 |          |           |           |
   *    |<-----------|          |           |           |
   * 10 | ACK        |          |           |           |
   *    |----------->|          |           |           |
   * 11 |            | ACK      |           |           |
   *    |            |--------------------->|           |
   * 12 | BYE        |          |           |           |
   *    |----------->|          |           |           |
   * 13 |            | BYE      |           |           |
   *    |            |--------------------->|           |
   * 14 |            |          |       200 |           |
   *    |            |<---------------------|           |
   * 15 |        200 |          |           |           |
   *    |<-----------|          |           |           |
   * </pre>
   */
  @Test
  public void testProxyDiameter() throws Throwable {
    Endpoint bob = createEndpoint("bob");
    UaRunnable callB = new UasScript.NotFound(bob.getUserAgent());
    Endpoint bob2 = createEndpoint("bob");
    UaRunnable callC = new UasScript.OkBye(bob2.getUserAgent());

    callB.start();
    callC.start();

    SipServletRequest request = _ua.createRequest(SipMethods.INVITE, bob.getUri());
    request.setRequestURI(bob.getContact().getURI());
    request.addHeader("proxy", bob2.getContact().toString());
    Call callA = _ua.createCall(request);

    try {
      assertThat(callA.waitForResponse(), isSuccess());
      callA.createAck().send();
      Thread.sleep(200);
      callA.createBye().send();
      assertThat(callA.waitForResponse(), isSuccess());
      callB.assertDone();
      callC.assertDone();
    } finally {
      checkForFailure();
    }
  }
Пример #4
0
 @Override
 public void doTest() throws Throwable {
   SipServletRequest invite = waitForInitialRequest();
   _ua.createResponse(invite, SipServletResponse.SC_RINGING).send();
   SipServletRequest cancel = _dialog.waitForRequest();
   assert cancel.getMethod().equals(SipMethods.CANCEL);
 }
  protected void doRegister(SipServletRequest req) throws ServletException, IOException {
    logger.info("Received register request: " + req.getTo());
    int response = SipServletResponse.SC_OK;
    SipServletResponse resp = req.createResponse(response);
    HashMap<String, String> users =
        (HashMap<String, String>) getServletContext().getAttribute("registeredUsersMap");
    if (users == null) users = new HashMap<String, String>();
    getServletContext().setAttribute("registeredUsersMap", users);

    Address address = req.getAddressHeader(CONTACT_HEADER);
    String fromURI = req.getFrom().getURI().toString();

    int expires = address.getExpires();
    if (expires < 0) {
      expires = req.getExpires();
    }
    if (expires == 0) {
      users.remove(fromURI);
      logger.info("User " + fromURI + " unregistered");
    } else {
      resp.setAddressHeader(CONTACT_HEADER, address);
      users.put(fromURI, address.getURI().toString());
      logger.info("User " + fromURI + " registered with an Expire time of " + expires);
    }

    resp.send();
  }
  public void connectionOpenResponse(MsConnectionEvent event, SipServletResponse response) {
    logger.info("connection opened " + event);

    String sdp = event.getConnection().getLocalDescriptor();
    SipServletRequest ack = response.createAck();

    try {
      ack.setContent(sdp, "application/sdp");
      ack.send();
    } catch (Exception e) {
      logger.error(e);
    }
    provider = ConferenceCenter.getInstance().getProvider();
    MsConnection connection = event.getConnection();
    MsEndpoint endpoint = connection.getEndpoint();
    MsSession session = connection.getSession();
    String callerName = response.getTo().getURI().toString();

    ConferenceParticipant participant =
        new EndpointConferenceParticipant(callerName, endpoint, session, response, connection);

    String key = SipGwtConferenceConsole.CONFERENCE_NAME;

    ConferenceCenter.getInstance().getConference(key).joinParticipant(participant);
  }
 public void timeout(ServletTimer timer, SipSession sipSession) {
   serverEntryLog();
   String reasonPhrase;
   if (sipSession.getAttribute("cancelled") != null) {
     reasonPhrase = "got cancelled";
   } else {
     logger.error("***ERROR: didn't receive notification of CANCEL***");
     reasonPhrase = "didn't get cancelled";
   }
   try {
     SipServletRequest invite = (SipServletRequest) sipSession.getAttribute("invite");
     SipServletResponse resp = invite.createResponse(500, reasonPhrase);
     try {
       resp.send();
     } catch (IOException ex) {
       logger.error("***failed to send subsequent request***", ex);
     }
     logger.error(
         "***ERROR: sending final response after CANCEL didn't "
             + "cause IllegalStateException***");
   } catch (IllegalStateException ex) {
     logger.info(
         "===SUCCESS: sending final response after CANCEL " + "cause IllegalStateException===");
   }
 }
Пример #8
0
  public SipServletRequest createInitialRequest(String method, Address local, Address remote) {
    if (_session != null) throw new IllegalStateException("Session already created");

    SipApplicationSession appSession = getFactory().createApplicationSession();
    SipServletRequest request = getFactory().createRequest(appSession, method, local, remote);
    if (_outboundProxy != null) request.pushRoute(_outboundProxy);
    return request;
  }
 @Observer("connectionOpen")
 public void doConnectionOpen(MsConnectionEvent event) throws IOException {
   conferenceEndpointName = event.getConnection().getEndpoint().getLocalName();
   SipServletRequest request = (SipServletRequest) sipSession.getAttribute("inviteRequest");
   SipServletResponse response = request.createResponse(200);
   response.setContent(event.getConnection().getLocalDescriptor(), "application/sdp");
   response.send();
 }
Пример #10
0
 @Override
 protected void handleAck(final SIPCallImpl call, final SipServletRequest req) throws Exception {
   final SipServletResponse res =
       (SipServletResponse) req.getSession().getAttribute(REINVITE_PEER_RES);
   final SipServletRequest newReq = res.createAck();
   SIPHelper.copyContent(req, newReq);
   newReq.send();
 }
Пример #11
0
  public SipServletRequest createRequest(String method) {
    if (_session == null) throw new IllegalStateException("Session not created");

    SipServletRequest request = _session.createRequest(method);
    if (_session.getState() == State.INITIAL && _outboundProxy != null)
      request.pushRoute(_outboundProxy);

    return request;
  }
 @Observer("INVITE")
 @CreateProcess(definition = "demo")
 public void doInvite(SipServletRequest request) throws Exception {
   String sdp = new String((byte[]) request.getContent());
   request.createResponse(180).send();
   sipSession.setAttribute("inviteRequest", request);
   if (conferenceEndpointName == null) conferenceEndpointName = "media/trunk/Conference/$";
   mediaController.createConnection(conferenceEndpointName).modify("$", sdp);
 }
Пример #13
0
  @Override
  protected void unmute(SIPCallImpl call) throws IOException, SdpException {
    final SIPCallImpl peer = (SIPCallImpl) call.getLastPeer();

    SipServletRequest reInvite = call.getSipSession().createRequest("INVITE");
    reInvite.setAttribute(SIPCallDelegate.SIPCALL_UNMUTE_REQUEST, "true");
    reInvite.setContent(createSendrecvSDP(call, peer.getRemoteSdp()), "application/sdp");
    reInvite.send();
  }
Пример #14
0
 @Override
 public void doTest() throws Throwable {
   SipServletRequest request = waitForInitialRequest();
   _ua.createResponse(request, SipServletResponse.SC_OK).send();
   request = _dialog.waitForRequest();
   assert request.getMethod().equals(SipMethods.ACK);
   request = _dialog.waitForRequest();
   assert request.getMethod().equals(SipMethods.BYE);
   _ua.createResponse(request, SipServletResponse.SC_OK).send();
 }
 protected void doInvite(SipServletRequest req) throws ServletException, IOException {
   serverEntryLog();
   logger.debug("---doInvite---");
   SipServletResponse resp = req.createResponse(180);
   resp.send();
   // just set timer - we expect a CANCEL to arrive...
   SipSession sipSession = req.getSession();
   sipSession.setAttribute("invite", req);
   timerService.createTimer(
       req.getApplicationSession(), 5000, true, UasCancelServlet.class.getName());
 }
Пример #16
0
 @Override
 protected void handleReinvite(
     final SIPCallImpl call, final SipServletRequest req, final Map<String, String> headers)
     throws Exception {
   final SIPCallImpl peer = (SIPCallImpl) call.getLastPeer();
   final SipServletRequest newReq = peer.getSipSession().createRequest(req.getMethod());
   SIPHelper.addHeaders(newReq, headers);
   SIPHelper.copyContent(req, newReq);
   SIPHelper.linkSIPMessage(req, newReq);
   newReq.send();
 }
 public void connectionFailed(MsConnectionEvent arg0) {
   logger.error("connection failed " + arg0);
   if (sipMessage instanceof SipServletRequest) {
     SipServletRequest inviteRequest = (SipServletRequest) sipMessage;
     try {
       inviteRequest.createResponse(SipServletResponse.SC_SERVER_INTERNAL_ERROR).send();
     } catch (IOException e) {
       logger.error("Unexpected exception while sending the error response", e);
     }
   }
 }
Пример #18
0
  @Override
  protected void hold(SIPCallImpl call, boolean send)
      throws MsControlException, IOException, SdpException {
    final SIPCallImpl peer = (SIPCallImpl) call.getLastPeer();

    SipServletRequest reInvite = call.getSipSession().createRequest("INVITE");
    reInvite.setAttribute(SIPCallDelegate.SIPCALL_HOLD_REQUEST, "true");
    reInvite.setContent(createSendonlySDP(call, peer.getRemoteSdp()), "application/sdp");
    reInvite.send();

    peer.hold();
  }
Пример #19
0
  /**
   *
   *
   * <pre>
   *  Alice        Proxy         Bob
   * 1  | INVITE     |            |
   *    |----------->|            |
   * 2  |            | INVITE     |
   *    |            |----------->|
   * 3  |            |        180 |
   *    |            |<-----------|
   * 4  |        180 |            |
   *    |<-----------|            |
   * 5  |            | CANCEL     |
   *    |            |----------->|
   * 6  |        408 |            |
   *    |<-----------|            |
   * 7  |            | 200/CANCEL |
   *    |            |<-----------|
   * 8  |            | 487/INVITE |
   *    |            |<-----------|
   * 9  |            | ACK        |
   *    |            |----------->|
   * 10 | ACK        |            |
   *    |----------->|            |
   * </pre>
   */
  @Test
  public void testVirtualBranch() throws Exception {
    Endpoint bob = createEndpoint("bob");
    UaRunnable callB = new UasScript.RingingCanceled(bob.getUserAgent());

    callB.start();

    SipServletRequest request = _ua.createRequest(SipMethods.INVITE, bob.getUri());
    request.setRequestURI(bob.getContact().getURI());
    Call callA = _ua.createCall(request);

    assertThat(callA.waitForResponse(), hasStatus(SipServletResponse.SC_REQUEST_TIMEOUT));
    checkForFailure();
  }
Пример #20
0
  @Override
  protected void doBye(SipServletRequest req) {
    SipSession session = req.getSession(false);
    SipSession linkedSession = (SipSession) session.getAttribute(Constant.LINKED_SESSION);

    logger.info("SIP BYE From : " + req.getFrom().toString());

    // caller session
    if (null != session.getAttribute(Constant.INVITE_USER_REQUEST)) {
      doBye(session, req);
    }
    // callee session
    else {
      logger.info("callee do bye!");
      doBye(linkedSession, req);
    }
  }
Пример #21
0
  private boolean isSipTrunk(SipServletRequest request) {
    String deviceAddress = request.getFrom().getValue();
    if (deviceAddress.contains("sip_trunk")) {
      return true;
    }

    return false;
  }
Пример #22
0
 @Override
 public synchronized void forwardTo(final Endpoint endpoint, final Map<String, String> headers)
     throws SignalException, IllegalStateException {
   URI target = null;
   try {
     target = _ctx.getSipFactory().createURI(endpoint.getURI().toString());
   } catch (final ServletParseException e) {
     throw new IllegalArgumentException(e);
   }
   this.checkState();
   _forwarded = true;
   final SipServletRequest req =
       _ctx.getSipFactory()
           .createRequest(
               _req.getApplicationSession(), _req.getMethod(), _req.getFrom(), _req.getTo());
   req.setRequestURI(target);
   SIPHelper.addHeaders(req, headers);
   SIPHelper.copyContent(_req, req);
   SIPHelper.linkSIPMessage(_req, req);
   try {
     req.send();
   } catch (final IOException e) {
     throw new SignalException(e);
   }
 }
  public void onEvent(PlayerEvent event) {
    try {
      logger.info("ENDING CALL ");
      Player player = event.getSource();
      MediaGroup mg = player.getContainer();
      if (event.isSuccessful() && (PlayerEvent.PLAY_COMPLETED == event.getEventType())) {
        MediaSession session = (MediaSession) sipSession.getAttribute("mediaSession");
        session.release();
        Thread.sleep(1500);

        SipServletRequest byeRequest = sipSession.createRequest("BYE");
        byeRequest.send();
      }

    } catch (Exception e) {
      logger.error("Error", e);
    }
  }
Пример #24
0
 protected synchronized void doPrack(final SipServletRequest req) throws IOException {
   if (_cstate == SIPCall.State.PROGRESSED) {
     final SipServletResponse res = req.createResponse(SipServletResponse.SC_OK);
     if (getLocalSDP() != null) {
       res.setContent(getLocalSDP(), "application/sdp");
     }
     res.send();
   }
 }
Пример #25
0
  /**
   * Ensure that the servlet is not invoked if session is invalidated.
   *
   * <p>See http://jira.cipango.org/browse/CIPANGO-121
   *
   * <pre>
   *  Alice        Proxy       Bob
   * 1  | INVITE     |          |
   *    |----------->|          |
   * 2  |            | INVITE   |
   *    |            |--------->|
   * 3  |            |      200 |
   *    |            |<---------|
   * 4  |        200 |          |
   *    |<-----------|          |
   * 5  | ACK        |          |
   *    |----------->|          |
   * 6  |            | ACK      |
   *    |            |--------->|
   * 7  | BYE        |          |
   *    |----------->|          |
   * 8  |            | BYE      |
   *    |            |--------->|
   * 9  |            |      200 |
   *    |            |<---------|
   * 10 |        200 |          |
   *    |<-----------|          |
   * </pre>
   */
  @Test
  public void testInvalidateBefore200() throws Exception {
    Endpoint bob = createEndpoint("bob");
    UaRunnable callB = new UasScript.OkBye(bob.getUserAgent());

    callB.start();

    SipServletRequest request = _ua.createRequest(SipMethods.INVITE, bob.getUri());
    request.setRequestURI(bob.getContact().getURI());
    Call callA = _ua.createCall(request);
    assertThat(callA.waitForResponse(), isSuccess());
    callA.createAck().send();
    callA.createBye().send();

    SipServletResponse response = callA.waitForResponse();
    assertThat(response, isSuccess());
    assertThat(response.getHeader("error"), is(nullValue()));
  }
Пример #26
0
  /** Invoked for SIP INVITE requests. */
  @Override
  protected void doInvite(final SipServletRequest req) throws ServletException, IOException {
    if (req.isInitial()) {
      // Get a reference to the Proxy helper.
      final Proxy proxy = req.getProxy();

      // Set Proxy parameters to control various aspects of the proxying
      // operation:
      proxy.setRecordRoute(true);
      proxy.setSupervised(true);
      // Set the flag indicates the working mode. True for Follow-Me; false for
      // Find-me.

      proxy.setParallel(m_parallel);

      // Proxies a SIP request to the specified set of destinations.
      proxy.proxyTo(m_targets);
    }
  }
Пример #27
0
  private void initialize(SipServletRequest request) throws ServletException {
    if (_session != null) throw new ServletException("Dialog already started");

    _sessionHandler = new SessionHandler();
    _session = request.getSession();
    _session.setAttribute(MessageHandler.class.getName(), _sessionHandler);
    _session.setAttribute(INITIAL_REQUEST_ATTRIBUTE, request);

    _sessionHandler.setTimeout(_timeout);
    _sessionHandler.setCredentials(_credentials);
  }
Пример #28
0
  /**
   * Ensures that - DNS resolution is done using NAPTR and SRV in proxy mode; - retry is done if a
   * 503 is received.
   *
   * <p>To run this test, the DNS server for domain cipango.voip should be configured with
   *
   * <pre>
   * bob         IN NAPTR 90  40  "s"  "SIP+D2U"      ""  _sip._udp.bob
   * _sip._udp.bob           SRV 0 0 5064 local
   * _sip._udp.bob           SRV 5 0 5063 local
   * </pre>
   *
   * Note:This test is marked as ignored as it requires a specific DNS configuration.
   */
  @Ignore
  public void dnsCase() throws Exception {
    final Endpoint bob = createEndpoint("bob");
    bob.getUserAgent()
        .setDefaultHandler(
            new MessageHandler() {
              public void handleRequest(SipServletRequest request)
                  throws IOException, ServletException {
                SipServletResponse response =
                    bob.getUserAgent().createResponse(request, SipServletResponse.SC_ACCEPTED);
                response.addHeader("X-Dns", "ok");
                response.send();
              }

              public void handleResponse(SipServletResponse response)
                  throws IOException, ServletException {}
            });

    final Endpoint bob2 = createEndpoint("bob");
    bob2.getUserAgent()
        .setDefaultHandler(
            new MessageHandler() {
              public void handleRequest(SipServletRequest request)
                  throws IOException, ServletException {
                SipServletResponse response =
                    bob.getUserAgent()
                        .createResponse(request, SipServletResponse.SC_SERVICE_UNAVAILABLE);
                response.send();
              }

              public void handleResponse(SipServletResponse response)
                  throws IOException, ServletException {}
            });

    SipServletRequest request = _ua.createRequest(SipMethods.MESSAGE, bob.getUri());
    request.setRequestURI(_sipClient.getFactory().createURI("sip:bob.cipango.voip"));
    Call call = _ua.createCall(request);
    assertThat(call.waitForResponse(), hasStatus(SipServletResponse.SC_ACCEPTED));

    checkForFailure();
  }
Пример #29
0
  private void doBye(SipSession session, SipServletRequest request) {
    // send bye to its linked user session and notify
    SipSession reqSession = request.getSession(false);
    if (null == reqSession.getAttribute(Constant.INVITE_USER_REQUEST)) {
      logger.info("callee ok");
      SipServletRequest bye = session.createRequest(Constant.BYE);
      try {
        bye.send();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }

    // send 200 OK to the session
    SipServletResponse resp = request.createResponse(SipServletResponse.SC_OK);
    try {
      resp.send();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Пример #30
0
  /**
   *
   *
   * <pre>
   *  Alice         Proxy             Proxy       Bob
   * 1  | INVITE      |                 |          |
   *    |------------>|                 |          |
   * 2  |             |INVITE tel:1234  |          |
   *    |             |---------------->|          |
   * 3  |             |                 | INVITE   |
   *    |             |                 |--------->|
   * 4  |             |                 |      603 |
   *    |             |                 |<---------|
   * 5  |             |             603 |          |
   *    |             |<----------------|          |
   * 6  |         603 |                 |          |
   *    |<------------|                 |          |
   * 7  | ACK         |                 |          |
   *    |------------>|                 |          |
   * 8  |             |ACK              |          |
   *    |             |---------------->|          |
   * 9  |             |                 | ACK      |
   *    |             |                 |--------->|
   * </pre>
   */
  @Test
  public void testTelUri() throws Exception {
    final Endpoint bob = createEndpoint("bob");
    bob.getUserAgent()
        .setDefaultHandler(
            new MessageHandler() {
              public void handleRequest(SipServletRequest request)
                  throws IOException, ServletException {
                assertThat(request.getHeader("req-uri"), containsString("tel:1234"));
                bob.getUserAgent().createResponse(request, SipServletResponse.SC_DECLINE).send();
              }

              public void handleResponse(SipServletResponse response)
                  throws IOException, ServletException {}
            });

    SipServletRequest request = _ua.createRequest(SipMethods.INVITE, bob.getUri());
    request.setRequestURI(bob.getContact().getURI());
    Call call = _ua.createCall(request);
    assertThat(call.waitForResponse(), hasStatus(SipServletResponse.SC_DECLINE));
  }