Re: returning a static file gives a indexoutofbounds exception

128 views
Skip to first unread message

James Reeves

unread,
Jan 18, 2013, 2:13:06 PM1/18/13
to Compojure
The stacktrace looks like it's falling afoul of a bug in clj-stacktrace. Try adding {:stacktraces? false} to your Ring options in your project file, and see what happens then when you run it.

- James


On 18 January 2013 18:22, Sid Kurias <sid.k...@gmail.com> wrote:
My routes are defined as follows
(defroutes main-routes
 
  (wrap-json (GET "/services/location/actions/List/invocation" []
                  req/availability))
  (route/resources "/app" {:root "public/app"})
  (GET "/*" [] (resource-response "index.html" {:root "public/app"})))

What I am trying to do is build a single page application. The client connects to a url http://localhost/app/index.html and is shown the index page. The client can navigate back and forth in the single page api successfully. For now the non source resources are in a directory called app, under resources/public. I am using the pushstate api and angularjs on the client side. When there is a page refresh I want to send the client back to index page - else they will receive a page not found error. How do I do it? The above gives me the following error

java.lang.IndexOutOfBoundsException

RT.java:784clojure.lang.RT.nthFrom
RT.java:753clojure.lang.RT.nth
utils.clj:52 clj-stacktrace.utils/quartile1
utils.clj:69clj-stacktrace.utils/fence
repl.clj:98clj-stacktrace.repl/find-source-width
repl.clj:107clj-stacktrace.repl/pst-on
repl.clj:123clj-stacktrace.repl/pst-str
RestFn.java:408 clojure.lang.RestFn.invoke
stacktrace.clj:17ring.middleware.stacktrace/wrap-stacktrace-log[fn]
stacktrace.clj:79ring.middleware.stacktrace/wrap-stacktrace-web[fn]
reload.clj:18ring.middleware.reload/wrap-reload[fn]
jetty.clj:18ring.adapter.jetty/proxy-handler[fn]
(Unknown Source) ring.adapter.jetty.proxy$org.eclipse.jetty.server.handler.AbstractHandler$0.handle
HandlerWrapper.java:111 org.eclipse.jetty.server.handler.HandlerWrapper.handle
Server.java:349org.eclipse.jetty.server.Server.handle
AbstractHttpConnection.java:452org.eclipse.jetty.server.AbstractHttpConnection.handleRequest
AbstractHttpConnection.java:884org.eclipse.jetty.server.AbstractHttpConnection.headerComplete
AbstractHttpConnection.java:938org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete
HttpParser.java:634org.eclipse.jetty.http.HttpParser.parseNext
HttpParser.java:230org.eclipse.jetty.http.HttpParser.parseAvailable
AsyncHttpConnection.java:76org.eclipse.jetty.server.AsyncHttpConnection.handle
SelectChannelEndPoint.java:609org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle
SelectChannelEndPoint.java:45org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run
QueuedThreadPool.java:599org.eclipse.jetty.util.thread.QueuedThreadPool.runJob
QueuedThreadPool.java:534org.eclipse.jetty.util.thread.QueuedThreadPool$3.run
Thread.java:722java.lang.Thread.run

I am using clojure 1.4, compojure 1.1.3 and ring 1.1.6.
I get a similar exception when I try to return the index.html file as a file-response.

Thank you
Sid
P.s: James, this is a followup to the post on the lein group you had responded to yesterday.

--
You received this message because you are subscribed to the Google Groups "Compojure" group.
To view this discussion on the web visit https://groups.google.com/d/msg/compojure/-/HI2NtAgzAo4J.
To post to this group, send email to comp...@googlegroups.com.
To unsubscribe from this group, send email to compojure+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/compojure?hl=en.

Sid Kurias

unread,
Jan 19, 2013, 12:12:00 AM1/19/13
to comp...@googlegroups.com, ja...@booleanknot.com
I did try setting stacktrace to false, I still get an error. A slightly different one

2013-01-19 10:08:09.709:WARN:oejs.AbstractHttpConnection:/app/services/reservation/actions/FindAvailable
java.lang.NullPointerException
2013-01-19 10:08:09.850:WARN:oejs.AbstractHttpConnection:/favicon.ico
java.lang.NullPointerException

One refers to favicon and the other to the url of the page being refreshed.

When I enable stacktraces again,  I get the previous outofbounds exception. But a curious case is when jetty starts up and kicks off the browser, it tries to reach the url localhost (http://localhost:3000, really); not localhost:3000/app/index.html or localhost:3000/. I don't believe I have a route matching this url.  At this point I can see the following error (on the server console, if stacktrace is turned off, otherwise both on the console and the page that is returned)

java.lang.NullPointerException

Matcher.java:1234java.util.regex.Matcher.getTextLength
Matcher.java:308java.util.regex.Matcher.reset
Matcher.java:228java.util.regex.Matcher.<init>
Pattern.java:1088java.util.regex.Pattern.matcher
core.clj:4286clojure.core/re-matcher
core.clj:4338clojure.core/re-find
refresh.clj:18ring.middleware.refresh/html-content?
refresh.clj:84ring.middleware.refresh/wrap-with-script[fn]
core.clj:106compojure.core/routing[fn]
core.clj:2390clojure.core/some
core.clj:106compojure.core/routing
RestFn.java:139clojure.lang.RestFn.applyTo
core.clj:603clojure.core/apply
core.clj:111compojure.core/routes[fn]
params.clj:55ring.middleware.params/wrap-params[fn]
stacktrace.clj:15ring.middleware.stacktrace/wrap-stacktrace-log[fn]

If I then navigate to http:/localhost:3000/app/index.html that works.
This initial error is present irrespective of whether stacktrace is set or not. I assume that it is the same error I get when I try to refresh a page with stacktrace set to false.
To the end of my routes defn, I have added the following
  (route/not-found "Ha!"). FYI.

All very confusing :-).

Thanks
Sid

Sid Kurias

unread,
Jan 19, 2013, 12:21:30 AM1/19/13
to comp...@googlegroups.com, ja...@booleanknot.com
Forgot to add that if I comment out the final route i.e.
(GET "/*" [] (resource-response "index.html" {:root "public/app"} the errors go away. The intended behaviour is still missing.
If i replace that route with the following

(GET "/*" [] "Are we there yet?)
I can see the string "Are we there yet?" when I refresh the page. So I think the routing works, but I can't seem to get file-response or resource-response to work.
Might be a 'ring' issue then...

James Reeves

unread,
Jan 19, 2013, 6:57:11 AM1/19/13
to Compojure
Did adding a not-found route fix the issue?

- James


To view this discussion on the web visit https://groups.google.com/d/msg/compojure/-/0nwTrqjGFHoJ.

James Reeves

unread,
Jan 19, 2013, 7:03:14 AM1/19/13
to Compojure
On 19 January 2013 05:21, Sid Kurias <sid.k...@gmail.com> wrote:
Forgot to add that if I comment out the final route i.e.
(GET "/*" [] (resource-response "index.html" {:root "public/app"} the errors go away. The intended behaviour is still missing.

What do you mean by this? Does it except, or does it 404?

What happens when you run that resource-response function in a REPL?

Is this code open source, or is it possible to take a look at the whole project?

- James

Sid Kurias

unread,
Jan 19, 2013, 11:30:42 AM1/19/13
to comp...@googlegroups.com, ja...@booleanknot.com
Ok the answers to your questions follow after this new discovery....
 As I was getting ready to send you the files, I looked at my project.clj file.  I have setup ring to do an autorefresh and autoreload.
When I comment out the autorefresh, everything works fine, just fine. I can navigate back and forth between pages and manually refresh to my heart's content.  :-). Seems like there is a problem with the autorefreshing on the ring server
I don't know if this is a bug or there is a problem with my setup. I have included my project.clj, core.clj files.
You can use them in a lein2 project. Add an app directory under resources/public and place any html file there called index.html. Then
curl -X GET http://localhost:3000/app/index.html should work and
curl -X GET http://localhost:3000/app/ will throw the exception if the autorefresh is enabled. It will return the index.html if autorefresh is turned off
If you find nothing amiss with my files perhaps I can report it as a bug on ring?

The answers to your questions(which perhaps are not relevant now)

nope adding a not-found does not fix the issue.

What I meant by my earlier statement is that on commenting out the (GET "/*" [] (resource-response ...) is that no exceptions are thrown. The not-found route is successfully executed. That is not the behaviour I would like. I would like the index page to be reloaded once again...

When I run the (resource-response ....) from the repl I get the following....

vms.core> (resource-response "index.html" {:root "public/app"})
{:status 200, :headers {}, :body #<File /home/sid/Documents/workspace/vms/resources/public/app/index.html>}


which is pointing to the right resource.
core.clj.txt
project.clj.txt

James Reeves

unread,
Jan 19, 2013, 3:33:05 PM1/19/13
to Compojure
I've tracked down the issue to a bug in the ring-refresh project. If a HTML file is returned in a resource, ring-refresh doesn't handle it correctly. Feel free to open a bug report here: https://github.com/weavejester/ring-refresh/issues

- James


To view this discussion on the web visit https://groups.google.com/d/msg/compojure/-/CByt8tNSeaAJ.

Sid Kurias

unread,
Jan 20, 2013, 1:46:17 AM1/20/13
to comp...@googlegroups.com, ja...@booleanknot.com
ok done and thanks for all the help and libraries you provide.

Sid
Reply all
Reply to author
Forward
0 new messages