tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dean Hiller" <d...@xsoftware.biz>
Subject intercept and redirect to war file of my choosing(based on URL)
Date Mon, 26 Jun 2006 21:31:39 GMT
I have a url of this format http://<machine>/<variable>/<warfilename>

Where no matter what <variable> is equal to, I would like to be able to
direct the to tomcat/webapps/<warfilename>.war servlet.  I have been trying
to do this with a valve on the engine hoping I could modify the request URL
before the tomcat engine decided which war  file would service the request.
Is this even possible?  I tried this with a generic filter and a forward but
that failed and tomcat said http://machine/<warfilename> resource does not
exist when using the above url.  If I use http://<machine>/<warfilename>, it
works fine and the resource exists when using a filter I deployed to
common/lib.

Below is the code I tried to use for that valve(since I could not get the
filter to work) in the engine to modify the request so that the url would be
http://<machine>/<warfilename> and I was planning on sticking <variable>
in
as a request attribute or something so the war file could access it.  Any
ideas?

thanks,
dean

    public void invoke(Request req, Response resp) throws IOException,
ServletException {

        log.info("testing testingzzzzzzzzzzzzzzzzzzzzzzzzzt");
        System.out.println("req1="+req.getContextPath());
        System.out.println("req2="+req.getDecodedRequestURI());
        System.out.println("req3="+req.getPathInfo());
        System.out.println("req4="+req.getPathTranslated());
        System.out.println("req5="+req.getRequestURI());
        System.out.println("req6="+req.getRequestURL());
        System.out.println("req7="+req.getServletPath());

        modifyRequest(req);

        nextValve.invoke(req, resp);
    }

    private void modifyRequest(Request req) {
        String uri = req.getRequestURI();
        int first = uri.indexOf("/");
        int second = uri.lastIndexOf("/");

        if(second > 0) {
            String company = uri.substring(first+1);
            company = company.substring(0, second-1);

            System.out.println("company="+company);
            if("company".equals(company)) {
                uri = uri.substring(second);
                System.out.println("setting uri to="+uri);
                log.info("modifying uri="+uri);
                req.setRequestURI(uri);
                req.setServletPath(uri);
            }
        }
    }

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message