Example usage for com.google.gwt.xhr.client XMLHttpRequest send

List of usage examples for com.google.gwt.xhr.client XMLHttpRequest send

Introduction

In this page you can find the example usage for com.google.gwt.xhr.client XMLHttpRequest send.

Prototype

public void send() 

Source Link

Document

Initiates a request with no request data.

Usage

From source file:org.parallax3d.parallax.platforms.gwt.preloader.AssetDownloader.java

License:Apache License

public void loadBinary(final String url, final FileListener<Blob> listener) {
    XMLHttpRequest request = XMLHttpRequest.create();
    request.setOnReadyStateChange(new ReadyStateChangeHandler() {
        @Override//from   ww w  .ja  va  2 s .  c  om
        public void onReadyStateChange(XMLHttpRequest xhr) {
            if (xhr.getReadyState() == XMLHttpRequest.DONE) {
                if (xhr.getStatus() != 200) {
                    listener.onFailure();
                } else {
                    Int8Array data = TypedArrays.createInt8Array(xhr.getResponseArrayBuffer());
                    listener.onSuccess(new Blob(data));
                }
            }
        }
    });
    setOnProgress(request, listener);
    request.open("GET", url);
    request.setResponseType(ResponseType.ArrayBuffer);
    request.send();
}

From source file:playn.html.HtmlAssetManager.java

License:Apache License

private void doXhr(final String fullPath, final ResourceCallback<String> callback) {
    XMLHttpRequest xhr = XMLHttpRequest.create();
    xhr.setOnReadyStateChange(new ReadyStateChangeHandler() {
        @Override/*from www .  j a  v  a  2  s . c  o  m*/
        public void onReadyStateChange(XMLHttpRequest xhr) {
            int readyState = xhr.getReadyState();
            if (readyState == XMLHttpRequest.DONE) {
                int status = xhr.getStatus();
                // status code 0 will be returned for non-http requests, e.g. file://
                if (status != 0 && (status < 200 || status >= 400)) {
                    PlayN.log().error("xhr::onReadyStateChange[" + fullPath + "](readyState = " + readyState
                            + "; status = " + status + ")");
                    callback.error(
                            new RuntimeException("Error getting " + fullPath + " : " + xhr.getStatusText()));
                } else {
                    if (LOG_XHR_SUCCESS) {
                        PlayN.log().debug("xhr::onReadyStateChange[" + fullPath + "](readyState = " + readyState
                                + "; status = " + status + ")");
                    }
                    // TODO(fredsa): Remove try-catch and materialized exception once issue 6562 is fixed
                    // http://code.google.com/p/google-web-toolkit/issues/detail?id=6562
                    try {
                        callback.done(xhr.getResponseText());
                    } catch (JavaScriptException e) {
                        if (GWT.isProdMode()) {
                            throw e;
                        } else {
                            JavaScriptException materialized = new JavaScriptException(e.getName(),
                                    e.getDescription());
                            materialized.setStackTrace(e.getStackTrace());
                            throw materialized;
                        }
                    }
                }
            }
        }
    });

    if (LOG_XHR_SUCCESS) {
        PlayN.log().debug("xhr.open('GET', '" + fullPath + "')...");
    }
    xhr.open("GET", fullPath);

    if (LOG_XHR_SUCCESS) {
        PlayN.log().debug("xhr.send()...");
    }
    xhr.send();
}

From source file:playn.html.HtmlNet.java

License:Apache License

public void get(String url, final Callback<String> callback) {
    try {/*www. j a v  a 2 s  .  c o m*/
        XMLHttpRequest xhr = XMLHttpRequest.create();
        xhr.open("GET", url);
        xhr.setOnReadyStateChange(new ReadyStateChangeHandler() {
            @Override
            public void onReadyStateChange(XMLHttpRequest xhr) {
                if (xhr.getReadyState() == XMLHttpRequest.DONE) {
                    if (xhr.getStatus() >= 400) {
                        callback.onFailure(new RuntimeException("Bad HTTP status code: " + xhr.getStatus()));
                    } else {
                        callback.onSuccess(xhr.getResponseText());
                    }
                }
            }
        });
        xhr.send();
    } catch (Exception e) {
        callback.onFailure(e);
    }
}

From source file:thothbot.parallax.core.client.textures.CompressedTexture.java

License:Open Source License

public CompressedTexture(final String url, final ImageLoadHandler imageLoadHandler) {

    this.mipmaps = new ArrayList<DataTexture>();

    XMLHttpRequest binxhr = (XMLHttpRequest) XMLHttpRequest.create();
    binxhr.open("GET", url);
    binxhr.setResponseType("arraybuffer");
    binxhr.send();

    binxhr.setOnReadyStateChange(new ReadyStateChangeHandler() {
        @Override//from  w  w w.ja  v  a2  s  .c o m
        public void onReadyStateChange(XMLHttpRequest xhr) {
            XMLHttpRequest binxhr = (XMLHttpRequest) xhr;
            if (binxhr.getReadyState() == XMLHttpRequest.DONE) {
                binxhr.clearOnReadyStateChange();
                ArrayBuffer buffer = binxhr.getResponseArrayBuffer();
                parseDDS(buffer, true);

                setGenerateMipmaps(false);
                setNeedsUpdate(true);

                if (imageLoadHandler != null)
                    imageLoadHandler.onImageLoad(CompressedTexture.this);
            }
        }
    });
}