Short urls with apache causing error 500 for main page / trailing slash missing?

I installed XWiki 11.5 via deb-packages on debian 9 with mysql and tomcat 8.

I followed the instructions for short urls with apache on https://www.xwiki.org/xwiki/bin/view/Documentation/AdminGuide/ShortURLs/ and the debian specific instructions on https://www.xwiki.org/xwiki/bin/view/Documentation/AdminGuide/Installation/InstallationViaAPT/#HXWikiasrootwebapp28shortURLs29

So as a result I have a running tomcat on port 8080 and httpd on port 80.

When calling http://myserver.com/ I get an error 500:

17-Jul-2019 13:10:19.432 SEVERE [http-nio-8080-exec-3] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [action] in context with path [] threw exception
 java.io.IOException: Failed to extract the Entity Action from URL [http://127.0.0.1:8080/]
        at com.xpn.xwiki.web.XWikiRequestProcessor.processPath(XWikiRequestProcessor.java:133)
        at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:154)
        at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
        at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at com.xpn.xwiki.web.ActionFilter.doFilter(ActionFilter.java:112)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.xwiki.wysiwyg.filter.ConversionFilter.doFilter(ConversionFilter.java:109)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.xwiki.container.servlet.filters.internal.SetHTTPHeaderFilter.doFilter(SetHTTPHeaderFilter.java:63)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.xwiki.container.servlet.filters.internal.SavedRequestRestorerFilter.doFilter(SavedRequestRestorerFilter.java:208)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.xwiki.container.servlet.filters.internal.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:111)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.xwiki.resource.servlet.RoutingFilter.doFilter(RoutingFilter.java:108)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
        at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799)
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1458)
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
        at java.util.ArrayList.rangeCheck(ArrayList.java:657)
        at java.util.ArrayList.get(ArrayList.java:433)
        at org.xwiki.url.internal.AbstractExtendedURLResourceTypeResolver.resolve(AbstractExtendedURLResourceTypeResolver.java:88)
        at org.xwiki.url.internal.standard.StandardExtendedURLResourceTypeResolver.resolve(StandardExtendedURLResourceTypeResolver.java:100)
        at org.xwiki.url.internal.standard.StandardExtendedURLResourceTypeResolver.resolve(StandardExtendedURLResourceTypeResolver.java:57)
        at org.xwiki.url.internal.DefaultResourceTypeResolver.resolve(DefaultResourceTypeResolver.java:76)
        at org.xwiki.url.internal.DefaultResourceTypeResolver.resolve(DefaultResourceTypeResolver.java:45)
        at com.xpn.xwiki.web.XWikiRequestProcessor.processPath(XWikiRequestProcessor.java:126)
        ... 42 more

Calling http://myserver.com:8080/ gives me exactly the same error except for the URL in the brackets.

But calling http://myserver.com:8080// opens my wikis homepage just fine.

Opening http://myserver.com:8080/wiki gives me the error 500, http://myserver.com:8080/wiki/ gives me the wikis content.

So by combining these findings I assume somewhere in the process there is an trailing slash expected which is missing. My knowledge in java and tomcat is limited so I don’t know how to continue debugging.

Hi, the problem is probably in the urlrewrite filter XML content. You need to provide a URL that matches what XWiki expects, (see https://www.xwiki.org/xwiki/bin/view/Documentation/DevGuide/Architecture/URL%20Architecture/Standard%20URL%20Format/).

The simplest is to follow the example at https://www.xwiki.org/xwiki/bin/view/Documentation/AdminGuide/ShortURLs/#HUrlRewriteFilter

Hope it helps

Did I get the manual wrong? As far as I understood it I have to use either the UrlRewriteFilter or Apache? I choose Apache because I know more about it than about deploying java applications.

You can do it the way you want, but your frontend needs to produce URLs that XWiki can understand :wink: ie matching https://www.xwiki.org/xwiki/bin/view/Documentation/DevGuide/Architecture/URL%20Architecture/Standard%20URL%20Format/

Now to be fair, I’m surprised you get some IndexOutOfBoundsException error since the parsing code is not supposed to fail. I’d be curious to know what URL is provided to XWiki by your apache front end so that I could check our code and see why we throw an IndexOutOfBoundsException

EDIT: ok the URL is http://127.0.0.1:8080/ and that’s why. We don’t check when there’s no segment since it’s supposed to always have at least one segment… :wink: The code is:

        List<String> segments = extendedURL.getSegments();

        resourceType = this.defaultStringResourceTypeResolver.resolve(segments.get(0), Collections
            .<String, Object>emptyMap());

So get(0) doesn’t exist. We need to fix that.

But the issue for you is that you should generate some URL with “bin//<space*>/”.

But isn’t the point of adding

<servlet-mapping>
  <servlet-name>action</servlet-name>
  <url-pattern>/*</url-pattern>
</servlet-mapping>

to web.xml not requiring the bin/ in the url?

Until now I just followed the manual, except from some tests. But I reverted to the clean files just modified like the manual says before posting here.

If you tell me that it can’t work that way I will search for another solution and update the manual if I can add something usefull.