5

Using JavaFx WebEngine, how can I detect if there is a 404 page not found error. I have searched but not able to find anything. Any ideas? or Is it possible?

2
  • Have you tried listening to the worker status? Maybe it shows a State.FAILED status? Commented Jan 31, 2014 at 13:19
  • Nope it does not. It shows Success. :( Commented Jan 31, 2014 at 13:35

1 Answer 1

3

Most likely you would have to add your own URL handler (like in this post javafx 2 webview custom url handler, don't work relative url) and retrieve/detect 404 messages and conditions yourself.

This article (How to check if a URL exists or returns 404 with Java?) shows you how to detect a 404 condition.

In the handler you have 2 choices, either create a HEAD request for a URL (and subsequently ignore HEAD requests so you don't get yourself into an infinite loop) or masquerade the returned URLConnection after checking for a 404.

@Override
protected URLConnection openConnection(URL u) throws IOException {
    // 1. Use Apache HTTPClient or something else to grab the url
    // 2. Read the resultCode and report if it's a 404
    // 3. Return an object that subclasses URLConnection
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the answer. I will check and update here.
What a horrible solution! Changing a write-once JVM-global property that's invasive enough to screw up the entire classloading mechanism... just to be able to read a status code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.