/** Process the invite request. */ public void processInvite(RequestEvent requestEvent, ServerTransaction serverTransaction) { try { // System.out.println("ProcessInvite"); Request request = requestEvent.getRequest(); SipProvider sipProvider = (SipProvider) requestEvent.getSource(); // Note you need to create the Server Transaction // before the listener returns but you can delay sending the response ServerTransaction st = sipProvider.getNewServerTransaction(request); if (transactionIDs.containsKey(st.getBranchId())) { System.out.println( "OOOPS -- seen this guy before!! This must be a late guy " + st.getBranchId() + " st = " + transactionIDs.get(st.getBranchId())); return; } else { transactionIDs.put(st.getBranchId(), st); } TTask ttask = new TTask(requestEvent, st); int ttime; if ((numInvite % 4) == 0) ttime = 5000; else if ((numInvite % 4) == 1) ttime = 1000; else ttime = 300; numInvite++; new Timer().schedule(ttask, ttime); } catch (Exception ex) { ex.printStackTrace(); } }
/** * Sends a request from the RI and tests whether the tested implementation properly creates a * ServerTransaction. */ public void testGetNewServerTransaction() { try { Request invite = createRiInviteRequest(null, null, null); ServerTransaction tran = null; RequestEvent receivedRequestEvent = null; try { // Send using RI and collect using TI eventCollector.collectRequestEvent(tiSipProvider); riSipProvider.sendRequest(invite); waitForMessage(); receivedRequestEvent = eventCollector.extractCollectedRequestEvent(); if (receivedRequestEvent == null || receivedRequestEvent.getRequest() == null) throw new TiUnexpectedError("The sent request was not received by the RI!"); } catch (TooManyListenersException ex) { throw new TiUnexpectedError( "A TooManyListenersException was thrown while trying to add " + "a SipListener to a TI SipProvider.", ex); } catch (SipException ex) { throw new TckInternalError("The RI failed to send the request!", ex); } try { tran = tiSipProvider.getNewServerTransaction(invite); } catch (TransactionUnavailableException exc) { exc.printStackTrace(); fail( "A TransactionUnavailableException was thrown while trying to " + "create a new client transaction"); } catch (TransactionAlreadyExistsException exc) { exc.printStackTrace(); fail( "A TransactionAlreadyExistsException was thrown while trying to " + "create a new server transaction"); } assertNotNull( "A null ServerTransaction was returned by SipProvider." + "getNewServerTransaction().", tran); String tranBranch = tran.getBranchId(); String reqBranch = ((ViaHeader) invite.getHeader(ViaHeader.NAME)).getBranch(); assertEquals( "The newly created transaction did not have the same " + "branch id as the request that created it!", tranBranch, reqBranch); assertNotNull( "The newly created transaction returned a null Dialog. " + "Please check the docs on Transaction.getDialog()", tran.getDialog()); assertNotNull( "The transaction's getRequest() method returned a null Request ", tran.getRequest()); assertEquals( "The transaction's getRequest() method returned a Request " + "that did not match the one that we used to create it!", tran.getRequest(), invite); } catch (Throwable exc) { exc.printStackTrace(); fail(exc.getClass().getName() + ": " + exc.getMessage()); } assertTrue(new Exception().getStackTrace()[0].toString(), true); }