{"action":"created","issue":{"url":"https://api.github.com/repos/google/guice/issues/1027","repository_url":"https://api.github.com/repos/google/guice","labels_url":"https://api.github.com/repos/google/guice/issues/1027/labels{/name}","comments_url":"https://api.github.com/repos/google/guice/issues/1027/comments","events_url":"https://api.github.com/repos/google/guice/issues/1027/events","html_url":"https://github.com/google/guice/issues/1027","id":164309746,"number":1027,"title":"Request parameter get lost when forwarding from one servlet to another","user":{"login":"stebeg","id":8576735,"avatar_url":"https://avatars.githubusercontent.com/u/8576735?v=3","gravatar_id":"","url":"https://api.github.com/users/stebeg","html_url":"https://github.com/stebeg","followers_url":"https://api.github.com/users/stebeg/followers","following_url":"https://api.github.com/users/stebeg/following{/other_user}","gists_url":"https://api.github.com/users/stebeg/gists{/gist_id}","starred_url":"https://api.github.com/users/stebeg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stebeg/subscriptions","organizations_url":"https://api.github.com/users/stebeg/orgs","repos_url":"https://api.github.com/users/stebeg/repos","events_url":"https://api.github.com/users/stebeg/events{/privacy}","received_events_url":"https://api.github.com/users/stebeg/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-07-07T13:32:49Z","updated_at":"2016-11-21T08:28:41Z","closed_at":null,"body":"Hi,\n\nI think I've found a bug in the servlet extension of guice.\nIn a servlet, I'm forwarding the request to another servlet.\n\nI've mapped to servlets:\n\n```\nserve(\"/\", \"/index.jsp\").with(MainEntryServlet.class);\nserve(\"/foobar.jsp\").with(FooBarServlet.class);\n```\n\nI'm using the following code in my FooBar-Servlet:\n\n```\nString url = \"/index.jsp?target=foo.jsp\";\nrequest.getRequestDispatcher(url).forward(request, response);\n```\n\nThe MainEntryServlet gets called, but the paramter \"target\" is missing.\nWhen I use the web.xml for servlet mapping, everything works fine.\n\nAny idea, why the paramater gets lost, when mapping the servlets in the servlet module?\n"},"comment":{"url":"https://api.github.com/repos/google/guice/issues/comments/261873885","html_url":"https://github.com/google/guice/issues/1027#issuecomment-261873885","issue_url":"https://api.github.com/repos/google/guice/issues/1027","id":261873885,"user":{"login":"stebeg","id":8576735,"avatar_url":"https://avatars.githubusercontent.com/u/8576735?v=3","gravatar_id":"","url":"https://api.github.com/users/stebeg","html_url":"https://github.com/stebeg","followers_url":"https://api.github.com/users/stebeg/followers","following_url":"https://api.github.com/users/stebeg/following{/other_user}","gists_url":"https://api.github.com/users/stebeg/gists{/gist_id}","starred_url":"https://api.github.com/users/stebeg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stebeg/subscriptions","organizations_url":"https://api.github.com/users/stebeg/orgs","repos_url":"https://api.github.com/users/stebeg/repos","events_url":"https://api.github.com/users/stebeg/events{/privacy}","received_events_url":"https://api.github.com/users/stebeg/received_events","type":"User","site_admin":false},"created_at":"2016-11-21T08:28:41Z","updated_at":"2016-11-21T08:28:41Z","body":"I think I've found the source of this bug:\r\ncom.google.inject.servlet.ServletDefinition#doService at line 212\r\n\r\n```java\r\nvoid doService(final ServletRequest servletRequest, ServletResponse servletResponse)\r\n      throws ServletException, IOException {\r\n\r\n    HttpServletRequest request = new HttpServletRequestWrapper(\r\n        (HttpServletRequest) servletRequest) {\r\n      private boolean pathComputed;\r\n      private String path;\r\n\r\n      private boolean pathInfoComputed;\r\n      private String pathInfo;\r\n\r\n      @Override\r\n      public String getPathInfo() {\r\n        if (!isPathInfoComputed()) {\r\n          String servletPath = getServletPath();\r\n          int servletPathLength = servletPath.length();\r\n          String requestUri = getRequestURI();\r\n          // ***** Bug here!!! *****\r\n          pathInfo = requestUri.substring(getContextPath().length()).replaceAll(\"[/]{2,}\", \"/\"); \r\n          // See: https://github.com/google/guice/issues/372\r\n          if (pathInfo.startsWith(servletPath)) {\r\n            pathInfo = pathInfo.substring(servletPathLength);\r\n            // Corner case: when servlet path & request path match exactly (without trailing '/'),\r\n            // then pathinfo is null.\r\n            if (pathInfo.isEmpty() && servletPathLength > 0) {\r\n              pathInfo = null;\r\n            } else {\r\n              try {\r\n                pathInfo = new URI(pathInfo).getPath();\r\n              } catch (URISyntaxException e) {\r\n                // ugh, just leave it alone then\r\n              }\r\n            }\r\n          } else {\r\n            pathInfo = null; // we know nothing additional about the URI.\r\n          }\r\n          pathInfoComputed = true;\r\n        }\r\n\r\n        return pathInfo;\r\n      }\r\n    // ... rest of the code\r\n  }\r\n```\r\n\r\nThe path returned by getContextPath() is for example \"/MyApp\". Normally the requestUri returned by getRequestURI looks like \"/MyApp/index.jsp\".\r\nWhen forwarding from one servlet to another servlet like the example above, the requestUri is \"/index.jsp\".\r\nThat's why ```java pathInfo = requestUri.substring(getContextPath().length()).replaceAll(\"[/]{2,}\", \"/\"); ``` is not working. It throws an exception when the contextPath is longer then the requestUri.\r\n\r\nI hope it will be fixed soon."}}
{"actor":{"display_login":"stebeg"}}