Package org.cipango.sipapp

Examples of org.cipango.sipapp.SipAppContext$Context


        {
            InitialContext ic = new InitialContext();

            Server server = new Server();

            SipAppContext context = new SipAppContext();
            context.setServer(server);
            context.getSipMetaData().setAppName("myApp");
            context.setClassLoader(new WebAppClassLoader(Thread.currentThread().getContextClassLoader(), context));
            context.setOverrideSipDescriptors(Arrays.asList(getClass().getResource("/sip.xml").toString()));
            context.setServletHandler(new SipServletHandler());
           
            Thread.currentThread().setContextClassLoader(context.getClassLoader());
           
      PlusConfiguration plusConfiguration = new PlusConfiguration();
      EnvConfiguration envConfiguration = new EnvConfiguration();
      envConfiguration.setJettyEnvXml(getClass().getResource("/jetty-env.xml"));

      // Need to add a listener or a servlet to ensure that SipFactory is set in JNDI
      context.getSipMetaData().addListener("org.cipango.plus.sipapp.Listener");
     
      context.setConfigurations(new Configuration[] {envConfiguration, plusConfiguration, new SipXmlConfiguration()});
      context.preConfigure();
      context.configure();
      context.postConfigure();   
      context.getSipMetaData().resolve(context);
     

       Object lookup = ic.lookup("java:comp/env/resource/sample");
       Assert.assertNotNull(lookup);
       Assert.assertEquals("1234", lookup);
      
       Assert.assertEquals(context.getSipFactory(), ic.lookup("java:comp/env/sip/myApp/SipFactory"));
       Assert.assertEquals(context.getTimerService(), ic.lookup("java:comp/env/sip/myApp/TimerService"));
       Assert.assertEquals(context.getSipSessionsUtil(), ic.lookup("java:comp/env/sip/myApp/SipSessionsUtil"));
        }
        finally
        {
            Thread.currentThread().setContextClassLoader(old_loader);
        }
View Full Code Here


  {
    Session session = null;
   
    if (request.isInitial())
    {
      SipAppContext appContext = (SipAppContext) request.getHandlerAttribute(ID.CONTEXT_ATTRIBUTE);
      SipServletHolder handler = ((SipServletHandler) appContext.getServletHandler()).findHolder(request);
 
      if (handler == null)
      {
        Log.debug("SIP application {} has no matching servlet for {}", appContext.getName(), request.getMethod());
        if (!request.isAck())
        {           
          SipResponse response = (SipResponse) request.createResponse(SipServletResponse.SC_NOT_FOUND);
          response.to().setParameter(SipParams.TAG, ID.newTag());
          ((ServerTransaction) request.getTransaction()).send(response);
        }
        return;
      }
     
      AppSession appSession;
     
      String key = (String) request.getHandlerAttribute(ID.SESSION_KEY_ATTRIBUTE);
     
      if (key != null)
      {
        String id = ID.getIdFromKey(appContext.getName(), key);
        appSession = request.getCallSession().getAppSession(id);
        if (appSession == null)
          appSession = request.getCallSession().createAppSession(appContext, id);
      }
      else
View Full Code Here

      if (isInitial(request))
          {
        request.setInitial(true);
       
        SipApplicationRouterInfo routerInfo = null;
        SipAppContext appContext = null;
       
        try
        {
          if (route != null)
          {
            SipURI uri = (SipURI) route.getURI();
            if (RouterInfoUtil.ROUTER_INFO.equals(uri.getUser()))
            {
              routerInfo = RouterInfoUtil.decode(uri);
              route = popLocalRoute(request);
            }
            if (route != null)
              request.setPoppedRoute(route);
          }
         
          if (routerInfo == null)
          {
            routerInfo = ((Server) getServer()).getApplicationRouter().getNextApplication(
              request, null, SipApplicationRoutingDirective.NEW, null, null);
          }
        }
        catch (Throwable t)
        {
          if (!request.isAck())
          {
            SipResponse response = new SipResponse(
                request,
                SipServletResponse.SC_SERVER_INTERNAL_ERROR,
                "Application router error: " + t.getMessage());
            ExceptionUtil.fillStackTrace(response, t);
            getConnectorManager().sendResponse(response);
          }
          return;
        }
       
        if (routerInfo != null && routerInfo.getNextApplicationName() != null)
        {
          boolean handle = handlingRoute(request, routerInfo);
          if (handle)
            return;
         
          request.setStateInfo(routerInfo.getStateInfo());
          request.setRegion(routerInfo.getRoutingRegion());
         
          String s = routerInfo.getSubscriberURI();
          if (s != null)
          {
            try
            {
              request.setSubscriberURI(URIFactory.parseURI(s));
            }
            catch (ServletParseException e)
            {
              Log.debug(e);
            }
          }
         
          String applicationName = routerInfo.getNextApplicationName();
          appContext = (SipAppContext) getContext(applicationName);
                   
          Method method = appContext == null ? null : appContext.getSipApplicationKeyMethod();
          if (method != null)
          {
            try
            {
              String sessionKey = (String) method.invoke(null, request);
View Full Code Here

      {
        String sessionKey = (String) request.getHandlerAttribute(ID.SESSION_KEY_ATTRIBUTE);
     
        if (sessionKey != null)
        {
          SipAppContext context = (SipAppContext) request.getHandlerAttribute(ID.CONTEXT_ATTRIBUTE);
          return ID.getIdFromKey(context.getName(), sessionKey);
        }
      }
      else
      {   
        String appSessionId = request.getParameter(ID.APP_SESSION_ID_PARAMETER);
View Full Code Here

   */
  public void setHandler(String name) throws ServletException
  {
    checkValid();
   
    SipAppContext context = _appSession.getContext();
    SipServletHolder handler = context.getSipServletHandler().getHolder(name);
   
    if (handler == null)
      throw new ServletException("No handler named " + name);
   
    setHandler(handler);
View Full Code Here

 
  public void invalidateIfReady()
  {
    if (isValid() && getInvalidateWhenReady() && isReadyToInvalidate())
    {
      SipAppContext context = _appSession.getContext();
      SipSessionListener[] listeners = context.getSipSessionListeners();
      if (listeners.length > 0)
        context.fire(listeners, AppSession.__sessionReadyToInvalidate, new SipSessionEvent(this));
     
      if (isValid() && getInvalidateWhenReady())
        invalidate();
    }
  }
View Full Code Here

        SipServlet annotation = (SipServlet) clazz.getAnnotation(SipServlet.class);
       
       
        SipServletHolder holder = new SipServletHolder();
       
        SipAppContext context = (SipAppContext) _context;
   
        if (!Util.isEmpty(annotation.applicationName()))
        {
         
          if (context.getName() != null && !context.getName().equals(annotation.applicationName()))
          throw new IllegalStateException("App-name in sip.xml: " + context.getName()
              + " does not match with SipApplication annotation: " + annotation.applicationName());
          context.getSipMetaData().setAppName(annotation.applicationName());
        }
       
        if (annotation.name() != null && !"".equals(annotation.name()))
          holder.setName(annotation.name());
        else
          holder.setName(_className.substring(_className.lastIndexOf('.') + 1));
       
        holder.setInitOrder(annotation.loadOnStartup());
        holder.setDisplayName(annotation.description());
        holder.setClassName(_className);
       
        context.addSipServlet(holder);
    }
View Full Code Here

        }
       
        SipListener annotation = (SipListener) clazz.getAnnotation(SipListener.class);
       
  
        SipAppContext context = (SipAppContext) _context;
   
        if (!Util.isEmpty(annotation.applicationName()))
        {
         
          if (context.getName() != null && !context.getName().equals(annotation.applicationName()))
          throw new IllegalStateException("App-name in sip.xml: " + context.getName()
              + " does not match with SipApplication annotation: " + annotation.applicationName());
          context.getSipMetaData().setAppName(annotation.applicationName());
        }
 
        context.getSipMetaData().addListener(_className);
    }
View Full Code Here

    {
      context.addDecorator(new AnnotationDecorator(context));
      
        AnnotationParser parser = new AnnotationParser();

        SipAppContext sac = (SipAppContext) context;
        if (sac.getSpecVersion() == SipAppContext.VERSION_10)
          return;
       
        if (Log.isDebugEnabled())
          Log.debug("parsing annotations");
       
View Full Code Here

       
    
        SipApplication annotation = (SipApplication) clazz.getAnnotation(SipApplication.class);
       
  
        SipAppContext context = (SipAppContext) _context;
       
    if (context.getName() != null && !context.getName().equals(annotation.name()))
      throw new IllegalStateException("App-name in sip.xml: " + context.getName()
          + " does not match with SipApplication annotation: " + annotation.name());
    context.getSipMetaData().setAppName(annotation.name());
   
    context.setDistributable(annotation.distributable());
    context.setDisplayName(annotation.displayName());
    context.setProxyTimeout(annotation.proxyTimeout());
    context.setSessionTimeout(annotation.sessionTimeout());
        context.getSipMetaData().setMainServletName(annotation.mainServlet());
    }
View Full Code Here

TOP

Related Classes of org.cipango.sipapp.SipAppContext$Context

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.