List of usage examples for com.google.gwt.http.client RequestBuilder POST
Method POST
To view the source code for com.google.gwt.http.client RequestBuilder POST.
Click Source Link
From source file:org.pentaho.mantle.client.commands.RunInBackgroundCommand.java
License:Open Source License
protected void performOperation(boolean feedback) { final String filePath = (this.getSolutionPath() != null) ? this.getSolutionPath() : repositoryFile.getPath();/*from www . jav a2 s.co m*/ String urlPath = NameUtils.URLEncode(NameUtils.encodeRepositoryPath(filePath)); RequestBuilder scheduleFileRequestBuilder = createParametersChecker(urlPath); final boolean isXAction = isXAction(urlPath); try { scheduleFileRequestBuilder.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(); } public void onResponseReceived(Request request, Response response) { if (response.getStatusCode() == Response.SC_OK) { final JSONObject scheduleRequest = new JSONObject(); scheduleRequest.put("inputFile", new JSONString(filePath)); //$NON-NLS-1$ // Set job name if (StringUtils.isEmpty(getOutputName())) { scheduleRequest.put("jobName", JSONNull.getInstance()); //$NON-NLS-1$ } else { scheduleRequest.put("jobName", new JSONString(getOutputName())); //$NON-NLS-1$ } // Set output path location if (StringUtils.isEmpty(getOutputLocationPath())) { scheduleRequest.put("outputFile", JSONNull.getInstance()); //$NON-NLS-1$ } else { scheduleRequest.put("outputFile", new JSONString(getOutputLocationPath())); //$NON-NLS-1$ } // BISERVER-9321 scheduleRequest.put("runInBackground", JSONBoolean.getInstance(true)); String responseMessage = response.getText(); final boolean hasParams = hasParameters(responseMessage, isXAction); RequestBuilder emailValidRequest = new RequestBuilder(RequestBuilder.GET, contextURL + "api/emailconfig/isValid"); //$NON-NLS-1$ emailValidRequest.setHeader("accept", "text/plain"); //$NON-NLS-1$ //$NON-NLS-2$ emailValidRequest.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT"); 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(); } public void onResponseReceived(Request request, Response response) { if (response.getStatusCode() == Response.SC_OK) { // final boolean isEmailConfValid = Boolean.parseBoolean(response.getText()); // force false for now, I have a feeling PM is going to want this, making it easy to turn back // on final boolean isEmailConfValid = false; if (hasParams) { ScheduleParamsDialog dialog = new ScheduleParamsDialog(filePath, scheduleRequest, isEmailConfValid); dialog.center(); dialog.setAfterResponseCallback(scheduleParamsDialogCallback); } else if (isEmailConfValid) { ScheduleEmailDialog scheduleEmailDialog = new ScheduleEmailDialog(null, filePath, scheduleRequest, null, null); scheduleEmailDialog.center(); } else { // just run it RequestBuilder scheduleFileRequestBuilder = new RequestBuilder( RequestBuilder.POST, contextURL + "api/scheduler/job"); //$NON-NLS-1$ scheduleFileRequestBuilder.setHeader("Content-Type", //$NON-NLS-1$ "application/json"); //$NON-NLS-1$ scheduleFileRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT"); try { scheduleFileRequestBuilder.sendRequest(scheduleRequest.toString(), new RequestCallback() { @Override public void onError(Request request, Throwable exception) { MessageDialogBox dialogBox = new MessageDialogBox( Messages.getString("error"), //$NON-NLS-1$ exception.toString(), false, false, true); dialogBox.center(); } @Override public void onResponseReceived(Request request, Response response) { if (response.getStatusCode() == 200) { MessageDialogBox dialogBox = new MessageDialogBox( Messages.getString("runInBackground"), //$NON-NLS-1$ Messages.getString( "backgroundExecutionStarted"), //$NON-NLS-1$ false, false, true); dialogBox.center(); } else { MessageDialogBox dialogBox = new MessageDialogBox( Messages.getString("error"), //$NON-NLS-1$ Messages.getString("serverErrorColon") //$NON-NLS-1$ + " " //$NON-NLS-1$ + response.getStatusCode(), false, false, true); dialogBox.center(); } } }); } catch (RequestException e) { MessageDialogBox dialogBox = new MessageDialogBox( Messages.getString("error"), e.toString(), //$NON-NLS-1$ false, false, true); dialogBox.center(); } } } } }); } catch (RequestException e) { MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$ e.toString(), false, false, true); dialogBox.center(); } } 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.toString(), false, //$NON-NLS-1$ false, true); dialogBox.center(); } }
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 w w.j av a 2 s . c om } 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 {// w w w . j a 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() { }// ww w. j a va2 s . 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.scheduling.ScheduleHelper.java
License:Open Source License
public static RequestBuilder buildRequestForJob(JsJob editJob, JSONObject requestPayload) { RequestBuilder scheduleFileRequestBuilder = null; if (editJob == null || editJob.getJobId() == null) { scheduleFileRequestBuilder = new RequestBuilder(RequestBuilder.POST, getFullyQualifiedURL() + JOB_SCHEDULER_URL); } else {/*from www. ja v a 2s . c o m*/ scheduleFileRequestBuilder = new RequestBuilder(RequestBuilder.POST, getFullyQualifiedURL() + UPDATE_JOB_SCHEDULER_URL); if (null != requestPayload) { requestPayload.put("jobId", new JSONString(editJob.getJobId())); } } scheduleFileRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT"); scheduleFileRequestBuilder.setHeader("Content-Type", "application/json"); //$NON-NLS-1$//$NON-NLS-2$ return scheduleFileRequestBuilder; }
From source file:org.pentaho.mantle.client.dialogs.scheduling.ScheduleOutputLocationDialogExecutor.java
License:Open Source License
protected void performOperation(boolean feedback) { final String filePath = reportFile; String urlPath = NameUtils.URLEncode(NameUtils.encodeRepositoryPath(filePath)); RequestBuilder scheduleFileRequestBuilder = createParametersChecker(urlPath); final boolean isXAction = isXAction(urlPath); try {//from w ww . ja v a 2 s . c o m scheduleFileRequestBuilder.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(); } public void onResponseReceived(Request request, Response response) { if (response.getStatusCode() == Response.SC_OK) { final JSONObject scheduleRequest = new JSONObject(); scheduleRequest.put("inputFile", new JSONString(filePath)); //$NON-NLS-1$ // Set job name if (StringUtils.isEmpty(getOutputName())) { scheduleRequest.put("jobName", JSONNull.getInstance()); //$NON-NLS-1$ } else { scheduleRequest.put("jobName", new JSONString(getOutputName())); //$NON-NLS-1$ } // Set output path location if (StringUtils.isEmpty(getOutputLocationPath())) { scheduleRequest.put("outputFile", JSONNull.getInstance()); //$NON-NLS-1$ } else { scheduleRequest.put("outputFile", new JSONString(getOutputLocationPath())); //$NON-NLS-1$ } // BISERVER-9321 scheduleRequest.put("runInBackground", JSONBoolean.getInstance(true)); String responseMessage = response.getText(); final boolean hasParams = hasParameters(responseMessage, isXAction); RequestBuilder emailValidRequest = new RequestBuilder(RequestBuilder.GET, ScheduleHelper.getFullyQualifiedURL() + "api/emailconfig/isValid"); //$NON-NLS-1$ emailValidRequest.setHeader("accept", "text/plain"); //$NON-NLS-1$ //$NON-NLS-2$ emailValidRequest.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT"); 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(); } public void onResponseReceived(Request request, Response response) { if (response.getStatusCode() == Response.SC_OK) { // final boolean isEmailConfValid = Boolean.parseBoolean(response.getText()); // force false for now, I have a feeling PM is going to want this, making it easy to turn back // on final boolean isEmailConfValid = false; if (hasParams) { ScheduleParamsDialog dialog = new ScheduleParamsDialog(filePath, scheduleRequest, isEmailConfValid); dialog.center(); dialog.setAfterResponseCallback(scheduleParamsDialogCallback); } else if (isEmailConfValid) { ScheduleEmailDialog scheduleEmailDialog = new ScheduleEmailDialog(null, filePath, scheduleRequest, null, null); scheduleEmailDialog.center(); } else { // just run it RequestBuilder scheduleFileRequestBuilder = new RequestBuilder( RequestBuilder.POST, ScheduleHelper.getFullyQualifiedURL() + "api/scheduler/job"); //$NON-NLS-1$ scheduleFileRequestBuilder.setHeader("Content-Type", //$NON-NLS-1$ "application/json"); //$NON-NLS-1$ scheduleFileRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT"); try { scheduleFileRequestBuilder.sendRequest(scheduleRequest.toString(), new RequestCallback() { @Override public void onError(Request request, Throwable exception) { MessageDialogBox dialogBox = new MessageDialogBox( Messages.getString("error"), //$NON-NLS-1$ exception.toString(), false, false, true); dialogBox.center(); } @Override public void onResponseReceived(Request request, Response response) { if (response.getStatusCode() == 200) { MessageDialogBox dialogBox = new MessageDialogBox( Messages.getString("runInBackground"), //$NON-NLS-1$ Messages.getString( "backgroundExecutionStarted"), //$NON-NLS-1$ false, false, true); dialogBox.center(); } else { MessageDialogBox dialogBox = new MessageDialogBox( Messages.getString("error"), //$NON-NLS-1$ Messages.getString("serverErrorColon") //$NON-NLS-1$ + " " //$NON-NLS-1$ + response.getStatusCode(), false, false, true); dialogBox.center(); } } }); } catch (RequestException e) { MessageDialogBox dialogBox = new MessageDialogBox( Messages.getString("error"), e.toString(), //$NON-NLS-1$ false, false, true); dialogBox.center(); } } } } }); } catch (RequestException e) { MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$ e.toString(), false, false, true); dialogBox.center(); } } 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.toString(), false, //$NON-NLS-1$ false, true); dialogBox.center(); } }
From source file:org.pentaho.mantle.client.dialogs.scheduling.ScheduleRecurrenceDialog.java
License:Open Source License
protected boolean addBlockoutPeriod(final JSONObject schedule, final JsJobTrigger trigger, String urlSuffix) { String url = ScheduleHelper.getFullyQualifiedURL() + "api/scheduler/blockout/" + urlSuffix; //$NON-NLS-1$ RequestBuilder addBlockoutPeriodRequest = new RequestBuilder(RequestBuilder.POST, url); addBlockoutPeriodRequest.setHeader("accept", "text/plain"); //$NON-NLS-1$ //$NON-NLS-2$ addBlockoutPeriodRequest.setHeader("Content-Type", "application/json"); //$NON-NLS-1$ //$NON-NLS-2$ addBlockoutPeriodRequest.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT"); // Create a unique blockout period name final Long duration = trigger.getBlockDuration(); final String blockoutPeriodName = trigger.getScheduleType() + Random.nextInt() + ":" + //$NON-NLS-1$ /* PentahoSessionHolder.getSession().getName() */"admin" + ":" + duration; //$NON-NLS-1$ //$NON-NLS-2$ // Add blockout specific parameters JSONObject addBlockoutParams = schedule; addBlockoutParams.put("jobName", new JSONString(blockoutPeriodName)); //$NON-NLS-1$ addBlockoutParams.put("duration", new JSONNumber(duration)); //$NON-NLS-1$ addBlockoutParams.put("timeZone", new JSONString(scheduleEditorWizardPanel.getTimeZone())); try {/*from w w w . j ava2 s . co m*/ addBlockoutPeriodRequest.sendRequest(addBlockoutParams.toString(), new RequestCallback() { @Override public void onError(Request request, Throwable exception) { MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$ exception.toString(), false, false, true); dialogBox.center(); setDone(false); } @Override public void onResponseReceived(Request request, Response response) { if (response.getStatusCode() == Response.SC_OK) { if (null != callback) { callback.okPressed(); } } } }); } catch (RequestException e) { // ignored } return true; }
From source file:org.pentaho.mantle.client.dialogs.scheduling.ScheduleRecurrenceDialog.java
License:Open Source License
/** * Before creating a new schedule, we want to check to see if the schedule that is being created is going to conflict * with any one of the blockout periods if one is provisioned. * * @param schedule/*from w w w.jav a 2s . co m*/ * @param trigger */ protected void verifyBlockoutConflict(final JSONObject schedule, final JsJobTrigger trigger) { String url = ScheduleHelper.getFullyQualifiedURL() + "api/scheduler/blockout/blockstatus"; //$NON-NLS-1$ RequestBuilder blockoutConflictRequest = new RequestBuilder(RequestBuilder.POST, url); blockoutConflictRequest.setHeader("accept", "application/json"); //$NON-NLS-1$ //$NON-NLS-2$ blockoutConflictRequest.setHeader("Content-Type", "application/json"); //$NON-NLS-1$ //$NON-NLS-2$ blockoutConflictRequest.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT"); final JSONObject verifyBlockoutParams = schedule; verifyBlockoutParams.put("jobName", new JSONString(scheduleName)); //$NON-NLS-1$ try { blockoutConflictRequest.sendRequest(verifyBlockoutParams.toString(), new RequestCallback() { @Override public void onError(Request request, Throwable exception) { MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$ exception.toString(), false, false, true); dialogBox.center(); setDone(false); } @Override public void onResponseReceived(Request request, Response response) { if (response.getStatusCode() == Response.SC_OK) { JsBlockStatus statusResponse = (JsBlockStatus) parseJson( JsonUtils.escapeJsonForEval(response.getText())); // Determine if this schedule conflicts all the time or some of the time boolean partiallyBlocked = Boolean.parseBoolean(statusResponse.getPartiallyBlocked()); boolean totallyBlocked = Boolean.parseBoolean(statusResponse.getTotallyBlocked()); if (partiallyBlocked || totallyBlocked) { promptDueToBlockoutConflicts(totallyBlocked, partiallyBlocked, schedule, trigger); } else { // Continue with other panels in the wizard (params, email) handleWizardPanels(schedule, trigger); } } else { handleWizardPanels(schedule, trigger); } } }); } catch (RequestException e) { // ignored } super.nextClicked(); }
From source file:org.pentaho.mantle.client.MantleEntryPoint.java
License:Open Source License
/** * This is the entry point method./*from w ww . ja v a 2s. co m*/ */ 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 w w w . ja va2 s .c om*/ * @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); } }