public SipContext getSipContext() { return this.sipApplicationSession.getSipContext(); }
public static SipContext lookupContext() { SipContext ctx = null; SipApplicationSessionCreationThreadLocal get = sessionsTH.get(); if (get != null) { Iterator<MobicentsSipApplicationSession> iterator = get.getSipApplicationSessions().iterator(); if (iterator.hasNext()) { ctx = iterator.next().getSipContext(); } } return ctx; } }
protected SipSessionImpl (SipSessionKey key, SipFactoryImpl sipFactoryImpl, MobicentsSipApplicationSession mobicentsSipApplicationSession) { this.key = key; setSipApplicationSession(mobicentsSipApplicationSession); this.sipFactory = sipFactoryImpl; this.creationTime = this.lastAccessedTime = System.currentTimeMillis(); this.state = State.INITIAL; this.isValidInternal = new AtomicBoolean(true); this.isValid = true; this.ongoingTransactions = new CopyOnWriteArraySet<Transaction>(); if(mobicentsSipApplicationSession.getSipContext() != null && ConcurrencyControlMode.SipSession.equals(mobicentsSipApplicationSession.getSipContext().getConcurrencyControlMode())) { semaphore = new Semaphore(1); } } /**
/** * {@inheritDoc} */ public ServletContext getServletContext() { return getSipApplicationSession().getSipContext().getServletContext(); }
public static boolean securityCheck(MobicentsSipServletRequest request) { MobicentsSipApplicationSession appSession = (MobicentsSipApplicationSession) request.getSipApplicationSession(true); SipContext sipStandardContext = appSession.getSipContext(); boolean authorized = sipStandardContext.authorize(request); // This will propagate the identity for the thread and all called components // TODO: FIXME: This would introduce a dependency on JBoss // SecurityAssociation.setPrincipal(request.getUserPrincipal()); return authorized; }
protected MobicentsSipSession createSipSession(final SipSessionKey key, final boolean create, final SipFactoryImpl sipFactoryImpl, final MobicentsSipApplicationSession sipApplicationSessionImpl) { MobicentsSipSession sipSessionImpl = null; final MobicentsSipSession newSipSessionImpl = getNewMobicentsSipSession(key, sipFactoryImpl, sipApplicationSessionImpl); // notification moved out of the sip session constructor so that for derived sessions it can be // called after the attribute map has been set to avoid that the application can create a different one // in accessing the sip session attributes in the sip session creation callback if(sipApplicationSessionImpl.getSipContext() != null) { // the sip context can be null if the AR returned an application that was not deployed newSipSessionImpl.notifySipSessionListeners(SipSessionEventType.CREATION); } sipSessionImpl = sipSessions.putIfAbsent(key, newSipSessionImpl); if(sipSessionImpl == null) { if(logger.isDebugEnabled()) { logger.debug("Adding a sip session with the key : " + key); } // put succeeded, use new value sipSessionImpl = newSipSessionImpl; } return sipSessionImpl; }
protected ClusteredSipSession(SipSessionKey key, SipFactoryImpl sipFactoryImpl, MobicentsSipApplicationSession mobicentsSipApplicationSession, boolean useJK) { super(key, sipFactoryImpl, mobicentsSipApplicationSession); if(mobicentsSipApplicationSession.getSipContext() != null) { manager = ((JBossCacheSipManager)mobicentsSipApplicationSession.getSipContext().getSipManager()); invalidationPolicy = manager.getInvalidateSessionPolicy(); } this.useJK = useJK; this.firstAccess = true; isNew = true; // it starts with true so that it gets replicated when first created sessionMetadataDirty = true; checkAlwaysReplicateMetadata(); haId = SessionManagerUtil.getSipSessionHaKey(key); }
/** * {@inheritDoc} */ public javax.servlet.RequestDispatcher getRequestDispatcher(String handler) { MobicentsSipServlet sipServletImpl = (MobicentsSipServlet) getSipSession().getSipApplicationSession().getSipContext().findSipServletByName(handler); if(sipServletImpl == null) { throw new IllegalArgumentException(handler + " is not a valid servlet name"); } return new SipRequestDispatcher(sipServletImpl); }
public ServletTimer createTimer(SipApplicationSession appSession, long delay, boolean isPersistent, Serializable info) { MobicentsSipApplicationSession sipApplicationSessionImpl =(MobicentsSipApplicationSession)appSession; if (sipApplicationSessionImpl.isValid() == false) { throw new IllegalStateException("Sip application session has been invalidated!!!"); } if (!sipApplicationSessionImpl.hasTimerListener()) { throw new IllegalStateException("No Timer listeners have been configured for this application "); } TimerListener listener = sipApplicationSessionImpl.getSipContext().getListeners().getTimerListener(); ServletTimerImpl servletTimer = createTimerLocaly(listener, delay, isPersistent, info, sipApplicationSessionImpl); return servletTimer; }
public ServletTimer createTimer(SipApplicationSession appSession, long delay, long period, boolean fixedDelay, boolean isPersistent, Serializable info) { if (period < 1) { throw new IllegalArgumentException( "Period should be greater than 0"); } MobicentsSipApplicationSession sipApplicationSessionImpl = (MobicentsSipApplicationSession) appSession; if (sipApplicationSessionImpl.isValid() == false) { throw new IllegalStateException("Sip application session has been invalidated!!!"); } if (!sipApplicationSessionImpl.hasTimerListener()) { throw new IllegalStateException("No Timer listeners have been configured for this application "); } TimerListener timerListener = sipApplicationSessionImpl.getSipContext().getListeners().getTimerListener(); ServletTimerImpl servletTimer = createTimerLocaly(timerListener , delay, period, fixedDelay,isPersistent, info,sipApplicationSessionImpl); return servletTimer; }
public MobicentsSipSessionFacade getFacade() { MobicentsSipApplicationSession sipApplicationSession = getSipApplicationSession(); if (facade == null && sipApplicationSession != null){ SipContext sipContext = sipApplicationSession.getSipContext(); if (sipContext.isPackageProtectionEnabled()){ final MobicentsSipSession fsession = this; facade = (MobicentsSipSessionFacade)AccessController.doPrivileged(new PrivilegedAction(){ public Object run(){ return new MobicentsSipSessionFacade(fsession); } }); } else { facade = new MobicentsSipSessionFacade(this); } } return (facade); } @Override
public void dispatchAndHandleExceptions () { try { dispatch(); } catch (Throwable t) { logger.error("Unexpected exception while processing message " + sipServletMessage, t); if(sipServletMessage instanceof SipServletRequestImpl) { SipServletRequestImpl sipServletRequest = (SipServletRequestImpl) sipServletMessage; if(!Request.ACK.equalsIgnoreCase(sipServletRequest.getMethod()) && !Request.PRACK.equalsIgnoreCase(sipServletRequest.getMethod())) { MessageDispatcher.sendErrorResponse(sipServletRequest.getSipSession().getSipApplicationSession().getSipContext().getSipApplicationDispatcher(), Response.SERVER_INTERNAL_ERROR, sipServletRequest, sipProvider); } } } }
/** * Advise our manager to remove this expired session. * * @param localCall * whether this call originated from local activity or from a * remote invalidation. In this default implementation, this * parameter is ignored. * @param localOnly * whether the rest of the cluster should be made aware of the * removal */ protected void removeFromManager(boolean localCall, boolean localOnly) { if (localOnly) { ((JBossCacheSipManager) getSipApplicationSession().getSipContext().getSipManager()).removeLocal(this); } else { getSipApplicationSession().getSipContext().getSipManager().removeSipSession(key); } }
@Override public void run() { final SipContext sipContext = sipApplicationSession.getSipContext(); boolean batchStarted = false; try { // https://github.com/Mobicents/sip-servlets/issues/70 This timer task needs to be executed // only if the sipapplicationsession is not currently in use or there is concurrency issues sipContext.enterSipApp(sipApplicationSession, null, false, true); batchStarted = sipContext.enterSipAppHa(true); if(proxyBranch != null) { proxyBranch.onTimeout(this.responseType); } } catch (Exception e) { logger.error("Problem in timeout task", e); } finally { this.proxyBranch = null; sipContext.exitSipAppHa(null, null, batchStarted); sipContext.exitSipApp(sipApplicationSession, null); } }
public void setHandler(String name) throws ServletException { if(!isValid()) { throw new IllegalStateException("the session has already been invalidated, no handler can be set on it anymore !"); } if(name != null && name.equals(handlerServlet)) { return ; } SipContext sipContext = getSipApplicationSession().getSipContext(); MobicentsSipServlet container = sipContext.findSipServletByName(name); if(container == null && sipContext.getSipRubyController() == null) { throw new ServletException("the sip servlet with the name "+ name + " doesn't exist in the sip application " + sipContext.getApplicationName()); } this.handlerServlet = name; getSipApplicationSession().setCurrentRequestHandler(handlerServlet); if(logger.isDebugEnabled()) { if(name !=null) { logger.debug("Session Handler for application " + getKey().getApplicationName() + " set to " + handlerServlet + " on sip session " + key); } else { logger.debug("Session Handler for application " + getKey().getApplicationName() + " set to " + sipContext.getSipRubyController() + " on sip session " + key); } } }
public ProxyImpl(SipServletRequestImpl request, SipFactoryImpl sipFactoryImpl) { this.proxyTimerService = ((MobicentsSipApplicationSession)request.getSipApplicationSession(false)).getSipContext().getProxyTimerService(); this.originalRequest = request; this.sipFactoryImpl = sipFactoryImpl; this.proxyBranches = new LinkedHashMap<URI, ProxyBranchImpl> (); this.proxyTimeout = 180; // 180 secs default this.proxy1xxTimeout = -1; // not activated by default String outboundInterfaceStringified = ((MobicentsSipSession)request.getSession()).getOutboundInterface(); if(outboundInterfaceStringified != null) { try { outboundInterface = (SipURI) sipFactoryImpl.createURI(outboundInterfaceStringified); } catch (ServletParseException e) { throw new IllegalArgumentException("couldn't parse the outbound interface " + outboundInterface, e); } } this.callerFromTag = ((MessageExt)request.getMessage()).getFromHeader().getTag(); this.previousNode = extractPreviousNodeFromRequest(request); putTransaction(originalRequest); } // https://code.google.com/p/sipservlets/issues/detail?id=238
public B2buaHelper getB2buaHelper() { checkReadOnly(); final MobicentsSipSession session = getSipSession(); if (session.getProxy() != null) throw new IllegalStateException("Proxy already present"); MobicentsB2BUAHelper b2buaHelper = session.getB2buaHelper(); if (b2buaHelper != null) return b2buaHelper; b2buaHelper = new B2buaHelperImpl(); b2buaHelper.setMobicentsSipFactory(sipFactoryImpl); b2buaHelper.setSipManager(session.getSipApplicationSession().getSipContext().getSipManager()); if(JainSipUtils.DIALOG_CREATING_METHODS.contains(getMethod())) { this.createDialog = true; // flag that we want to create a dialog for outgoing request. } session.setB2buaHelper(b2buaHelper); return b2buaHelper; }
protected void scheduleExpirationTimer(MobicentsSipApplicationSession sipApplicationSession) { // Sip Application Session Timer Task moved out of the SipApplicationSession constructor // as for clustering it might not be needed to reschedule them on recreation final SipContext sipContext = sipApplicationSession.getSipContext(); if(sipContext != null) { if(sipContext.getSipApplicationSessionTimeout() > 0) { SipApplicationSessionTimerTask expirationTimerTask = sipContext.getSipApplicationSessionTimerService().createSipApplicationSessionTimerTask(sipApplicationSession); expirationTimerTask = sipContext.getSipApplicationSessionTimerService().schedule(expirationTimerTask, sipApplicationSession.getSipApplicationSessionTimeout(), TimeUnit.MILLISECONDS); sipApplicationSession.setExpirationTimerTask(expirationTimerTask); } sipApplicationSession.notifySipApplicationSessionListeners(SipApplicationSessionEventType.CREATION); } }
private void addChallengeResponse( WWWAuthenticateHeader wwwAuthHeader, String username, String password, String uri) { int nc = generateNcFromMessage(message); AuthorizationHeader authorization = getSipSession().getSipApplicationSession().getSipContext().getDigestAuthenticator().getAuthorizationHeader( getMethod(), uri, "", // TODO: What is this entity-body? wwwAuthHeader, username, password, wwwAuthHeader.getNonce(), nc); message.addHeader(authorization); }
public SipSession getSession(boolean create) { MobicentsSipSession session = getSipSession(); if (session == null && create) { MobicentsSipApplicationSession sipApplicationSessionImpl = (MobicentsSipApplicationSession)getSipApplicationSession(create); MobicentsSipSessionKey sessionKey = SessionManagerUtil.getSipSessionKey(sipApplicationSessionImpl.getKey().getId(), currentApplicationName, message, false); session = sipApplicationSessionImpl.getSipContext().getSipManager().getSipSession(sessionKey, create, sipFactoryImpl, sipApplicationSessionImpl); session.setSessionCreatingTransactionRequest(this); session.setOrphan(isOrphan()); sessionKey = session.getKey(); } if(session != null) { return session.getFacade(); } return null; }