LinkedDataFragments / Server.Java

A Triple Pattern Fragments server for Java
MIT License
27 stars 20 forks source link

Crash when sending invalid accept header #47

Closed rubensworks closed 6 years ago

rubensworks commented 6 years ago

Sending an invalid accept header results in the following crash, while I assume this should result in a 400 or 415:

<body><h2>HTTP ERROR 500</h2>
<p>Problem accessing /bigdata/ldf. Reason:
<pre>    Server Error</pre></p><h3>Caused by:</h3><pre>javax.servlet.ServletException: java.lang.ArrayIndexOutOfBoundsException: 1
    at org.linkeddatafragments.servlet.LinkedDataFragmentServlet.doGet(LinkedDataFragmentServlet.java:197)
    at org.wikidata.query.rdf.blazegraph.ldf.LDFServlet.doGet(LDFServlet.java:42)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:769)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1667)
    at ch.qos.logback.classic.helpers.MDCInsertingServletFilter.doFilter(MDCInsertingServletFilter.java:49)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1650)
    at org.wikidata.query.rdf.blazegraph.filters.ClientIPFilter.doFilter(ClientIPFilter.java:43)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1650)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:583)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1125)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1059)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:215)
    at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:110)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
    at org.eclipse.jetty.server.Server.handle(Server.java:497)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:248)
    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:610)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:539)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
    at org.linkeddatafragments.util.MIMEParse.parseMimeType(MIMEParse.java:99)
    at org.linkeddatafragments.util.MIMEParse.parseMediaRange(MIMEParse.java:119)
    at org.linkeddatafragments.util.MIMEParse.bestMatch(MIMEParse.java:268)
    at org.linkeddatafragments.util.MIMEParse.bestMatch(MIMEParse.java:292)
    at org.linkeddatafragments.servlet.LinkedDataFragmentServlet.doGet(LinkedDataFragmentServlet.java:161)
    ... 28 more
</pre>

Source: https://github.com/LinkedDataFragments/Server.Java/blob/master/src/main/java/org/linkeddatafragments/util/MIMEParse.java#L99

This can be reproduced by executing the following:

curl -H "Accept: text/turtle;q=1.0,application/n-triples;q=0.7,text/n3,q=0.6" "https://query.wikidata.org/bigdata/ldf"

Note that in this case, the last , should actually be ; to be correct.

mielvds commented 6 years ago

Correct, should be minor to fix.

mielvds commented 6 years ago

Fixed in https://github.com/LinkedDataFragments/Server.Java/releases/tag/v0.2.2