ContactHeader contact = tiHeaderFactory.createContactHeader();
ContactHeader contact = this.createTiContact();
	public void testProceedingTerminatedScenario() {		try {			Request invite = createRiInviteRequest(null, null, null);			SipEventCollector responseCollector = new SipEventCollector();			//Before Sending the request we should first register a listener with the			//RI that would catch the TRYING response			try {				responseCollector.collectResponseEvent(riSipProvider);			} catch (TooManyListenersException ex) {				throw new TckInternalError(					"Failed to register a SipListener with an RI SipProvider",					ex);			}			//Send the initial request			try {				eventCollector.collectRequestEvent(tiSipProvider);				riSipProvider.sendRequest(invite);			} catch (SipException ex) {				throw new TckInternalError(					"A SipExceptionOccurred while trying to send request!",					ex);			} catch (TooManyListenersException ex) {				throw new TiUnexpectedError(					"Failed to register a SipListener with a TI SipProvider",					ex);			}			waitForMessage();			RequestEvent inviteReceivedEvent =				eventCollector.extractCollectedRequestEvent();			if (inviteReceivedEvent == null				|| inviteReceivedEvent.getRequest() == null)				throw new TiUnexpectedError("The initial invite request was not received by the TI!");			//Let's create the transaction			ServerTransaction tran = null;			try {				tran =					tiSipProvider.getNewServerTransaction(						inviteReceivedEvent.getRequest());			} catch (Exception ex) {				ex.printStackTrace();				fail(					ex.getClass().getName()						+ "was thrown while trying to "						+ "create the server transaction");			}			assertNotNull(				"tiSipProvider.getNewServerTransaction() returned null",				tran);			//Check whether a TRYING response has been sent.			//wait for the trying response			waitForMessage();			// State must be proceeding After Response has been sent.			assertEquals(TransactionState.PROCEEDING, tran.getState());			ResponseEvent responseEvent =				responseCollector.extractCollectedResponseEvent();			assertNotNull(				"No TRYING response has been sent by the TI upon reception "					+ "of an INVITE request",				responseEvent);			assertTrue(				"A response different from 100 was sent by the TI upon "					+ "reception of INVITE",				Response.TRYING == responseEvent.getResponse().getStatusCode());			//Resend the invite and see that a TRYING response is resent			try {				//listen for the Trying response				responseCollector.collectResponseEvent(riSipProvider);			} catch (TooManyListenersException ex) {				throw new TckInternalError(					"Failed to register a SipListener with an RI SipProvider",					ex);			}			try {				eventCollector.collectRequestEvent(tiSipProvider);				riSipProvider.sendRequest(invite);			} catch (SipException ex) {				throw new TckInternalError(					"A SipExceptionOccurred while trying to send request!",					ex);			} catch (TooManyListenersException ex) {				throw new TiUnexpectedError(					"Failed to register a SipListener with a TI SipProvider",					ex);			}			//Wait for the INVITE			waitForMessage();			inviteReceivedEvent = eventCollector.extractCollectedRequestEvent();			assertNull(				"Retransmitted INVITEs should not be passed to the TU",				inviteReceivedEvent);			//Wait for a retransmitted TRYING response			waitForMessage();			//Verify whether there was a TRYING response			responseEvent = responseCollector.extractCollectedResponseEvent();			assertNotNull(				"No TRYING response has been sent by the TI upon reception "					+ "of an INVITE request",				responseEvent);			assertTrue(				"A response different from 100 was sent by the TI upon "					+ "reception of INVITE",				Response.TRYING == responseEvent.getResponse().getStatusCode());			//Create & send RINGING. See that it is properly sent			//and that tran state doesn't change			Response ringing = null;			try {				ringing =					tiMessageFactory.createResponse(						Response.RINGING,						tran.getRequest());				((ToHeader) ringing.getHeader(ToHeader.NAME)).setTag(					Integer.toString(hashCode()));				addStatus(tran.getRequest(), ringing);                // BUG report from Ben Evans: 				// set contact header on dialog-creating response                ringing.setHeader(createTiContact());			} catch (ParseException ex) {				throw new TiUnexpectedError(					"A ParseException was thrown while trying to create a ringing "						+ "response using TI",					ex);			}			try {				//listen for the RINGING response				responseCollector.collectResponseEvent(riSipProvider);			} catch (TooManyListenersException ex) {				throw new TckInternalError(					"Failed to register a SipListener with an RI SipProvider",					ex);			}			try {				tran.sendResponse(ringing);			} catch (SipException ex) {				ex.printStackTrace();				fail("The TI failed to send a RINGING response");			}			//The Transaction should still be PROCEEDING			assertEquals(				"The Transaction did not remain PROCEEDING after transmitting a RINGING response",				TransactionState.PROCEEDING,				tran.getState());			//Check whether the RINGING is received by the RI.			waitForMessage();			responseEvent = responseCollector.extractCollectedResponseEvent();			assertNotNull(				"The RINGING response was not received by the RI",				responseEvent);			assertTrue(				"A response different from RINGING was sent by the TI",				Response.RINGING					== responseEvent.getResponse().getStatusCode());			//Resend the INVITE, see that it is hidden from the TU and see that			//the _RINGING_ response is resent (and not the TRYING)			try {				//listen for the Trying response				responseCollector.collectResponseEvent(riSipProvider);			} catch (TooManyListenersException ex) {				throw new TckInternalError(					"Failed to register a SipListener with an RI SipProvider",					ex);			}			try {				eventCollector.collectRequestEvent(tiSipProvider);				riSipProvider.sendRequest(invite);			} catch (SipException ex) {				throw new TckInternalError(					"A SipExceptionOccurred while trying to send request!",					ex);			} catch (TooManyListenersException ex) {				throw new TiUnexpectedError(					"Failed to register a SipListener with a TI SipProvider",					ex);			}			//Wait for the INVITE			waitForMessage();			inviteReceivedEvent = eventCollector.extractCollectedRequestEvent();			assertNull(				"Retransmitted INVITEs should not be passed to the TU",				inviteReceivedEvent);			//Wait for a retransmitted RINGING response			waitForMessage();			//Verify whether there was a RINGING response			responseEvent = responseCollector.extractCollectedResponseEvent();			assertNotNull(				"No RINGING response has been sent by the TI upon reception "					+ "of an INVITE request",				responseEvent);			assertTrue(				"A response different from RINGING was sent by the TI upon "					+ "reception of a retransmitted invite INVITE",				Response.RINGING					== responseEvent.getResponse().getStatusCode());			//We should still be proceeding			assertEquals(				"The server transaction left the PROCEEDING state.",				TransactionState.PROCEEDING,				tran.getState());			//Create a 2xx final response and test transaction termination			Response ok = null;			try {				ok =					tiMessageFactory.createResponse(						Response.OK,						tran.getRequest());				//!			discuss				ContactHeader contact = tiHeaderFactory.createContactHeader();				ok.addHeader(contact);				((ToHeader) ok.getHeader(ToHeader.NAME)).setTag(					Integer.toString(hashCode()));				addStatus(tran.getRequest(), ok);			} catch (ParseException ex) {				throw new TiUnexpectedError(					"A ParseException was thrown while trying to create an ok "						+ "response using TI",					ex);			}			try {				//listen for the OK response				responseCollector.collectResponseEvent(riSipProvider);			} catch (TooManyListenersException ex) {				throw new TckInternalError(					"Failed to register a SipListener with an RI SipProvider",					ex);			}			try {				tran.sendResponse(ok);			} catch (SipException ex) {				ex.printStackTrace();				fail("The TI failed to send a OK response");			}			//The Transaction should now be TERMINATED			assertEquals(				"The Transaction did not move to the TERMINATED state "					+ "after transmitting an OK response",				TransactionState.TERMINATED,				tran.getState());			//Check whether the OK is received by the RI.			waitForMessage();			responseEvent = responseCollector.extractCollectedResponseEvent();			assertNotNull(				"The OK response was not received by the RI",				responseEvent);			assertTrue(				"A response different from OK was sent by the TI",				Response.OK == responseEvent.getResponse().getStatusCode());			// Send an ACK to the other side.			Request ack = (Request) invite.clone();			ack.setMethod(Request.ACK);			((ToHeader) ack.getHeader(ToHeader.NAME)).setTag(				(((ToHeader) ok.getHeader(ToHeader.NAME)).getParameter("tag")));			try {				riSipProvider.sendRequest(ack);			} catch (SipException ex) {				ex.printStackTrace();				fail("error sending ack ");			}		} catch (Throwable exc) {			exc.printStackTrace();			fail(exc.getClass().getName() + ": " + exc.getMessage());		}		assertTrue(new Exception().getStackTrace()[0].toString(), true);	}