public void acquire() { sipSession.acquire(); }
public void release() { sipSession.release(); }
MobicentsSipSession sipSessionImpl = getNewMobicentsSipSession(sessionKey, sipFactoryImpl, parentSipSession.getSipApplicationSession()); if(logger.isDebugEnabled()) { logger.debug("Created derived session " + sipSessionImpl + " with sessionKey " + sessionKey + " for parent session " + parentSipSession + " with parent session key " + parentSipSession.getKey()); sipSessionImpl.setSipSessionAttributeMap(parentSipSession.getSipSessionAttributeMap()); try { sipSessionImpl.setHandler(parentSipSession.getHandler()); } catch (ServletException e) { sipSessionImpl.setState(State.INITIAL); sipSessionImpl.setStateInfo(parentSipSession.getStateInfo()); sipSessionImpl.setProxy(parentSipSession.getProxy()); if(parentSipSession.getSipSubscriberURI() != null) { sipSessionImpl.setSipSubscriberURI(parentSipSession.getSipSubscriberURI()); sipSessionImpl.setUserPrincipal(parentSipSession.getUserPrincipal()); sipSessionImpl.setParentSession(parentSipSession); parentSipSession.addDerivedSipSessions(sipSessionImpl); if(parentSipSession.getSipApplicationSession().getSipContext() != null) { sipSessionImpl.notifySipSessionListeners(SipSessionEventType.CREATION);
public MobicentsSipSessionFacade(MobicentsSipSession sipSession) { this.sipSession = sipSession; this.sipSessionKey = sipSession.getKey(); this.sipAppSessionKey = sipSession.getSipApplicationSession().getKey(); }
if(!((MobicentsSipSession)session1).isValidInternal() || !((MobicentsSipSession)session2).isValidInternal() || State.TERMINATED.equals(((MobicentsSipSession)session1).getState()) || State.TERMINATED.equals(((MobicentsSipSession)session2).getState()) || !session1.getApplicationSession().equals(session2.getApplicationSession()) || (sessionMap.get(((MobicentsSipSession)session1).getKey()) != null && sessionMap.get(((MobicentsSipSession)session1).getKey()) != ((MobicentsSipSession)session2).getKey()) || (sessionMap.get(((MobicentsSipSession)session2).getKey()) != null && sessionMap.get(((MobicentsSipSession)session2).getKey()) != ((MobicentsSipSession)session1).getKey())) { throw new IllegalArgumentException("either of the specified sessions has been terminated " + "or the sessions do not belong to the same application session or " + "one or both the sessions are already linked with some other session(s)"); this.sessionMap.put(((MobicentsSipSession)session1).getKey(), ((MobicentsSipSession)session2).getKey()); this.sessionMap.put(((MobicentsSipSession)session2).getKey(), ((MobicentsSipSession) session1).getKey()); if(!this.equals(((MobicentsSipSession)session1).getB2buaHelper())) { if(((MobicentsSipSession)session1).getB2buaHelper() == null) { ((MobicentsSipSession)session1).setB2buaHelper(this); } else { Map<MobicentsSipSessionKey, MobicentsSipSessionKey> forkedSessionMap = ((MobicentsSipSession)session1).getB2buaHelper().getSessionMap(); forkedSessionMap.put(((MobicentsSipSession)session1).getKey(), ((MobicentsSipSession)session2).getKey()); forkedSessionMap.put(((MobicentsSipSession)session2).getKey(), ((MobicentsSipSession) session1).getKey()); if(!this.equals(((MobicentsSipSession)session2).getB2buaHelper())) { if(((MobicentsSipSession)session2).getB2buaHelper() == null) { ((MobicentsSipSession)session2).setB2buaHelper(this); } else { Map<MobicentsSipSessionKey, MobicentsSipSessionKey> forkedSessionMap = ((MobicentsSipSession)session2).getB2buaHelper().getSessionMap(); forkedSessionMap.put(((MobicentsSipSession)session1).getKey(), ((MobicentsSipSession)session2).getKey()); forkedSessionMap.put(((MobicentsSipSession)session2).getKey(), ((MobicentsSipSession) session1).getKey());
final String requestMethod = getMethod(); final MobicentsSipSession session = getSipSession(); final String sessionTransport = session.getTransport(); final SipNetworkInterfaceManager sipNetworkInterfaceManager = sipFactoryImpl.getSipNetworkInterfaceManager(); final MobicentsSipApplicationSession sipApplicationSession = session.getSipApplicationSession(); if(session != null && session.getProxy() == null) { ((MessageExt)message).setApplicationData(session.getTransport()); getSipSession().setRequestsPending(0); Transaction tx = inviteTransactionToCancel; if(logger.isDebugEnabled()) { session.setTransport(transport); String outboundInterface = session.getOutboundInterface(); if(outboundInterface != null) { if(logger.isDebugEnabled()) { addInfoForRoutingBackToContainer(routerInfo, session.getSipApplicationSession().getKey().getId(), session.getKey().getApplicationName()); addDNSRoute = false; logger.debug("bypassLoadBalancer: " + session.getBypassLoadBalancer() + ", sipFactoryImpl UseLoadBalancer: " + sipFactoryImpl.isUseLoadBalancer() + ", matchingListeningPoint: " + matchingListeningPoint); if(!session.getBypassLoadBalancer() && sipFactoryImpl.isUseLoadBalancer()) { if(matchingListeningPoint != null && matchingListeningPoint.isUseLoadBalancer()) { sipFactoryImpl.addLoadBalancerRouteHeader(request, matchingListeningPoint);
public static void callServlet(MobicentsSipServletResponse response) throws ServletException, IOException { final MobicentsSipSession session = response.getSipSession(); final String sessionHandler = session.getHandler(); final MobicentsSipApplicationSession sipApplicationSessionImpl = session.getSipApplicationSession(); final SipContext sipContext = sipApplicationSessionImpl.getSipContext(); final MobicentsSipServlet sipServletImpl = (MobicentsSipServlet) sipContext.findSipServletByName(sessionHandler); " to following App/ruby controller => " + response.getSipSession().getKey().getApplicationName()+ "/" + sipContext.getSipRubyController().getName()); if(logger.isDebugEnabled()) { logger.debug("Dispatching response " + response.toString() + " to following App/servlet => " + session.getKey().getApplicationName()+ "/" + session.getHandler() + " on following sip session " + session.getId());
public void setUserPrincipal(SipPrincipal principal) { getSipSession().setUserPrincipal(principal); }
if(checkSession && !mobicentsSipSession.isValidInternal()) { throw new IllegalArgumentException("the session " + mobicentsSipSession + " is invalid"); MobicentsSipSessionKey sipSessionKey = this.sessionMap.get(mobicentsSipSession.getKey()); if(sipSessionKey == null) { dumpLinkedSessions(); MobicentsSipSession linkedSession = sipManager.getSipSession(sipSessionKey, false, null, mobicentsSipSession.getSipApplicationSession()); if(logger.isDebugEnabled()) { if(linkedSession != null) { if(mobicentsSipSession.getParentSession() != null) { if(logger.isDebugEnabled()) { logger.debug(mobicentsSipSession + " has a parent session, it means we need to handle a forked case"); String linkedDerivedSessionId = derivedSessionMap.get(mobicentsSipSession.getId()); if(linkedDerivedSessionId == null) { SipServletRequestImpl originalSipServletRequestImpl = (SipServletRequestImpl) linkedSession.getSessionCreatingTransactionRequest(); linkedSession = sipManager.getSipSession(sipSessionKey, false, null, mobicentsSipSession.getSipApplicationSession()); linkedSession.setSessionCreatingDialog(null); linkedSession.setSessionCreatingTransactionRequest(clonedOriginalRequest); derivedSessionMap.put(mobicentsSipSession.getId(), linkedSession.getId()); derivedSessionMap.put(linkedSession.getId(), mobicentsSipSession.getId()); } else { if(logger.isDebugEnabled()) {
.getSipApplicationSession(); newFromHeader.setTag(ApplicationRoutingHeaderComposer.getHash(sipFactoryImpl.getSipApplicationDispatcher(), originalSession.getKey().getApplicationName(), appSession.getKey().getId())); final MobicentsSipSessionKey key = SessionManagerUtil.getSipSessionKey(appSession.getKey().getId(), originalSession.getKey().getApplicationName(), newRequest, false); final MobicentsSipSession session = appSession.getSipContext().getSipManager().getSipSession(key, true, sipFactoryImpl, appSession); session.setHandler(originalSession.getHandler()); final String branch = JainSipUtils.createBranch(appSession.getKey().getId(), sipApplicationDispatcher.getHashFromApplicationName(appSession.getKey().getApplicationName())); ViaHeader viaHeader = JainSipUtils.createViaHeader( sipFactoryImpl.getSipNetworkInterfaceManager(), newRequest, branch, session.getOutboundInterface()); newRequest.addHeader(viaHeader); MobicentsExtendedListeningPoint listeningPoint = JainSipUtils.findListeningPoint(sipFactoryImpl.getSipNetworkInterfaceManager(), newRequest, session.getOutboundInterface()); if(listeningPoint != null && listeningPoint.isUseLoadBalancer()) { contactHeader = JainSipUtils.createContactHeader(sipFactoryImpl.getSipNetworkInterfaceManager(), newRequest, diaplayName, fromName, session.getOutboundInterface()); contactHeader = JainSipUtils.createContactHeader(sipFactoryImpl.getSipNetworkInterfaceManager(), newRequest, diaplayName, fromName, session.getOutboundInterface()); sessionMap.put(originalSession.getKey(), session.getKey()); sessionMap.put(session.getKey(), originalSession.getKey()); dumpLinkedSessions(); session.setB2buaHelper(this); originalSession.setB2buaHelper(this); session.setSessionCreatingTransactionRequest(newSipServletRequest);
public String getHandler() { return getSipSession().getHandler(); }
logger.debug("the encoded URI Sip Application Session is " + sipApplicationSession); if(joinReplacesSipSession != null && nextApplicationName.equals(joinReplacesSipSession.getKey().getApplicationName())) { sipApplicationSession = joinReplacesSipSession.getSipApplicationSession(); if(logger.isDebugEnabled()) { logger.debug("Reusing the application session from the Join/Replaces " + sipApplicationSession.getId()); sipServletRequest.setSipSession(sipSessionImpl); if(joinReplacesSipSession != null && nextApplicationName.equals(joinReplacesSipSession.getKey().getApplicationName())) { final JoinHeader joinHeader = (JoinHeader)request.getHeader(JoinHeader.NAME); final ReplacesHeader replacesHeader = (ReplacesHeader)request.getHeader(ReplacesHeader.NAME); sipSessionImpl.setStateInfo(applicationRouterInfo.getStateInfo()); sipSessionImpl.setRoutingRegion(applicationRouterInfo.getRoutingRegion()); sipServletRequest.setRoutingRegion(applicationRouterInfo.getRoutingRegion()); if (sipServletRequest.getSubscriberURI() != null) { sipSessionImpl.setSipSubscriberURI(sipServletRequest.getSubscriberURI().toString()); sipSessionImpl.setCseq(cSeq); sipSessionImpl.setRequestsPending(sipSessionImpl.getRequestsPending() + 1); sipSessionImpl.setAckReceived(cSeq, false); sipSessionImpl.setTransport(via.getTransport());
public void dispatch() throws DispatcherException { final SipServletRequestImpl sipServletRequest = (SipServletRequestImpl)sipServletMessage; final MobicentsSipSession sipSessionImpl = sipServletRequest.getSipSession(); final MobicentsSipApplicationSession appSession = sipSessionImpl.getSipApplicationSession(); final SipContext sipContext = appSession.getSipContext(); final Request request = (Request) sipServletRequest.getMessage(); sipSessionImpl.setSessionCreatingTransactionRequest(sipServletRequest); String sipSessionHandlerName = sipSessionImpl.getHandler(); if(logger.isDebugEnabled()) { logger.debug("sipSessionHandlerName = " + sipSessionHandlerName); sipSessionImpl.setHandler(sipSessionHandlerName); } catch (ServletException e) { sipSessionImpl.setRoutingRegion(null); sipSessionImpl.setSipSubscriberURI(null);
String outboundInterface = null; if(session != null) { outboundInterface = session.getOutboundInterface(); if(SipSessionRoutingType.CURRENT_SESSION.equals(sipSessionRoutingType)) { String handlerName = session.getHandler(); if(handlerName != null) { final String branch = JainSipUtils.createBranch(session.getSipApplicationSession().getKey().getId(), sipApplicationDispatcher.getHashFromApplicationName(session.getKey().getApplicationName())); viaHeader.setBranch(branch); } else { final String branch = JainSipUtils.createBranch(session.getSipApplicationSession().getKey().getId(), sipApplicationDispatcher.getHashFromApplicationName(session.getKey().getApplicationName())); viaHeader.setBranch(branch); appNotDeployed = session.getKey().getApplicationName();
final int statusCode = response.getStatusCode(); final MobicentsSipSession session = getSipSession(); final MobicentsSipApplicationSession sipApplicationSession = session.getSipApplicationSession(); final MobicentsSipApplicationSessionKey sipAppSessionKey = sipApplicationSession.getKey(); final MobicentsProxy proxy = session.getProxy(); response); sipURI.setParameter(MessageDispatcher.RR_PARAM_SERVER_NAME, sipFactoryImpl.getSipApplicationDispatcher().getApplicationServerId()); sipURI.setParameter(MessageDispatcher.RR_PARAM_APPLICATION_NAME, sipFactoryImpl.getSipApplicationDispatcher().getHashFromApplicationName(session.getKey().getApplicationName())); sipURI.setParameter(MessageDispatcher.APP_ID, sipAppSessionKey.getId()); sipURI.setLrParam(); session.updateStateOnResponse(this, false); if(Request.SUBSCRIBE.equals(getMethod()) && statusCode >= 200 && statusCode <= 300 && session.getProxy() == null) { session.addSubscription(this); ((DialogExt)dialog).disableSequenceNumberValidation(); session.setSessionCreatingDialog(dialog); if(logger.isDebugEnabled()) { logger.debug("created following dialog since the application is acting as an endpoint " + dialog); session.access(); sipApplicationSession.access(); session.setSessionCreatingDialog(dialog);
/** * @param session the session to set */ public void setSipSession(MobicentsSipSession session) { // we store the session in JVM to cope with race conditions on session invalidation // See Issue 1294 http://code.google.com/p/mobicents/issues/detail?id=1294 // but it will not be persisted to avoid unecessary replication if the message is persisted this.sipSession = session; if (session != null){ this.sessionKey = session.getKey(); } else { this.sessionKey = null; } }
logger.debug("Trying to remove sip session " + mobicentsSipSession); final SipSessionKey key = (SipSessionKey) mobicentsSipSession.getKey(); MobicentsSipSession parentSession = mobicentsSipSession.getParentSession(); if(parentSession != null) { Iterator<MobicentsSipSession> itDerivedSessions = parentSession.getDerivedSipSessions(); if(itDerivedSessions.hasNext()) { if(logger.isDebugEnabled()) { logger.debug("parent session " + parentSession.getKey() + " still contains derived sip sessions so not removing"); logger.debug("Derived sip sessions left are : "); while (itDerivedSessions.hasNext()) { MobicentsSipSession derivedSipSession = itDerivedSessions.next(); logger.debug("Derived sip session : " + derivedSipSession.getKey() + " isValid " + derivedSipSession.isValidInternal() + " isReadyToInvalidate " + derivedSipSession.isReadyToInvalidateInternal()); if(parentSession.isValidInternal()) { if(logger.isDebugEnabled()) { logger.debug("not removing parent sip session " + parentSession.getKey() + " without derived sessions since it's still valid"); Iterator<MobicentsSipSession> itDerivedSessions = mobicentsSipSession.getDerivedSipSessions(); if(itDerivedSessions.hasNext()) { if(logger.isDebugEnabled()) { logger.debug("Sip Session " + mobicentsSipSession.getKey() + " still contains derived sip sessions so not removing"); logger.debug("Derived sip sessions left are : "); while (itDerivedSessions.hasNext()) { MobicentsSipSession derivedSipSession = itDerivedSessions.next(); logger.debug("Derived sip session : " + derivedSipSession.getKey() + " isValid " + derivedSipSession.isValidInternal() + " isReadyToInvalidate " + derivedSipSession.isReadyToInvalidateInternal());
&& session.getKey().getToTag() != null && session.getKey().getToTag().length() >0) { if(!dialog.getLocalTag().equals(session.getKey().getToTag())) { logger.debug("setting session ToTag: " + session.getKey().getToTag()); toHeader.setTag(session.getKey().getToTag()); } else { if(logger.isDebugEnabled()) { } else if(session != null && session.getSipApplicationSession() != null) { final MobicentsSipApplicationSessionKey sipAppSessionKey = session.getSipApplicationSession().getKey(); final MobicentsSipSessionKey sipSessionKey = session.getKey(); session.getKey().setToTag(toTag, false); String outboundInterface = null; if(session != null) { outboundInterface = session.getOutboundInterface(); super.sipFactoryImpl.getSipNetworkInterfaceManager(), request, null, null, outboundInterface); String transport = "udp"; if(session != null && session.getTransport() != null) transport = session.getTransport(); SipConnector sipConnector = StaticServiceHolder.sipStandardService.findSipConnector(transport); if(sipConnector != null && sipConnector.isUseStaticAddress()) { if(session != null && session.getProxy() == null) { boolean sipURI = contactHeader.getAddress().getURI().isSipURI(); if(sipURI) { if(session != null && session.getCopyRecordRouteHeadersOnSubsequentResponses() && !isInitial() && Request.INVITE.equals(requestMethod)) {
clonedRequest.setCurrentApplicationName(originalRequest.getCurrentApplicationName()); if(clonedRequest.getCurrentApplicationName() == null && subsequent) { clonedRequest.setCurrentApplicationName(originalSipSession.getSipApplicationSession().getApplicationName()); newSession.setHandler(originalSipSession.getHandler()); } catch (ServletException e) { logger.error("could not set the session handler while forwarding the request", e); newSession.setProxy(proxy);
/** * set the handler for this request if none already exists. * The handler will be the main servlet of the sip context * @param request the session of this request will have its handler set. */ private void checkHandler(SipServletRequest request) { MobicentsSipSession sipSessionImpl = (MobicentsSipSession)request.getSession(); if(sipSessionImpl.getHandler() == null) { try { sipSessionImpl.setHandler(sipContext.getServletHandler()); // ((SipApplicationSessionImpl)sipSessionImpl.getApplicationSession()).setSipContext(sipContext); } catch (ServletException se) { //should never happen logger.error("Impossible to set the default handler on the newly created request "+ request.toString(),se); } } }