List of usage examples for com.google.gwt.http.client RequestBuilder setHeader
public void setHeader(String header, String value)
From source file:org.pentaho.mantle.client.commands.ShareFileCommand.java
License:Open Source License
public void performOperation() { final SolutionFileActionEvent event = new SolutionFileActionEvent(); event.setAction(this.getClass().getName()); if (selectedList != null && selectedList.size() == 1) { final RepositoryFile item = selectedList.get(0); // Checking if the user has access to manage permissions String url = contextURL + "api/repo/files/" + SolutionBrowserPanel.pathToId(item.getPath()) //$NON-NLS-1$ + "/canAccess?permissions=" + MANAGE_ACLS; //$NON-NLS-1$ RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url); try {//ww w . j a v a2s .co m builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT"); builder.sendRequest(null, new RequestCallback() { public void onError(Request request, Throwable exception) { FilePropertiesDialog dialog = new FilePropertiesDialog(item, new PentahoTabPanel(), null, defaultTab, false); dialog.showTab(defaultTab); dialog.center(); event.setMessage(exception.getMessage()); EventBusUtil.EVENT_BUS.fireEvent(event); } public void onResponseReceived(Request request, Response response) { FilePropertiesDialog dialog = new FilePropertiesDialog(item, new PentahoTabPanel(), null, defaultTab, Boolean.parseBoolean(response.getText())); dialog.showTab(FilePropertiesDialog.Tabs.PERMISSION); dialog.center(); event.setMessage("Success"); EventBusUtil.EVENT_BUS.fireEvent(event); } }); } catch (RequestException e) { FilePropertiesDialog dialog = new FilePropertiesDialog(item, new PentahoTabPanel(), null, defaultTab, false); dialog.showTab(FilePropertiesDialog.Tabs.PERMISSION); dialog.center(); event.setMessage(e.getMessage()); EventBusUtil.EVENT_BUS.fireEvent(event); } } }
From source file:org.pentaho.mantle.client.commands.ShowBrowserCommand.java
License:Open Source License
public void execute() { final SolutionBrowserPanel solutionBrowserPerspective = SolutionBrowserPanel.getInstance(); solutionBrowserPerspective.setNavigatorShowing(state); if (solutionBrowserPerspective != null) { if (PerspectiveManager.getInstance().getActivePerspective().getId() .equalsIgnoreCase(PerspectiveManager.OPENED_PERSPECTIVE)) { PerspectiveManager.getInstance().setPerspective(PerspectiveManager.OPENED_PERSPECTIVE); }//from w ww .j a v a 2 s .com } final String url = GWT.getHostPageBaseURL() + "api/user-settings/MANTLE_SHOW_NAVIGATOR"; //$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("" + state, EmptyRequestCallback.getInstance()); } catch (RequestException e) { // showError(e); } }
From source file:org.pentaho.mantle.client.commands.SwitchLocaleCommand.java
License:Open Source License
protected void performOperation(boolean feedback) { // stuff the locale in the server's session so we can use it // to override the browser setting, as needed final String url = GWT.getHostPageBaseURL() + "api/mantle/locale"; //$NON-NLS-1$ RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url); try {//from w w w. ja v a 2 s.c o m builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT"); 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); } String newLocalePath = "Home?locale=" + locale; String baseUrl = GWT.getModuleBaseURL(); int index = baseUrl.indexOf("/mantle/"); if (index >= 0) { newLocalePath = baseUrl.substring(0, index) + "/Home?locale=" + locale; } Window.Location.replace(newLocalePath); }
From source file:org.pentaho.mantle.client.commands.SwitchThemeCommand.java
License:Open Source License
protected void performOperation(boolean feedback) { final HTML messageTextBox = new HTML(Messages.getString("confirmSwitchTheme.message")); final PromptDialogBox fileMoveToTrashWarningDialogBox = new PromptDialogBox( Messages.getString("confirmSwitchTheme.title"), Messages.getString("confirmSwitchTheme.ok"), Messages.getString("confirmSwitchTheme.cancel"), true, true); fileMoveToTrashWarningDialogBox.setContent(messageTextBox); final IDialogCallback callback = new IDialogCallback() { public void cancelPressed() { }/* w ww. j a v a2s.c o m*/ public void okPressed() { final String url = GWT.getHostPageBaseURL() + "api/theme/set"; //$NON-NLS-1$ RequestBuilder setThemeRequestBuilder = new RequestBuilder(RequestBuilder.POST, url); setThemeRequestBuilder.setHeader("accept", "text/plain"); setThemeRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT"); try { setThemeRequestBuilder.sendRequest(theme, new RequestCallback() { public void onError(Request request, Throwable exception) { // showError(exception); } public void onResponseReceived(Request request, Response response) { // forcing a setTimeout to fix a problem in IE BISERVER-6385 Scheduler.get().scheduleDeferred(new Command() { public void execute() { Window.Location.reload(); } }); } }); } catch (RequestException e) { Window.alert(e.getMessage()); // showError(e); } } }; fileMoveToTrashWarningDialogBox.setCallback(callback); fileMoveToTrashWarningDialogBox.center(); }
From source file:org.pentaho.mantle.client.dialogs.folderchooser.FolderTree.java
License:Open Source License
public void fetchRepositoryFileTree(final AsyncCallback<RepositoryFileTree> callback, Integer depth, String filter, Boolean showHidden) { // notify listeners that we are about to talk to the server (in case there's anything they want to do // such as busy cursor or tree loading indicators) beforeFetchRepositoryFileTree();/*from w w w . j a va 2s . c o m*/ RequestBuilder builder = null; String url = ScheduleHelper.getFullyQualifiedURL() + "api/repo/files/:/tree?"; //$NON-NLS-1$ if (depth == null) { depth = -1; } if (filter == null) { filter = "*"; //$NON-NLS-1$ } if (showHidden == null) { showHidden = Boolean.FALSE; } url = url + "depth=" + depth + "&filter=" + filter + "&showHidden=" + showHidden + "&ts=" //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ + System.currentTimeMillis(); builder = new RequestBuilder(RequestBuilder.GET, url); builder.setHeader("Accept", "application/json"); builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT"); RequestCallback innerCallback = new RequestCallback() { public void onError(Request request, Throwable exception) { Window.alert(exception.toString()); } public void onResponseReceived(Request request, Response response) { if (response.getStatusCode() == Response.SC_OK) { String json = response.getText(); System.out.println(json); final JsonToRepositoryFileTreeConverter converter = new JsonToRepositoryFileTreeConverter( response.getText()); final RepositoryFileTree fileTree = converter.getTree(); String deletedFilesUrl = ScheduleHelper.getFullyQualifiedURL() + "api/repo/files/deleted?ts=" + System.currentTimeMillis(); RequestBuilder deletedFilesRequestBuilder = new RequestBuilder(RequestBuilder.GET, deletedFilesUrl); deletedFilesRequestBuilder.setHeader("Accept", "application/json"); deletedFilesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT"); try { deletedFilesRequestBuilder.sendRequest(null, new RequestCallback() { public void onError(Request request, Throwable exception) { onFetchRepositoryFileTree(fileTree, Collections.<RepositoryFile>emptyList()); Window.alert(exception.toString()); } public void onResponseReceived(Request delRequest, Response delResponse) { if (delResponse.getStatusCode() == Response.SC_OK) { try { trashItems = JsonToRepositoryFileTreeConverter .getTrashFiles(delResponse.getText()); } catch (Throwable t) { // apparently this happens when you have no trash } onFetchRepositoryFileTree(fileTree, Collections.<RepositoryFile>emptyList()); } else { onFetchRepositoryFileTree(fileTree, Collections.<RepositoryFile>emptyList()); } if (callback != null) { callback.onSuccess(fileTree); } } }); } catch (Exception e) { onFetchRepositoryFileTree(fileTree, Collections.<RepositoryFile>emptyList()); } } else { /*fileTree = new RepositoryFileTree(); RepositoryFile errorFile = new RepositoryFile(); errorFile.setFolder( true ); errorFile.setName( "!ERROR!" ); repositoryFileTree.setFile( errorFile );*/ } } }; try { builder.sendRequest(null, innerCallback); } catch (RequestException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.pentaho.mantle.client.dialogs.folderchooser.NewFolderCommand.java
License:Open Source License
protected void performOperation(boolean feedback) { final TextBox folderNameTextBox = new TextBox(); folderNameTextBox.setTabIndex(1);/*from w ww . ja v a 2 s. c om*/ folderNameTextBox.setVisibleLength(40); VerticalPanel vp = new VerticalPanel(); vp.add(new Label(Messages.getString("newFolderName"))); //$NON-NLS-1$ vp.add(folderNameTextBox); final PromptDialogBox newFolderDialog = new PromptDialogBox(Messages.getString("newFolder"), //$NON-NLS-1$ Messages.getString("ok"), Messages.getString("cancel"), false, true, vp); //$NON-NLS-1$ //$NON-NLS-2$ newFolderDialog.setFocusWidget(folderNameTextBox); folderNameTextBox.setFocus(true); final IDialogCallback callback = new IDialogCallback() { public void cancelPressed() { newFolderDialog.hide(); } public void okPressed() { if (!NameUtils.isValidFolderName(folderNameTextBox.getText())) { //event.setMessage( Messages.getString( "containsIllegalCharacters", folderNameTextBox.getText() ) ); //EventBusUtil.EVENT_BUS.fireEvent( event ); MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$ Messages.getString("containsIllegalCharacters", folderNameTextBox.getText()), //$NON-NLS-1$ false, false, true); dialogBox.center(); return; } solutionPath = parentFolder.getPath() + "/" + URL.encodePathSegment(folderNameTextBox.getText()); String createDirUrl = contextURL + "api/repo/dirs/" + pathToId(solutionPath); //$NON-NLS-1$ RequestBuilder createDirRequestBuilder = new RequestBuilder(RequestBuilder.PUT, createDirUrl); try { createDirRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT"); createDirRequestBuilder.sendRequest("", new RequestCallback() { @Override public void onError(Request createFolderRequest, Throwable exception) { MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$ Messages.getString("couldNotCreateFolder", folderNameTextBox.getText()), //$NON-NLS-1$ false, false, true); dialogBox.center(); //event.setMessage( Messages.getString( "couldNotCreateFolder", folderNameTextBox.getText() ) ); //EventBusUtil.EVENT_BUS.fireEvent( event ); } @Override public void onResponseReceived(Request createFolderRequest, Response createFolderResponse) { if (createFolderResponse.getStatusText().equalsIgnoreCase("OK")) { //$NON-NLS-1$ NewFolderCommand.this.callback.onHandle(solutionPath); //new RefreshRepositoryCommand().execute( false ); //event.setMessage( "Success" ); FileChooserDialog.setIsDirty(Boolean.TRUE); setBrowseRepoDirty(Boolean.TRUE); //EventBusUtil.EVENT_BUS.fireEvent( event ); } else { String errorMessage = StringUtils.isEmpty(createFolderResponse.getText()) || Messages.getString(createFolderResponse.getText()) == null ? Messages.getString("couldNotCreateFolder", //$NON-NLS-1$ folderNameTextBox.getText()) : Messages.getString(createFolderResponse.getText(), folderNameTextBox.getText()); MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$ errorMessage, //$NON-NLS-2$ false, false, true); dialogBox.center(); /*event.setMessage( StringUtils.isEmpty( createFolderResponse.getText() ) || Messages.getString( createFolderResponse.getText() ) == null ? Messages.getString( "couldNotCreateFolder", folderNameTextBox.getText() ) //$NON-NLS-1$ : Messages.getString( createFolderResponse.getText(), folderNameTextBox.getText() ) ); EventBusUtil.EVENT_BUS.fireEvent( event ); */ } } }); } catch (RequestException e) { Window.alert(e.getLocalizedMessage()); /*event.setMessage( e.getLocalizedMessage() ); EventBusUtil.EVENT_BUS.fireEvent( event );*/ } } }; newFolderDialog.setCallback(callback); newFolderDialog.center(); }
From source file:org.pentaho.mantle.client.dialogs.scheduling.NewScheduleDialog.java
License:Open Source License
protected void onOk() { String name = scheduleNameTextBox.getText(); if (!NameUtils.isValidFileName(name)) { MessageDialogBox errorDialog = new MessageDialogBox(Messages.getString("error"), Messages.getString("prohibitedNameSymbols", name, NameUtils.reservedCharListForDisplay(" ")), //$NON-NLS-2$ false, false, true); //$NON-NLS-2$ errorDialog.center();/*ww w . j a v a 2 s . c o m*/ return; } // check if has parameterizable WaitPopup.getInstance().setVisible(true); String urlPath = URL.encodePathSegment(NameUtils.encodeRepositoryPath(filePath)); RequestBuilder scheduleFileRequestBuilder; final boolean isXAction; if ((urlPath != null) && (urlPath.endsWith("xaction"))) { isXAction = true; scheduleFileRequestBuilder = new RequestBuilder(RequestBuilder.GET, ScheduleHelper.getFullyQualifiedURL() + "api/repos/" + urlPath + "/parameterUi"); } else { isXAction = false; scheduleFileRequestBuilder = new RequestBuilder(RequestBuilder.GET, ScheduleHelper.getFullyQualifiedURL() + "api/repo/files/" + urlPath + "/parameterizable"); } scheduleFileRequestBuilder.setHeader("accept", "text/plain"); scheduleFileRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT"); try { scheduleFileRequestBuilder.sendRequest(null, new RequestCallback() { public void onError(Request request, Throwable exception) { WaitPopup.getInstance().setVisible(false); MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$ exception.toString(), false, false, true); dialogBox.center(); } public void onResponseReceived(Request request, Response response) { WaitPopup.getInstance().setVisible(false); if (response.getStatusCode() == Response.SC_OK) { String responseMessage = response.getText(); boolean hasParams; if (isXAction) { int numOfInputs = StringUtils.countMatches(responseMessage, "<input"); int NumOfHiddenInputs = StringUtils.countMatches(responseMessage, "type=\"hidden\""); hasParams = numOfInputs - NumOfHiddenInputs > 0 ? true : false; } else { hasParams = Boolean.parseBoolean(response.getText()); } if (jsJob != null) { jsJob.setJobName(scheduleNameTextBox.getText()); jsJob.setOutputPath(scheduleLocationTextBox.getText(), scheduleNameTextBox.getText()); if (recurrenceDialog == null) { recurrenceDialog = new ScheduleRecurrenceDialog(NewScheduleDialog.this, jsJob, callback, hasParams, isEmailConfValid, ScheduleDialogType.SCHEDULER); } } else if (recurrenceDialog == null) { recurrenceDialog = new ScheduleRecurrenceDialog(NewScheduleDialog.this, filePath, scheduleLocationTextBox.getText(), scheduleNameTextBox.getText(), callback, hasParams, isEmailConfValid); } else { recurrenceDialog.scheduleName = scheduleNameTextBox.getText(); recurrenceDialog.outputLocation = scheduleLocationTextBox.getText(); } recurrenceDialog.setParentDialog(NewScheduleDialog.this); recurrenceDialog.center(); NewScheduleDialog.super.onOk(); } } }); } catch (RequestException e) { WaitPopup.getInstance().setVisible(false); // showError(e); } }
From source file:org.pentaho.mantle.client.dialogs.scheduling.OutputLocationUtils.java
License:Open Source License
public static void validateOutputLocation(final String outputLocation, final Command successCallback, final Command errorCallback) { if (StringUtils.isEmpty(outputLocation)) { return;/*w w w. j av a 2 s . c o m*/ } final String outputLocationPath = NameUtils.encodeRepositoryPath(outputLocation); final String url = ScheduleHelper.getFullyQualifiedURL() + "api/repo/files/" + outputLocationPath //$NON-NLS-1$ + "/tree?depth=1"; 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) { if (errorCallback != null) { errorCallback.execute(); } } public void onResponseReceived(Request request, Response response) { if (response.getStatusCode() == Response.SC_OK) { if (successCallback != null) { successCallback.execute(); } } else { if (errorCallback != null) { errorCallback.execute(); } } } }); } catch (RequestException e) { if (errorCallback != null) { errorCallback.execute(); } } }
From source file:org.pentaho.mantle.client.dialogs.scheduling.ScheduleEditor.java
License:Open Source License
private void populateTimeZonePicker() { String url = ScheduleHelper.getFullyQualifiedURL() + "api/system/timezones"; //$NON-NLS-1$ RequestBuilder timeZonesRequest = new RequestBuilder(RequestBuilder.GET, url); timeZonesRequest.setHeader("accept", "application/json"); //$NON-NLS-1$ //$NON-NLS-2$ timeZonesRequest.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT"); try {/*from www. j a va 2 s .c o m*/ timeZonesRequest.sendRequest(null, new RequestCallback() { @Override public void onResponseReceived(Request request, Response response) { timeZonePicker.clear(); String responseText = response.getText(); JSONValue value = JSONParser.parseLenient(responseText); JSONObject object = value.isObject(); value = object.get("timeZones"); JSONValue serverTZvalue = object.get("serverTzId"); JSONString serverTZIdString = serverTZvalue.isString(); String serverTZId = serverTZIdString.stringValue(); object = value.isObject(); value = object.get("entry"); JSONArray timeZonesJSONArray = value.isArray(); for (int i = 0; i < timeZonesJSONArray.size(); i++) { JSONValue entryValue = timeZonesJSONArray.get(i); JSONObject entryObject = entryValue.isObject(); JSONValue keyValue = entryObject.get("key"); JSONValue theValue = entryObject.get("value"); String key = keyValue.isString().stringValue(); String valueForKey = theValue.isString().stringValue(); timeZonePicker.addItem(valueForKey, key); } for (int i = 0; i < timeZonePicker.getItemCount(); i++) { if (timeZonePicker.getValue(i).equalsIgnoreCase(serverTZId)) { timeZonePicker.setSelectedIndex(i); break; } } } @Override public void onError(Request request, Throwable exception) { // TODO Auto-generated method stub } }); } catch (RequestException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.pentaho.mantle.client.dialogs.scheduling.ScheduleHelper.java
License:Open Source License
public static void showScheduleDialog(final String fileNameWithPath, final IDialogCallback callback) { final SolutionFileActionEvent event = new SolutionFileActionEvent(); event.setAction(ScheduleHelper.class.getName()); try {/*from w w w . ja va 2 s . c om*/ final String url = ScheduleHelper.getFullyQualifiedURL() + "api/mantle/isAuthenticated"; //$NON-NLS-1$ RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url); requestBuilder.setHeader("accept", "text/plain"); requestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT"); requestBuilder.sendRequest(null, new RequestCallback() { public void onError(Request request, Throwable caught) { MantleLoginDialog.performLogin(new AsyncCallback<Boolean>() { public void onFailure(Throwable caught) { } public void onSuccess(Boolean result) { showScheduleDialog(fileNameWithPath, callback); } }); } public void onResponseReceived(Request request, Response response) { String moduleBaseURL = GWT.getModuleBaseURL(); String moduleName = GWT.getModuleName(); final String contextURL = moduleBaseURL.substring(0, moduleBaseURL.lastIndexOf(moduleName)); RequestBuilder emailValidRequest = new RequestBuilder(RequestBuilder.GET, contextURL + "api/emailconfig/isValid"); emailValidRequest.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT"); emailValidRequest.setHeader("accept", "text/plain"); try { emailValidRequest.sendRequest(null, new RequestCallback() { public void onError(Request request, Throwable exception) { MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$ exception.toString(), false, false, true); dialogBox.center(); event.setMessage(exception.getLocalizedMessage()); EventBusUtil.EVENT_BUS.fireEvent(event); } public void onResponseReceived(Request request, Response response) { if (response.getStatusCode() == Response.SC_OK) { final boolean isEmailConfValid = Boolean.parseBoolean(response.getText()); NewScheduleDialog dialog = new NewScheduleDialog(fileNameWithPath, callback, isEmailConfValid); dialog.center(); event.setMessage("Open"); EventBusUtil.EVENT_BUS.fireEvent(event); } } }); } catch (RequestException e) { MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), e.toString(), //$NON-NLS-1$ false, false, true); dialogBox.center(); event.setMessage(e.getLocalizedMessage()); EventBusUtil.EVENT_BUS.fireEvent(event); } } }); } catch (RequestException e) { Window.alert(e.getMessage()); event.setMessage(e.getLocalizedMessage()); EventBusUtil.EVENT_BUS.fireEvent(event); } }