Examples of ServerTransaction


Examples of javax.sip.ServerTransaction

   
    SubscribeSession presenceSession = new SubscribeSession(getAlicePhone(), "presence");
    Request subscribe = presenceSession.newInitialSubscribe(100, getBobUri()); // 3
    presenceSession.sendRequest(subscribe, Response.OK); // 4

    ServerTransaction tx = presenceSession.waitForNotify(); // 5
    //System.out.println("3:\n" + tx.getRequest());
    presenceSession.sendResponse(Response.OK, tx); // 6
    Presence presence = getPresence(tx.getRequest());
    assertEquals(Basic.OPEN, presence.getTupleArray()[0].getStatus().getBasic());
   
   
    SubscribeSession winfoSession = new SubscribeSession(getBobPhone(), "presence.winfo"); // 7
    subscribe = winfoSession.newInitialSubscribe(60, getBobUri());
    winfoSession.sendRequest(subscribe, Response.OK); // 8
   
    tx = winfoSession.waitForNotify(); // 9
    Request notify = tx.getRequest();
    //System.out.println(notify);
    winfoSession.sendResponse(Response.OK, tx); // 10
    SubscriptionStateHeader subState = (SubscriptionStateHeader) notify.getHeader(SubscriptionStateHeader.NAME);
    assertEquals(SubscriptionStateHeader.ACTIVE.toLowerCase(), subState.getState().toLowerCase());
    assertEquals(WatcherInfoEventPackage.NAME, ((EventHeader) notify.getHeader(EventHeader.NAME)).getEventType());
    Watcherinfo watcherinfo = getWatcherinfo(notify);
    assertEquals(0, watcherinfo.getVersion().intValue());
    assertEquals(Watcherinfo.State.FULL, watcherinfo.getState());
    assertEquals(1, watcherinfo.getWatcherListArray().length);
    WatcherList watcherList = watcherinfo.getWatcherListArray(0);
    assertEquals(getBobUri(), watcherList.getResource());
    assertEquals(PresenceEventPackage.NAME, watcherList.getPackage());
    assertEquals(1, watcherList.getWatcherArray().length);
    Watcher watcher = watcherList.getWatcherArray(0);
    assertEquals(Event.SUBSCRIBE, watcher.getEvent());
    assertEquals(getAliceUri(), watcher.getStringValue());
    assertEquals(Status.ACTIVE, watcher.getStatus());
   
   
    HttpClient httpClient = new HttpClient();
    PutMethod put = new PutMethod(getHttpXcapUri() + BOB_PRES_RULES_URI); // 11
   
    InputStream is = WatcherInfoTest.class.getResourceAsStream("/xcap-root/pres-rules/users/put/elementPoliteBlock.xml");
    RequestEntity entity = new InputStreamRequestEntity(is, "application/xcap-el+xml");
    put.setRequestEntity(entity);
   
    int result = httpClient.executeMethod(put);
    assertEquals(200, result); // 12
    put.releaseConnection();
   
    tx = presenceSession.waitForNotify(); // 13
    //System.out.println("11:\n" + tx.getRequest());
    presenceSession.sendResponse(Response.OK, tx); // 14
    presence = getPresence(tx.getRequest());
    assertEquals(Basic.CLOSED, presence.getTupleArray()[0].getStatus().getBasic());
   
    tx = winfoSession.waitForNotify(); // 15
    notify = tx.getRequest();
    winfoSession.sendResponse(Response.OK, tx); // 16
    System.out.println(notify);
    subState = (SubscriptionStateHeader) notify.getHeader(SubscriptionStateHeader.NAME);
    assertEquals(SubscriptionStateHeader.ACTIVE.toLowerCase(), subState.getState().toLowerCase());
    assertEquals(WatcherInfoEventPackage.NAME, ((EventHeader) notify.getHeader(EventHeader.NAME)).getEventType());
View Full Code Here

Examples of javax.sip.ServerTransaction

       
        SubscribeSession presenceSession = new SubscribeSession(getBobPhone(), "presence");
    Request subscribe = presenceSession.newInitialSubscribe(0, getAliceUri()); // 3
    presenceSession.sendRequest(subscribe, Response.OK); // 4

    ServerTransaction tx = presenceSession.waitForNotify(); // 5
    System.out.println("5:\n" + tx.getRequest());
    presenceSession.sendResponse(Response.OK, tx); // 6
    Presence presence = getPresence(tx.getRequest());
    assertEquals(Basic.CLOSED, presence.getTupleArray()[0].getStatus().getBasic());
   
   
    SubscribeSession winfoSession = new SubscribeSession(getAlicePhone(), "presence.winfo"); // 7
    subscribe = winfoSession.newInitialSubscribe(60, getAliceUri());
    winfoSession.sendRequest(subscribe, Response.OK); // 8
   
    tx = winfoSession.waitForNotify(); // 9
    Request notify = tx.getRequest();
    System.out.println("9:\n" +notify);
    winfoSession.sendResponse(Response.OK, tx); // 10
    SubscriptionStateHeader subState = (SubscriptionStateHeader) notify.getHeader(SubscriptionStateHeader.NAME);
    assertEquals(SubscriptionStateHeader.ACTIVE.toLowerCase(), subState.getState().toLowerCase());
    assertEquals(WatcherInfoEventPackage.NAME, ((EventHeader) notify.getHeader(EventHeader.NAME)).getEventType());
    Watcherinfo watcherinfo = getWatcherinfo(notify);
    assertEquals(0, watcherinfo.getVersion().intValue());
    assertEquals(Watcherinfo.State.FULL, watcherinfo.getState());
    assertEquals(1, watcherinfo.getWatcherListArray().length);
    WatcherList watcherList = watcherinfo.getWatcherListArray(0);
    assertEquals(getAliceUri(), watcherList.getResource());
    assertEquals(PresenceEventPackage.NAME, watcherList.getPackage());
    assertEquals(1, watcherList.getWatcherArray().length);
    Watcher watcher = watcherList.getWatcherArray(0);
    assertEquals(Event.TIMEOUT, watcher.getEvent());
    assertEquals(getBobUri(), watcher.getStringValue());
    assertEquals(Status.WAITING, watcher.getStatus())
   
   
    HttpClient httpClient = new HttpClient();
    PutMethod put = new PutMethod(getHttpXcapUri() + ALICE_PRES_RULES_URI); // 11
   
    InputStream is = WatcherInfoTest.class.getResourceAsStream("/xcap-root/pres-rules/users/put/elementCondAliceBob.xml");
    RequestEntity entity = new InputStreamRequestEntity(is, "application/xcap-el+xml");
    put.setRequestEntity(entity);
   
    int result = httpClient.executeMethod(put);
    assertEquals(200, result); // 12
    put.releaseConnection();
   
    presenceSession = new SubscribeSession(getBobPhone(), "presence");
    subscribe = presenceSession.newInitialSubscribe(0, getAliceUri()); // 13
    presenceSession.sendRequest(subscribe, Response.OK); // 14

    tx = presenceSession.waitForNotify(); // 15
    System.out.println("15:\n" + tx.getRequest());
    presenceSession.sendResponse(Response.OK, tx); // 16
    presence = getPresence(tx.getRequest());
    assertEquals(Basic.OPEN, presence.getTupleArray()[0].getStatus().getBasic());
   
    publish = publishSession.newUnpublish(); // 25
    publishSession.sendRequest(publish, Response.OK); // 26
  }
View Full Code Here

Examples of javax.sip.ServerTransaction

    public boolean isLastRequestUncommited()
    {
         if (_indexLastReadRequest >= _receivedRequests.size())
           return false;
        
         ServerTransaction tx = _receivedRequests.get(_indexLastReadRequest).getServerTransaction();
         return  tx.getState() != TransactionState.COMPLETED
             && tx.getState() != TransactionState.TERMINATED;
    }
View Full Code Here

Examples of javax.sip.ServerTransaction



        public void processRequest(RequestEvent requestEvent) {
            Request request = requestEvent.getRequest();
            ServerTransaction serverTransactionId = requestEvent
                    .getServerTransaction();

            System.out.println("\n\nRequest " + request.getMethod()
                    + " received at " + sipStack.getStackName()
                    + " with server transaction id " + serverTransactionId);
View Full Code Here

Examples of javax.sip.ServerTransaction



        public void processRequest(RequestEvent requestEvent) {
            Request request = requestEvent.getRequest();
            ServerTransaction serverTransactionId = requestEvent
                    .getServerTransaction();

            System.out.println("\n\nRequest " + request.getMethod()
                    + " received at " + sipStack.getStackName()
                    + " with server transaction id " + serverTransactionId);
View Full Code Here

Examples of javax.sip.ServerTransaction

    }

    public void processRequest(RequestEvent requestEvent) {

        Request request = requestEvent.getRequest();
        ServerTransaction serverTransactionId = requestEvent
                .getServerTransaction();

        logger.info("\n\nRequest " + request.getMethod()
                + " received at " + sipStack.getStackName()
                + " with server transaction id " + serverTransactionId
View Full Code Here

Examples of javax.sip.ServerTransaction

                return;
            }

            // Always create a ServerTransaction, best as early as possible in the code
            Response response = null;
            ServerTransaction st = requestEvent.getServerTransaction();
            if (st == null) {
                st = sipProvider.getNewServerTransaction(refer);
            }

            // Check if it is an initial SUBSCRIBE or a refresh / unsubscribe
            String toTag = Integer.toHexString( (int) (Math.random() * Integer.MAX_VALUE) );
            response = messageFactory.createResponse(202, refer);
            ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME);

            // Sanity check: to header should not have a tag. Else the dialog
            // should have matched
            TestHarness.assertNull("To-tag!=null but no dialog match! My dialog=" + dialog, toHeader.getTag());
            toHeader.setTag(toTag); // Application is supposed to set.

            this.dialog = st.getDialog();
            // REFER dialogs do not terminate on bye.
            this.dialog.terminateOnBye(false);
            if (dialog != null) {
                logger.info("Dialog " + dialog);
                logger.info("Dialog state " + dialog.getState());
                logger.info( "local tag=" + dialog.getLocalTag() );
                logger.info( "remote tag=" + dialog.getRemoteTag() );
            }

            // Both 2xx response to SUBSCRIBE and NOTIFY need a Contact
            Address address = addressFactory.createAddress("Referee <sip:127.0.0.1>");
            ((SipURI)address.getURI()).setPort( mySipProvider.getListeningPoint(transport).getPort() );
            ContactHeader contactHeader = headerFactory.createContactHeader(address);
            response.addHeader(contactHeader);

            // Expires header is mandatory in 2xx responses to REFER
            ExpiresHeader expires = (ExpiresHeader) refer.getHeader( ExpiresHeader.NAME );
            if (expires==null) {
                expires = headerFactory.createExpiresHeader(30);// rather short
            }
            response.addHeader( expires );

            /*
             * The REFER MUST be answered first.
             */
            TestHarness.assertNull( dialog.getState() );
            st.sendResponse(response);
            TestHarness.assertEquals( DialogState.CONFIRMED, dialog.getState() );

            // NOTIFY MUST have "refer" event, possibly with id
            referEvent = headerFactory.createEventHeader("refer");

View Full Code Here

Examples of javax.sip.ServerTransaction

      } catch(SipException e){ 
        e.printStackTrace();
        System.err.println(e.getMessage());
      }
           
        ServerTransaction serverTransaction = requestEvent.getServerTransaction();
        if(serverTransaction==null){
          try {
            serverTransaction = sipProvider.getNewServerTransaction(requestEvent.getRequest());
          } catch (TransactionAlreadyExistsException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          } catch (TransactionUnavailableException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        }
        serverTransactions.add(callIDheaders.size()-1,serverTransaction);
       
    }
    if(requestEvent.getRequest().getMethod().equals(Request.ACK))
    {
      //System.out.println("ACK bekommen");
      //System.out.println(requestEvent.getDialog());
      //DialogsOfA for BYE User B
      //DialogsOfA.add(requestEvent.getDialog());
    }
    if(requestEvent.getRequest().getMethod().equals(Request.BYE))
    {
      //System.out.println("Bye bekommen");
      //System.out.println(requestEvent.getDialog());
      Response responseOk;
      try {
        responseOk = messageFactory.createResponse(Response.OK, requestEvent.getRequest());
        ServerTransaction serverTransaction = requestEvent.getServerTransaction();
        serverTransaction.sendResponse(responseOk);
      } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (SipException e) {
        // TODO Auto-generated catch block
View Full Code Here

Examples of javax.sip.ServerTransaction

 
  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 < callIDheaders.size(); i++) {
          if(callIDheaders.get(i).equals(responseEvent.getResponse().getHeader(CallIdHeader.NAME))){
            requestEventz = (RequestEvent) requestEvents.get(i);
            serverTransactiond = (ServerTransaction) serverTransactions.get(callIDheaders.indexOf(callIDheaders.get(i)));
            break;
          }
        }
      }catch(Exception e){
        System.out.println("For-loop Exception:" + e);
      }

      try {
          sendResponse(serverTransactiond,messageFactory.createResponse(Response.RINGING, requestEventz.getRequest()));
      } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    CSeqHeader cseq2 = (CSeqHeader) responseEvent.getResponse().getHeader(CSeqHeader.NAME);
    //OK BEKOMMEN
    if(responseEvent.getResponse().getStatusCode() == 200 && cseq2.getMethod().equals("INVITE")){
      //System.out.println("confirmed OK bekommen");
      DialogsOfB.add(responseEvent.getDialog());
      callIDheadersDia.add((CallIdHeader) responseEvent.getResponse().getHeader(CallIdHeader.NAME));
     
      CSeqHeader cseq = (CSeqHeader) responseEvent.getResponse().getHeader(CSeqHeader.NAME);
      try{
        Dialog dialog = responseEvent.getClientTransaction().getDialog();
        Request ack = dialog.createAck(cseq.getSeqNumber());
        //System.out.println("Ack sent");
        dialog.sendAck(ack);
      }catch (SipException e) {
        e.printStackTrace();
        System.err.println(e.getMessage());
      }catch (InvalidArgumentException e) {
        e.printStackTrace();
        System.err.println(e.getMessage());
      }
     
      RequestEvent requestEventz = null;
      ServerTransaction serverTransactiond = null;
      try{
        //For Loop again
        for (int i = 0; i < callIDheaders.size(); i++) { 
          if(callIDheaders.get(i).equals(responseEvent.getResponse().getHeader(CallIdHeader.NAME))){
            requestEventz = (RequestEvent) requestEvents.get(i);
View Full Code Here

Examples of javax.sip.ServerTransaction

  public void processRequest(RequestEvent requestEvent) {
    //Invite received
    if(requestEvent.getRequest().getMethod().equals(Request.INVITE)){
      //System.out.println("INVITE bekommen");
      try
        ServerTransaction serverTransaction = requestEvent.getServerTransaction();
        if(serverTransaction==null){
          serverTransaction = sipProvider.getNewServerTransaction(requestEvent.getRequest());
        }
        Response responseRing = messageFactory.createResponse(Response.RINGING, requestEvent.getRequest());
        responseRing.addHeader(contactHeader);
        serverTransaction.sendResponse(responseRing);
        //System.out.println("Ringing sent");
        //System.out.println("Ringing sent");
        Response responseOk = messageFactory.createResponse(Response.OK, requestEvent.getRequest());
        responseOk.addHeader(contactHeader);
        serverTransaction.sendResponse(responseOk);
        //System.out.println("OK sent");
        //System.out.println("Ok sent");
      } catch (SipException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (InvalidArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    if(requestEvent.getRequest().getMethod().equals(Request.ACK))
    {
      //System.out.println("ACK bekommen");
      //System.out.println("ACK bekommen");
      //System.out.println(requestEvent.getDialog());
    }
    if(requestEvent.getRequest().getMethod().equals(Request.BYE))
    {
      //System.out.println("BYE bekommen");
      //System.out.println("Bye bekommen");
      //System.out.println(requestEvent.getDialog());
     
      Response responseOk;
      try {
        responseOk = messageFactory.createResponse(Response.OK, requestEvent.getRequest());
        ServerTransaction serverTransaction = requestEvent.getServerTransaction();
        serverTransaction.sendResponse(responseOk);
       
      } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (SipException e) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.