Example usage for com.google.gwt.http.client RequestBuilder setHeader

List of usage examples for com.google.gwt.http.client RequestBuilder setHeader

Introduction

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

Prototype

public void setHeader(String header, String value) 

Source Link

Document

Sets a request header with the given name and value.

Usage

From source file:org.pentaho.mantle.client.dialogs.scheduling.ScheduleRecurrenceDialog.java

License:Open Source License

private void showScheduleParamsDialog(final JsJobTrigger trigger, final JSONObject schedule) {
    try {//ww w  . j a va  2 s .  com
        final String url = ScheduleHelper.getFullyQualifiedURL() + "api/mantle/isAuthenticated"; //$NON-NLS-1$
        RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url);
        requestBuilder.setHeader("accept", "text/plain"); //$NON-NLS-1$ //$NON-NLS-2$
        requestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
        requestBuilder.sendRequest(null, new RequestCallback() {

            @Override
            public void onError(Request request, Throwable caught) {
                MantleLoginDialog.performLogin(new AsyncCallback<Boolean>() {

                    @Override
                    public void onFailure(Throwable caught) {
                    }

                    @Override
                    public void onSuccess(Boolean result) {
                        showScheduleParamsDialog(trigger, schedule);
                    }
                });
            }

            @Override
            public void onResponseReceived(Request request, Response response) {
                if (scheduleParamsDialog == null) {
                    scheduleParamsDialog = new ScheduleParamsDialog(ScheduleRecurrenceDialog.this,
                            isEmailConfValid, editJob);
                    scheduleParamsDialog.setCallback(callback);
                } else {
                    scheduleParamsDialog.setJobSchedule(schedule);
                }
                scheduleParamsDialog.setNewSchedule(newSchedule);
                scheduleParamsDialog.center();
                hide();
            }

        });
    } catch (RequestException e) {
        Window.alert(e.getMessage());
    }

}

From source file:org.pentaho.mantle.client.MantleApplication.java

License:Open Source License

public void onMantleSettingsLoaded(MantleSettingsLoadedEvent event) {
    final HashMap<String, String> settings = event.getSettings();

    final boolean showOnlyPerspective = Boolean
            .parseBoolean(StringUtils.isEmpty(Window.Location.getParameter("showOnlyPerspective"))
                    ? settings.get("showOnlyPerspective")
                    : Window.Location.getParameter("showOnlyPerspective"));
    final String startupPerspective = StringUtils.isEmpty(Window.Location.getParameter("startupPerspective"))
            ? settings.get("startupPerspective")
            : Window.Location.getParameter("startupPerspective");

    mantleRevisionOverride = settings.get("user-console-revision");

    RootPanel.get("pucMenuBar").add(MantleXul.getInstance().getMenubar());
    RootPanel.get("pucPerspectives").add(PerspectiveManager.getInstance());
    RootPanel.get("pucToolBar").add(MantleXul.getInstance().getToolbar());
    RootPanel.get("pucUserDropDown").add(new UserDropDown());

    if (showOnlyPerspective && !StringUtils.isEmpty(startupPerspective)) {
        RootPanel.get("pucHeader").setVisible(false);
        RootPanel.get("pucContent").getElement().getStyle().setTop(0, Unit.PX);
    }//w ww  . j av a 2 s  . c om

    // update supported file types
    PluginOptionsHelper.buildEnabledOptionsList(settings);

    // show stuff we've created/configured
    contentDeck.add(new Label());
    contentDeck.showWidget(0);
    contentDeck.add(SolutionBrowserPanel.getInstance());
    if (showOnlyPerspective && !StringUtils.isEmpty(startupPerspective)) {
        SolutionBrowserPanel.getInstance().setVisible(false);
    }

    contentDeck.getElement().setId("applicationShell");
    contentDeck.setStyleName("applicationShell");

    // menubar=no,location=no,resizable=yes,scrollbars=no,status=no,width=1200,height=800
    try {
        RootPanel.get("pucContent").add(contentDeck);
    } catch (Throwable t) {
        // onLoad of something is causing problems
    }

    RootPanel.get().add(WaitPopup.getInstance());

    // Add in the overlay panel
    overlayPanel.setVisible(false);
    overlayPanel.setHeight("100%");
    overlayPanel.setWidth("100%");
    overlayPanel.getElement().getStyle().setProperty("zIndex", "1000");
    overlayPanel.getElement().getStyle().setProperty("position", "absolute");
    RootPanel.get().add(overlayPanel, 0, 0);

    String submitOnEnterSetting = settings.get("submit-on-enter-key");
    submitOnEnter = submitOnEnterSetting == null ? submitOnEnter : Boolean.parseBoolean(submitOnEnterSetting);

    try {
        String restUrl = GWT.getHostPageBaseURL() + "api/repo/files/canAdminister"; //$NON-NLS-1$
        RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, restUrl);
        requestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
        requestBuilder.sendRequest(null, new RequestCallback() {

            @Override
            public void onError(Request arg0, Throwable arg1) {
                MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$
                        arg1.getLocalizedMessage(), false, false, true);
                dialogBox.center();
            }

            @Override
            public void onResponseReceived(Request arg0, Response response) {
                Boolean isAdministrator = Boolean.parseBoolean(response.getText());
                SolutionBrowserPanel.getInstance().setAdministrator(isAdministrator);

                try {
                    String restUrl2 = GWT.getHostPageBaseURL() + "api/scheduler/canSchedule"; //$NON-NLS-1$
                    RequestBuilder requestBuilder2 = new RequestBuilder(RequestBuilder.GET, restUrl2);
                    requestBuilder2.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
                    requestBuilder2.sendRequest(null, new RequestCallback() {
                        @Override
                        public void onError(Request arg0, Throwable arg1) {
                            MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$
                                    arg1.getLocalizedMessage(), false, false, true);
                            dialogBox.center();
                        }

                        public void onResponseReceived(Request arg0, Response response) {
                            Boolean isScheduler = Boolean.parseBoolean(response.getText());
                            SolutionBrowserPanel.getInstance().setScheduler(isScheduler);

                            String numStartupURLsSetting = settings.get("num-startup-urls");
                            if (numStartupURLsSetting != null) {
                                int numStartupURLs = Integer.parseInt(numStartupURLsSetting); //$NON-NLS-1$
                                for (int i = 0; i < numStartupURLs; i++) {
                                    String url = settings.get("startup-url-" + (i + 1)); //$NON-NLS-1$
                                    String name = settings.get("startup-name-" + (i + 1)); //$NON-NLS-1$
                                    if (StringUtils.isEmpty(url) == false) { //$NON-NLS-1$
                                        url = URL.decodeQueryString(url);
                                        name = URL.decodeQueryString(name);
                                        SolutionBrowserPanel.getInstance().getContentTabPanel()
                                                .showNewURLTab(name != null ? name : url, url, url, false);
                                    }
                                }
                            }
                            if (SolutionBrowserPanel.getInstance().getContentTabPanel().getWidgetCount() > 0) {
                                SolutionBrowserPanel.getInstance().getContentTabPanel().selectTab(0);
                            }

                            // startup-url on the URL for the app, wins over settings
                            String startupURL = Window.Location.getParameter("startup-url"); //$NON-NLS-1$
                            if (startupURL != null && !"".equals(startupURL)) { //$NON-NLS-1$
                                // Spaces were double encoded so that they wouldn't be replaced with '+' when creating a deep
                                // link so when following a deep link we need to replace '%20' with a space even after decoding
                                String title = Window.Location.getParameter("name").replaceAll("%20", " "); //$NON-NLS-1$
                                SolutionBrowserPanel.getInstance().getContentTabPanel().showNewURLTab(title,
                                        title, startupURL, false);
                            }
                        }
                    });
                } catch (RequestException e) {
                    MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$
                            e.getLocalizedMessage(), false, false, true);
                    dialogBox.center();
                }
            }
        });
    } catch (RequestException e) {
        MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), e.getLocalizedMessage(), //$NON-NLS-1$
                false, false, true);
        dialogBox.center();
    }

    if (!StringUtils.isEmpty(startupPerspective)) {
        if (PerspectiveManager.getInstance().isLoaded()) {
            PerspectiveManager.getInstance().setPerspective(startupPerspective);
        } else {
            EventBusUtil.EVENT_BUS.addHandler(PerspectivesLoadedEvent.TYPE,
                    new PerspectivesLoadedEventHandler() {
                        public void onPerspectivesLoaded(PerspectivesLoadedEvent event) {
                            PerspectiveManager.getInstance().setPerspective(startupPerspective);
                        }
                    });
        }
    }

}

From source file:org.pentaho.mantle.client.MantleEntryPoint.java

License:Open Source License

/**
 * This is the entry point method./*  w ww .ja v a  2s  .  com*/
 */
public void onModuleLoad() {
    // just some quick sanity setting of the platform effective locale based on the override
    // which comes from the url parameter
    if (!StringUtils.isEmpty(Window.Location.getParameter("locale"))) {
        String locale = Window.Location.getParameter("locale");
        final String url = GWT.getHostPageBaseURL() + "api/mantle/locale"; //$NON-NLS-1$
        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);
    messages.loadBundle(GWT.getModuleBaseURL() + "messages/", "mantleMessages", true, MantleEntryPoint.this); //$NON-NLS-1$ //$NON-NLS-2$
}

From source file:org.pentaho.mantle.client.solutionbrowser.filepicklist.AbstractFilePickList.java

License:Open Source License

/**
 * Convert the FilePickList to JSON and save it to a user setting
 * //from ww w.j a v a  2 s .  c o m
 * @param settingName
 */
public void save(String settingName) {
    final String url = GWT.getHostPageBaseURL() + "api/user-settings/" + settingName; //$NON-NLS-1$

    RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);
    try {
        builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
        builder.sendRequest(toJson().toString(), new RequestCallback() {

            public void onError(Request request, Throwable exception) {
                MessageDialogBox dialog = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$
                        Messages.getString("couldNotSetUserSettings"), true, false, true); //$NON-NLS-1$
                dialog.center();
            }

            public void onResponseReceived(Request request, Response response) {
                fireOnSavedEvent();
            }
        });
    } catch (RequestException e) {
        // showError(e);
    }
}

From source file:org.pentaho.mantle.client.solutionbrowser.filepicklist.AbstractFilePickList.java

License:Open Source License

public void reloadFavorites(final T pickListItem, final String command) {
    final String url = GWT.getHostPageBaseURL() + "api/user-settings/favorites"; //$NON-NLS-1$

    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
    try {/*ww  w.ja  v a 2s .  c  o m*/
        builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
        builder.setHeader("accept", "application/json");
        builder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                // showError(exception);
            }

            public void onResponseReceived(Request request, Response response) {
                if (response.getStatusCode() == Response.SC_OK) {
                    try {
                        JSONArray jsonArr = (JSONArray) JSONParser.parse(response.getText());
                        filePickList = new ArrayList<T>();
                        T filePickItem;
                        for (int i = 0; i < jsonArr.size(); i++) {
                            filePickItem = createFilePickItem(jsonArr.get(i).isObject());
                            filePickList.add(filePickItem);
                        }
                        if (FILE_PICK_ADD.equals(command)) {
                            add(filePickList.size(), pickListItem);
                        } else if (FILE_PICK_REMOVE.equals(command)) {
                            filePickList.remove(pickListItem);
                            fireItemsChangedEvent();
                        }
                    } catch (Exception e) {
                        if (FILE_PICK_ADD.equals(command)) {
                            add(filePickList.size(), pickListItem);
                        } else if (FILE_PICK_REMOVE.equals(command)) {
                            filePickList.remove(pickListItem);
                            fireItemsChangedEvent();
                        }
                    }
                }
            }
        });
    } catch (RequestException e) {
        // showError(e);
    }
}

From source file:org.pentaho.mantle.client.solutionbrowser.filepicklist.AbstractFilePickList.java

License:Open Source License

public void reloadRecents(final T pickListItem, final String command) {
    final String url = GWT.getHostPageBaseURL() + "api/user-settings/recent"; //$NON-NLS-1$

    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
    try {/*from   w w  w. j a v a2  s  .co  m*/
        builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
        builder.setHeader("accept", "application/json");
        builder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                // showError(exception);
            }

            public void onResponseReceived(Request request, Response response) {
                if (response.getStatusCode() == Response.SC_OK) {
                    try {
                        JSONArray jsonArr = (JSONArray) JSONParser.parse(response.getText());
                        filePickList = new ArrayList<T>();
                        T filePickItem;
                        for (int i = 0; i < jsonArr.size(); i++) {
                            filePickItem = createFilePickItem(jsonArr.get(i).isObject());
                            filePickList.add(filePickItem);
                        }
                        if (FILE_PICK_REMOVE.equals(command)) {
                            filePickList.remove(pickListItem);
                            fireItemsChangedEvent();
                        }
                    } catch (Exception e) {
                        if (FILE_PICK_REMOVE.equals(command)) {
                            filePickList.remove(pickListItem);
                            fireItemsChangedEvent();
                        }
                    }
                }
            }
        });
    } catch (RequestException e) {
        // showError(e);
    }
}

From source file:org.pentaho.mantle.client.solutionbrowser.fileproperties.FilePropertiesDialog.java

License:Open Source License

/**
 *
 *//*ww  w .  ja v a 2s .  c o  m*/
private void applyPanel() {
    ArrayList<RequestBuilder> requestBuilders = new ArrayList<RequestBuilder>();
    for (int i = 0; i < propertyTabs.getTabCount(); i++) {
        Widget w = propertyTabs.getTab(i).getContent();
        if (w instanceof IFileModifier) {
            // get requests from sub panels
            if (((IFileModifier) w).prepareRequests() != null) {
                requestBuilders.addAll(((IFileModifier) w).prepareRequests());
            }
        }
    }

    RequestCallback requestCallback;
    // chain requests from subpanels using callbacks to try and avoid any StaleItemStateExceptions
    for (int i = 0; i <= requestBuilders.size() - 1; i++) {
        RequestBuilder requestBuilder = requestBuilders.get(i);
        if (i < requestBuilders.size() - 1) {
            final RequestBuilder nextRequest = requestBuilders.get(i + 1);
            // This header is required to force Internet Explorer to not cache values from the GET response.
            nextRequest.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
            requestCallback = new ChainedRequestCallback(nextRequest);
        } else {
            requestCallback = new RequestCallback() {
                @Override
                public void onError(Request request, Throwable th) {
                    WaitPopup.getInstance().setVisible(false);
                    MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$
                            th.toString(), false, false, true);
                    dialogBox.center();
                }

                @Override
                public void onResponseReceived(Request arg0, Response arg1) {
                    WaitPopup.getInstance().setVisible(false);
                    if (arg1.getStatusCode() == Response.SC_OK) {
                        dirty = false;
                        // Refresh current folder or parent folder
                        PerspectiveManager.getInstance().setPerspective(PerspectiveManager.BROWSER_PERSPECTIVE);

                        GenericEvent ge = new GenericEvent();
                        ge.setEventSubType("RefreshFolderEvent");
                        ge.setStringParam(parentPath);

                        EventBusUtil.EVENT_BUS.fireEvent(ge);

                    } else {
                        MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$
                                Messages.getString("operationPermissionDenied"), false, false, true);
                        dialogBox.center();
                    }
                }
            };
        }
        requestBuilder.setCallback(requestCallback);
    }

    // start the chain
    try {
        if (!requestBuilders.isEmpty()) {
            WaitPopup.getInstance().setVisible(true);
            requestBuilders.get(0).send();
        }
    } catch (RequestException e) {
        // ignored
    }
}

From source file:org.pentaho.mantle.client.solutionbrowser.fileproperties.FilePropertiesDialog.java

License:Open Source License

/**
 * @param fileSummary/*w ww  .  ja  v a 2s.c  o  m*/
 */
protected void getAcls(RepositoryFile fileSummary) {
    String url = contextURL + "api/repo/files/" + SolutionBrowserPanel.pathToId(fileSummary.getPath()) + "/acl"; //$NON-NLS-1$ //$NON-NLS-2$
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
    // This header is required to force Internet Explorer to not cache values from the GET response.
    builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    try {
        builder.sendRequest(null, new RequestCallback() {

            public void onError(Request request, Throwable exception) {
                MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$
                        exception.getLocalizedMessage(), false, false, true);
                dialogBox.center();
            }

            public void onResponseReceived(Request request, Response response) {
                if (response.getStatusCode() == Response.SC_OK) {
                    generalTab.setAclResponse(response);
                    if (permissionsTab != null) {
                        permissionsTab.setAclResponse(response);
                    }
                } else {
                    MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$
                            Messages.getString("serverErrorColon") + " " + response.getStatusCode(), false, //$NON-NLS-1$//$NON-NLS-2$
                            false, true);
                    dialogBox.center();
                }
            }
        });
    } catch (RequestException e) {
        MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), e.getLocalizedMessage(), //$NON-NLS-1$
                false, false, true);
        dialogBox.center();
    }
}

From source file:org.pentaho.mantle.client.solutionbrowser.fileproperties.FilePropertiesDialog.java

License:Open Source License

/**
 * @param fileSummary/*  w w  w. j  a v  a  2 s  . c o m*/
 */
protected void getMetadata(RepositoryFile fileSummary) {
    String metadataUrl = contextURL + "api/repo/files/" + SolutionBrowserPanel.pathToId(fileSummary.getPath()) //$NON-NLS-1$
            + "/metadata?cb=" + System.currentTimeMillis(); //$NON-NLS-1$
    RequestBuilder metadataBuilder = new RequestBuilder(RequestBuilder.GET, metadataUrl);
    // This header is required to force Internet Explorer to not cache values from the GET response.
    metadataBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    metadataBuilder.setHeader("accept", "application/json");
    try {
        metadataBuilder.sendRequest(null, new RequestCallback() {

            public void onError(Request request, Throwable exception) {
                MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$
                        exception.getLocalizedMessage(), false, false, true);
                dialogBox.center();
            }

            public void onResponseReceived(Request request, Response response) {
                if (response.getStatusCode() == Response.SC_OK) {
                    if (response.getText() != null && !"".equals(response.getText())
                            && !response.getText().equals("null")) {
                        generalTab.setMetadataResponse(response);
                    }
                } else {
                    MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$
                            Messages.getString("serverErrorColon") + " " + response.getStatusCode(), false, //$NON-NLS-1$//$NON-NLS-2$
                            false, true);
                    dialogBox.center();
                }
            }
        });
    } catch (RequestException e) {
        MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), e.getLocalizedMessage(), //$NON-NLS-1$
                false, false, true);
        dialogBox.center();
    }
}

From source file:org.pentaho.mantle.client.solutionbrowser.fileproperties.GeneralPanel.java

License:Open Source License

@Override
public List<RequestBuilder> prepareRequests() {
    ArrayList<RequestBuilder> requestBuilders = new ArrayList<RequestBuilder>();
    String moduleBaseURL = GWT.getModuleBaseURL();
    String moduleName = GWT.getModuleName();
    String contextURL = moduleBaseURL.substring(0, moduleBaseURL.lastIndexOf(moduleName));
    String setMetadataUrl = contextURL + "api/repo/files/" //$NON-NLS-1$
            + SolutionBrowserPanel.pathToId(fileSummary.getPath()) + "/metadata?cb=" //$NON-NLS-1$
            + System.currentTimeMillis();
    RequestBuilder setMetadataBuilder = new RequestBuilder(RequestBuilder.PUT, setMetadataUrl);
    setMetadataBuilder.setHeader("Content-Type", "application/json");
    setMetadataBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");

    // prepare request data
    JSONArray arr = new JSONArray();
    JSONObject metadata = new JSONObject();
    metadata.put("stringKeyStringValueDto", arr);
    for (int i = 0; i < metadataPerms.size(); i++) {
        Set<String> keys = metadataPerms.get(i).keySet();
        for (String key : keys) {
            if (key != null && SolutionBrowserPanel.getInstance().isAdministrator()) {
                if (key.equals(org.pentaho.platform.api.repository2.unified.RepositoryFile.SCHEDULABLE_KEY)
                        && !fileSummary.isFolder()
                        || key.equals(org.pentaho.platform.api.repository2.unified.RepositoryFile.HIDDEN_KEY)) {
                    JSONObject obj = new JSONObject();
                    obj.put("key", new JSONString(key));
                    obj.put("value", metadataPerms.get(i).get(key).isString());
                    arr.set(i, obj);//  w w  w .j  av  a2s . c om
                }
            }
        }
    }
    // setMetadataBuilder.sendRequest(metadata.toString(), setMetadataCallback);
    if (arr.size() > 0) {
        setMetadataBuilder.setRequestData(metadata.toString());
        requestBuilders.add(setMetadataBuilder);
    }

    return requestBuilders;
}