Ignore:
Timestamp:
2021-08-09T13:42:09+12:00 (3 years ago)
Author:
kjdon
Message:

when running my new local twso library, it ran into trouble. My collection was twso, and my library name was also twso. It ended up with greenstone3/collection/twso as the baseURL. The baseURL should be everyhting up to the library name. The problem occurs when the library_name appears in the domain name, or elsewhere in the url (in my case as the collection name). Can't use teh first or the last occurence of library_name, due to these cases. So now, lets test for /library-name, but also check to make sure thats not the start of the domain name, eg if had library.waikato.ac.nz/greenstone3/library.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/LibraryServlet.java

    r34479 r35266  
    462462    String requestedURL = request.getRequestURL().toString();
    463463    String baseURL = "";
     464    //logger.error("requested URL = "+requestedURL);
    464465    if (requestedURL.indexOf(library_name) != -1)
    465466    {
    466     baseURL = requestedURL.substring(0, requestedURL.lastIndexOf(library_name));
    467    
    468     int protocol_boundary_pos = baseURL.indexOf("://");
    469     if (protocol_boundary_pos>=1) {
    470         baseURL = baseURL.substring(protocol_boundary_pos+1); // change things like http:// or https:// to //
    471     }
     467      // we need to work out the baseURL and set it
     468      baseURL = requestedURL;
     469      int protocol_boundary_pos = baseURL.indexOf("://");
     470      if (protocol_boundary_pos>=1) {
     471        baseURL = baseURL.substring(protocol_boundary_pos+1); // change things like http:// or https:// to //
     472      }
     473      // The baseURL is everything up to the library_name.
     474      // eg https://community.greenstone.org/greenstone3/library/collection/twso/page/about
     475      // baseURL is //community.greenstone.org/greenstone3
     476      // Issues: the library_name may occur in more than one place - eg if its part of the domain name mylibrary.heritage.nz/greenstone3/library
     477      // or if a collection name is the same as the library name eg localhost:8585/greenstone3/twso/collection/twso/page/about.
     478      // So can't just use teh first or last occurrence. Look for /library-name, and check its not the first position (eg //library.nzdl.org/greenstone3/library)
     479      int library_name_index = baseURL.indexOf("/"+library_name);
     480      if (library_name_index == 1) {
     481        // we have library name at the start of the url - need to use the second one
     482        library_name_index = baseURL.indexOf("/"+library_name, 2);
     483      }
     484      baseURL = baseURL.substring(0, library_name_index+1);
     485      //logger.error("new base url = "+baseURL);
    472486       
    473487    }
     488
    474489    String fullURL;
    475490    if (request.getQueryString() != null)
Note: See TracChangeset for help on using the changeset viewer.