0

Trying to get check if a URL is reachable (actually able to be loaded from a browser) in GWT. The problem is that I'm getting an error because of the requested domain (same origin policy) with this code:

    RequestBuilder checkRequest = new RequestBuilder(RequestBuilder.HEAD, urlString);
    checkRequest.setCallback(new RequestCallback(){
        @Override
        public void onResponseReceived(Request request, Response response) {
            if (response.getStatusCode() > 199 && response.getStatusCode() < 300)
                Window.open(urlString, "", "");
        }

        @Override
        public void onError(Request request, Throwable exception) {
            // Handle error 
        }

    });*/

Since urlString could be any URL, I need to check whether it's actually valid or not before navigating to it. Is there another way to go about doing this in GWT (that works for IE, Chrome, and Firefox)

  • 2
    [GWT: Check if URL is dead](http://stackoverflow.com/questions/7622869/gwt-check-if-url-is-dead) ? – Perdomoff Dec 03 '15 at 22:56
  • Was hoping to avoid doing it on the server side –  Dec 04 '15 at 16:43
  • 1
    Because of the same origin policy, you won't be able to do it client-side, at least not for all browsers. But what's your actual goal? Do you want to open the URL in a browser window? If so, just keep in mind what I took away from a GWT session about offline mode: you may check if a server is there, but the connection might break anytime after that. So finally you can only be sure it works while you are actually connecting to it - and that would be the case to be handled. – Sebastian Baumhekel Dec 08 '15 at 06:56

0 Answers0