/** 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 sendBye(String localSipURL, String remoteSipURL, ChatSession chatSession) { // Send a Bye only if there were exchanged messages!!! if (chatSession.isEstablishedSession()) { try { logger.debug("Sending a BYE in progress to " + remoteSipURL); SipProvider sipProvider = imUA.getSipProvider(); javax.sip.Dialog dialog = chatSession.getDialog(); Request request = dialog.createRequest(Request.BYE); // ProxyAuthorization header if not null: ProxyAuthorizationHeader proxyAuthHeader = imUA.getProxyAuthorizationHeader(); if (proxyAuthHeader != null) request.setHeader(proxyAuthHeader); ClientTransaction clientTransaction = sipProvider.getNewClientTransaction(request); dialog.sendRequest(clientTransaction); logger.debug("BYE sent:\n" + request); } catch (Exception ex) { ex.printStackTrace(); } } else { logger.debug("BYE not sent because of no exchanged messages!!!"); } }
/** * Creates and sends a SUBSCRIBE request to the subscription <tt>Address</tt>/Request URI of a * specific <tt>Subscription</tt> in order to request receiving event notifications and adds the * specified <tt>Subscription</tt> to the list of subscriptions managed by this instance. The * added <tt>Subscription</tt> may later receive notifications to process the <tt>Request</tt>s * and/or <tt>Response</tt>s which constitute the signaling session associated with it. If the * attempt to create and send the SUBSCRIBE request fails, the specified <tt>Subscription</tt> is * not added to the list of subscriptions managed by this instance. * * @param subscription a <tt>Subscription</tt> which specifies the properties of the SUBSCRIBE * request to be created and sent, to be added to the list of subscriptions managed by this * instance * @throws OperationFailedException if we fail constructing or sending the subscription request. */ public void subscribe(Subscription subscription) throws OperationFailedException { Dialog dialog = subscription.getDialog(); if ((dialog != null) && DialogState.TERMINATED.equals(dialog.getState())) dialog = null; // create the subscription ClientTransaction subscribeTransaction = null; try { subscribeTransaction = (dialog == null) ? createSubscription(subscription, subscriptionDuration) : createSubscription(subscription, dialog, subscriptionDuration); } catch (OperationFailedException ex) { ProtocolProviderServiceSipImpl.throwOperationFailedException( "Failed to create the subscription", OperationFailedException.INTERNAL_ERROR, ex, logger); } // we register the contact to find him when the OK will arrive CallIdHeader callIdHeader = (CallIdHeader) subscribeTransaction.getRequest().getHeader(CallIdHeader.NAME); String callId = callIdHeader.getCallId(); addSubscription(callId, subscription); // send the message try { if (dialog == null) subscribeTransaction.sendRequest(); else dialog.sendRequest(subscribeTransaction); } catch (SipException ex) { // this contact will never been accepted or rejected removeSubscription(callId, subscription); ProtocolProviderServiceSipImpl.throwOperationFailedException( "Failed to send the subscription", OperationFailedException.NETWORK_FAILURE, ex, logger); } }
/** 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 processResponse(ResponseEvent responseReceivedEvent) { System.out.println("Got a response"); Response response = (Response) responseReceivedEvent.getResponse(); Transaction tid = responseReceivedEvent.getClientTransaction(); System.out.println( "Response received with client transaction id " + tid + ":\n" + response.getStatusCode()); if (tid == null) { System.out.println("Stray response -- dropping "); return; } System.out.println("transaction state is " + tid.getState()); System.out.println("Dialog = " + tid.getDialog()); System.out.println("Dialog State is " + tid.getDialog().getState()); try { if (response.getStatusCode() == Response.OK && ((CSeqHeader) response.getHeader(CSeqHeader.NAME)) .getMethod() .equals(Request.INVITE)) { // Request cancel = inviteTid.createCancel(); // ClientTransaction ct = // sipProvider.getNewClientTransaction(cancel); // ct.sendRequest(); Dialog dialog = tid.getDialog(); CSeqHeader cseq = (CSeqHeader) response.getHeader(CSeqHeader.NAME); Request ackRequest = dialog.createAck(cseq.getSeqNumber()); System.out.println("Sending ACK"); dialog.sendAck(ackRequest); // Send a Re INVITE but this time force it // to use UDP as the transport. Else, it will // Use whatever transport was used to create // the dialog. if (reInviteCount == 0) { Request inviteRequest = dialog.createRequest(Request.INVITE); ((SipURI) inviteRequest.getRequestURI()).removeParameter("transport"); ((ViaHeader) inviteRequest.getHeader(ViaHeader.NAME)).setTransport("udp"); inviteRequest.addHeader(contactHeader); try { Thread.sleep(100); } catch (Exception ex) { } ClientTransaction ct = udpProvider.getNewClientTransaction(inviteRequest); dialog.sendRequest(ct); reInviteCount++; } } } catch (Exception ex) { ex.printStackTrace(); System.exit(0); } }
public void notifySipSubscriber( Object content, ContentTypeHeader contentTypeHeader, Subscription subscription, EntityManager entityManager, ImplementedSubscriptionControlSbbLocalObject childSbb) { try { // get subscription dialog ActivityContextInterface dialogACI = sipSubscriptionHandler .sbb .getActivityContextNamingfacility() .lookup(subscription.getKey().toString()); if (dialogACI != null) { Dialog dialog = (Dialog) dialogACI.getActivity(); // create notify Request notify = createNotify(dialog, subscription); // add content if (content != null) { notify = setNotifyContent(subscription, notify, content, contentTypeHeader, childSbb); } // ....aayush added code here (with ref issue #567) notify.addHeader(addPChargingVectorHeader()); // send notify in dialog related with subscription dialog.sendRequest( sipSubscriptionHandler.sbb.getSipProvider().getNewClientTransaction(notify)); if (logger.isDebugEnabled()) { logger.debug( "NotifySubscribers: subscription " + subscription.getKey() + " sent request:\n" + notify.toString()); } } else { // clean up logger.warn( "Unable to find dialog aci to notify subscription " + subscription.getKey() + ". Removing subscription data"); sipSubscriptionHandler.sbb.removeSubscriptionData( entityManager, subscription, null, null, childSbb); } } catch (Exception e) { logger.error("failed to notify subscriber", e); } }
/** Process the ACK request. Send the bye and complete the call flow. */ public void processAck(RequestEvent requestEvent, ServerTransaction serverTransaction) { try { System.out.println("shootme: got an ACK! "); System.out.println("Dialog State = " + dialog.getState()); SipProvider provider = (SipProvider) requestEvent.getSource(); if (!callerSendsBye) { Request byeRequest = dialog.createRequest(Request.BYE); ClientTransaction ct = provider.getNewClientTransaction(byeRequest); dialog.sendRequest(ct); } } catch (Exception ex) { ex.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 processDialogTerminated(DialogTerminatedEvent dialogTerminatedEvent) { Dialog dialog = dialogTerminatedEvent.getDialog(); this.terminatedCount++; System.out.println( "Dialog Terminated Event " + dialog.getDialogId() + " terminatedCount = " + terminatedCount); if (!this.dialogIds.contains(dialog.getDialogId())) { System.out.println("Saw a terminated event for an unknown dialog id"); } else { this.dialogIds.remove(dialog.getDialogId()); } }
/** Process the bye request. */ public void processBye(RequestEvent requestEvent, ServerTransaction serverTransactionId) { Request request = requestEvent.getRequest(); Dialog dialog = requestEvent.getDialog(); System.out.println("local party = " + dialog.getLocalParty()); try { System.out.println("cutme: 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); } }
/** JAIN Listener method. */ public void processTimeout(TimeoutEvent timeOutEvent) { ProxyDebug.println("TimeoutEvent received"); SipProvider sipProvider = (SipProvider) timeOutEvent.getSource(); TransactionsMapping transactionsMapping = null; if (timeOutEvent.isServerTransaction()) { ServerTransaction serverTransaction = timeOutEvent.getServerTransaction(); Dialog dialog = serverTransaction.getDialog(); if (dialog != null) { transactionsMapping = (TransactionsMapping) dialog.getApplicationData(); transactionsMapping.removeMapping(serverTransaction); } } else { ClientTransaction clientTransaction = timeOutEvent.getClientTransaction(); Dialog dialog = clientTransaction.getDialog(); ServerTransaction st = null; if (dialog != null) { transactionsMapping = (TransactionsMapping) dialog.getApplicationData(); if (transactionsMapping != null) { st = transactionsMapping.getServerTransaction(clientTransaction); } if (st == null) { ProxyDebug.println( "ERROR, Unable to retrieve the server transaction," + " cannot process timeout!"); return; } } else { ProxyDebug.println( "ERROR, Unable to retrieve the transaction Mapping," + " cannot process timeout!"); return; } Request request = st.getRequest(); // This removes the given mapping from the table but not // necessarily the whole thing. transactionsMapping.removeMapping(clientTransaction); if (!transactionsMapping.hasMapping(st)) { // No more mappings left in the transaction table. try { Response response = messageFactory.createResponse(Response.REQUEST_TIMEOUT, request); st.sendResponse(response); } catch (ParseException ex) { ex.printStackTrace(); } catch (SipException ex1) { ex1.printStackTrace(); } } } }
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()); } catch (Exception ex) { fail("Unexpected exception"); } }
public void run() { try { Request byeRequest = this.dialog.createRequest(Request.BYE); ClientTransaction ct = sipProvider.getNewClientTransaction(byeRequest); dialog.sendRequest(ct); } catch (Exception ex) { ex.printStackTrace(); fail("Unexpected exception "); } }
/* * for internal usage, creates a NOTIFY notify, asks the content to the * concrete implementation component, and then sends the request to the * subscriber */ public void createAndSendNotify( EntityManager entityManager, Subscription subscription, Dialog dialog, ImplementedSubscriptionControlSbbLocalObject childSbb) throws TransactionDoesNotExistException, SipException, ParseException { // create notify Request notify = createNotify(dialog, subscription); // add content if subscription is active if (subscription.getStatus().equals(Subscription.Status.active)) { if (subscription.getKey().getEventPackage().endsWith(".winfo")) { // winfo content, increment version before adding the content subscription.incrementVersion(); entityManager.persist(subscription); entityManager.flush(); notify.setContent( sipSubscriptionHandler .sbb .getWInfoSubscriptionHandler() .getFullWatcherInfoContent(entityManager, subscription), sipSubscriptionHandler.sbb.getWInfoSubscriptionHandler().getWatcherInfoContentHeader()); } else { // specific event package content NotifyContent notifyContent = childSbb.getNotifyContent(subscription); // add content if (notifyContent != null) { try { notify = setNotifyContent( subscription, notify, notifyContent.getContent(), notifyContent.getContentTypeHeader(), childSbb); } catch (Exception e) { logger.error("failed to set notify content", e); } } } } // ....aayush added code here (with ref issue #567) notify.addHeader(addPChargingVectorHeader()); // send notify ClientTransaction clientTransaction = sipSubscriptionHandler.sbb.getSipProvider().getNewClientTransaction(notify); dialog.sendRequest(clientTransaction); if (logger.isDebugEnabled()) { logger.debug("Request sent:\n" + notify.toString()); } }
public Request newSubsequentSubscribe(int expires) { if (_dialog == null) fail("Could not create subsequent request, no dialog established"); try { Request subscribe = _dialog.createRequest(Request.SUBSCRIBE); HeaderFactory hf = getHeaderFactory(); subscribe.addHeader(hf.createEventHeader(_event)); subscribe.addHeader(hf.createExpiresHeader(expires)); subscribe.setHeader(_sipPhone.getContactInfo().getContactHeader()); return subscribe; } catch (Exception e) { throw new RuntimeException(e); } }
/** 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(); } }
/** * Creates and sends a SUBSCRIBE request to a specific subscription <tt>Address</tt>/Request URI * if it matches a <tt>Subscription</tt> with an id tag of its Event header of a specific value in * the list of subscriptions managed by this instance with an Expires header value of zero in * order to terminate receiving event notifications and removes the specified * <tt>Subscription</tt> from the list of subscriptions managed by this instance. The removed * <tt>Subscription</tt> may receive notifications to process the <tt>Request</tt>s and/or * <tt>Response</tt>s which constitute the signaling session associated with it. If the attempt to * create the SUBSCRIBE request fails, the associated <tt>Subscription</tt> is not removed from * the list of subscriptions managed by this instance. If the specified <tt>Address</tt> does not * identify an existing <tt>Subscription</tt> in the list of subscriptions managed by this * instance, an assertion may optionally be performed or no reaction can be taken. * * @param toAddress a subscription <tt>Address</tt>/Request URI which identifies a * <tt>Subscription</tt> to be removed from the list of subscriptions managed by this instance * @param eventId the id tag placed in the Event header of the <tt>Subscription</tt> to be matched * if there is one or <tt>null</tt> if the <tt>Subscription</tt> should have no id tag in its * Event header * @param assertSubscribed <tt>true</tt> to assert if the specified subscription * <tt>Address</tt>/Request URI does not identify an existing <tt>Subscription</tt> in the * list of subscriptions managed by this instance; <tt>false</tt> to not assert if the * mentioned condition is met * @throws IllegalArgumentException if <tt>assertSubscribed</tt> is <tt>true</tt> and * <tt>toAddress</tt> and <tt>eventId</tt> do not identify an existing <tt>Subscription</tt> * in the list of subscriptions managed by this instance * @throws OperationFailedException if we fail constructing or sending the unSUBSCRIBE request. */ public void unsubscribe(Address toAddress, String eventId, boolean assertSubscribed) throws IllegalArgumentException, OperationFailedException { Subscription subscription = getSubscription(toAddress, eventId); if (subscription == null) if (assertSubscribed) throw new IllegalArgumentException("trying to unregister a not registered contact"); else return; Dialog dialog = subscription.getDialog(); // we stop the subscription if we're subscribed to this contact if (dialog != null) { String callId = dialog.getCallId().getCallId(); ClientTransaction subscribeTransaction; try { subscribeTransaction = createSubscription(subscription, dialog, 0); } catch (OperationFailedException e) { if (logger.isDebugEnabled()) logger.debug("failed to create the unsubscription", e); throw e; } // we are not anymore subscribed to this contact // this ensure that the response of this request will be // handled as an unsubscription response removeSubscription(callId, subscription); try { dialog.sendRequest(subscribeTransaction); } catch (SipException e) { if (logger.isDebugEnabled()) logger.debug("Can't send the request", e); throw new OperationFailedException( "Failed to send the subscription message", OperationFailedException.NETWORK_FAILURE, e); } } }
public synchronized void processNotify( RequestEvent requestEvent, ServerTransaction serverTransactionId) { LOG.debug("Notification received at Subscriber"); SipProvider provider = (SipProvider) requestEvent.getSource(); Request notify = requestEvent.getRequest(); try { if (serverTransactionId == null) { LOG.info("ServerTransaction is null. Creating new Server transaction"); serverTransactionId = provider.getNewServerTransaction(notify); } Dialog dialog = serverTransactionId.getDialog(); if (dialog != subscriberDialog) { forkedDialog = dialog; } // Dispatch the response along the route dispatchExchange(notify.getContent()); // Send back an success response Response response = sipSubscriber.getConfiguration().getMessageFactory().createResponse(200, notify); response.addHeader(sipSubscriber.getConfiguration().getContactHeader()); serverTransactionId.sendResponse(response); SubscriptionStateHeader subscriptionState = (SubscriptionStateHeader) notify.getHeader(SubscriptionStateHeader.NAME); // Subscription is terminated? if (subscriptionState.getState().equalsIgnoreCase(SubscriptionStateHeader.TERMINATED)) { LOG.info("Subscription state is terminated. Deleting the current dialog"); dialog.delete(); } } catch (Exception e) { LOG.error("Exception thrown during Notify processing in the SipSubscriptionListener.", e); } }
/** * Creates a new SUBSCRIBE request in the form of a <tt>ClientTransaction</tt> with the parameters * of a specific <tt>Subscription</tt>. * * @param subscription the <tt>Subscription</tt> to be described in a SUBSCRIBE request * @param dialog the <tt>Dialog</tt> with which this request should be associated * @param expires the subscription duration of the SUBSCRIBE request to be created * @return a new <tt>ClientTransaction</tt> initialized with a new SUBSCRIBE request which matches * the parameters of the specified <tt>Subscription</tt> and is associated with the specified * <tt>Dialog</tt> * @throws OperationFailedException if the message could not be generated */ private ClientTransaction createSubscription( Subscription subscription, Dialog dialog, int expires) throws OperationFailedException { Request req = messageFactory.createRequest(dialog, Request.SUBSCRIBE); // Address Address toAddress = dialog.getRemoteTarget(); // no Contact field if (toAddress == null) toAddress = dialog.getRemoteParty(); // MaxForwards MaxForwardsHeader maxForwards = protocolProvider.getMaxForwardsHeader(); req.setHeader(maxForwards); /* * Create the transaction and then add the via header as recommended by * the jain-sip documentation at * http://snad.ncsl.nist.gov/proj/iptel/jain-sip-1.2/javadoc * /javax/sip/Dialog.html#createRequest(String). */ ClientTransaction transac = null; try { transac = protocolProvider.getDefaultJainSipProvider().getNewClientTransaction(req); } catch (TransactionUnavailableException ex) { logger.error( "Failed to create subscriptionTransaction.\n" + "This is most probably a network connection error.", ex); throw new OperationFailedException( "Failed to create the subscription transaction", OperationFailedException.NETWORK_FAILURE); } populateSubscribeRequest(req, subscription, expires); return transac; }
/** Refreshes the <tt>Subscription</tt> associated with this <tt>TimerTask</tt>. */ @Override public void run() { Dialog dialog = subscription.getDialog(); if (dialog == null) { logger.warn( "null dialog associated with " + subscription + ", can't refresh the subscription"); return; } ClientTransaction transac = null; try { transac = createSubscription(subscription, dialog, subscriptionDuration); } catch (OperationFailedException e) { logger.error("Failed to create subscriptionTransaction.", e); return; } try { dialog.sendRequest(transac); } catch (SipException e) { logger.error("Can't send the request", e); } }
public void processResponse(ResponseEvent responseReceivedEvent) { // System.out.println("Got a response"); Response response = (Response) responseReceivedEvent.getResponse(); Transaction tid = responseReceivedEvent.getClientTransaction(); // System.out.println("Response received with client transaction id " // + tid + ":\n" + response); try { if (response.getStatusCode() == Response.OK && ((CSeqHeader) response.getHeader(CSeqHeader.NAME)) .getMethod() .equals(Request.INVITE)) { Dialog dialog = tid.getDialog(); Request request = tid.getRequest(); dialog.sendAck(request); } } catch (Exception ex) { ex.printStackTrace(); System.exit(0); } }
/** Process the ACK request. Send the bye and complete the call flow. */ public void processAck(RequestEvent requestEvent, ServerTransaction serverTransaction) { try { System.out.println("shootme: got an ACK! "); System.out.println("Dialog State = " + dialog.getState()); // SipProvider provider = (SipProvider) requestEvent.getSource(); // stopping the node // Collection<Dialog> // dialogs=((SipStackImpl)sipStack).getDialogs(DialogState.CONFIRMED); stop(); // shootmeRecoveryNode.init(); // if (!callerSendsBye && !byeTaskRunning) { // byeTaskRunning = true; // new Timer().schedule(new ByeTask(dialog), 4000) ; // } } 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); } }
/** 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 sendSubscribe(String localURL, String buddyURI, boolean EXPIRED) { try { logger.debug("Sending SUBSCRIBE in progress to the buddy: " + buddyURI); int proxyPort = imUA.getProxyPort(); String proxyAddress = imUA.getProxyAddress(); String imProtocol = imUA.getIMProtocol(); SipStack sipStack = imUA.getSipStack(); SipProvider sipProvider = imUA.getSipProvider(); MessageFactory messageFactory = imUA.getMessageFactory(); HeaderFactory headerFactory = imUA.getHeaderFactory(); AddressFactory addressFactory = imUA.getAddressFactory(); // Request-URI: // URI requestURI=addressFactory.createURI(buddyURI); SipURI requestURI = addressFactory.createSipURI(null, proxyAddress); requestURI.setPort(proxyPort); requestURI.setTransportParam(imProtocol); // Call-Id: CallIdHeader callIdHeader = null; // CSeq: CSeqHeader cseqHeader = null; // To header: ToHeader toHeader = null; // From Header: FromHeader fromHeader = null; // Via header String branchId = Utils.generateBranchId(); ViaHeader viaHeader = headerFactory.createViaHeader( imUA.getIMAddress(), imUA.getIMPort(), imProtocol, branchId); Vector viaList = new Vector(); viaList.addElement(viaHeader); PresenceManager presenceManager = imUA.getPresenceManager(); Presentity presentity = presenceManager.getPresentity(buddyURI); Dialog dialog = null; if (presentity != null) dialog = presentity.getDialog(); if (dialog != null) { // We have to remove the subscriber and the Presentity related // with this Buddy... presenceManager.removePresentity(buddyURI); Subscriber subscriber = presenceManager.getSubscriber(buddyURI); if (subscriber == null) { // It means that the guy does not have us in his buddy list // nothing to do!!! } else { presenceManager.removeSubscriber(buddyURI); } Address localAddress = dialog.getLocalParty(); Address remoteAddress = dialog.getRemoteParty(); fromHeader = headerFactory.createFromHeader(localAddress, dialog.getLocalTag()); toHeader = headerFactory.createToHeader(remoteAddress, dialog.getRemoteTag()); long cseq = dialog.getLocalSeqNumber(); cseqHeader = headerFactory.createCSeqHeader(cseq, "MESSAGE"); callIdHeader = dialog.getCallId(); } else { String localTag = Utils.generateTag(); Address toAddress = addressFactory.createAddress(buddyURI); Address fromAddress = addressFactory.createAddress(localURL); fromHeader = headerFactory.createFromHeader(fromAddress, localTag); toHeader = headerFactory.createToHeader(toAddress, null); // CSeq: cseqHeader = headerFactory.createCSeqHeader(1L, "SUBSCRIBE"); callIdCounter++; // Call-ID: callIdHeader = (CallIdHeader) headerFactory.createCallIdHeader("nist-sip-im-subscribe-callId" + callIdCounter); } // MaxForwards header: MaxForwardsHeader maxForwardsHeader = headerFactory.createMaxForwardsHeader(70); Request request = messageFactory.createRequest( requestURI, "SUBSCRIBE", callIdHeader, cseqHeader, fromHeader, toHeader, viaList, maxForwardsHeader); RouteHeader rh = this.imUA.getRouteToProxy(); request.setHeader(rh); // Contact header: SipURI sipURI = addressFactory.createSipURI(null, imUA.getIMAddress()); sipURI.setPort(imUA.getIMPort()); sipURI.setTransportParam(imUA.getIMProtocol()); Address contactAddress = addressFactory.createAddress(sipURI); ContactHeader contactHeader = headerFactory.createContactHeader(contactAddress); request.setHeader(contactHeader); ExpiresHeader expiresHeader = null; if (EXPIRED) { expiresHeader = headerFactory.createExpiresHeader(0); } else { expiresHeader = headerFactory.createExpiresHeader(presenceManager.getExpiresTime()); } request.setHeader(expiresHeader); // WE have to add a new Header: "Event" Header eventHeader = headerFactory.createHeader("Event", "presence"); request.setHeader(eventHeader); // Add Acceptw Header Header acceptHeader = headerFactory.createHeader("Accept", "application/pidf+xml"); request.setHeader(acceptHeader); // ProxyAuthorization header if not null: ProxyAuthorizationHeader proxyAuthHeader = imUA.getProxyAuthorizationHeader(); if (proxyAuthHeader != null) request.setHeader(proxyAuthHeader); ClientTransaction clientTransaction = sipProvider.getNewClientTransaction(request); if (dialog != null) { dialog.sendRequest(clientTransaction); } else { clientTransaction.sendRequest(); } logger.debug("IMSubscribeProcessing, sendSubscribe(), SUBSCRIBE sent:\n" + request); } catch (Exception ex) { ex.printStackTrace(); } }
public void processDialogTerminated(DialogTerminatedEvent dialogTerminatedEvent) { Dialog d = dialogTerminatedEvent.getDialog(); System.out.println("Local Party = " + d.getLocalParty()); }
/** Process the ACK request. Send the bye and complete the call flow. */ public void processAck(RequestEvent requestEvent, ServerTransaction serverTransaction) { System.out.println("shootme: got an ACK! "); System.out.println("Dialog State = " + dialog.getState()); }
public void processResponse(ResponseEvent responseReceivedEvent) { /// System.out.println("=> BUNDLE: br.ufes.inf.ngn.televoto.client.logic | CLASS: LogicListener // | METOD: processResponse ");//By Ju try { Response myResponse = responseReceivedEvent.getResponse(); logger.info("<<< " + myResponse.toString()); ClientTransaction thisClientTransaction = responseReceivedEvent.getClientTransaction(); int myStatusCode = myResponse.getStatusCode(); switch (status) { case WAIT_PROV: if (!thisClientTransaction.equals(myClientTransaction)) myClientTransaction = thisClientTransaction; if (myStatusCode < 200) { status = WAIT_FINAL; myDialog = thisClientTransaction.getDialog(); } else if (myStatusCode < 300) { myDialog = thisClientTransaction.getDialog(); CSeqHeader originalCSeq = (CSeqHeader) myClientTransaction.getRequest().getHeader(CSeqHeader.NAME); long numseq = originalCSeq.getSeqNumber(); Request myAck = myDialog.createAck(numseq); myAck.addHeader(myContactHeader); myDialog.sendAck(myAck); // logger.info(">>> "+myAck.toString()); status = ESTABLISHED; byte[] cont = (byte[]) myResponse.getContent(); answerInfo = mySdpManager.getSdp(cont); } else { if (myStatusCode == 401) { } else { status = IDLE; CSeqHeader originalCSeq = (CSeqHeader) myClientTransaction.getRequest().getHeader(CSeqHeader.NAME); long numseq = originalCSeq.getSeqNumber(); Request myAck = myDialog.createAck(numseq); myAck.addHeader(myContactHeader); myDialog.sendAck(myAck); // logger.info(">>> "+myAck.toString()); } } break; case WAIT_FINAL: if (!thisClientTransaction.equals(myClientTransaction)) myClientTransaction = thisClientTransaction; if (myStatusCode < 200) { status = WAIT_FINAL; myDialog = thisClientTransaction.getDialog(); } else if (myStatusCode < 300) { if (useQueue.equals("yes")) { status = IDLE; } else { status = ESTABLISHED; } myDialog = thisClientTransaction.getDialog(); CSeqHeader originalCSeq = (CSeqHeader) myClientTransaction.getRequest().getHeader(CSeqHeader.NAME); long numseq = originalCSeq.getSeqNumber(); Request myAck = myDialog.createAck(numseq); // Aquiiii myAck.addHeader(myContactHeader); myDialog.sendAck(myAck); // logger.info(">>> "+myAck.toString()); byte[] cont = (byte[]) myResponse.getContent(); answerInfo = mySdpManager.getSdp(cont); } else { // Cancelando requisição ao cliente Request myCancelRequest = myClientTransaction.createCancel(); ClientTransaction myCancelClientTransaction = mySipProvider.getNewClientTransaction(myCancelRequest); myCancelClientTransaction.sendRequest(); // logger.info(">>> " + myCancelRequest.toString()); status = IDLE; } break; case REGISTERING: if (!thisClientTransaction.equals(myClientTransaction)) myClientTransaction = thisClientTransaction; if (myStatusCode == 200) { status = IDLE; if (!Unregistring) { System.out.println(myName + ": Registrado"); // inserir captura de timestamp // logger.info(myName + ";INVITE;" + getTime()); // Random gerador = new Random(); // int temp = gerador.nextInt(10); // System.out.println(myName + ": Esperando " + temp + "segundos"); // Thread.sleep(temp); System.out.println(myName + ": chamando " + destination); SdpInfo offerInfo = new SdpInfo(); offerInfo.IpAddress = myIP; offerInfo.aport = myAudioPort; offerInfo.aformat = 0; byte[] content = mySdpManager.createSdp(offerInfo); // Via // ViaHeader comentei myViaHeader = myHeaderFactory.createViaHeader(myIP, myPort, "udp", null); myViaHeader.setRPort(); ArrayList viaHeaders = new ArrayList(); viaHeaders.add(myViaHeader); // From Address addressOfRecord = myAddressFactory.createAddress("<sip:" + myUserID + ">"); FromHeader myFromHeader = myHeaderFactory.createFromHeader(addressOfRecord, "456249"); // To String dstURI[] = destination.split("@"); String dstSipAlias = dstURI[0]; Address destinationAddress = myAddressFactory.createAddress("<sip:" + destination + ">"); javax.sip.address.URI myRequestURI = destinationAddress.getURI(); ToHeader myToHeader = myHeaderFactory.createToHeader(destinationAddress, null); // MaxForwards MaxForwardsHeader myMaxForwardsHeader = myHeaderFactory.createMaxForwardsHeader(70); // Call-ID CallIdHeader myCallIdHeader = mySipProvider.getNewCallId(); // CSeq Random random = new Random(); CSeqHeader myCSeqHeader = myHeaderFactory.createCSeqHeader(random.nextInt(1000) * 1L, "INVITE"); // Create SIP request Request myRequest = myMessageFactory.createRequest( myRequestURI, "INVITE", myCallIdHeader, myCSeqHeader, myFromHeader, myToHeader, viaHeaders, myMaxForwardsHeader); // Contact Address contactAddress = myAddressFactory.createAddress( "<sip:" + mySipAlias + "@" + myIP + ":" + myPort + ";transport=udp>"); myContactHeader = myHeaderFactory.createContactHeader(contactAddress); myRequest.addHeader(myContactHeader); // Allow Allow myAllow = new Allow(); myAllow.setMethod( "INVITE, ACK, CANCEL, BYE, MESSAGE, OPTIONS, NOTIFY, PRACK, UPDATE, REFER"); myRequest.addHeader(myAllow); // Privacy Privacy myPrivacy = new Privacy("none"); myRequest.addHeader(myPrivacy); // PPreferredIdentity HeaderFactoryImpl myHeaderFactoryImpl = new HeaderFactoryImpl(); PPreferredIdentityHeader myPPreferredIdentityHeader = myHeaderFactoryImpl.createPPreferredIdentityHeader( myAddressFactory.createAddress("sip:" + myName + '@' + myServer)); myRequest.addHeader(myPPreferredIdentityHeader); // Route Address routeAddress = myAddressFactory.createAddress("sip:orig@scscf." + myServer + ":6060;lr"); // RouteHeader comentei myRouteHeader = myHeaderFactory.createRouteHeader(routeAddress); myRequest.addHeader(myRouteHeader); // Para proxy funcionar SipURI outboundProxyURI = myAddressFactory.createSipURI("proxy", myProxyIP); outboundProxyURI.setLrParam(); outboundProxyURI.setPort(myProxyPort); myRouteHeader = myHeaderFactory.createRouteHeader( myAddressFactory.createAddress(outboundProxyURI)); myRequest.addFirst(myRouteHeader); // Content Type ContentTypeHeader contentTypeHeader = myHeaderFactory.createContentTypeHeader("application", "sdp"); myRequest.setContent(content, contentTypeHeader); // ClientTransaction comentei aqui myClientTransaction = mySipProvider.getNewClientTransaction(myRequest); myClientTransaction.setRetransmitTimer(700); myClientTransaction.sendRequest(); status = WAIT_PROV; logger.info(">>> " + myRequest.toString()); } else { this.setOff(mySipStack); } } else { if (myStatusCode == 403) { System.out.println("Problemas com credenciais!!!!\n"); } else if (myStatusCode == 401) { myName = (String) this.getLocalName(); myUserID = (String) this.getLocalName() + "@" + myServer; Address contactAddress = myAddressFactory.createAddress("sip:" + myName + '@' + myIP + ":" + myPort); myContactHeader = myHeaderFactory.createContactHeader(contactAddress); myViaHeader = myHeaderFactory.createViaHeader(myIP, myPort, "udp", null); fromAddress = myAddressFactory.createAddress(myName + " <sip:" + myUserID + ">"); Address registrarAddress = myAddressFactory.createAddress("sip:" + myServer); Address registerToAddress = fromAddress; Address registerFromAddress = fromAddress; ToHeader myToHeader = myHeaderFactory.createToHeader(registerToAddress, null); FromHeader myFromHeader = myHeaderFactory.createFromHeader(registerFromAddress, "647554"); ArrayList myViaHeaders = new ArrayList(); myViaHeaders.add(myViaHeader); // System.out.println("myClientTransaction.getRequest():"+ // myClientTransaction.getRequest()); CSeqHeader originalCSeq = (CSeqHeader) myClientTransaction.getRequest().getHeader(CSeqHeader.NAME); long numseq = originalCSeq.getSeqNumber(); MaxForwardsHeader myMaxForwardsHeader = myHeaderFactory.createMaxForwardsHeader(70); CSeqHeader myCSeqHeader = myHeaderFactory.createCSeqHeader(numseq + 1L, "REGISTER"); CallIdHeader myCallID = (CallIdHeader) myClientTransaction.getRequest().getHeader(CallIdHeader.NAME); CallIdHeader myCallIDHeader = myCallID; SipURI myRequestURI = (SipURI) registrarAddress.getURI(); Request myRegisterRequest = myMessageFactory.createRequest( myRequestURI, "REGISTER", myCallIDHeader, myCSeqHeader, myFromHeader, myToHeader, myViaHeaders, myMaxForwardsHeader); myRegisterRequest.addHeader(myContactHeader); // Expires ExpiresHeader myExpiresHeader; if (Unregistring) { myExpiresHeader = myHeaderFactory.createExpiresHeader(0); myContactHeader.setExpires(0); } else { myExpiresHeader = myHeaderFactory.createExpiresHeader(60000); } myRegisterRequest.addHeader(myExpiresHeader); // Allow Allow myAllow = new Allow(); myAllow.setMethod( "INVITE, ACK, CANCEL, BYE, MESSAGE, OPTIONS, NOTIFY, PRACK, UPDATE, REFER"); myRegisterRequest.addHeader(myAllow); // Privacy Privacy myPrivacy = new Privacy("none"); myRegisterRequest.addHeader(myPrivacy); // PPreferredIdentity HeaderFactoryImpl myHeaderFactoryImpl = new HeaderFactoryImpl(); PPreferredIdentityHeader myPPreferredIdentityHeader = myHeaderFactoryImpl.createPPreferredIdentityHeader( myAddressFactory.createAddress("sip:" + myName + '@' + myServer)); myRegisterRequest.addHeader(myPPreferredIdentityHeader); // Supported Supported mySupported = new Supported("path"); myRegisterRequest.addHeader(mySupported); myWWWAuthenticateHeader = Utils.makeAuthHeader( myHeaderFactory, myResponse, myRegisterRequest, myUserID, myPassword); myRegisterRequest.addHeader(myWWWAuthenticateHeader); myClientTransaction = mySipProvider.getNewClientTransaction(myRegisterRequest); myClientTransaction.sendRequest(); // logger.info(">>> "+myRegisterRequest.toString()); // System.out.println(">>> " + myRegisterRequest.toString()); status = REGISTERING; } } break; } } catch (Exception excep) { excep.printStackTrace(); } }
public void init() { SipFactory sipFactory = null; sipStack = null; sipFactory = SipFactory.getInstance(); sipFactory.setPathName("org.mobicents.ha"); Properties properties = new Properties(); properties.setProperty("javax.sip.STACK_NAME", stackName); // properties.setProperty("javax.sip.OUTBOUND_PROXY", Integer // .toString(BALANCER_PORT)); // You need 16 for logging traces. 32 for debug + traces. // Your code will limp at 32 but it is best for debugging. properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", "32"); properties.setProperty("gov.nist.javax.sip.DEBUG_LOG", "logs/" + stackName + "debug.txt"); properties.setProperty("gov.nist.javax.sip.SERVER_LOG", "logs/" + stackName + "log.xml"); try { // Create SipStack object sipStack = sipFactory.createSipStack(properties); System.out.println("sipStack = " + sipStack); } catch (PeerUnavailableException e) { // could not find // gov.nist.jain.protocol.ip.sip.SipStackImpl // in the classpath e.printStackTrace(); System.err.println(e.getMessage()); if (e.getCause() != null) e.getCause().printStackTrace(); System.exit(0); } try { headerFactory = sipFactory.createHeaderFactory(); addressFactory = sipFactory.createAddressFactory(); messageFactory = sipFactory.createMessageFactory(); ListeningPoint lp = sipStack.createListeningPoint(myAddress, myPort, ListeningPoint.UDP); Shootme listener = this; sipProvider = sipStack.createSipProvider(lp); System.out.println("udp provider " + sipProvider); sipProvider.addSipListener(listener); // if(dialogs != null) { // Collection<Dialog> serializedDialogs = // simulateDialogSerialization(dialogs); // for (Dialog dialog : serializedDialogs) { // ((SIPDialog)dialog).setSipProvider((SipProviderImpl)sipProvider); // ((SipStackImpl)sipStack).putDialog((SIPDialog)dialog); // } // this.dialog = (SIPDialog)serializedDialogs.iterator().next(); // } sipStack.start(); if (!callerSendsBye && this.dialog != null) { try { Request byeRequest = this.dialog.createRequest(Request.BYE); ClientTransaction ct = sipProvider.getNewClientTransaction(byeRequest); System.out.println("sending BYE " + byeRequest); dialog.sendRequest(ct); } catch (Exception ex) { ex.printStackTrace(); fail("Unexpected exception "); } } } catch (Exception ex) { System.out.println(ex.getMessage()); ex.printStackTrace(); fail("Unexpected exception"); } }
public void processResponse(ResponseEvent responseReceivedEvent) { System.out.println("Got a response"); Response response = (Response) responseReceivedEvent.getResponse(); ClientTransaction tid = responseReceivedEvent.getClientTransaction(); CSeqHeader cseq = (CSeqHeader) response.getHeader(CSeqHeader.NAME); System.out.println( "Response received : Status Code = " + response.getStatusCode() + " " + cseq); if (tid == null) { // RFC3261: MUST respond to every 2xx if (ackRequest != null && dialog != null) { System.out.println("re-sending ACK"); try { dialog.sendAck(ackRequest); } catch (SipException se) { se.printStackTrace(); fail("Unxpected exception "); } } return; } // If the caller is supposed to send the bye if (callerSendsBye && !byeTaskRunning) { byeTaskRunning = true; new Timer().schedule(new ByeTask(dialog), 4000); } System.out.println("transaction state is " + tid.getState()); System.out.println("Dialog = " + tid.getDialog()); System.out.println("Dialog State is " + tid.getDialog().getState()); assertSame("Checking dialog identity", tid.getDialog(), this.dialog); try { if (response.getStatusCode() == Response.OK) { if (cseq.getMethod().equals(Request.INVITE)) { System.out.println("Dialog after 200 OK " + dialog); System.out.println("Dialog State after 200 OK " + dialog.getState()); Request ackRequest = dialog.createAck(cseq.getSeqNumber()); System.out.println("Sending ACK"); dialog.sendAck(ackRequest); // JvB: test REFER, reported bug in tag handling // Request referRequest = dialog.createRequest("REFER"); // //simulating a balancer that will forward the request to the // recovery node // SipURI referRequestURI = addressFactory.createSipURI(null, // "127.0.0.1:5080"); // referRequest.setRequestURI(referRequestURI); // dialog.sendRequest( // sipProvider.getNewClientTransaction(referRequest)); // } else if (cseq.getMethod().equals(Request.CANCEL)) { if (dialog.getState() == DialogState.CONFIRMED) { // oops cancel went in too late. Need to hang up the // dialog. System.out.println("Sending BYE -- cancel went in too late !!"); Request byeRequest = dialog.createRequest(Request.BYE); ClientTransaction ct = sipProvider.getNewClientTransaction(byeRequest); dialog.sendRequest(ct); } } else if (cseq.getMethod().equals(Request.BYE)) { okToByeReceived = true; } } } catch (Exception ex) { ex.printStackTrace(); System.exit(0); } }