Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package performance.uas_uac;
  
  import java.util.Vector;
  
 
 
 public class Two implements SipListener{
 	private static SipStack sipStack;
 	private static ListeningPoint listeningPoint;
 	private static SipProvider sipProvider;
 	private static AddressFactory addressFactory;
 	private static MessageFactory messageFactory;
 	private static HeaderFactory headerFactory;
 	private static Vector<StringbusyNumbers = new Vector<String>();
 	private static Vector<RequestEventrequestEvents = new Vector<RequestEvent>();
 	private static Vector<DialogDialogsOfB = new Vector<Dialog>();
 	private static Vector<DialogDialogsOfA = new Vector<Dialog>();
 	private static Vector<CallIdHeadercallIDheaders = new Vector<CallIdHeader>();
 	private static Vector<CallIdHeadercallIDheadersDia = new Vector<CallIdHeader>();
 	private static long countId = 0;
 	private static ContactHeader contactHeader = null;
 	private static String transport="udp";
 	
 	public static void main(String[] args) {
 		//Factorys
 		SipFactory sipFactory = SipFactory.getInstance();
 		sipFactory.setPathName("gov.nist");
 		
 		try {
 		} catch (PeerUnavailableException e) {
 		}
 		//Stack
 		try{
 			Properties properties = new Properties();
 			
 			properties.setProperty("javax.sip.STACK_NAME""empf");
 //			properties.setProperty("gov.nist.javax.sip.REENTRANT_LISTENER", "true");
 //			properties.setProperty("gov.nist.javax.sip.THREAD_POOL_SIZE", "2");
 //			properties.setProperty("gov.nist.javax.sip.DEBUG_LOG","debug.txt");
 			properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL""NONE");
 //			properties.setProperty("gov.nist.javax.sip.DELIVER_TERMINATED_EVENT_FOR_ACK", "false");
 //			properties.setProperty("gov.nist.javax.sip.MAX_LISTENER_RESPONSE_TIME", "60");
 			
 			 = sipFactory.createSipStack(properties);
 		}
 		catch (PeerUnavailableException e) {
 		}
 		
 		//Listening Point
 		try{
 		}
		}
		}
		//SIP Provider
		try{
		}
		}
		try
		{
		}
		{
		}
		//Set reroute numbers
		.add("003244");
		.add("0703344552");
		//Lists
//		while(true){
//			try {
//				Thread.sleep(1000);
//			} catch (InterruptedException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//			System.out.println(requestEvents);
//			System.out.println(DialogsOfA);
//			System.out.println(DialogsOfB);
//			System.out.println(callIDheadersDia);
//			System.out.println(callIDheaders);
//			System.out.println(serverTransactions);
//		}
	}
	private static Request createMessage(String fromString toCallIdHeader callId){
		Request request = null;
		 += 1;//increase it for new hash
		//Invite
		try {	
			// create From Header
			SipURI fromAddress = .createSipURI(from"send.com");
			Address fromNameAddress = .createAddress(fromAddress);
			fromNameAddress.setDisplayName(from);
			FromHeader fromHeader = .createFromHeader(fromNameAddress,"12345");
			// create To Header
			SipURI toAddress = .createSipURI(to"empf.com");
			Address toNameAddress = .createAddress(toAddress);
			toNameAddress.setDisplayName(to);
			ToHeader toHeader = .createToHeader(toNameAddressnull);
			// create Request URI
			SipURI requestURI = .createSipURI(from"127.0.0.1:5070");
			// Create ViaHeaders
			ArrayList viaHeaders = new ArrayList();
			ViaHeader viaHeader = .createViaHeader("127.0.0.1",
			viaHeaders.add(viaHeader);
			// Create a new CallId header
			CallIdHeader callIdHeader = callId;
			//callIdHeader.setCallId("1");
			// Create a new Cseq header
			// Create a new MaxForwardsHeader
			// Create the request.
					callIdHeadercSeqHeaderfromHeadertoHeaderviaHeadersmaxForwards);
			// Create contact headers
			String host = "127.0.0.1";
			SipURI contactUrl = .createSipURI(fromhost);
			// Create the contact name address.
			SipURI contactURI = .createSipURI(fromhost);
			Address contactAddress = .createAddress(contactURI);
			// Add the contact address.
			contactAddress.setDisplayName(from);
catch (ParseException e) {
		}
		return request;
	}
	}
	public void processIOException(IOExceptionEvent arg0) {
	    ..println("processIOException----------------------------------");
	}
	public void processRequest(RequestEvent requestEvent) {
		//Invite received
		if(requestEvent.getRequest().getMethod().equals(.)){
			//System.out.println("INVITE bekommen");
			//send new invite
			FromHeader fromHeader = (FromHeaderrequestEvent.getRequest().getHeader(.);
			String fromHeaderName = fromHeader.getAddress().getDisplayName();
			//Get callID
//			invitesDone.add(callID);
//			invitesSent++;
			//Save Event for responding later
			Request request = createMessage(fromHeaderName"reroute"callID);
			try{
				ClientTransaction clientTransaction = .getNewClientTransaction(request);
//				clientTransaction.setRetransmitTimer(990000);
				clientTransaction.sendRequest();
				//System.out.println("Invite sent");
catch(SipException e){	
			}
				ServerTransaction serverTransaction = requestEvent.getServerTransaction();
				if(serverTransaction==null){
					try {
						serverTransaction = .getNewServerTransaction(requestEvent.getRequest());
						// TODO Auto-generated catch block
						// TODO Auto-generated catch block
					}
				}
				.add(.size()-1,serverTransaction);
		}
		if(requestEvent.getRequest().getMethod().equals(.))
		{
			//System.out.println("ACK bekommen");
			//System.out.println(requestEvent.getDialog());
			//DialogsOfA for BYE User B
			//DialogsOfA.add(requestEvent.getDialog());
		}
		if(requestEvent.getRequest().getMethod().equals(.))
		{
			//System.out.println("Bye bekommen");
			//System.out.println(requestEvent.getDialog());
			Response responseOk;
			try {
				responseOk = .createResponse(.requestEvent.getRequest());
				ServerTransaction serverTransaction = requestEvent.getServerTransaction();
				serverTransaction.sendResponse(responseOk);
catch (ParseException e) {
				// TODO Auto-generated catch block
catch (SipException e) {
				// TODO Auto-generated catch block
catch (InvalidArgumentException e) {
				// TODO Auto-generated catch block
			}	
			//System.out.println("Ok (bye) sent");
			Dialog dialog = null;
			try{
			for (int i = 0; i < .size(); i++) {
					dialog = .get(i);
					break;
				}
			}
		}catch(Exception e){
			..println("For-loop Exception:" + e);
		}
			Request byeRequest;
			try {
				byeRequest = dialog.createRequest(.);
catch (SipException e) {
				// TODO Auto-generated catch block
			}
			//System.out.println("Bye sent");
		}
	}
	public void sendResponse(ServerTransaction serverTransaction,Response response){
		try {
			serverTransaction.sendResponse(response);
			//System.out.println(response.getStatusCode()+" gesendet");
catch (SipException e) {
			// TODO Auto-generated catch block
catch (InvalidArgumentException e) {
			// TODO Auto-generated catch block
		}
	}
	public void processResponse(ResponseEvent responseEvent) {
		if(responseEvent.getResponse().getStatusCode() == 180){
			//System.out.println("Ringing bekommen");
			RequestEvent requestEventz = null;
			ServerTransaction serverTransactiond = null;
			try{
				//For Loop again
				for (int i = 0; i < .size(); i++) {
						requestEventz = (RequestEvent.get(i);
						break;
					}
				}
			}catch(Exception e){
				..println("For-loop Exception:" + e);
			}
			try {
					sendResponse(serverTransactiond,.createResponse(.requestEventz.getRequest()));
catch (ParseException e) {
				// TODO Auto-generated catch block
			}
		}
		CSeqHeader cseq2 = (CSeqHeaderresponseEvent.getResponse().getHeader(.);
		//OK BEKOMMEN
		if(responseEvent.getResponse().getStatusCode() == 200 && cseq2.getMethod().equals("INVITE")){
			//System.out.println("confirmed OK bekommen");
			.add(responseEvent.getDialog());
			try{
				Dialog dialog = responseEvent.getClientTransaction().getDialog();
				Request ack = dialog.createAck(cseq.getSeqNumber());
				//System.out.println("Ack sent");
				dialog.sendAck(ack);
			}catch (SipException e) {
			}
			RequestEvent requestEventz = null;
			ServerTransaction serverTransactiond = null;
			try{
				//For Loop again
				for (int i = 0; i < .size(); i++) {	
						requestEventz = (RequestEvent.get(i);
						serverTransactiond = (ServerTransaction.get(i);
						break;
					}
				}
			}catch(Exception e){
				..println("For-loop Exception:" + e);
			}
			.remove(requestEventz);
			.remove(serverTransactiond);
			try {
					sendResponse(serverTransactiond,.createResponse(.requestEventz.getRequest()));
catch (ParseException e) {
				// TODO Auto-generated catch block
			}
		}
		if(responseEvent.getResponse().getStatusCode() == 200 && cseq2.getMethod().equals("BYE")){
			//System.out.println("Terminated Ok bekommen");
		}
	}
	public void processTimeout(TimeoutEvent arg0) {
		{
		}
		..println("Timeout----------------------------------");
	}
	}
New to GrepCode? Check out our FAQ X