Example usage for com.google.gwt.http.client RequestCallback RequestCallback

List of usage examples for com.google.gwt.http.client RequestCallback RequestCallback

Introduction

In this page you can find the example usage for com.google.gwt.http.client RequestCallback RequestCallback.

Prototype

RequestCallback

Source Link

Usage

From source file:com.gsr.myschool.common.client.request.ExcelRequestBuilder.java

License:Apache License

public void sendRequestReportConvocation(ValueProxy data) {
    AutoBean autobean = AutoBeanUtils.getAutoBean(data);
    String requestdata = AutoBeanCodex.encode(autobean).getPayload();
    setRequestData(requestdata);//from   ww  w.  j a va  2 s . com
    setCallback(new RequestCallback() {
        @Override
        public void onResponseReceived(Request request, Response response) {
            if (GWT.isScript()) {
                Window.open("/preinscription/resource/dossierconvoques?fileName=" + response.getText(),
                        "_blank", "");
            } else {
                Window.open("/resource/dossierconvoques?fileName=" + response.getText(), "_blank", "");
            }
        }

        @Override
        public void onError(Request request, Throwable exception) {
        }
    });
    try {
        send();
    } catch (RequestException e) {
        e.printStackTrace();
    }
}

From source file:com.gwt.conn.client.Communicate.java

public static boolean hasInternet() {

    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
    builder.setHeader("Content-Type", "application/x-www-form-urlencoded");
    //      builder.setHeader("Access-Control-Allow-Origin", "*");
    //      builder.setHeader("Access-Control-Allow-Headers", "X-Requested-With");
    try {//from w w  w.  jav a  2 s .  c  om
        Request response = builder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
            }

            public void onResponseReceived(Request request, Response response) {

            }
        });

    } catch (RequestException e) {
        return false;
    }

    return true;
}

From source file:com.gwt.conn.client.Communicate.java

public static String sync(String menuName, String restID, final boolean authenticating) {
    RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url + "menu/update");
    builder.setHeader("Content-Type", "application/x-www-form-urlencoded");
    //      builder.setHeader("Access-Control-Allow-Origin", "*");
    //      builder.setHeader("Access-Control-Allow-Headers", "X-Requested-With");
    try {//w  ww.j  a  v a2 s .  co  m
        String doc = StorageContainer.getMenu(menuName);

        String timestamp = new Date().getTime() + "";
        String secret_key = ""; // TODO get secret key from storage
        String message = doc + secret_key + timestamp;
        String hash = "";
        hash = "" + getSHA1(message + secret_key + timestamp);

        String[] keys = { "doc", "message", "timestamp", "message_hash", "restaurant_id" };
        String[] values = { doc, doc, timestamp, hash, restID };

        String postData = buildQueryString(keys, values);
        System.out.println(postData);
        Request response = builder.sendRequest(postData, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                if (authenticating)
                    storage.setItem("authenticated?", "no");
                else
                    showDialog("Synchronize could not be completed.");
            }

            public void onResponseReceived(Request request, Response response) {
                System.out.println("response.getText() - " + response.getText());
                if (response.getText().equals("ERROR: Incomplete or Malformed doc") && authenticating) {
                    showDialog("Invalid Restaurant ID");
                    storage.setItem("authenticated?", "no");
                    return;
                } else if (response.getText().equals("ERROR: Incomplete or Malformed doc") && !authenticating) {
                    showDialog("Synchronize could not be completed.");
                    storage.setItem("authenticated?", "no");
                    return;
                }
                storage.setItem("menu", response.getText());

                if (authenticating)
                    storage.setItem("authenticated?", "yes");
                else
                    showDialog("You have successfully synchronized your menu!");
            }
        });

    } catch (RequestException e) {
        return "Update Unsuccessful";
    }

    return ""; // asynchronous callback, so whether or not successful is determined later
}

From source file:com.gwtext.client.widgets.tree.XMLTreeLoader.java

License:Open Source License

private static void requestData(final JavaScriptObject treeLoaderJS, final TreeNode root,
        final XMLTreeLoader treeLoader, String method, String url, final JavaScriptObject success,
        final JavaScriptObject failure, final JavaScriptObject callback, String params) {
    //build side nav tree from xml data
    RequestBuilder.Method httpMethod = "post".equalsIgnoreCase(method) ? RequestBuilder.POST
            : RequestBuilder.GET;//from www .  j  ava  2  s  .com

    RequestBuilder builder = new RequestBuilder(httpMethod, url);
    builder.setHeader("Content-type", "application/x-www-form-urlencoded");
    try {
        builder.sendRequest(params, new RequestCallback() {

            public void onResponseReceived(Request request, Response response) {
                if (response.getStatusCode() == 200) {
                    Document xml = null;
                    try {
                        xml = XMLParser.parse(response.getText());
                    } catch (Exception e) {
                        call(failure, treeLoaderJS, root.getJsObj(), callback, e.getMessage());
                        return;
                    }
                    String rootTag = treeLoader.getRootTag();
                    Node rootNode = null;
                    if (rootTag == null) {
                        rootNode = xml.getDocumentElement().getParentNode().getChildNodes().item(0);
                    } else {
                        rootNode = xml.getElementsByTagName(rootTag).item(0);
                    }
                    load(treeLoader, root, rootNode.getChildNodes());
                    call(success, treeLoaderJS, root.getJsObj(), callback, response.getText());

                } else {
                    call(failure, treeLoaderJS, root.getJsObj(), callback,
                            response.getStatusCode() + ":" + response.getText());
                }
            }

            public void onError(Request request, Throwable throwable) {
                call(failure, treeLoaderJS, root.getJsObj(), callback, throwable.getMessage());
            }
        });
    } catch (RequestException e) {
        call(failure, treeLoaderJS, root.getJsObj(), callback, e.getMessage());
    }
}

From source file:com.gwtplatform.dispatch.client.rest.RestDispatchAsync.java

License:Apache License

private <R extends Result> RequestCallback createRequestCallback(final RestAction<R> action,
        final AsyncCallback<R> callback) {
    return new RequestCallback() {
        @Override/*  w  ww  .  j a  v  a 2  s .  co  m*/
        public void onResponseReceived(Request request, Response response) {
            try {
                R result = restResponseDeserializer.deserialize(action, response);

                onExecuteSuccess(action, result, response, callback);
            } catch (ActionException e) {
                onExecuteFailure(action, e, response, callback);
            }
        }

        @Override
        public void onError(Request request, Throwable exception) {
            onExecuteFailure(action, exception, callback);
        }
    };
}

From source file:com.gwtplatform.dispatch.rest.client.core.RestDispatchCall.java

License:Apache License

private RequestCallback createRequestCallback() {
    return new RequestCallback() {
        @Override//from   w  ww  .java 2  s  . c o m
        public void onResponseReceived(Request request, Response response) {
            RestDispatchCall.this.onResponseReceived(response);
        }

        @Override
        public void onError(Request request, Throwable exception) {
            onExecuteFailure(exception);
        }
    };
}

From source file:com.gwtsite.musicplayer.client.MusicPlayer.java

License:Apache License

private void addListeners() {
    grid.addGridRowListener(new GridRowListenerAdapter() {

        public void onRowClick(GridPanel grid, int rowIndex, EventObject e) {
            Record record = grid.getStore().getAt(rowIndex);
            String title = record.getAsString("title");
            lyricsArea.setVisible(true);
            lyricsArea.setTitle("Lyrics for " + title);
            displaySongLyrics(title);//  w  w  w  .  j a  va 2  s. c  o m
        }

        private void displaySongLyrics(String title) {
            try {
                RequestBuilder request = new RequestBuilder(RequestBuilder.GET, title + ".txt");
                request.sendRequest(null, new RequestCallback() {
                    public void onError(Request request, Throwable exception) {
                        System.out.println("doh, error: " + exception.getStackTrace());
                    }

                    public void onResponseReceived(Request request, Response response) {
                        lyricsArea.setHtml(response.getText());
                    }

                });
            } catch (RequestException e) {
                // unable to fetch lyrics
                e.printStackTrace();
            }
        }

        public void onRowDblClick(GridPanel grid, int rowIndex, EventObject e) {
            if (currentSong != null) {
                currentSong.stop();
            }

            Record record = grid.getStore().getAt(rowIndex);
            final String title = record.getAsString("title");
            String mp3Name = title + ".mp3";

            currentSong = soundController.createSound(Sound.MIME_TYPE_AUDIO_MPEG, mp3Name);

            currentSong.addEventHandler(new SoundHandler() {
                public void onSoundComplete(SoundCompleteEvent event) {
                    songPlaying(false);
                }

                public void onSoundLoadStateChange(SoundLoadStateChangeEvent event) {
                    nowPlaying.setText("Now Playing - " + title);
                }

            });
            currentSong.play();
            nowPlaying.setHTML("<img class=\"loading-img\" src=\"1-0.gif\"/>Loading song - " + title);
            songPlaying(true);
        }

    });

    stopSongBtn.addListener(new ButtonListenerAdapter() {
        public void onClick(Button button, EventObject e) {
            currentSong.stop();
            songPlaying(false);
        }
    });

}

From source file:com.hiramchirino.restygwt.client.Method.java

License:Apache License

public void send(final RequestCallback callback) throws RequestException {
    builder.setCallback(new RequestCallback() {
        public void onResponseReceived(Request request, Response response) {
            callback.onResponseReceived(request, response);
        }/*from  w  ww  . j  av  a2 s  .  c o  m*/

        public void onError(Request request, Throwable exception) {
            callback.onResponseReceived(request, response);
        }
    });
    GWT.log("Sending http request: " + builder.getHTTPMethod() + " " + builder.getUrl(), null);
    String content = builder.getRequestData();
    if (content != null && content.length() > 0) {
        GWT.log(content, null);
    }
    request = builder.send();
}

From source file:com.isotrol.impe3.pms.gui.client.Pms.java

License:Open Source License

private void getPropertiesFileAndShowLogin(final LoginPanel loginPanel) {
    RequestBuilder json = new RequestBuilder(RequestBuilder.GET, "properties.json");
    json.setCallback(new RequestCallback() {

        public void onResponseReceived(Request request, Response response) {
            loginPanel.getPmsUtil().loadProperties(response);
            showLogin(loginPanel);/*  ww w . ja  v a2  s .  co m*/
        }

        public void onError(Request request, Throwable exception) {
            GWT.log("Throwable: " + exception.getMessage());
            exception.printStackTrace();
        }
    });
    try {
        json.send();
    } catch (RequestException e) {
        GWT.log("RequestException: " + e.getMessage());
        e.printStackTrace();
    }

}

From source file:com.isotrol.impe3.pms.gui.client.util.PmsUtil.java

License:Open Source License

/**
 * Read the json file "frameColumns.json" to build the arrays to show the default columns in columns palette in the
 * page design.//from  ww  w. j  ava  2s .c o m
 */
public void loadDesignColumns() {
    RequestBuilder json = new RequestBuilder(RequestBuilder.GET, "properties.json");
    json.setCallback(new RequestCallback() {

        public void onResponseReceived(Request request, Response response) {
            JSONObject fileJson = null;
            try {
                fileJson = (JSONObject) JSONParser.parseLenient(response.getText()).isObject();
            } catch (JSONException e) {
                util.error(pmsMessages.msgErrorParseColumnsJson());
            }

            if (fileJson != null) {
                JSONObject properties = fileJson.get("properties").isObject();
                JSONObject oProp = properties.isObject();
                // read frame columns
                parseFrameColumns(oProp);
                // read visibility of external services menus and disable login
                parseOtherProperties(oProp);
            }
        }

        public void onError(Request request, Throwable exception) {
            GWT.log("Throwable: " + exception.getMessage());
            exception.printStackTrace();
        }
    });
    try {
        json.send();
    } catch (RequestException e) {
        GWT.log("RequestException: " + e.getMessage());
        e.printStackTrace();
    }
}