Ignore:
Timestamp:
2011-05-09T14:37:04+12:00 (13 years ago)
Author:
sjm84
Message:

Updating this branch to match the latest Greenstone3 changes

Location:
main/branches/64_bit_Greenstone/greenstone3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/branches/64_bit_Greenstone/greenstone3

  • main/branches/64_bit_Greenstone/greenstone3/src/java/org/greenstone/gsdl3/OAIServer.java

    r21802 r24007  
    2929import java.util.Enumeration;
    3030import java.util.HashSet;
     31import java.util.Iterator;
     32import java.util.Map;
     33import java.util.Map.Entry;
    3134import java.io.File;
    3235
     
    7881  protected String oai_stylesheet = "interfaces/oai/oai2.xsl";
    7982
     83    // there is no getQueryString() method in the HttpServletRequest returned from doPost,
     84    // since that is actually of type apache RequestFacade, and doesn't define such a method
     85    protected String queryString = null;
     86
    8087  static Logger logger = Logger.getLogger(org.greenstone.gsdl3.OAIServer.class.getName());
    8188 
     
    223230    String usageInfo = "";
    224231   
     232    String query = (queryString == null) ? request.getQueryString() : queryString;
     233
    225234    //logged info = general-info + session-info
    226235    usageInfo =
    227236      request.getContextPath()+" "+ //session id
    228237      request.getServletPath()+" "+ //serlvet
    229       "["+request.getQueryString()+"]" +" "+ //the query string
     238      "["+query+"]" +" "+ //the query string
    230239      "["+usageInfo.trim()+"]" +" "+ // params stored in a session
    231240      request.getRemoteAddr()+" "+   //remote address
     
    256265    return query.substring(verb_start_index, verb_end_index);
    257266  }
     267
    258268  public void doGet(HttpServletRequest request, HttpServletResponse response)
    259269    throws ServletException, IOException {
     
    276286    //For example, puka.cs.waikato.ac.nz vs www.greenstone.org
    277287    //String base_url = request.getRequestURL().toString();
    278     String query = request.getQueryString();
     288    // if called by doPost (if this was originally a POST request), var queryString would have been set
     289    String query = (queryString == null) ? request.getQueryString() : queryString;
     290    queryString = null; // reset member variable, else no doGet will work as long as the server remains running
     291
    279292    String[] pairs = (query==null)? null : query.split("&");//split into key/value pairs
    280293    String verb = getVerb(query);
     
    377390    }
    378391  }
     392
     393  // For OAI version 2.0, validation tests indicated that POST needs to be supported. Some
     394  // modification was required in order to ensure that the request is passed intact to doGet()
    379395  public void doPost(HttpServletRequest request,
    380396    HttpServletResponse response)
    381397    throws ServletException, IOException {
     398
     399      // the post method returns a wrapper of type RequestFacade by apache and there
     400      // is no getQueryString() method defined for it. Therefore, need to work this out
     401      // manually before calling doGet(request, response) so that doGet can work as before.
     402     
     403      queryString = "";
     404      Iterator parameter_entries = request.getParameterMap().entrySet().iterator();
     405      while(parameter_entries.hasNext()) {   
     406      Map.Entry param_entry = (Map.Entry)parameter_entries.next();
     407      String[] paramVals = (String[]) param_entry.getValue();
     408      if(paramVals != null) {
     409          if(paramVals.length > 0) {
     410          logger.error("POST request received: " + param_entry.getKey() + " - " + paramVals[0]);
     411          queryString = queryString + "&" + param_entry.getKey() + "=" + paramVals[0];
     412          }
     413      }   
     414      }
     415      if(queryString.length() > 0) {
     416      queryString = queryString.substring(1);
     417      //queryString = OAIXML.oaiEncode(queryString);
     418      }
     419      if(queryString.equals("")) {
     420      queryString = null;
     421      }
    382422    doGet(request,response);   
    383423  }
Note: See TracChangeset for help on using the changeset viewer.