"OPeNDAP-Server4", "OPeNDAP", request.getRequestURI().substring(0, request.getRequestURI().indexOf(request.getPathInfo()) + 1));
"OPeNDAP-Server4", "OPeNDAP", request.getRequestURI().substring(0, request.getRequestURI().lastIndexOf(request.getPathInfo()) + 1));
    public void sendCatalog(HttpServletRequest request,                            HttpServletResponse response,                            ReqState rs)            throws IOException, ServletException, DODSException, PPTException, JDOMException, BESException {        response.setContentType("text/xml");        response.setHeader("XDODS-Server", getXDODSServerVersion());        response.setHeader("XOPeNDAP-Server", getXOPeNDAPServerVersion());        response.setHeader("XDAP", getXDAPVersion(request));        response.setHeader("Content-Description", "dods_catalog");        PrintWriter pw = new PrintWriter(response.getOutputStream());//        System.out.println("rootPath:    "+rootPath);//        System.out.println("contentPath: "+contentPath);//        System.out.println("myPath:      "+"/"+rs.getDataset());/*        if(catHandler.processReqForCatalog(this,request,response, contentPath)){            System.out.println("Processed Catalog Request");        }        else {            System.out.println("Rejected Catalog Request");        }        if (Debug.isSet("showResponse")){            System.out.println("doGetCatalog() - Instantiating BESCrawlableDataset object (a CrawlableDataset)");        }*/        // Strip off the catalog request        String path = rs.getDataset();        path = path.endsWith("/catalog") ? path.substring(0, path.length() - 8) : path;        path = BESCrawlableDataset.besPath2ThreddsPath(path);        BESCrawlableDataset s4cd = new BESCrawlableDataset(path, null);        if (s4cd.isCollection()) {            if (Debug.isSet("showResponse")) {                System.out.println("doGetCatalog() - Instantiating SimpleCatalogBuilder");            }            SimpleCatalogBuilder scb = new SimpleCatalogBuilder(                    "",                                  // CollectionID, which for us needs to be empty.                    BESCrawlableDataset.getRootDataset(), // Root dataset of this collection                    "OPeNDAP-Server4",                   // Service Name                    "OPeNDAP",                           // Service Type Name                    request.getRequestURI().substring(0, request.getRequestURI().indexOf(request.getPathInfo()) + 1)); // Base URL for this service            if (Debug.isSet("showResponse")) {                System.out.println("doGetCatalog() - Generating catalog");            }            pw.print(scb.generateCatalogAsString(s4cd));        } else {            response.setContentType("text/html");            String msg = "ERROR: THREDDS catalogs may only be requested for collections, not for individual data sets.";            throw new DODSException(msg);        }        //printCatalog(request, pw);        pw.flush();        response.setStatus(HttpServletResponse.SC_OK);    }