Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 363402

Summary: incorrect path build for org.eclipse.jetty.servlets.CGI
Product: [RT] Jetty Reporter: Paul-Andre Panon <ppanon>
Component: otherAssignee: Project Inbox <jetty-inbox>
Status: CLOSED INVALID QA Contact:
Severity: normal    
Priority: P3    
Version: 7.5.0   
Target Milestone: 7.5.x   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Paul-Andre Panon CLA 2011-11-09 18:15:47 EST
Trying to use the CGI servlet with few examples on the web. The following is the web.xml definition used

  <servlet>
      <servlet-name>CGI</servlet-name>
      <servlet-class>org.eclipse.jetty.servlets.CGI</servlet-class>
      <init-param>
          <param-name>Path</param-name>
          <param-value>/usr/bin</param-value>
      </init-param>
      <init-param>
          <param-name>cgibinResourceBase</param-name>
          <param-value>/opt/opennms/jetty-webapps/opennmstest/WEB-INF</param-value>
      </init-param>
      <load-on-startup>5</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>CGI</servlet-name>
    <url-pattern>/cgi/*</url-pattern>
  </servlet-mapping>



Turning on debug logging this produces:

2011-11-09 15:04:21,311 DEBUG [qtp1903689809-2137 - /opennmstest/cgi/viewvc/CaNetwork/configs/cacal-ar1.ca.goldcorp.net?view=log] CGI: CGI: ContextPath : /opennmstest
2011-11-09 15:04:21,311 DEBUG [qtp1903689809-2137 - /opennmstest/cgi/viewvc/CaNetwork/configs/cacal-ar1.ca.goldcorp.net?view=log] CGI: CGI: ServletPath : /cgi
2011-11-09 15:04:21,311 DEBUG [qtp1903689809-2137 - /opennmstest/cgi/viewvc/CaNetwork/configs/cacal-ar1.ca.goldcorp.net?view=log] CGI: CGI: PathInfo    : /cgi/viewvc/CaNetwork/configs/cacal-ar1.ca.goldcorp.net
2011-11-09 15:04:21,311 DEBUG [qtp1903689809-2137 - /opennmstest/cgi/viewvc/CaNetwork/configs/cacal-ar1.ca.goldcorp.net?view=log] CGI: CGI: _docRoot    : /opt/opennms/jetty-webapps/opennmstest/WEB-INF
2011-11-09 15:04:21,311 DEBUG [qtp1903689809-2137 - /opennmstest/cgi/viewvc/CaNetwork/configs/cacal-ar1.ca.goldcorp.net?view=log] CGI: CGI: _path       : /usr/bin:/bin:/usr/local/bin
2011-11-09 15:04:21,311 DEBUG [qtp1903689809-2137 - /opennmstest/cgi/viewvc/CaNetwork/configs/cacal-ar1.ca.goldcorp.net?view=log] CGI: CGI: _ignoreExitState: false
2011-11-09 15:04:21,313 DEBUG [qtp1903689809-2137 - /opennmstest/cgi/viewvc/CaNetwork/configs/cacal-ar1.ca.goldcorp.net?view=log] ContextHandler: scope {} @ {}
2011-11-09 15:04:21,313 DEBUG [qtp1903689809-2137 - /opennmstest/cgi/viewvc/CaNetwork/configs/cacal-ar1.ca.goldcorp.net?view=log] ContextHandler: scope {} @ {}
2011-11-09 15:04:21,313 DEBUG [qtp1903689809-2137 - /opennmstest/cgi/viewvc/CaNetwork/configs/cacal-ar1.ca.goldcorp.net?view=log] Server: RESPONSE /opennmstest/cgi/viewvc/CaNetwork/configs/cacal-ar1.ca.goldcorp.net  404


However attempting to connect to the URL https://server/context/cgi/viewvc/CaNetwork/configs/testservername.net?view=log produces the following error message.

HTTP ERROR 404
Problem accessing /opennmstest/cgi/cgi/viewvc/CaNetwork/configs/cacal-ar1.ca.goldcorp.net

Note that the cgi servlet name is doubled. This would appear to be due to the statement

       String pathInContext=StringUtil.nonNull(req.getServletPath())+StringUtil.nonNull(req.getPathInfo());

since, from the DEBUG log entries, ServletPath is /cgi and PathInfo is /cgi/viewvc/...
It would seem that pathInContext should instead be assigned by

pathInContext=req.getPathInfo();
if (pathInContext == null)
    pathInContext = StringUtil.nonNull(req.getServletPath());
Comment 1 Paul-Andre Panon CLA 2011-11-10 16:54:46 EST
There's also something weird happening with the pathInfo processing before it ever gets to the servlet.  In the exmaple above, I tried to use just .../viewvc/... because I was having the following result with /viewvc.cgi (the real name of the CGI file)

2011-11-10 13:31:58,449 DEBUG [qtp138884512-1989 - /opennmstest/cgi/viewvc.cgi/CaNetwork/configs/cacal-ar1.ca.goldcorp.net?view=log] CGI: CGI: PathInfo    : /cgi/viewvc.cgi.cgi/CaNetwork/configs/cacal-ar1.ca.goldcorp.net

Note that something is doubling the .cgi extension in the pathInfo property, even though it's only once in the URL, but that it doesn't add it when it isn't there in the URL.
Comment 2 Paul-Andre Panon CLA 2011-11-10 17:53:55 EST
Hmm, it appears that pathContext really should be a concatenation of 
the ServletPath and PathInfo, because the CGI script seems to do the same thing. So presumably the problem is further up the call chain where ServletPath and PathInfo are split out from the URL. The doubling of the .cgi extension in the PathInfo may be happening in the same piece of buggy code, wherever that is.
Comment 3 Paul-Andre Panon CLA 2011-11-10 18:25:42 EST
Sigh, never mind. It turns out that the rewrite rule I wrote was somehow being executed twice. I rewrote the regexp so that it would still make the correct change even if executed twice.