Package org.apache.tomcat.core

Examples of org.apache.tomcat.core.Handler


     " PI=" + newPathInfo);
 
   req.servletPath().setString(newServletPath);
  req.pathInfo().setString(newPathInfo);
 
  Handler wrapper = ctx.getServletByName(servletName);
  if (wrapper != null) {
      req.setHandler( wrapper );
      return 0;
  }
     
  // Dynamic add for the wrapper
 
  // even if the server doesn't supports dynamic mappings,
  // we'll avoid the interceptor for include() and
  // it's a much cleaner way to construct the servlet and
  // make sure all interceptors are up to date.
  try {
      ctx.addServletMapping( newServletPath + "/*" ,
           servletName );
      // The facade should create the servlet name
     
      Handler sw=ctx.getServletByName( servletName );
      //       sw.setContext(ctx);
      //       sw.setServletName(servletName);
      //      ctx.addServlet( sw );
      //      sw.setServletClass( servletName );
      //sw.setOrigin( Handler.ORIGIN_INVOKER );
View Full Code Here


    Enumeration sE=ctx.getServletNames();
    while( sE.hasMoreElements() ) {
        try {
      String sN=(String)sE.nextElement();
      Handler sw=ctx.getServletByName( sN );
      sw.reload();
        } catch( Exception ex ) {
      log( "Reload exception: " + ex);
        }
    }
View Full Code Here

    private final void handleStatusImpl( ContextManager cm, Context ctx,
           Request req, Response res,
           int code )
    {
  String errorPath=null;
  Handler errorServlet=null;

  // don't log normal cases ( redirect and need_auth ), they are not
  // error
  // XXX this log was intended to debug the status code generation.
  // it can be removed for all cases.
  if( code > 401 ) {// tuneme
      if( ctx==null )
    cm.log( "Status code:" + code + " request:"  + req + " msg:" +
         req.getAttribute("javax.servlet.error.message"));
      else
    ctx.log( "Status code:" + code + " request:"  + req + " msg:" +
         req.getAttribute("javax.servlet.error.message"));
  }
 
  errorPath = ctx.getErrorPage( code );
  if( errorPath != null ) {
      errorServlet=getHandlerForPath( cm, ctx, errorPath );

      String cpath=ctx.getPath();
      if( "/".equals(cpath))  cpath="";
     
      // Make sure Jsps will work - needed if the error page is a jsp
      if ( null!=errorPath && errorPath.startsWith("/") ) {
    req.setAttribute( "javax.servlet.include.request_uri",
          cpath  + errorPath );
      } else {
    req.setAttribute( "javax.servlet.include.request_uri",
          cpath  + "/" + errorPath );
      }
      req.setAttribute( "javax.servlet.include.servlet_path", errorPath );
  }

  boolean isDefaultHandler = false;
        if ( statusLoop( ctx, req, code ) ){
            log( "Error loop for " + req + " error code " + code);
            return;
        }
  if( errorServlet==null ) {
            if( code == 404 )
                errorServlet=ctx.getServletByName( "tomcat.notFoundHandler");
            else
                errorServlet=ctx.getServletByName( "tomcat.statusHandler");
      isDefaultHandler = true;
  }

  if (errorServlet == null) {
      ctx.log( "Handler errorServlet is null! errorPath:" + errorPath);
      return;
  }

  // XXX The original code didn't reset the buffer if
  // isDefaultHandler :  if (!isDefaultHandler && ...
  // Is there any reason for that ?
  // I also think we should reset the buffer anyway, to get
  // in a stable state - even if the buffer is commited
  if ( !res.isBufferCommitted())
      res.resetBuffer();

  req.setAttribute("javax.servlet.error.status_code",new Integer( code));
  req.setAttribute("tomcat.servlet.error.request", req);

  if( debug>0 )
      ctx.log( "Handler " + errorServlet + " " + errorPath);

  // reset error exception
  res.setErrorException( null );
  Exception ex=null;
  try {
      errorServlet.service( req, res );
      ex=res.getErrorException();
  } catch (Exception ex1 ) {
      ex=ex1;
  }
  if( ex!=null && ! (ex instanceof IOException) ) {
View Full Code Here

      // we are in handleRequest for the "default" error handler
      log("ERROR: can't find default error handler, or error in default error page", t);
  }

  String errorPath=null;
  Handler errorServlet=null;

  // Scan the exception's inheritance tree looking for a rule
  // that this type of exception should be forwarded
  Class clazz = t.getClass();
  while (errorPath == null && clazz != null) {
      String name = clazz.getName();
      errorPath = ctx.getErrorPage(name);
      clazz = clazz.getSuperclass();
  }

  // Bug 3233, ps@psncc.at (Peter Stamfest)
  if (errorPath == null ) {
      // Use introspection - the error handler is at a lower level,
      // doesn't depend on servlet api
      Throwable t2=null;
      try {
    Method m=t.getClass().getMethod( "getRootCause", new Class[] {} );
    t2 = (Throwable)m.invoke( t, new Object[] {} );
      } catch(Exception ex) {
      }

      if (t2 != null) {
    clazz = t2.getClass();
    while (errorPath == null && clazz != null) {
        String name = clazz.getName();
        errorPath = ctx.getErrorPage(name);
        clazz = clazz.getSuperclass();
    }
      }
      if (errorPath != null) t = t2;
  }

  if( errorPath != null ) {
      errorServlet=getHandlerForPath( cm, ctx, errorPath );

      String cpath=ctx.getPath();
      if( "/".equals( cpath ))  cpath="";
     
      // Make sure Jsps will work - needed if the error page is a jsp
      if ( null!=errorPath && errorPath.startsWith("/") ) {
    req.setAttribute( "javax.servlet.include.request_uri",
          cpath  + errorPath );
      } else {
    req.setAttribute( "javax.servlet.include.request_uri",
          cpath  + "/" + errorPath );
      }
      req.setAttribute( "javax.servlet.include.servlet_path", errorPath );
  }

  boolean isDefaultHandler = false;
  if ( errorLoop( ctx, req ) ){
      log( "Error loop for " + req + " error " + t);
      return;
        }
        if ( errorServlet==null) {
      errorServlet = ctx.getServletByName("tomcat.exceptionHandler");
      isDefaultHandler = true;
      if( debug>0 ) ctx.log( "Using default handler " + errorServlet );
  }

  if (errorServlet == null) {
      ctx.log( "Handler errorServlet is null! errorPath:" + errorPath);
      return;
  }


  // XXX The original code didn't reset the buffer if
  // isDefaultHandler :  if (!isDefaultHandler && ...
  // Is there any reason for that ?
  // I also think we should reset the buffer anyway, to get
  // in a stable state - even if the buffer is commited
  if ( !res.isBufferCommitted())
      res.resetBuffer();

  req.setAttribute("javax.servlet.error.exception_type", t.getClass());
  req.setAttribute("javax.servlet.error.message", t.getMessage());
  req.setAttribute("javax.servlet.jsp.jspException", t);
  req.setAttribute("tomcat.servlet.error.throwable", t);
  req.setAttribute("tomcat.servlet.error.request", req);

  if( debug>0 )
      ctx.log( "Handler " + errorServlet + " " + errorPath);

  // reset error exception
  res.setErrorException( null );
  Exception ex=null;
  try {
      errorServlet.service( req, res );
      ex=res.getErrorException();
  } catch(Exception ex1 ) {
      ex=ex1;
  }
  if( ex!=null && ! (ex instanceof IOException) ) {
View Full Code Here

      Integer key = (Integer)orderedKeys.elementAt(i);
      Enumeration sOnLevel =  ((Vector)loadableServlets.get( key )).
    elements();
      while (sOnLevel.hasMoreElements()) {
    String servletName = (String)sOnLevel.nextElement();
    Handler result = ctx.getServletByName(servletName);

    if( ctx.getDebug() > 0 )
        ctx.log("Loading " + key + " "  + servletName );
    if(result==null)
        log("Warning: we try to load an undefined servlet " +
View Full Code Here

      // of the processing as before ( all processing
      // will happen in the handle() pipeline.
      return 0;
  }

  Handler wrapper=req.getHandler();
 
  if( wrapper==null )
      return 0;

  // It's not a jsp if it's not "*.jsp" mapped or a servlet
  if( (! "jsp".equals( wrapper.getName())) &&
      (! (wrapper instanceof ServletHandler)) ) {
      return 0;
  }

  ServletHandler handler=null;
  String jspFile=null;

  // There are 2 cases: extension mapped and exact map with
  // a <servlet> with file-name declaration

  // note that this code is called only the first time
  // the jsp page is called - all other calls will treat the jsp
  // as a regular servlet, nothing is special except the initial
  // processing.

  // XXX deal with jsp_compile
 
  if( "jsp".equals( wrapper.getName())) {
      // if it's an extension mapped file, construct and map a handler
      jspFile=req.servletPath().toString();
      // extension mapped jsp - define a new handler,
      // add the exact mapping to avoid future overhead
      handler= mapJspPage( req.getContext(), jspFile );
View Full Code Here

  String servletName= SERVLET_NAME_PREFIX + uri;

  if( debug>0)
      log( "mapJspPage " + ctx + " " + " " + servletName + " " +  uri  );

  Handler h=ctx.getServletByName( servletName );
  if( h!= null ) {
      log( "Name already exists " + servletName +
     " while mapping " + uri);
      return (ServletHandler)h; // exception ?
  }
View Full Code Here

  // in which case the attribute will create problems
  realRequest.removeAttribute( A_REQUEST_URI);
  realRequest.removeAttribute( A_SERVLET_PATH);

  // CM should have set the wrapper - call it
  Handler wr=realRequest.getHandler();
  if( wr!=null ) {
      try {
    wr.service(realRequest, realResponse);
      } catch( Exception ex ) {
    realResponse.setErrorException(ex);
      }
  }
View Full Code Here

 
   // now it's really strange: we call the wrapper on the subrequest
  // for the realRequest ( since the real request will still have the
  // original handler/wrapper )

  Handler wr=subRequest.getHandler();
  if( wr!=null ) {
      try {
    wr.service(realRequest, realResponse);
      } catch( Exception ex ) {
    realResponse.setErrorException(ex);
      }
  }
View Full Code Here

     */
    private void includeNamed(ServletRequest request, ServletResponse response)
  throws ServletException, IOException
    {
  // We got here if name!=null, so assert it
  Handler wr = context.getServletByName( name );
  // Use the original request - as in specification !
  Request realRequest=((HttpServletRequestFacade)request).getRealRequest();
  Response realResponse = realRequest.getResponse();

  // Set the "included" flag so that things like header setting in the
  // included servlet will be correctly ignored
  boolean old_included=realResponse.isIncluded();
  if( ! old_included ) realResponse.setIncluded( true );

  if( wr!=null) {
      try {
    wr.service(realRequest, realResponse);
      } catch( Exception ex ) {
    realResponse.setErrorException( ex );
      }
  }

View Full Code Here

TOP

Related Classes of org.apache.tomcat.core.Handler

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.