Search in sources :

Example 41 with RequestCallback

use of com.google.gwt.http.client.RequestCallback in project pentaho-platform by pentaho.

the class MantleEntryPoint method onModuleLoad.

/**
 * This is the entry point method.
 */
public void onModuleLoad() {
    // which comes from the url parameter
    if (!StringUtils.isEmpty(Window.Location.getParameter("locale"))) {
        String locale = Window.Location.getParameter("locale");
        // $NON-NLS-1$
        final String url = GWT.getHostPageBaseURL() + "api/mantle/locale";
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);
        builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
        try {
            builder.sendRequest(locale, new RequestCallback() {

                public void onError(Request request, Throwable exception) {
                // showError(exception);
                }

                public void onResponseReceived(Request request, Response response) {
                }
            });
        } catch (RequestException e) {
        // showError(e);
        }
    }
    ResourceBundle messages = new ResourceBundle();
    Messages.setResourceBundle(messages);
    // $NON-NLS-1$ //$NON-NLS-2$
    messages.loadBundle(GWT.getModuleBaseURL() + "messages/", "mantleMessages", true, MantleEntryPoint.this);
}
Also used : Response(com.google.gwt.http.client.Response) RequestBuilder(com.google.gwt.http.client.RequestBuilder) RequestCallback(com.google.gwt.http.client.RequestCallback) Request(com.google.gwt.http.client.Request) ResourceBundle(org.pentaho.gwt.widgets.client.utils.i18n.ResourceBundle) RequestException(com.google.gwt.http.client.RequestException)

Example 42 with RequestCallback

use of com.google.gwt.http.client.RequestCallback in project pentaho-platform by pentaho.

the class ContentCleanerPanel method deleteContentNow.

/**
 * @param age
 *          in milliseconds
 */
public void deleteContentNow(long age) {
    showLoadingIndicator();
    String date = DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(new Date());
    String json = "{\"jobName\": \"Content Cleaner\", \"actionClass\": \"org.pentaho.platform.admin.GeneratedContentCleaner\"," + " \"jobParameters\":[ { \"name\": \"age\", \"stringValue\": \"" + age + "\", \"type\": \"string\" }], \"simpleJobTrigger\": { \"endTime\": null, \"repeatCount\": \"0\", " + "\"repeatInterval\": \"0\", \"startTime\": \"" + date + "\", \"uiPassParam\": \"RUN_ONCE\"} }";
    RequestBuilder scheduleFileRequestBuilder = new RequestBuilder(RequestBuilder.POST, GWT.getHostPageBaseURL() + "api/scheduler/job");
    scheduleFileRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    // $NON-NLS-1$//$NON-NLS-2$
    scheduleFileRequestBuilder.setHeader("Content-Type", "application/json");
    try {
        scheduleFileRequestBuilder.sendRequest(json, new RequestCallback() {

            public void onError(Request request, Throwable exception) {
            }

            public void onResponseReceived(Request request, Response response) {
                String jobId = response.getText();
                final RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, GWT.getHostPageBaseURL() + "api/scheduler/jobinfo?jobId=" + URL.encodeQueryString(jobId));
                requestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
                // $NON-NLS-1$//$NON-NLS-2$
                requestBuilder.setHeader("Content-Type", "application/json");
                // $NON-NLS-1$//$NON-NLS-2$
                requestBuilder.setHeader("accept", "application/json");
                // create a timer to check if the job has finished
                Timer t = new Timer() {

                    public void run() {
                        try {
                            requestBuilder.sendRequest(null, new RequestCallback() {

                                @Override
                                public void onResponseReceived(Request request, Response response) {
                                    // once the job is finished, it is removed from scheduler and we should receive a 404 code.
                                    if (response.getStatusCode() != Response.SC_OK) {
                                        hideLoadingIndicator();
                                        cancel();
                                    }
                                }

                                @Override
                                public void onError(Request request, Throwable throwable) {
                                    hideLoadingIndicator();
                                    cancel();
                                }
                            });
                        } catch (RequestException e) {
                            hideLoadingIndicator();
                            cancel();
                        }
                    }
                };
                t.scheduleRepeating(1000);
            }
        });
    } catch (RequestException re) {
        hideLoadingIndicator();
    }
}
Also used : Response(com.google.gwt.http.client.Response) RequestBuilder(com.google.gwt.http.client.RequestBuilder) RequestCallback(com.google.gwt.http.client.RequestCallback) Timer(com.google.gwt.user.client.Timer) Request(com.google.gwt.http.client.Request) JSONString(com.google.gwt.json.client.JSONString) RequestException(com.google.gwt.http.client.RequestException) Date(java.util.Date)

Example 43 with RequestCallback

use of com.google.gwt.http.client.RequestCallback in project pentaho-platform by pentaho.

the class EmailAdminPanelController method getEmailConfig.

private void getEmailConfig() {
    String serviceUrl = GWT.getHostPageBaseURL() + "api/emailconfig/getEmailConfig?cb=" + System.currentTimeMillis();
    RequestBuilder executableTypesRequestBuilder = new RequestBuilder(RequestBuilder.GET, serviceUrl);
    executableTypesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    executableTypesRequestBuilder.setHeader("accept", "application/json");
    try {
        executableTypesRequestBuilder.sendRequest(null, new RequestCallback() {

            public void onError(Request request, Throwable exception) {
            }

            public void onResponseReceived(Request request, Response response) {
                emailConfig = JsEmailConfiguration.parseJsonString(response.getText());
                authenticationCheckBox.setValue(Boolean.parseBoolean(emailConfig.isAuthenticate() + ""));
                authenticationPanel.setVisible(Boolean.parseBoolean(emailConfig.isAuthenticate() + ""));
                smtpHostTextBox.setValue(emailConfig.getSmtpHost());
                portTextBox.setValue(emailConfig.getSmtpPort() + "");
                useStartTLSCheckBox.setValue(Boolean.parseBoolean(emailConfig.isUseStartTls() + ""));
                useSSLCheckBox.setValue(Boolean.parseBoolean(emailConfig.isUseSsl() + ""));
                fromAddressTextBox.setValue(emailConfig.getDefaultFrom());
                fromNameTextBox.setValue(emailConfig.getFromName());
                userNameTextBox.setValue(emailConfig.getUserId());
                // If password is non-empty.. disable the text-box
                String password = emailConfig.getPassword();
                passwordTextBox.setValue(password);
                String protocol = emailConfig.getSmtpProtocol();
                protocolsListBox.setSelectedIndex(-1);
                if (!StringUtils.isEmpty(protocol)) {
                    for (int i = 0; i < protocolsListBox.getItemCount(); ++i) {
                        if (protocol.equalsIgnoreCase(protocolsListBox.getItemText(i))) {
                            protocolsListBox.setSelectedIndex(i);
                            break;
                        }
                    }
                }
            }
        });
    } catch (RequestException e) {
    // ignored
    }
}
Also used : Response(com.google.gwt.http.client.Response) RequestBuilder(com.google.gwt.http.client.RequestBuilder) RequestCallback(com.google.gwt.http.client.RequestCallback) Request(com.google.gwt.http.client.Request) RequestException(com.google.gwt.http.client.RequestException)

Example 44 with RequestCallback

use of com.google.gwt.http.client.RequestCallback in project pentaho-platform by pentaho.

the class DeleteFileCommand method doDelete.

public void doDelete(String filesList, final SolutionFileActionEvent event) {
    // $NON-NLS-1$
    String deleteFilesURL = contextURL + "api/repo/files/delete";
    RequestBuilder deleteFilesRequestBuilder = new RequestBuilder(RequestBuilder.PUT, deleteFilesURL);
    // $NON-NLS-1$//$NON-NLS-2$
    deleteFilesRequestBuilder.setHeader("Content-Type", "text/plain");
    deleteFilesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    try {
        deleteFilesRequestBuilder.sendRequest(filesList, new RequestCallback() {

            @Override
            public void onError(Request request, Throwable exception) {
                MessageDialogBox dialogBox = new // $NON-NLS-1$ //$NON-NLS-2$
                MessageDialogBox(// $NON-NLS-1$ //$NON-NLS-2$
                Messages.getString("error"), // $NON-NLS-1$ //$NON-NLS-2$
                Messages.getString("couldNotDeleteFile"), false, false, true);
                dialogBox.center();
                event.setMessage(Messages.getString("couldNotDeleteFile"));
                EventBusUtil.EVENT_BUS.fireEvent(event);
            }

            @Override
            public void onResponseReceived(Request request, Response response) {
                if (response.getStatusCode() == 200) {
                    event.setMessage("Success");
                    EventBusUtil.EVENT_BUS.fireEvent(event);
                    new RefreshRepositoryCommand().execute(false);
                    FileChooserDialog.setIsDirty(Boolean.TRUE);
                    setBrowseRepoDirty(Boolean.TRUE);
                    for (SolutionBrowserFile file : filesToDelete) {
                        if (file.getPath() != null) {
                            SolutionBrowserPanel.getInstance().removeRecent(file.getPath());
                            SolutionBrowserPanel.getInstance().removeFavorite(file.getPath());
                        }
                    }
                } else {
                    event.setMessage(Messages.getString("couldNotDeleteFile"));
                    EventBusUtil.EVENT_BUS.fireEvent(event);
                }
            }
        });
    } catch (RequestException e) {
        MessageDialogBox dialogBox = new // $NON-NLS-1$ //$NON-NLS-2$
        MessageDialogBox(// $NON-NLS-1$ //$NON-NLS-2$
        Messages.getString("error"), // $NON-NLS-1$ //$NON-NLS-2$
        Messages.getString("couldNotDeleteFile"), false, false, true);
        dialogBox.center();
        event.setMessage(Messages.getString("couldNotDeleteFile"));
        EventBusUtil.EVENT_BUS.fireEvent(event);
    }
}
Also used : Response(com.google.gwt.http.client.Response) SolutionBrowserFile(org.pentaho.mantle.client.solutionbrowser.SolutionBrowserFile) RequestBuilder(com.google.gwt.http.client.RequestBuilder) RequestCallback(com.google.gwt.http.client.RequestCallback) MessageDialogBox(org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox) Request(com.google.gwt.http.client.Request) RequestException(com.google.gwt.http.client.RequestException)

Example 45 with RequestCallback

use of com.google.gwt.http.client.RequestCallback in project pentaho-platform by pentaho.

the class ExecuteGlobalActionsCommand method performOperation.

protected void performOperation() {
    // $NON-NLS-1$
    final String url = GWT.getHostPageBaseURL() + "api/system/refresh/globalActions";
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url);
    requestBuilder.setHeader("accept", "text/plain");
    requestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    try {
        requestBuilder.sendRequest(null, new RequestCallback() {

            public void onError(Request request, Throwable exception) {
            // showError(exception);
            }

            public void onResponseReceived(Request request, Response response) {
                MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("info"), Messages.getString("globalActionsExecutedSuccessfully"), false, false, // $NON-NLS-1$ //$NON-NLS-2$
                true);
                dialogBox.center();
            }
        });
    } catch (RequestException e) {
        Window.alert(e.getMessage());
    // showError(e);
    }
}
Also used : Response(com.google.gwt.http.client.Response) RequestBuilder(com.google.gwt.http.client.RequestBuilder) RequestCallback(com.google.gwt.http.client.RequestCallback) MessageDialogBox(org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox) Request(com.google.gwt.http.client.Request) RequestException(com.google.gwt.http.client.RequestException)

Aggregations

RequestCallback (com.google.gwt.http.client.RequestCallback)166 Response (com.google.gwt.http.client.Response)165 Request (com.google.gwt.http.client.Request)164 RequestException (com.google.gwt.http.client.RequestException)159 RequestBuilder (com.google.gwt.http.client.RequestBuilder)109 JSONException (com.google.gwt.json.client.JSONException)55 HttpException (com.willshex.gson.web.service.client.HttpException)55 MessageDialogBox (org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox)17 BlockUsersRequest (com.willshex.blogwt.shared.api.user.call.BlockUsersRequest)12 BlockUsersResponse (com.willshex.blogwt.shared.api.user.call.BlockUsersResponse)12 ChangePasswordRequest (com.willshex.blogwt.shared.api.user.call.ChangePasswordRequest)12 ChangePasswordResponse (com.willshex.blogwt.shared.api.user.call.ChangePasswordResponse)12 ChangeUserAccessRequest (com.willshex.blogwt.shared.api.user.call.ChangeUserAccessRequest)12 ChangeUserAccessResponse (com.willshex.blogwt.shared.api.user.call.ChangeUserAccessResponse)12 ChangeUserDetailsRequest (com.willshex.blogwt.shared.api.user.call.ChangeUserDetailsRequest)12 ChangeUserDetailsResponse (com.willshex.blogwt.shared.api.user.call.ChangeUserDetailsResponse)12 CheckUsernameRequest (com.willshex.blogwt.shared.api.user.call.CheckUsernameRequest)12 CheckUsernameResponse (com.willshex.blogwt.shared.api.user.call.CheckUsernameResponse)12 FollowUsersRequest (com.willshex.blogwt.shared.api.user.call.FollowUsersRequest)12 FollowUsersResponse (com.willshex.blogwt.shared.api.user.call.FollowUsersResponse)12