Changeset 30482


Ignore:
Timestamp:
2016-04-24T14:43:02+12:00 (8 years ago)
Author:
davidb
Message:

Changes to help with compiling and running this for Android

File:
1 edited

Legend:

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

    r29555 r30482  
    1010import javax.servlet.FilterChain;
    1111import javax.servlet.FilterConfig;
     12import javax.servlet.ServletContext;
    1213import javax.servlet.ServletException;
    1314import javax.servlet.ServletOutputStream;
    1415import javax.servlet.ServletRequest;
    1516import javax.servlet.ServletResponse;
     17import javax.servlet.http.HttpSession;
    1618import javax.servlet.http.HttpServletRequest;
    1719import javax.servlet.http.HttpServletRequestWrapper;
     
    7072    }
    7173
     74        @SuppressWarnings("deprecation")
    7275    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
    7376    {
     
    7578        {
    7679            HttpServletRequest hRequest = ((HttpServletRequest) request);
     80            HttpSession hSession = hRequest.getSession();
     81            ServletContext context = hSession.getServletContext();
     82
    7783            GSHttpServletRequestWrapper gRequest = new GSHttpServletRequestWrapper(hRequest);
    7884
     
    120126                }
    121127
    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               
    123134                if (gsRouter == null)
    124135                {
     
    195206            else if (url.contains(INTERFACE_PATH))
    196207            {
    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));
    199234                if (!requestedFile.exists())
    200235                {
     
    203238                    String interfaceName = fileURL.substring(interfaceNameStart, interfaceNameEnd);
    204239                    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"));
    206241
    207242                    if (interfaceConfigFile.exists())
     
    212247                        if (baseInterface.length() > 0)
    213248                        {
    214                             File baseInterfaceFile = new File(request.getServletContext().getRealPath(fileURL.replace("/" + interfaceName + "/", "/" + baseInterface + "/")));
     249                            File baseInterfaceFile = new File(context.getRealPath(fileURL.replace("/" + interfaceName + "/", "/" + baseInterface + "/")));
    215250                            if (baseInterfaceFile.exists())
    216251                            {
     
    416451    }
    417452
    418     private class GSHttpServletRequestWrapper extends HttpServletRequestWrapper
    419     {
    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             else
    444             {
    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             else
    460             {
    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     }
    473453}
Note: See TracChangeset for help on using the changeset viewer.