Package org.apache.tomcat.core

Examples of org.apache.tomcat.core.Context


    public int requestMap(Request req) {
  //  if( debug>0 ) log("Req map " + req);
  if( req.getHandler() != null )
      return 0;

  Context ctx=req.getContext();

  // will call getRealPath(), all path normalization
  // and a number of checks
  String pathInfo=req.servletPath().toString();
  if( pathInfo==null ) pathInfo="";

  if( debug > 0 ) log("Method: " + req.method());
  if(req.method().equalsIgnoreCase("OPTIONS") ||
           req.method().equalsIgnoreCase("TRACE")) {
      req.setHandlerctx.getServletByName( "tomcat.fileHandler"));
      return 0;
  }
     
  String absPath=FileUtil.safePath( ctx.getAbsolutePath(),
            pathInfo);

  if( debug > 0 ) log( "RequestMap " + req + " " + absPath + " " +
           ctx.getAbsolutePath() );
  if( absPath == null ) return 0;
  String requestURI=req.requestURI().toString();

  if( debug > 0 )
      log( "Requested: "  + absPath );

  File file=new File( absPath );

  if( file.isFile() ) {
      if( debug > 0 ) log( "Setting handler to file " + absPath);
      req.setNote( realFileNote, absPath );
      req.setHandlerctx.getServletByName( "tomcat.fileHandler"));
      return 0;
  }

  if( ! file.isDirectory() ) {
      // we support only files and dirs
      if( debug > 0) log( "No file and no directory");
      return 0; // no handler is set - will end up as 404
  }


  // consistent with Apache
  if( ! requestURI.endsWith("/") && !req.getResponse().isIncluded()) {
      String redirectURI= requestURI + "/";
      redirectURI=fixURLRewriting( req, redirectURI );
      String query = req.query().toString();
      if( query != null && !query.equals("") )
    redirectURI += "?" + query;
      req.setAttribute("javax.servlet.error.message",
           redirectURI);
      if( debug > 0) log( "Redirect " + redirectURI );
      req.setHandler( ctx.getServletByName( "tomcat.redirectHandler"));
      return 0;
  }
  // Directory, check if we have a welcome file
 
  String welcomeFile = null;
  if( strict23Welcome ) {
      welcomeFile = getStrictWelcomeFile(ctx, file, pathInfo);
  } else {
      welcomeFile = getWelcomeFile(ctx, file);
  }
  if( debug > 0 )
      log( "DefaultServlet: welcome file: "  + welcomeFile);
 
  // Doesn't matter if we are or not in include
  if( welcomeFile == null  ) {
      // normal dir, no welcome.
      req.setHandler( ctx.getServletByName( "tomcat.dirHandler"));
      if( debug > 0) log( "Dir handler");
      return 0;
  }
  int status = 0;
  if(useInternal) {
View Full Code Here


     */
    private int doInternalRedirect(Request req, String welcomeFile) {
        BaseInterceptor ri[];
  String requestURI=req.requestURI().toString();
  String redirectURI=concatPath(requestURI,welcomeFile);
  Context ctx = req.getContext();
  req.requestURI().setString(redirectURI);
  req.unparsedURI().recycle();
  req.servletPath().recycle();
  req.pathInfo().recycle();

  /* We are using the real request here, so we don't want to have
     to repeat all of the pre-processing for cm.processRequest.
     This means that postReadRequest hooks aren't re-called for
     the new URI, but that shouldn't matter. And calling
     them again is more likely to do harm than good IMHO. However,
     we need to contextMap again to catch extention-mapped servlets.
  */
  int status = 0;
  if(ctx == null) {
      ri=cm.getContainer().getInterceptors(Container.H_contextMap);
  } else {
      ri = ctx.getContainer().getInterceptors(Container.H_contextMap);
  }
 
  for( int i=0; i< ri.length; i++ ) {
      status=ri[i].contextMap( req );
      if( status!=0 ) return status;
View Full Code Here

  redirectURI=concatPath( requestURI, welcomeFile);
  redirectURI=fixURLRewriting( req, redirectURI );
  String query = req.query().toString();
  if ( query != null && ! query.equals("") )
      redirectURI += "?" + query;
  Context lCtx = req.getContext();

  req.setAttribute("javax.servlet.error.message",
       redirectURI);
  if( debug > 0) log( "Redirect " + redirectURI );
  // allow processing to go on - another mapper may change the
  // outcome, we are just the default ( preventive for bad ordering,
  // in correct config Static is the last one anyway ).
  req.setHandler( lCtx.getServletByName( "tomcat.redirectHandler"));
  return 0;
    }
View Full Code Here

  // if we are in include, with req==original request
  // - just use the current sub-request
  Request subReq=req;
  if(req.getChild()!=null)
      subReq=req.getChild();
  Context ctx=subReq.getContext();
  // Use "javax.servlet.include.servlet_path" for path if defined.
  // ErrorHandler places the path here when invoking an error page.
  String pathInfo = (String)subReq.getAttribute("javax.servlet.include.servlet_path");
  if(pathInfo == null) {
      // If the attribute isn't there, then we aren't included.
      // In that case, we must use the real request.
      //*** DEBUG *** subReq = req;
      pathInfo=subReq.servletPath().toString();
  }
  String absPath = (String)subReq.getNote( realFileNote );
  if( absPath==null )
      absPath=FileUtil.safePath( context.getAbsolutePath(),
               pathInfo);

  if( debug>0) log( "Requested file = " + absPath);
  String base = ctx.getAbsolutePath();
  absPath = extraCheck( base, absPath );
  if( absPath==null ) {
      context.getContextManager().handleStatus( req, res, 404);
      return;
  }

  File file = new File( absPath );
  // If we are included, the If-Modified-Since isn't for us.
  if( ! res.isIncluded() ) {
      long date = req.getDateHeader("If-Modified-Since");
      if ((file.lastModified() <= (date + 1000)) ) {
    // The entity has not been modified since the date
    // specified by the client. This is not an error case.
    context.getContextManager().handleStatus( req, res, 304);
    return;
      }

  }
  if( debug>0) log( "After paranoic checks = " + absPath);

        String mimeType=ctx.getMimeMap().getContentTypeFor(absPath);

  if (mimeType == null) {
      mimeType = "text/plain";
  }
  if( debug>0) log( "Serving  " + absPath);
View Full Code Here

      new SimpleDateFormat(datePattern,locale );

  boolean inInclude=req.getChild()!=null;
  Request subReq=req;
  if( inInclude ) subReq = req.getChild();
  Context ctx=req.getContext();
  String pathInfo=subReq.servletPath().toString();
  if( pathInfo == null ) pathInfo="";
  String absPath=FileUtil.safePath( context.getAbsolutePath(),
            pathInfo);
  File file = new File( absPath );
  String requestURI=subReq.requestURI().toString();
  String base = ctx.getAbsolutePath();
  if (absPath.length() > base.length())
  {
    String relPath=absPath.substring( base.length() + 1);
    String relPathU=relPath.toUpperCase();
    if ( relPathU.startsWith("WEB-INF") ||
View Full Code Here

      debug( "addContext() invalid docRoot: " + docRoot );
      throw new RuntimeException("Invalid docRoot " + docRoot );
  }

  try {
      Context ctx=contextM.createContext();
      ctx.setDebug( dL );
      ctx.setContextManager( contextM );
      ctx.setPath( ctxPath );
      ctx.setDocBase( docRoot.getFile());
      if( hosts!=null && hosts.length>0 ) {
    ctx.setHost( hosts[0] );
    for( int i=1; i>hosts.length; i++) {
        ctx.addHostAlias( hosts[i]);
    }
      }

      contextM.addContext( ctx );
      ctx.init();
      return ctx;
  } catch( Exception ex ) {
      debug("exception adding context " + ctxPath + "/" + docRoot, ex);
  }
  return null;
View Full Code Here

    {
  // We don't support virtual hosts in embeded tomcat
  // ( it's not difficult, but can be done later )
  Enumeration ctxE=contextM.getContexts();
  while( ctxE.hasMoreElements() ) {
      Context ctx=(Context)ctxE.nextElement();
      // XXX check host too !
      if( ctx.getPath().equals( cpath )) {
    // find if the host matches
    if( ctx.getHost()==null )
        return ctx;
    if( host==null )
        return ctx;
    if( ctx.getHost().equals( host ))
        return ctx;
    Enumeration aliases=ctx.getHostAliases();
    while( aliases.hasMoreElements()){
        if( host.equals( (String)aliases.nextElement()))
      return ctx;
    }
      }
View Full Code Here

  if( state!=ContextManager.STATE_CONFIG ) return;
  Enumeration ctxsE= cm.getContexts();
  while( ctxsE.hasMoreElements() ) {
      // Set the paths - we do this in advanced, at this stage we should be
      // ready to do so.
      Context context=(Context)ctxsE.nextElement();
      addContext( cm, context);
  }
    }
View Full Code Here

     *
     */
    public void addContainer( Container ct )
  throws TomcatException
    {
  Context ctx=ct.getContext();
  String vhost=ctx.getHost();
        Enumeration vhostAliases=ctx.getHostAliases();
  String path=ct.getPath();
  String ctxP=ctx.getPath();

  // Special containers ( the default is url-mapping ).
  if( ct.isSpecial() ) return;
  if( ct.getNote( "type" ) != null return;
 
  if(ct.getRoles() != null || ct.getTransport() != null ) {
      // it was only a security map, no handler defined
      return;
  }

  switch( ct.getMapType() ) {
  case Container.PREFIX_MAP:
      // cut /* ( no need to do a string concat for every match )
      // workaround for frequent bug in web.xml ( backw. compat )
            if( ! path.startsWith( "/" ) ) {
                log("WARNING: Correcting error in web.xml for context \"" + ctxP +
                        "\". Mapping for path \"" + path + "\" is missing a leading '/'.");
                path="/" + path;
            }
            String prefixPath=ctxP + path.substring( 0, path.length()-2 );
      map.addMapping( vhost, prefixPath, ct);
      map.addMappings( vhostAliases, prefixPath, ct);

      if( debug>0 )
    log("SM: prefix map " + vhost + ":" +  ctxP +
        path + " -> " + ct + " " );
      break;
  case Container.DEFAULT_MAP:
      // This will be used if no other map match.
      // AVOID USING IT - STATIC FILES SHOULD BE HANDLED BY
      // APACHE ( or tomcat )
      Container defMapC=ct.getContext().getContainer();

      defMapC.setNote( defaultMapNOTE, ct );
      if( debug>0 )
    log("SM: default map " + vhost + ":" +  ctxP +
        path + " -> " + ct + " " );
      break;
  case Container.EXTENSION_MAP:
      // Add it per/defaultContainer - as spec require ( it may also be
      // possible to support type maps per/Container, i.e. /foo/*.jsp -
      // but that would require changes in the spec.
      Context mapCtx=ct.getContext();
      Container defC=mapCtx.getContainer();
     
      SimpleHashtable eM=(SimpleHashtable) defC.getNote( ctExtMapNote );
      if( eM==null ) {
    eM=new SimpleHashtable();
    defC.setNote( ctExtMapNote, eM );
View Full Code Here

    // XXX not implemented - will deal with that after everything else works.
    // Remove context will still work
    public void removeContainer( Container ct )
  throws TomcatException
    {
  Context ctx=ct.getContext();
  String mapping=ct.getPath();
  String ctxP=ctx.getPath();
        mapping = mapping.trim();
  if(debug>0) log( "Remove mapping " + mapping );
    }
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.