/** 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(); } }
/** Process the invite request. */ public void processInvite(RequestEvent requestEvent, ServerTransaction serverTransaction) { SipProvider sipProvider = (SipProvider) requestEvent.getSource(); Request request = requestEvent.getRequest(); try { System.out.println("shootme: got an Invite sending Trying"); // System.out.println("shootme: " + request); Response response = messageFactory.createResponse(Response.TRYING, request); ServerTransaction st = requestEvent.getServerTransaction(); if (st == null) { st = sipProvider.getNewServerTransaction(request); } dialog = st.getDialog(); st.sendResponse(response); this.okResponse = messageFactory.createResponse(Response.BUSY_HERE, request); ToHeader toHeader = (ToHeader) okResponse.getHeader(ToHeader.NAME); toHeader.setTag("4321"); // Application is supposed to set. this.inviteTid = st; // Defer sending the OK to simulate the phone ringing. this.inviteRequest = request; new Timer().schedule(new MyTimerTask(this), 100); } catch (Exception ex) { ex.printStackTrace(); System.exit(0); } }
/** Process the invite request. */ public void processInvite(RequestEvent requestEvent, ServerTransaction serverTransaction) { SipProvider sipProvider = (SipProvider) requestEvent.getSource(); Request request = requestEvent.getRequest(); try { System.out.println("b2bua: got an Invite sending Trying"); ServerTransaction st = requestEvent.getServerTransaction(); if (st == null) { st = sipProvider.getNewServerTransaction(request); } Dialog dialog = st.getDialog(); ToHeader to = (ToHeader) request.getHeader(ToHeader.NAME); SipURI toUri = (SipURI) to.getAddress().getURI(); SipURI target = registrar.get(toUri.getUser()); if (target == null) { System.out.println("User " + toUri + " is not registered."); throw new RuntimeException("User not registered " + toUri); } else { ClientTransaction otherLeg = call(target); otherLeg.setApplicationData(st); st.setApplicationData(otherLeg); dialog.setApplicationData(otherLeg.getDialog()); otherLeg.getDialog().setApplicationData(dialog); } } catch (Exception ex) { ex.printStackTrace(); System.exit(0); } }
public void run() { Request request = requestEvent.getRequest(); try { // System.out.println("shootme: got an Invite sending OK"); Response response = messageFactory.createResponse(180, request); ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME); Address address = addressFactory.createAddress("Shootme <sip:" + myAddress + ":" + myPort + ">"); ContactHeader contactHeader = headerFactory.createContactHeader(address); response.addHeader(contactHeader); // System.out.println("got a server tranasaction " + st); Dialog dialog = st.getDialog(); /* * if (dialog != null) { System.out.println("Dialog " + dialog); * System.out.println("Dialog state " + dialog.getState()); } */ st.sendResponse(response); // send 180(RING) response = messageFactory.createResponse(200, request); toHeader = (ToHeader) response.getHeader(ToHeader.NAME); String toTag = new Integer((int) (Math.random() * 1000)).toString(); toHeader.setTag(toTag); // Application is supposed to set. response.addHeader(contactHeader); st.sendResponse(response); // send 200(OK) } catch (Exception ex) { ex.printStackTrace(); System.exit(0); } }
/** Process the invite request. */ public void processInvite(RequestEvent requestEvent, ServerTransaction serverTransaction) { SipProvider sipProvider = (SipProvider) requestEvent.getSource(); Request request = requestEvent.getRequest(); try { logger.info("shootme: got an Invite sending Trying"); // logger.info("shootme: " + request); ServerTransaction st = requestEvent.getServerTransaction(); if (st == null) { logger.info("null server tx -- getting a new one"); st = sipProvider.getNewServerTransaction(request); } logger.info("getNewServerTransaction : " + st); String txId = ((ViaHeader) request.getHeader(ViaHeader.NAME)).getBranch(); this.serverTxTable.put(txId, st); // Create the 100 Trying response. Response response = protocolObjects.messageFactory.createResponse(Response.TRYING, request); ListeningPoint lp = sipProvider.getListeningPoint(protocolObjects.transport); int myPort = lp.getPort(); Address address = protocolObjects.addressFactory.createAddress( "Shootme <sip:" + myAddress + ":" + myPort + ">"); // Add a random sleep to stagger the two OK's for the benifit of implementations // that may not be too good about handling re-entrancy. int timeToSleep = (int) (Math.random() * 1000); Thread.sleep(timeToSleep); st.sendResponse(response); Response ringingResponse = protocolObjects.messageFactory.createResponse(Response.RINGING, request); ContactHeader contactHeader = protocolObjects.headerFactory.createContactHeader(address); response.addHeader(contactHeader); ToHeader toHeader = (ToHeader) ringingResponse.getHeader(ToHeader.NAME); String toTag = actAsNonRFC3261UAS ? null : new Integer((int) (Math.random() * 10000)).toString(); if (!actAsNonRFC3261UAS) toHeader.setTag(toTag); // Application is supposed to set. ringingResponse.addHeader(contactHeader); st.sendResponse(ringingResponse); Dialog dialog = st.getDialog(); dialog.setApplicationData(st); this.inviteSeen = true; new Timer().schedule(new MyTimerTask(requestEvent, st /*,toTag*/), 1000); } catch (Exception ex) { ex.printStackTrace(); System.exit(0); } }
public void skipApplyAndCommit(ServerTransaction txn) { final ChannelID channelID = txn.getChannelID(); final TransactionID txnID = txn.getTransactionID(); TransactionAccount ci = getTransactionAccount(channelID); fireTransactionAppliedEvent(txn.getServerTransactionID()); if (ci.skipApplyAndCommit(txnID)) { acknowledge(channelID, txnID); } }
private void sendInviteOK() { try { if (inviteTid.getState() != TransactionState.COMPLETED) { System.out.println("shootme: Dialog state before 486: " + inviteTid.getDialog().getState()); inviteTid.sendResponse(okResponse); System.out.println("shootme: Dialog state after 486: " + inviteTid.getDialog().getState()); } } catch (SipException ex) { ex.printStackTrace(); } catch (InvalidArgumentException ex) { ex.printStackTrace(); } }
/** Process the bye request. */ public void processBye(RequestEvent requestEvent, ServerTransaction serverTransactionId) { SipProvider sipProvider = (SipProvider) requestEvent.getSource(); Request request = requestEvent.getRequest(); try { System.out.println("shootme: got a bye sending OK."); Response response = messageFactory.createResponse(200, request); serverTransactionId.sendResponse(response); System.out.println("Dialog State is " + serverTransactionId.getDialog().getState()); } catch (Exception ex) { ex.printStackTrace(); System.exit(0); } }
public void processRegister(RequestEvent requestEvent, ServerTransaction serverTransactionId) { Request request = requestEvent.getRequest(); ContactHeader contact = (ContactHeader) request.getHeader(ContactHeader.NAME); SipURI contactUri = (SipURI) contact.getAddress().getURI(); FromHeader from = (FromHeader) request.getHeader(FromHeader.NAME); SipURI fromUri = (SipURI) from.getAddress().getURI(); registrar.put(fromUri.getUser(), contactUri); try { Response response = this.messageFactory.createResponse(200, request); ServerTransaction serverTransaction = sipProvider.getNewServerTransaction(request); serverTransaction.sendResponse(response); } catch (Exception e) { e.printStackTrace(); } }
/** Process the ACK request. Send the bye and complete the call flow. */ public void processAck(RequestEvent requestEvent, ServerTransaction serverTransaction) { SipProvider sipProvider = (SipProvider) requestEvent.getSource(); try { // System.out.println("*** shootme: got an ACK " // + requestEvent.getRequest()); if (serverTransaction == null) { System.out.println("null server transaction -- ignoring the ACK!"); return; } Dialog dialog = serverTransaction.getDialog(); this.createdCount++; System.out.println( "Dialog Created = " + dialog.getDialogId() + " createdCount " + this.createdCount + " Dialog State = " + dialog.getState()); if (this.dialogIds.contains(dialog.getDialogId())) { System.out.println("OOPS ! I already saw " + dialog.getDialogId()); } else { this.dialogIds.add(dialog.getDialogId()); } Request byeRequest = dialog.createRequest(Request.BYE); ClientTransaction tr = sipProvider.getNewClientTransaction(byeRequest); // System.out.println("shootme: got an ACK -- sending bye! "); dialog.sendRequest(tr); } catch (Exception ex) { ex.printStackTrace(); System.exit(0); } }
public void processBye(RequestEvent requestEvent, ServerTransaction serverTransaction) { try { logger.debug("DEBUG: IMByeProcessing, Processing BYE in progress..."); Request request = requestEvent.getRequest(); MessageFactory messageFactory = imUA.getMessageFactory(); InstantMessagingGUI instantMessagingGUI = imUA.getInstantMessagingGUI(); ListenerInstantMessaging listenerInstantMessaging = instantMessagingGUI.getListenerInstantMessaging(); ChatSessionManager chatSessionManager = listenerInstantMessaging.getChatSessionManager(); String buddy = IMUtilities.getKey(request, "From"); if (chatSessionManager.hasAlreadyChatSession(buddy)) { chatSessionManager.removeChatSession(buddy); // chatSession.setExitedSession(true,"Your contact has exited // the session"); } else { logger.debug("DEBUG: IMByeProcessing, processBye(), no active chatSession"); } // Send an OK Response response = messageFactory.createResponse(Response.OK, request); serverTransaction.sendResponse(response); logger.debug("DEBUG: IMByeProcessing, processBye(), OK replied to the BYE"); logger.debug("DEBUG: IMByeProcessing, Processing BYE completed..."); } catch (Exception ex) { ex.printStackTrace(); } }
private TransactionBatchContext transactionBatch(long clientId, long... transactionIds) { TransactionBatchContext context = mock(TransactionBatchContext.class); List<ServerTransaction> transactions = new ArrayList<ServerTransaction>(); List<ServerTransactionID> ids = transactionIDs(clientId, transactionIds); for (ServerTransactionID stxId : ids) { ServerTransaction transaction = mock(ServerTransaction.class); GlobalTransactionID globalTransactionID = getOrCreateGID(stxId); when(transaction.getGlobalTransactionID()).thenReturn(globalTransactionID); when(transaction.getServerTransactionID()).thenReturn(stxId); transactions.add(transaction); } when(context.getTransactionBatchReader()).thenReturn(batchReader); when(context.getNumTxns()).thenReturn(transactionIds.length); when(context.getTransactions()).thenReturn(transactions); when(context.getTransactionIDs()).thenReturn(Sets.newHashSet(ids)); when(context.getSourceNodeID()).thenReturn(new ClientID(clientId)); return context; }
public void incomingTransactions( ChannelID cid, Set txnIDs, Collection txns, boolean relayed, Collection completedTxnIds) { final boolean active = isActive(); TransactionAccount ci = getOrCreateTransactionAccount(cid); ci.incommingTransactions(txnIDs); for (Iterator i = txns.iterator(); i.hasNext(); ) { final ServerTransaction txn = (ServerTransaction) i.next(); final ServerTransactionID stxnID = txn.getServerTransactionID(); final TransactionID txnID = stxnID.getClientTransactionID(); if (active && !relayed) { ci.relayTransactionComplete(txnID); } else if (!active) { gtxm.createGlobalTransactionDescIfNeeded(stxnID, txn.getGlobalTransactionID()); } } fireIncomingTransactionsEvent(cid, txnIDs); resentTxnSequencer.addTransactions(txns, completedTxnIds); }
/** Process the ACK request, forward it to the other leg. */ public void processAck(RequestEvent requestEvent, ServerTransaction serverTransaction) { try { Dialog dialog = serverTransaction.getDialog(); System.out.println("b2bua: got an ACK! "); System.out.println("Dialog State = " + dialog.getState()); Dialog otherDialog = (Dialog) dialog.getApplicationData(); Request request = otherDialog.createAck(otherDialog.getLocalSeqNumber()); otherDialog.sendAck(request); } catch (Exception ex) { ex.printStackTrace(); } }
public void processCancel(RequestEvent requestEvent, ServerTransaction serverTransactionId) { SipProvider sipProvider = (SipProvider) requestEvent.getSource(); Request request = requestEvent.getRequest(); try { System.out.println("shootme: got a cancel."); if (serverTransactionId == null) { System.out.println("shootme: null tid."); return; } Response response = messageFactory.createResponse(200, request); serverTransactionId.sendResponse(response); if (dialog.getState() != DialogState.CONFIRMED) { response = messageFactory.createResponse(Response.REQUEST_TERMINATED, inviteRequest); inviteTid.sendResponse(response); } } catch (Exception ex) { ex.printStackTrace(); System.exit(0); } }
public void processBye(Request request, ServerTransaction serverTransactionId) { try { System.out.println("shootist: got a bye ."); if (serverTransactionId == null) { System.out.println("shootist: null TID."); return; } Dialog dialog = serverTransactionId.getDialog(); System.out.println("Dialog State = " + dialog.getState()); Response response = messageFactory.createResponse(200, request); serverTransactionId.sendResponse(response); System.out.println("shootist: Sending OK."); System.out.println("Dialog State = " + dialog.getState()); this.shutDown(); } catch (Exception ex) { ex.printStackTrace(); System.exit(0); } }
private void sendInviteOK(RequestEvent requestEvent, ServerTransaction inviteTid) { try { logger.info("sendInviteOK: " + inviteTid); if (inviteTid.getState() != TransactionState.COMPLETED) { logger.info("shootme: Dialog state before OK: " + inviteTid.getDialog().getState()); SipProvider sipProvider = (SipProvider) requestEvent.getSource(); Request request = requestEvent.getRequest(); Response okResponse = protocolObjects.messageFactory.createResponse(Response.OK, request); ListeningPoint lp = sipProvider.getListeningPoint(protocolObjects.transport); int myPort = lp.getPort(); Address address = protocolObjects.addressFactory.createAddress( "Shootme <sip:" + myAddress + ":" + myPort + ">"); ContactHeader contactHeader = protocolObjects.headerFactory.createContactHeader(address); okResponse.addHeader(contactHeader); inviteTid.sendResponse(okResponse); logger.info("shootme: Dialog state after OK: " + inviteTid.getDialog().getState()); TestHarness.assertEquals(DialogState.CONFIRMED, inviteTid.getDialog().getState()); } else { logger.info("semdInviteOK: inviteTid = " + inviteTid + " state = " + inviteTid.getState()); } } catch (Exception ex) { ex.printStackTrace(); } }
public void processCancel(RequestEvent requestEvent, ServerTransaction serverTransactionId) { Request request = requestEvent.getRequest(); SipProvider sipProvider = (SipProvider) requestEvent.getSource(); try { logger.info("shootme: got a cancel. "); // Because this is not an In-dialog request, you will get a null server Tx id here. if (serverTransactionId == null) { serverTransactionId = sipProvider.getNewServerTransaction(request); } Response response = protocolObjects.messageFactory.createResponse(200, request); serverTransactionId.sendResponse(response); String serverTxId = ((ViaHeader) response.getHeader(ViaHeader.NAME)).getBranch(); ServerTransaction serverTx = (ServerTransaction) this.serverTxTable.get(serverTxId); if (serverTx != null && (serverTx.getState().equals(TransactionState.TRYING) || serverTx.getState().equals(TransactionState.PROCEEDING))) { Request originalRequest = serverTx.getRequest(); Response resp = protocolObjects.messageFactory.createResponse( Response.REQUEST_TERMINATED, originalRequest); serverTx.sendResponse(resp); } } catch (Exception ex) { ex.printStackTrace(); System.exit(0); } }
public void processResponse(ResponseEvent responseEvent) { ClientTransaction ct = responseEvent.getClientTransaction(); Response response = responseEvent.getResponse(); ServerTransaction st = (ServerTransaction) ct.getApplicationData(); try { Response otherResponse = messageFactory.createResponse(response.getStatusCode(), st.getRequest()); if (response.getStatusCode() == 200 && ct.getRequest().getMethod().equals("INVITE")) { Address address = addressFactory.createAddress("B2BUA <sip:" + myAddress + ":" + myPort + ">"); ContactHeader contactHeader = headerFactory.createContactHeader(address); response.addHeader(contactHeader); ToHeader toHeader = (ToHeader) otherResponse.getHeader(ToHeader.NAME); if (toHeader.getTag() == null) toHeader.setTag(new Long(counter.getAndIncrement()).toString()); otherResponse.addHeader(contactHeader); } st.sendResponse(otherResponse); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
/** Process the any in dialog request - MESSAGE, BYE, INFO, UPDATE. */ public void processInDialogRequest( RequestEvent requestEvent, ServerTransaction serverTransactionId) { SipProvider sipProvider = (SipProvider) requestEvent.getSource(); Request request = requestEvent.getRequest(); Dialog dialog = requestEvent.getDialog(); System.out.println("local party = " + dialog.getLocalParty()); try { System.out.println("b2bua: got a bye sending OK."); Response response = messageFactory.createResponse(200, request); serverTransactionId.sendResponse(response); System.out.println("Dialog State is " + serverTransactionId.getDialog().getState()); Dialog otherLeg = (Dialog) dialog.getApplicationData(); Request otherBye = otherLeg.createRequest(request.getMethod()); ClientTransaction clientTransaction = sipProvider.getNewClientTransaction(otherBye); clientTransaction.setApplicationData(serverTransactionId); serverTransactionId.setApplicationData(clientTransaction); otherLeg.sendRequest(clientTransaction); } catch (Exception ex) { ex.printStackTrace(); System.exit(0); } }
public void apply( ServerTransaction txn, Map objects, BackReferences includeIDs, ObjectInstanceMonitor instanceMonitor) { final ServerTransactionID stxnID = txn.getServerTransactionID(); final ChannelID channelID = txn.getChannelID(); final TransactionID txnID = txn.getTransactionID(); final List changes = txn.getChanges(); GlobalTransactionID gtxID = txn.getGlobalTransactionID(); boolean active = isActive(); for (Iterator i = changes.iterator(); i.hasNext(); ) { DNA orgDNA = (DNA) i.next(); long version = orgDNA.getVersion(); if (version == DNA.NULL_VERSION) { Assert.assertFalse(gtxID.isNull()); version = gtxID.toLong(); } DNA change = new VersionizedDNAWrapper(orgDNA, version, true); ManagedObject mo = (ManagedObject) objects.get(change.getObjectID()); mo.apply(change, txnID, includeIDs, instanceMonitor, !active); if (active && !change.isDelta()) { // Only New objects reference are added here stateManager.addReference(txn.getChannelID(), mo.getID()); } } Map newRoots = txn.getNewRoots(); if (newRoots.size() > 0) { for (Iterator i = newRoots.entrySet().iterator(); i.hasNext(); ) { Entry entry = (Entry) i.next(); String rootName = (String) entry.getKey(); ObjectID newID = (ObjectID) entry.getValue(); objectManager.createRoot(rootName, newID); } } if (active) { channelStats.notifyTransaction(channelID); } transactionRateCounter.increment(); fireTransactionAppliedEvent(stxnID); }
/** Process the bye request. */ public void processBye(RequestEvent requestEvent, ServerTransaction serverTransactionId) { Request request = requestEvent.getRequest(); try { logger.info("shootme: got a bye sending OK."); logger.info("shootme: dialog = " + requestEvent.getDialog()); logger.info("shootme: dialogState = " + requestEvent.getDialog().getState()); Response response = protocolObjects.messageFactory.createResponse(200, request); if (serverTransactionId != null) { serverTransactionId.sendResponse(response); } logger.info("shootme: dialogState = " + requestEvent.getDialog().getState()); this.byeSeen = true; } catch (Exception ex) { ex.printStackTrace(); System.exit(0); } }
public void testWriteRead() throws IOException { long sequence = 0; ObjectStringSerializer serializer = new ObjectStringSerializer(); TestCommitTransactionMessageFactory mf = new TestCommitTransactionMessageFactory(); ChannelID channel = new ChannelID(69); TxnBatchID batchID = new TxnBatchID(42); List tx1Notifies = new LinkedList(); // A nested transaction (all this buys us is more than 1 lock in a txn) LockID lid1 = new LockID("1"); TransactionContext tc = new TransactionContext(lid1, TxnType.NORMAL, new LockID[] {lid1}); ClientTransaction tmp = new ClientTransactionImpl(new TransactionID(101), new NullRuntimeLogger(), null); tmp.setTransactionContext(tc); LockID lid2 = new LockID("2"); tc = new TransactionContext(lid2, TxnType.NORMAL, new LockID[] {lid1, lid2}); ClientTransaction txn1 = new ClientTransactionImpl(new TransactionID(1), new NullRuntimeLogger(), null); txn1.setTransactionContext(tc); txn1.fieldChanged( new MockTCObject(new ObjectID(1), this), "class", "class.field", ObjectID.NULL_ID, -1); txn1.createObject(new MockTCObject(new ObjectID(2), this)); txn1.createRoot("root", new ObjectID(3)); for (int i = 0; i < 10; i++) { Notify notify = new Notify(new LockID("" + i), new ThreadID(i), i % 2 == 0); tx1Notifies.add(notify); txn1.addNotify(notify); } tc = new TransactionContext(new LockID("3"), TxnType.CONCURRENT, new LockID[] {new LockID("3")}); ClientTransaction txn2 = new ClientTransactionImpl(new TransactionID(2), new NullRuntimeLogger(), null); txn2.setTransactionContext(tc); writer = new TransactionBatchWriter(batchID, serializer, encoding, mf); txn1.setSequenceID(new SequenceID(++sequence)); txn2.setSequenceID(new SequenceID(++sequence)); writer.addTransaction(txn1); writer.addTransaction(txn2); writer.wait4AllTxns2Serialize(); TransactionBatchReaderImpl reader = new TransactionBatchReaderImpl( gidGenerator, writer.getData(), channel, new HashSet(), serializer, new ActiveServerTransactionFactory()); assertEquals(2, reader.getNumTxns()); assertEquals(batchID, reader.getBatchID()); int count = 0; ServerTransaction txn; while ((txn = reader.getNextTransaction()) != null) { count++; assertEquals(channel, txn.getChannelID()); assertEquals(count, txn.getTransactionID().toLong()); switch (count) { case 1: assertEquals(2, txn.getChanges().size()); assertEquals(1, txn.getNewRoots().size()); assertEquals("root", txn.getNewRoots().keySet().toArray()[0]); assertEquals(new ObjectID(3), txn.getNewRoots().values().toArray()[0]); assertEquals(2, txn.getObjectIDs().size()); assertTrue( txn.getObjectIDs() .containsAll(Arrays.asList(new ObjectID[] {new ObjectID(1), new ObjectID(2)}))); assertEquals(TxnType.NORMAL, txn.getTransactionType()); assertTrue( Arrays.equals(new LockID[] {new LockID("1"), new LockID("2")}, txn.getLockIDs())); assertEquals(tx1Notifies, txn.getNotifies()); break; case 2: assertEquals(0, txn.getChanges().size()); assertEquals(0, txn.getNewRoots().size()); assertEquals(0, txn.getObjectIDs().size()); assertEquals(TxnType.CONCURRENT, txn.getTransactionType()); assertTrue(Arrays.equals(new LockID[] {new LockID("3")}, txn.getLockIDs())); break; default: fail("count is " + count); } } assertEquals(2, count); }
@Test public void testVis() throws Exception { TestEntry myEntry = new TestEntry(); myEntry.init(); MangledEntry myPackedEntry = _mangler.mangle(myEntry); EventListener myVis = new EventListener(); EventListener myVisOnly = new EventListener(); EventListener myNotify = new EventListener(); _space.visibility( new MangledEntry[] {myPackedEntry}, null, myVis, Lease.FOREVER, new MarshalledObject(new String("Here's a vis handback")), false); _space.visibility( new MangledEntry[] {myPackedEntry}, null, myVisOnly, Lease.FOREVER, new MarshalledObject(new String("Here's a vis-only handback")), true); _space.notify( myPackedEntry, null, myNotify, Lease.FOREVER, new MarshalledObject(new String("Here's a handback"))); for (int i = 0; i < 2; i++) { _space.write(myPackedEntry, null, Lease.FOREVER); } Assert.assertEquals(2, myVis.waitOnNotifyCount(2, 500)); Assert.assertEquals(2, myVis.getAvailabilityCount()); Assert.assertEquals(2, myVisOnly.waitOnNotifyCount(2, 500)); Assert.assertEquals(2, myVisOnly.getAvailabilityCount()); Assert.assertEquals(2, myNotify.waitOnNotifyCount(2, 500)); Assert.assertEquals(0, myNotify.getAvailabilityCount()); ServerTransaction myTxn = _mgr.newTxn(); Assert.assertNotNull(_space.take(myPackedEntry, myTxn, 0)); // Aborted take transaction causes a vis and avail change // myTxn.abort(); Assert.assertEquals(3, myVis.waitOnNotifyCount(3, 500)); Assert.assertEquals(3, myVis.getAvailabilityCount()); Assert.assertEquals(3, myVisOnly.waitOnNotifyCount(3, 500)); Assert.assertEquals(3, myVisOnly.getAvailabilityCount()); Assert.assertEquals(2, myNotify.waitOnNotifyCount(2, 500)); Assert.assertEquals(0, myNotify.getAvailabilityCount()); ServerTransaction myTxn1 = _mgr.newTxn(); ServerTransaction myTxn2 = _mgr.newTxn(); Assert.assertNotNull(_space.read(myPackedEntry, myTxn1, 0)); Assert.assertNotNull(_space.read(myPackedEntry, myTxn2, 0)); // Because there are two transactions "stacked" on the same entry, releasing the first one // generates // no events. Releasing the second one, causes a change in availability but not visibility // myTxn1.abort(); myTxn2.commit(); Assert.assertEquals(4, myVis.waitOnNotifyCount(4, 500)); Assert.assertEquals(4, myVis.getAvailabilityCount()); Assert.assertEquals(3, myVisOnly.waitOnNotifyCount(3, 500)); Assert.assertEquals(3, myVisOnly.getAvailabilityCount()); Assert.assertEquals(2, myNotify.waitOnNotifyCount(2, 500)); Assert.assertEquals(0, myNotify.getAvailabilityCount()); }
/** * Implements {@link MethodProcessor#processRequest(RequestEvent)}. Handles only NOTIFY requests * because they are the only requests concerning event package subscribers and if the processing * of a given request requires event package-specific handling, delivers the request to the * matching Subscription instance. Examples of such event package-specific handling include * handling the termination of an existing Subscription and processing the bodies of the NOTIFY * requests for active Subscriptions. * * @param requestEvent a <tt>RequestEvent</tt> specifying the SIP <tt>Request</tt> to be processed * @return <tt>true</tt> if the SIP <tt>Request</tt> specified by <tt>requestEvent</tt> was * processed; otherwise, <tt>false</tt> */ @Override public boolean processRequest(RequestEvent requestEvent) { Request request = requestEvent.getRequest(); EventHeader eventHeader = (EventHeader) request.getHeader(EventHeader.NAME); if ((eventHeader == null) || !eventPackage.equalsIgnoreCase(eventHeader.getEventType())) { /* * We are not concerned by this request, perhaps another listener * is. So don't send a 489 / Bad event answer here. */ return false; } if (!Request.NOTIFY.equals(request.getMethod())) return false; if (logger.isDebugEnabled()) logger.debug("notify received"); SubscriptionStateHeader sstateHeader = (SubscriptionStateHeader) request.getHeader(SubscriptionStateHeader.NAME); // notify must contain one (rfc3265) if (sstateHeader == null) { logger.error("no subscription state in this request"); return false; } String sstate = sstateHeader.getState(); ServerTransaction serverTransaction = getOrCreateServerTransaction(requestEvent); // first handle the case of a contact still pending // it's possible if the NOTIFY arrives before the OK CallIdHeader callIdHeader = (CallIdHeader) request.getHeader(CallIdHeader.NAME); String callId = callIdHeader.getCallId(); Subscription subscription = getSubscription(callId); // see if the notify correspond to an existing subscription if ((subscription == null) && !SubscriptionStateHeader.TERMINATED.equalsIgnoreCase(sstate)) { if (logger.isDebugEnabled()) logger.debug("subscription not found for callId " + callId); // send a 481 response (rfc3625) Response response; try { response = protocolProvider .getMessageFactory() .createResponse(Response.CALL_OR_TRANSACTION_DOES_NOT_EXIST, request); } catch (ParseException e) { logger.error("failed to create the 481 response", e); return false; } try { serverTransaction.sendResponse(response); } catch (SipException e) { logger.error("failed to send the response", e); } catch (InvalidArgumentException e) { // should not happen logger.error("invalid argument provided while trying to send the response", e); } return true; } // if we don't understand the content ContentTypeHeader ctheader = (ContentTypeHeader) request.getHeader(ContentTypeHeader.NAME); if ((ctheader != null) && !ctheader.getContentSubType().equalsIgnoreCase(contentSubType)) { // send a 415 response (rfc3261) Response response; try { response = protocolProvider .getMessageFactory() .createResponse(Response.UNSUPPORTED_MEDIA_TYPE, request); } catch (ParseException e) { logger.error("failed to create the OK response", e); return false; } // we want PIDF AcceptHeader acceptHeader; try { acceptHeader = protocolProvider.getHeaderFactory().createAcceptHeader("application", contentSubType); } catch (ParseException e) { // should not happen logger.error("failed to create the accept header", e); return false; } response.setHeader(acceptHeader); try { serverTransaction.sendResponse(response); } catch (SipException e) { logger.error("failed to send the response", e); } catch (InvalidArgumentException e) { // should not happen logger.error("invalid argument provided while trying" + " to send the response", e); } } // if the presentity doesn't want of us anymore if (SubscriptionStateHeader.TERMINATED.equalsIgnoreCase(sstate)) { // if we requested this end of subscription, subscription == null if (subscription != null) { removeSubscription(callId, subscription); subscription.processTerminatedRequest(requestEvent, sstateHeader.getReasonCode()); } } // send an OK response Response response; try { response = protocolProvider.getMessageFactory().createResponse(Response.OK, request); } catch (ParseException e) { logger.error("failed to create the OK response", e); return false; } try { serverTransaction.sendResponse(response); } catch (SipException e) { logger.error("failed to send the response", e); } catch (InvalidArgumentException e) { // should not happen logger.error("invalid argument provided while trying to send the response", e); } // transform the presence document in new presence status if (subscription != null) subscription.processActiveRequest(requestEvent, request.getRawContent()); return true; }
/** * Dispatches the event received from a JAIN-SIP <tt>SipProvider</tt> to one of our "candidate * recipient" listeners. * * @param event the event received for a <tt>SipProvider</tt>. */ public void processRequest(RequestEvent event) { try { Request request = event.getRequest(); if (logger.isTraceEnabled()) logger.trace("received request: " + request.getMethod()); /* * Create the transaction if it doesn't exist yet. If it is a * dialog-creating request, the dialog will also be automatically * created by the stack. */ if (event.getServerTransaction() == null) { try { // apply some hacks if needed on incoming request // to be compliant with some servers/clients // if needed stop further processing. if (applyNonConformanceHacks(event)) return; SipProvider source = (SipProvider) event.getSource(); ServerTransaction transaction = source.getNewServerTransaction(request); /* * Update the event, otherwise getServerTransaction() and * getDialog() will still return their previous value. */ event = new RequestEvent(source, transaction, transaction.getDialog(), request); } catch (SipException ex) { logger.error( "couldn't create transaction, please report " + "this to [email protected]", ex); } } ProtocolProviderServiceSipImpl service = getServiceData(event.getServerTransaction()); if (service != null) { service.processRequest(event); } else { service = findTargetFor(request); if (service == null) { logger.error("couldn't find a ProtocolProviderServiceSipImpl " + "to dispatch to"); if (event.getServerTransaction() != null) event.getServerTransaction().terminate(); } else { /* * Mark the dialog for the dispatching of later in-dialog * requests. If there is no dialog, we need to mark the * request to dispatch a possible timeout when sending the * response. */ Object container = event.getDialog(); if (container == null) container = request; SipApplicationData.setApplicationData(container, SipApplicationData.KEY_SERVICE, service); service.processRequest(event); } } } catch (Throwable exc) { /* * Any exception thrown within our code should be caught here so * that we could log it rather than interrupt stack activity with * it. */ this.logApplicationException(DialogTerminatedEvent.class, exc); // Unfortunately, death can hardly be ignored. if (exc instanceof ThreadDeath) throw (ThreadDeath) exc; } }
public void processSubscribe(Request request, ServerTransaction serverTransaction) { logger.debug("Processing SUBSCRIBE in progress "); try { MessageFactory messageFactory = imUA.getMessageFactory(); HeaderFactory headerFactory = imUA.getHeaderFactory(); AddressFactory addressFactory = imUA.getAddressFactory(); Dialog dialog = serverTransaction.getDialog(); // ********** Terminating subscriptions ********** ExpiresHeader expiresHeader = (ExpiresHeader) request.getHeader(ExpiresHeader.NAME); if (expiresHeader != null && expiresHeader.getExpires() == 0) { if (dialog != null) { // Terminating an existing subscription Response response = messageFactory.createResponse(Response.OK, request); serverTransaction.sendResponse(response); IMNotifyProcessing imNotifyProcessing = imUA.getIMNotifyProcessing(); imNotifyProcessing.sendNotify(response, null, dialog); return; } else { // Terminating an non existing subscription Response response = messageFactory.createResponse(Response.CALL_OR_TRANSACTION_DOES_NOT_EXIST, request); serverTransaction.sendResponse(response); return; } } // ********** Non-terminating subscriptions ************ // send a 202 Accepted while waiting for authorization from user Response response = messageFactory.createResponse(Response.ACCEPTED, request); // Tag: ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME); if (toHeader.getTag() == null) toHeader.setTag(new Integer((int) (Math.random() * 10000)).toString()); serverTransaction.sendResponse(response); logger.debug(response.toString()); // We have to ask the user to authorize the guy to be in his buddy // list String presentityURL = IMUtilities.getKey(request, "From"); SipProvider sipProvider = imUA.getSipProvider(); InstantMessagingGUI imGUI = imUA.getInstantMessagingGUI(); boolean authorization = imGUI.getAuthorizationForBuddy(presentityURL); if (authorization) { logger.debug( "DEBUG: SubscribeProcessing, processSubscribe(), " + " Response 202 Accepted sent."); // We have to create or update the subscriber! PresenceManager presenceManager = imUA.getPresenceManager(); String subscriberURL = IMUtilities.getKey(request, "From"); if (dialog != null) presenceManager.addSubscriber(subscriberURL, response, dialog); else { logger.debug( "ERROR, IMSubscribeProcessing, processSubscribe(), the" + " dialog for the SUBSCRIBE we received is null!!! No subscriber added...."); return; } // Let's see if this buddy is in our buddy list // if not let's ask to add him! BuddyList buddyList = imGUI.getBuddyList(); ListenerInstantMessaging listenerIM = imGUI.getListenerInstantMessaging(); if (!buddyList.hasBuddy(subscriberURL)) { // Let's ask: listenerIM.addContact(subscriberURL); } /** ********************** send NOTIFY ************************* */ // We send a NOTIFY for any of our status but offline String localStatus = listenerIM.getLocalStatus(); if (!localStatus.equals("offline")) { IMNotifyProcessing imNotifyProcessing = imUA.getIMNotifyProcessing(); Subscriber subscriber = presenceManager.getSubscriber(subscriberURL); // Response okSent=subscriber.getOkSent(); subscriberURL = subscriber.getSubscriberName(); String contactAddress = imUA.getIMAddress() + ":" + imUA.getIMPort(); String subStatus = listenerIM.getLocalStatus(); String status = null; if (subStatus.equals("offline")) status = "closed"; else status = "open"; String xmlBody = imNotifyProcessing.xmlPidfParser.createXMLBody( status, subStatus, subscriberURL, contactAddress); imNotifyProcessing.sendNotify(response, xmlBody, dialog); } } else { // User did not authorize subscription. Terminate it! logger.debug( "DEBUG, IMSubsribeProcessing, processSubscribe(), " + " Subscription declined!"); logger.debug( "DEBUG, IMSubsribeProcessing, processSubscribe(), " + " Sending a Notify with Subscribe-state=terminated"); IMNotifyProcessing imNotifyProcessing = imUA.getIMNotifyProcessing(); if (dialog != null) { imNotifyProcessing.sendNotify(response, null, dialog); logger.debug( "DEBUG, IMSubsribeProcessing, processSubscribe(), " + " Sending a Notify with Subscribe-state=terminated"); } else { logger.debug( "ERROR, IMSubscribeProcessing, processSubscribe(), the" + " dialog for the SUBSCRIBE we received is null!!! \n" + " No terminating Notify sent"); } imNotifyProcessing.sendNotify(response, null, dialog); } } 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); }