Changeset 30482
- Timestamp:
- 2016-04-24T14:43:02+12:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/URLFilter.java
r29555 r30482 10 10 import javax.servlet.FilterChain; 11 11 import javax.servlet.FilterConfig; 12 import javax.servlet.ServletContext; 12 13 import javax.servlet.ServletException; 13 14 import javax.servlet.ServletOutputStream; 14 15 import javax.servlet.ServletRequest; 15 16 import javax.servlet.ServletResponse; 17 import javax.servlet.http.HttpSession; 16 18 import javax.servlet.http.HttpServletRequest; 17 19 import javax.servlet.http.HttpServletRequestWrapper; … … 70 72 } 71 73 74 @SuppressWarnings("deprecation") 72 75 public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException 73 76 { … … 75 78 { 76 79 HttpServletRequest hRequest = ((HttpServletRequest) request); 80 HttpSession hSession = hRequest.getSession(); 81 ServletContext context = hSession.getServletContext(); 82 77 83 GSHttpServletRequestWrapper gRequest = new GSHttpServletRequestWrapper(hRequest); 78 84 … … 120 126 } 121 127 122 MessageRouter gsRouter = (MessageRouter) request.getServletContext().getAttribute("GSRouter"); 128 //MessageRouter gsRouter = (MessageRouter) request.getServletContext().getAttribute("GSRouter"); 129 // The above line didn't work in i-jetty (failed to find class) 130 // (See node below about ServletContext for more details) 131 // // Changed to the following (but hasn't been exhaustively tested) 132 MessageRouter gsRouter = (MessageRouter) context.getAttribute("GSRouter"); 133 123 134 if (gsRouter == null) 124 135 { … … 195 206 else if (url.contains(INTERFACE_PATH)) 196 207 { 197 String fileURL = url.replaceFirst(request.getServletContext().getContextPath(), ""); 198 File requestedFile = new File(request.getServletContext().getRealPath(fileURL)); 208 ////String fileURL = url.replaceFirst(request.getServletContext().getContextPath(), ""); 209 // 210 // The above line was changed to the line below to work on i-jetty. The above caused 211 // an exception to be thrown trying to load in the class at init time: 212 // javax.servlet.http.ServletContext 213 // 214 // And then later in the life-time the servlet, the above line fails when run 215 // The following (older) way to do this was found to work as a replacment 216 217 String fileURL = url.replaceFirst(context.getContextPath(), ""); 218 219 // A different theory is that the problem could be to do with version of Servlet 220 // Container implemented by the web-server: 221 // http://stackoverflow.com/questions/7860782/request-getservletcontext-not-found-even-with-new-jar 222 223 // Similar change in the following needed also ... 224 225 // Replacement line known to be deprecated, but very useful for us to use in this situation 226 // 227 // If this method is every offically removed, and the newer getServletContext() 228 // still can't be relied upon to work in all web servers Greenstone uses, 229 // then an alternative approach would be to get the core information (servlet context name, 230 // and where it is on the file system) from the gsdl properties file 231 232 ////File requestedFile = new File(request.getServletContext().getRealPath(fileURL)); 233 File requestedFile = new File(context.getRealPath(fileURL)); 199 234 if (!requestedFile.exists()) 200 235 { … … 203 238 String interfaceName = fileURL.substring(interfaceNameStart, interfaceNameEnd); 204 239 String interfacesDir = fileURL.substring(0, interfaceNameStart); 205 File interfaceConfigFile = new File( request.getServletContext().getRealPath(interfacesDir + interfaceName + "/interfaceConfig.xml"));240 File interfaceConfigFile = new File(context.getRealPath(interfacesDir + interfaceName + "/interfaceConfig.xml")); 206 241 207 242 if (interfaceConfigFile.exists()) … … 212 247 if (baseInterface.length() > 0) 213 248 { 214 File baseInterfaceFile = new File( request.getServletContext().getRealPath(fileURL.replace("/" + interfaceName + "/", "/" + baseInterface + "/")));249 File baseInterfaceFile = new File(context.getRealPath(fileURL.replace("/" + interfaceName + "/", "/" + baseInterface + "/"))); 215 250 if (baseInterfaceFile.exists()) 216 251 { … … 416 451 } 417 452 418 private class GSHttpServletRequestWrapper extends HttpServletRequestWrapper419 {420 private HashMap<String, String[]> _newParams = new HashMap<String, String[]>();421 422 public GSHttpServletRequestWrapper(ServletRequest request)423 {424 super((HttpServletRequest) request);425 }426 427 public void setParameter(String paramName, String[] paramValues)428 {429 _newParams.put(paramName, paramValues);430 }431 432 public void setParameter(String paramName, String paramValue)433 {434 _newParams.put(paramName, new String[] { paramValue });435 }436 437 public String getParameter(String paramName)438 {439 if (super.getParameter(paramName) != null)440 {441 return super.getParameter(paramName);442 }443 else444 {445 if (_newParams.get(paramName) != null && _newParams.get(paramName)[0] != null)446 {447 return _newParams.get(paramName)[0];448 }449 return null;450 }451 }452 453 public String[] getParameterValues(String paramName)454 {455 if (super.getParameterValues(paramName) != null)456 {457 return super.getParameterValues(paramName);458 }459 else460 {461 return _newParams.get(paramName);462 }463 }464 465 public Map<String, String[]> getParameterMap()466 {467 HashMap<String, String[]> returnMap = new HashMap<String, String[]>();468 returnMap.putAll(super.getParameterMap());469 returnMap.putAll(_newParams);470 return returnMap;471 }472 }473 453 }
Note:
See TracChangeset
for help on using the changeset viewer.