Package org.apache.tomcat.core

Examples of org.apache.tomcat.core.Context


     *  session id ( and set it only if valid ), and "touch" the
     *  session.
     */
    public int requestMap(Request request ) {
  String sessionId = null;
  Context ctx=request.getContext();
  if( ctx==null ) {
      log( "Configuration error in StandardSessionInterceptor " +
     " - no context " + request );
      return 0;
  }
View Full Code Here


  context.setClassLoader(loader);
  context.setAttribute( "org.apache.tomcat.classloader", loader);
    }

    public int contextMap( Request request ) {
  Context ctx=request.getContext();
  if( ctx==null) return 0;
 
  // XXX This interceptor will be added per/context.
  if( ! ctx.getReloadable() ) return 0;

  // We are remapping ?
  if( request.getAttribute("tomcat.ReloadInterceptor")!=null)
      return 0;
 
  DependManager dm=(DependManager)ctx.getContainer().
      getNote(dependManagerNote);
  if( ! dm.shouldReload() ) return 0;

  if( debug> 0 )
      log( "Detected changes in " + ctx.toString());

  try {
      // Reload context. 
      ContextManager cm=ctx.getContextManager();
     
      if( fullReload ) {
    synchronized(ctx) {
        if(ctx.getState() == Context.STATE_NEW)
      return 0; // Already reloaded.
        Vector sI=new Vector()// saved local interceptors
        BaseInterceptor[] eI;    // all exisiting interceptors

        // save the ones with the same context, they are local
        eI=ctx.getContainer().getInterceptors();
        for(int i=0; i < eI.length ; i++)
      if(ctx == eI[i].getContext()) sI.addElement(eI[i]);
       
        Enumeration e;
        // Need to find all the "config" that
        // was read from server.xml.
        // So far we work as if the admin interface was
        // used to remove/add the context.
        // Or like the deploytool in J2EE.
        Context ctx1=cm.createContext();
        ctx1.setContextManager( cm );
        ctx1.setPath(ctx.getPath());
        ctx1.setDocBase(ctx.getDocBase());
        ctx1.setReloadable( ctx.getReloadable());
        ctx1.setDebug( ctx.getDebug());
        ctx1.setHost( ctx.getHost());
        ctx1.setTrusted( ctx.isTrusted());
        e=ctx.getHostAliases();
        while( e.hasMoreElements())
      ctx1.addHostAlias( (String)e.nextElement());

        BaseInterceptor ri[] =
      cm.getContainer().getInterceptors(Container.H_copyContext);
        int i;
        for( i=0; i < ri.length; i++) {
      ri[i].copyContext(request, ctx, ctx1);
        }
        cm.removeContext( ctx );
       
        cm.addContext( ctx1 );

        // put back saved local interceptors
        e=sI.elements();
        while(e.hasMoreElements()){
      BaseInterceptor savedI=(BaseInterceptor)e.nextElement();
     
      ctx1.addInterceptor(savedI);
      savedI.setContext(ctx1);
      savedI.reload(request,ctx1);
        }

        ctx1.init();

        // remap the request
        request.setAttribute("tomcat.ReloadInterceptor", this);
        ri = cm.getContainer().getInterceptors(Container.H_contextMap);
       
View Full Code Here

      if( debug > 0 ) log("Registering new session for expiry checks");
      ts.setNew(true);
      ts.setValid(true);
     
      ts.setCreationTime(System.currentTimeMillis());
      Context ctx=session.getContext();
      ts.setMaxInactiveInterval( ctx.getSessionTimeOut() * 60000 );

      session.getTimeStamp().setParent( session );

      expirer.addManagedObject( ts );
  else if( state==ServerSession.STATE_EXPIRED ) {
View Full Code Here

  // Make sure we know about all contexts added before.
  Enumeration loadedCtx=cm.getContexts();
  // loaded but not initialized - since we are still configuring
  // the server
  while( loadedCtx.hasMoreElements() ) {
      Context ctx=(Context)loadedCtx.nextElement();
      String host=ctx.getHost();
      if(host==null) host="DEFAULT";
     
      Hashtable loaded=(Hashtable)hosts.get( host );
      if( loaded==null ) {
    loaded=new Hashtable();
    hosts.put(host, loaded );
      }
      loaded.put( ctx.getPath(), ctx );
  }
 
        File webappD=new File(appsD);
        if( !webappD.isAbsolute() ) {
            webappD=new File( cm.getHome(), appsD);
View Full Code Here

  }
  log("Auto-Adding " + host + ":" +
      ( "".equals(path) ? "/" : path ) );

  if (dir.isDirectory()) {
      Context ctx=cm.createContext();
      ctx.setContextManager( cm );
      ctx.setPath(prefix + path);
            ctx.setReloadable(reloadable);
      if( ! "DEFAULT".equals( host ) )
    ctx.setHost( host );
      try {
    ctx.setDocBase( dir.getCanonicalPath() );
      } catch(IOException ex ) {
    ctx.setDocBase( dir.getAbsolutePath());
      }

      if( trusted )
    ctx.setTrusted( true );
      if( profile!=null )
    ctx.setProperty( "profile", profile );
     
      if( debug > 0 )
    log("automatic add " + host + ":" + ctx.toString() + " " +
        path);
      cm.addContext(ctx);
  } else {
      log( "Not a dir " + dir.getAbsolutePath());
  }
View Full Code Here

  if( debug > 0 ) log( "Init " + ctx + " " + showDebugInfo);
    }

    public int handleError( Request req, Response res, Throwable t ) {
  ContextManager cm=req.getContextManager();
  Context ctx = req.getContext();
  if(ctx==null) {
      // that happens only if the request can't pass contextMap
      // hook. The reason for that is a malformed request, or any
      // other error.
      ctx=rootContext;
View Full Code Here

    public void doService(Request req, Response res)
  throws Exception
    {
  String location  = (String)
      req.getAttribute("javax.servlet.error.message");
  Context ctx=req.getContext();

  if( res.getStatus() != 301 &&
      res.getStatus() != 302 ) {
      res.setStatus( defaultRedirectStatus );
  }
 
  location = makeAbsolute(req, location);

  if( debug>0) ctx.log("Redirect " + location + " " + req );

  String charset = LocaleToCharsetMap.getCharset(Locale.getDefault());
  if (charset == null) {
      res.setContentType("text/html");
  } else {
View Full Code Here

  if( state!=ContextManager.STATE_CONFIG ) return;

  if( debug>0 ) log("TrustedLoader: " + state );
  Enumeration ctxsE= cm.getContexts();
  while( ctxsE.hasMoreElements() ) {
      Context context=(Context)ctxsE.nextElement();
      if( ! context.isTrusted() ) continue;

      File modules=getModuleFile( context );
      if( modules==null ) continue;

      /*  We'll create a temporary loader for this context, and use it
       *  to create a module. The module will be notified for all
       *  contexts that were added so far, as with any normal module.
       *
       *  What's special is that at init stage, the module will be
       *  removed and loaded again, with the real class loader.
       *  Same thing will happen when the application is reloaded.
       *
       *  BTW, modules are supposed to be reloadable, but there is
       *  a lot of work still needed ( mostly in modules, to make them
       *  aware )
       */
      LoaderInterceptor11 loaderHelper=new LoaderInterceptor11();
      loaderHelper.setContextManager( cm );
      loaderHelper.addContext( cm, context );
      loaderHelper.contextInit( context );

      Vector modV=new Vector();
      if(debug>0) log("loadInterceptors in a dummy classloader for setup " + context + " " +
          context.isTrusted() + " " + context.getDocBase());
      loadInterceptors( context, modules, modV );
      cm.setNote( "trustedLoader.currentContext", context );

            Vector ctxModules=new Vector();
            allModules.put( context, ctxModules );

      // Now add all modules to cm
      for( int i=0; i< modV.size(); i++ ) {
    BaseInterceptor bi=(BaseInterceptor)modV.elementAt( i );
    if(debug>0) log( "Add dummy module, for configuration " + context.getDocBase() + " " + context);
    cm.addInterceptor( bi );
                ctxModules.addElement( bi );
      }
      cm.setNote"trustedLoader.currentContext", null );
      context.setClassLoader( null );
            context.removeAttribute("org.apache.tomcat.classloader");
  }
    }
View Full Code Here

    path= FileUtil.catPath( request.servletPath().toString() + pI,
          path);
      if( path==null) return null;
  }

  Context ctx=request.getContext();
  return ((ServletContext)ctx.getFacade()).getRequestDispatcher(path);
    }
View Full Code Here

    /**
     * @deprecated
     */
    public String getRealPath(String name) {
  Context ctx=request.getContext();
        return FileUtil.safePath( ctx.getAbsolutePath(),
          name);
    }
View Full Code Here

TOP

Related Classes of org.apache.tomcat.core.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.