コード例 #1
0
  private void assertViaHeaders(final String... vias) throws Exception {
    final String[] formatedViaValues = new String[vias.length];
    for (int i = 0; i < vias.length; ++i) {
      formatedViaValues[i] = String.format(vias[i], i);
      if (formatedViaValues[i].startsWith("Via: ")) {
        formatedViaValues[i] = formatedViaValues[i].substring("Via: ".length());
      }
    }

    SipResponse response = createResponseWithViaHeaders(vias);

    // this should always return the top-most via header which will
    // always have the branchBase-0 as its branch since that is how we generate
    // the branches...
    final ViaHeader via = response.getViaHeader();
    assertThat(via.getBranch().toString(), is(this.branchBase + 0));
    assertThat(via.getValue().toString(), is(formatedViaValues[0]));

    // make sure that the other Via-header is still in the msg
    assertViasInMessageDump(response, formatedViaValues);

    // do it again but ask for all the Via headers up front since
    // the parsing may be slightly different (which it is)
    response = createResponseWithViaHeaders(vias);
    final List<ViaHeader> viaHeaders = response.getViaHeaders();
    assertThat(viaHeaders.size(), is(vias.length));
    for (int i = 0; i < viaHeaders.size(); ++i) {
      assertThat(viaHeaders.get(i).getBranch().toString().contains(this.branchBase + i), is(true));
    }
  }
コード例 #2
0
ファイル: SipProxy.java プロジェクト: abhishekdixit98/cipango
  private void forward(SipResponse response) {

    /*
    if (_tx.getRequest().getTo().getParameter("tag") == null)
    {
        if (response.getStatus() < 300 && (response.isInvite() || response.isSubscribe()))
        {
            response.session().registerProxy(response);
        }
    }
    */
    if (response.getStatus() >= 300) response.session().updateState(response, false);
    _tx.send(response);
    response.setCommitted(true);
  }
コード例 #3
0
ファイル: SipProxy.java プロジェクト: abhishekdixit98/cipango
  private void tryFinal() {
    assert (_actives == 0);

    if (LOG.isDebugEnabled()) LOG.debug("tryFinal, branches: {}, untried: {}", _branches, _targets);

    if (_best == null) {
      _best =
          (SipResponse) getOriginalRequest().createResponse(SipServletResponse.SC_REQUEST_TIMEOUT);
      _best.setToTag(ID.newTag());
    }

    if (LOG.isDebugEnabled()) LOG.debug("final response is {}", _best, null);

    _best.setBranchResponse(false);
    invokeServlet(_best);

    if (_actives > 0) {
      if (LOG.isDebugEnabled()) LOG.debug("new branch(es) created in callback {}", _branches, null);
      return;
    }
    forward(_best);
  }
コード例 #4
0
ファイル: SipProxy.java プロジェクト: abhishekdixit98/cipango
    public void handleResponse(SipResponse response) {
      _response = response;

      int status = response.getStatus();

      if (status == 100) return;

      if (_tx.isCompleted() && !response.is2xx()) {
        if (LOG.isDebugEnabled())
          LOG.debug("Dropping response " + response.getStatus() + " since proxy is completed");
        return;
      }

      if (LOG.isDebugEnabled()) LOG.debug("Got response {}", response, null);

      SipRequest request = _tx.getRequest();

      Session session = request.session();

      if (request.isInitial() && status < 300) {
        if (!session.isSameDialog(response)) {
          AppSession appSession = session.appSession();
          Session derived = appSession.getSession(response);
          if (derived == null) derived = appSession.createDerivedSession(session);
          session = derived;
        }
      }

      response.setSession(session);
      if (status < 300) session.updateState(response, false);

      response.removeTopVia();
      response.setProxyBranch(this);

      if (status < 200) {
        if (response.isInvite()) updateTimerC();

        invokeServlet(response);
        forward(response);
      } else {
        _actives--;

        stopTimerC();

        if ((300 <= status && status < 400) && _branchRecurse) {
          try {
            Iterator<Address> it = response.getAddressHeaders(SipHeaders.CONTACT);
            while (it.hasNext()) {
              Address contact = (Address) it.next();
              if (contact.getURI().isSipURI()) {
                Branch branch = addTarget(contact.getURI());
                if (branch != null) {
                  _recursedBranches = LazyList.add(_recursedBranches, branch);
                  branch.setRecurse(_branchRecurse);
                }
              }
            }
          } catch (ServletParseException e) {
            LOG.ignore(e);
          }
        }

        if (_best == null
            || (_best.getStatus() < 600 && (status < _best.getStatus() || status >= 600))) {
          _best = response;
        }

        if (status >= 600) {
          SipProxy.this.doCancel(null, null, null);
        }

        if (status < 300) {
          invokeServlet(response);
          forward(response);

          SipProxy.this.doCancel(null, null, null);
        } else {
          if (LazyList.size(_targets) > 0) startProxy();

          if (_actives > 0) {
            response.setBranchResponse(true);
            invokeServlet(response);
          } else {
            tryFinal();
          }
        }
      }
    }
コード例 #5
0
ファイル: SipProxy.java プロジェクト: abhishekdixit98/cipango
 private void invokeServlet(SipResponse response) {
   if (_supervised) response.session().invokeServlet(response);
 }