- Timestamp:
- 2019-10-31T11:00:37+13:00 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/LibraryServlet.java
r33387 r33612 1 /* 2 * LibraryServlet.java 3 * Copyright (C) 2008 New Zealand Digital Library, http://www.nzdl.org 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 */ 19 1 20 package org.greenstone.gsdl3; 2 21 … … 7 26 import java.lang.reflect.Type; 8 27 import java.util.ArrayList; 28 import java.util.Arrays; 9 29 import java.util.Enumeration; 10 30 import java.util.HashMap; … … 52 72 /** 53 73 * a servlet to serve the greenstone library - we are using servlets instead of 54 * cgi the init method is called only once - the first time the servlet classes 74 * cgi 75 * the init method is called only once - the first time the servlet classes 55 76 * are loaded. Each time a request comes in to the servlet, the session() method 56 77 * is called in a new thread (calls doGet/doPut etc) takes the a=p&p=home type … … 69 90 protected Receptionist recept = null; 70 91 92 /** We record the library name for later */ 93 protected String library_name = null; 94 /** Whether or not client-side XSLT support should be exposed */ 95 protected boolean supports_client_xslt = false; 96 71 97 /** 72 98 * the default language - is specified by setting a servlet param, otherwise … … 74 100 */ 75 101 protected String default_lang = null; 76 77 /** We record the library name for later */78 protected String library_name = null;79 /** Whether or not client-side XSLT support should be exposed */80 protected boolean supports_client_xslt = false;81 82 102 /** 83 103 * The default default - used if a default lang is not specified in the … … 304 324 //Allow the message router and the document to be accessed from anywhere in this servlet context 305 325 this.getServletContext().setAttribute(library_name+"Router", this.recept.getMessageRouter()); 306 //this.getServletContext().setAttribute("LibraryName", library_name);307 326 } 308 327 309 private void logUsageInfo(HttpServletRequest request)328 private void logUsageInfo(HttpServletRequest request, Map<String, String[]> queryMap) 310 329 { 311 330 String usageInfo = ""; … … 320 339 } 321 340 341 String queryParamStr = ""; 342 if (queryMap != null) 343 { 344 Iterator<String> queryIter = queryMap.keySet().iterator(); 345 while (queryIter.hasNext()) { 346 String q = queryIter.next(); 347 String[] vals = queryMap.get(q); 348 queryParamStr += q +"="+String.join(",",vals)+" "; 349 } 350 } 322 351 //logged info = general-info + session-info 323 352 usageInfo = request.getServletPath() + " " + //serlvet 324 "[" + request.getQueryString() + "]" + " " + //the query string325 "[" + usageInfo.trim() + "]" + " " + // params stored in a session326 request.getRemoteAddr() + " " + //remote address327 request.getRequestedSessionId() + " " + //session id328 request.getHeader("user-agent") + " "; //the remote brower info353 "[" + queryParamStr.trim()+"]"+" " + // query map params 354 "session:[" + usageInfo.trim() + "]" + " " + // params stored in a session 355 request.getRemoteAddr() + " " + //remote address 356 request.getRequestedSessionId() + " " + //session id 357 request.getHeader("user-agent") + " "; //the remote brower info 329 358 330 359 logger.info(usageInfo); … … 367 396 } 368 397 398 // if session cache id removed from session, this triggers this valueUnbound method on the value=this object 369 399 public void valueUnbound(HttpSessionBindingEvent event) 370 400 { … … 388 418 public void doGetOrPost(HttpServletRequest request, HttpServletResponse response, Map<String, String[]> queryMap) throws ServletException, IOException 389 419 { 390 logUsageInfo(request);420 logUsageInfo(request, queryMap); 391 421 392 422 if (queryMap != null) … … 541 571 542 572 // We clean up the cache session_ids_table if system 543 // commands are issued (and also don't need to do caching for this request)573 // commands are issued, and also don't need to do caching for these request requests 544 574 boolean should_cache = true; 545 575 if (action != null && action.equals(GSParams.SYSTEM_ACTION) … … 578 608 // TODO 579 609 session_ids_table = new Hashtable<String, UserSessionCache>(); 580 session.removeAttribute(GS XML.USER_SESSION_CACHE_ATT); // triggers valueUnbound(), which removes the session id from the session_ids_table610 session.removeAttribute(GSParams.USER_SESSION_CACHE); // triggers valueUnbound(), which removes the session id from the session_ids_table 581 611 } 582 612 else … … 604 634 } 605 635 606 //clear the collection-specific cache in the session, since we have no way to know whether this sessionis607 //about the same collection as the last sessionor not.636 //clear the collection-specific cache in the session, since we have no way to know whether this page is 637 //about the same collection as the last page or not. 608 638 Enumeration attributeNames = session.getAttributeNames(); 609 639 while (attributeNames.hasMoreElements()) 610 640 { 611 641 String name = (String) attributeNames.nextElement(); 612 if (!name.equals(GS XML.USER_SESSION_CACHE_ATT) && !name.equals(GSParams.LANGUAGE) && !name.equals(GSXML.USER_ID_ATT))642 if (!name.equals(GSParams.USER_SESSION_CACHE) && !name.equals(GSParams.LANGUAGE) && !name.equals(GSXML.USER_ID_ATT) && !this.gs_params.isGlobal(name)) 613 643 { 614 644 session.removeAttribute(name); 615 } 645 } 616 646 } 617 647 … … 621 651 boolean new_table = false; 622 652 String sid = session.getId(); 653 boolean new_session = false; 654 if (!session_ids_table.containsKey(sid)) { 655 new_session = true; 656 } 623 657 if (should_cache == true && cache_key != null && !cache_key.equals("")) 624 658 { 625 if ( session_ids_table.containsKey(sid))659 if (!new_session) 626 660 { 627 661 session_cache = session_ids_table.get(sid); … … 640 674 else 641 675 { 676 642 677 param_table = new Hashtable<String, Hashtable<String, String>>(); 643 678 table = new Hashtable<String, String>(); … … 645 680 session_cache = new UserSessionCache(sid, param_table); 646 681 session_ids_table.put(sid, session_cache); 647 session.setAttribute(GS XML.USER_SESSION_CACHE_ATT, session_cache);682 session.setAttribute(GSParams.USER_SESSION_CACHE, session_cache); 648 683 new_table = true; 649 684 } 650 685 651 // here we add in default params if we have a new table 652 ArrayList<String> defp = this.gs_params.getParamsWithDefaults(); 653 Iterator i = this.gs_params.getParamsWithDefaults().iterator(); 654 while (i.hasNext()) { 655 String p = (String)i.next(); 656 String v = this.gs_params.getParamDefault(p); 657 if (!p.equals(GSParams.ACTION) && !p.equals(GSParams.SUBACTION) && !p.equals(GSParams.LANGUAGE) && !p.equals(GSParams.OUTPUT)) { 658 table.put(p,v); 659 } 660 } 661 686 } 662 687 663 } 688 // here we add in default params values if need be - if we have a new session, or if we have a new table 689 // in an existing session 690 // don't override any existing values 691 if (new_session || new_table) { 692 693 Iterator i = this.gs_params.getParamsWithDefaults().iterator(); 694 while (i.hasNext()) { 695 String p = (String)i.next(); 696 String v = this.gs_params.getParamDefault(p); 697 if (this.gs_params.isGlobal(p)) { 698 //need to add in to session unless its already there 699 if (session.getAttribute(p) == null) { 700 session.setAttribute(p, v); 701 } 702 } else { 703 // add to table unless its already there 704 if (new_table && !table.containsKey(p)) { 705 table.put(p,v); 706 } 707 } 708 709 } 710 } 664 711 665 712 if (action == null || action.equals("")) 666 713 { 667 // should we do all the following stuff if using default page? 668 // display the home page - the default page 714 // display the home page - the default page 669 715 xml_request.setAttribute(GSXML.ACTION_ATT, "p"); 670 716 xml_request.setAttribute(GSXML.SUBACTION_ATT, PageAction.HOME_PAGE); … … 677 723 xml_request.setAttribute(GSXML.SUBACTION_ATT, subaction); 678 724 } 679 725 } 726 680 727 // create the param list for the greenstone request - includes 681 728 // the params from the current request and any others from the saved session … … 702 749 } 703 750 } 704 // either add it to the param list straight away, or save it to the session and add it later 705 if (this.gs_params.shouldSave(name) && table != null) 706 { 707 table.put(name, value); 751 // if we need to save the value, then add it to the session/cache table. 752 // otherwise add directly to the paramList 753 if (this.gs_params.shouldSave(name)) { 754 if (this.gs_params.isGlobal(name) || table == null) { 755 session.setAttribute(name, value); 756 } else { 757 table.put(name, value); 758 } 708 759 } 709 760 else … … 721 772 } 722 773 //put everything in the table into the session 723 // do we need to do this? why not just put from table into param list724 774 if (table != null) 725 775 { … … 737 787 { 738 788 String name = (String) params.nextElement(); 739 if (!name.equals(GS XML.USER_SESSION_CACHE_ATT) && !name.equals(GSParams.LANGUAGE) && !name.equals(GSXML.USER_ID_ATT))789 if (!name.equals(GSParams.USER_SESSION_CACHE) && !name.equals(GSParams.LANGUAGE) && !name.equals(GSXML.USER_ID_ATT)) 740 790 { 741 791 … … 751 801 } 752 802 } 753 }803 754 804 755 805 if (output.equals("json"))
Note:
See TracChangeset
for help on using the changeset viewer.