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.ScheduleHelper.java

License:Open Source License

public static void createSchedule(final RepositoryFile repositoryFile, final IDialogCallback callback) {
    AbstractCommand scheduleCommand = new AbstractCommand() {

        protected void performOperation() {

            // hit the server and check: isScheduleAllowed
            final String url = ScheduleHelper.getFullyQualifiedURL() + "api/scheduler/isScheduleAllowed?id=" //$NON-NLS-1$
                    + repositoryFile.getId();
            RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url);
            requestBuilder.setHeader("accept", "text/plain");
            requestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
            final MessageDialogBox errorDialog = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$
                    Messages.getString("noSchedulePermission"), false, false, true); //$NON-NLS-1$
            try {
                requestBuilder.sendRequest(null, new RequestCallback() {

                    public void onError(Request request, Throwable caught) {
                        errorDialog.center();
                    }/*from w ww  .  ja va  2s. co  m*/

                    public void onResponseReceived(Request request, Response response) {
                        if ("true".equalsIgnoreCase(response.getText())) {
                            callback.okPressed();
                        } else {
                            errorDialog.center();
                        }
                    }
                });
            } catch (RequestException re) {
                errorDialog.center();
            }

        }

        protected void performOperation(boolean feedback) {
            performOperation();
        }

    };
    scheduleCommand.execute();

}

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

License:Open Source License

/**
 * The passed in URL has all the parameters set for background execution. We simply call GET on the URL and
 * handle the response object. If the response object contains a particular string then we display success
 * message box./*from   ww w.j av a2s  .  co m*/
 *
 * @param url
 *          Complete url with all the parameters set for scheduling a job in the background.
 */
private static void runInBackground(final String url) {

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

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

            public void onResponseReceived(Request request, Response response) {
                /*
                 * We are checking for this specific string because if the job was scheduled successfully by
                 * QuartzBackgroundExecutionHelper then the response is an html that contains the specific string. We
                 * have coded this way because we did not want to touch the old way.
                 */
                if ("true".equals(response.getHeader("background_execution"))) {
                    MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("info"), //$NON-NLS-1$
                            Messages.getString("backgroundJobScheduled"), false, false, true); //$NON-NLS-1$
                    dialogBox.center();
                }
            }
        });
    } catch (RequestException e) {
        MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$
                Messages.getString("couldNotBackgroundExecute"), false, false, true); //$NON-NLS-1$
        dialogBox.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 w w w.  j  ava2  s  .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

private RequestBuilder createParametersChecker(String urlPath) {
    RequestBuilder scheduleFileRequestBuilder = null;
    if ((urlPath != null) && (urlPath.endsWith("xaction"))) {
        scheduleFileRequestBuilder = new RequestBuilder(RequestBuilder.GET,
                ScheduleHelper.getFullyQualifiedURL() + "api/repos/" + urlPath + "/parameterUi");
    } else {/*from ww  w .ja  v  a2 s.co  m*/
        scheduleFileRequestBuilder = new RequestBuilder(RequestBuilder.GET,
                ScheduleHelper.getFullyQualifiedURL() + "api/repo/files/" + urlPath + "/parameterizable");
    }
    scheduleFileRequestBuilder.setHeader("accept", "text/plain"); //$NON-NLS-1$ //$NON-NLS-2$
    scheduleFileRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    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 w  w. jav  a2s .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.ScheduleParamsDialog.java

License:Open Source License

private void showScheduleEmailDialog(final JSONArray scheduleParams) {

    try {/*from  w ww.  j  a  v  a 2 s .c  o m*/
        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() {

            @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) {
                        showScheduleEmailDialog(scheduleParams);
                    }
                });
            }

            @Override
            public void onResponseReceived(Request request, Response response) {
                if (scheduleEmailDialog == null) {
                    scheduleEmailDialog = new ScheduleEmailDialog(ScheduleParamsDialog.this, filePath,
                            jobSchedule, scheduleParams, editJob);
                    scheduleEmailDialog.setCallback(callback);
                } else {
                    scheduleEmailDialog.setScheduleParams(scheduleParams);
                    scheduleEmailDialog.setJobSchedule(jobSchedule);
                }
                scheduleEmailDialog.center();
                hide();
            }

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

}

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

License:Open Source License

private void constructDialog(String filePath, String outputLocation, String scheduleName, boolean hasParams,
        boolean isEmailConfValid, JsJob jsJob) {
    this.hasParams = hasParams;
    this.filePath = filePath;
    this.isEmailConfValid = isEmailConfValid;
    this.outputLocation = outputLocation;
    this.scheduleName = scheduleName;
    scheduleEditorWizardPanel = new ScheduleEditorWizardPanel(getDialogType());
    scheduleEditor = scheduleEditorWizardPanel.getScheduleEditor();
    String url = ScheduleHelper.getFullyQualifiedURL() + "api/scheduler/blockout/hasblockouts?ts=" //$NON-NLS-1$
            + System.currentTimeMillis();
    RequestBuilder hasBlockoutsRequest = new RequestBuilder(RequestBuilder.GET, url);
    hasBlockoutsRequest.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    hasBlockoutsRequest.setHeader("accept", "text/plain");
    try {//from ww w  . ja  v  a  2s.  c o m
        hasBlockoutsRequest.sendRequest(url, 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) {
                Boolean hasBlockouts = Boolean.valueOf(response.getText());
                if (hasBlockouts) {
                    scheduleEditor.setBlockoutButtonHandler(new ClickHandler() {
                        @Override
                        public void onClick(final ClickEvent clickEvent) {
                            PromptDialogBox box = new PromptDialogBox(Messages.getString("blockoutTimes"),
                                    Messages.getString("close"), null, null, false, true,
                                    new BlockoutPanel(false));
                            box.center();
                        }
                    });
                }
                scheduleEditor.getBlockoutCheckButton().setVisible(hasBlockouts);
            }
        });
    } catch (RequestException e) {
        MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), e.toString(), //$NON-NLS-1$
                false, false, true);
        dialogBox.center();
    }
    IWizardPanel[] wizardPanels = { scheduleEditorWizardPanel };
    setWizardPanels(wizardPanels);
    setPixelSize(475, 465);
    center();
    if ((hasParams || isEmailConfValid) && (isBlockoutDialog == false)) {
        finishButton.setText(Messages.getString("next")); //$NON-NLS-1$
    } else {
        finishButton.setText(Messages.getString("finish")); //$NON-NLS-1$
    }
    setupExisting(jsJob);

    wizardDeckPanel.getElement().getParentElement().addClassName("schedule-dialog-content");
    wizardDeckPanel.getElement().getParentElement().removeClassName("dialog-content");

    //setHeight("100%"); //$NON-NLS-1$
    setSize("650px", "450px");
    addStyleName("schedule-recurrence-dialog");
}

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  .  ja  va 2  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.  java2 s .  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.dialogs.scheduling.ScheduleRecurrenceDialog.java

License:Open Source License

private void showScheduleEmailDialog(final JSONObject schedule) {
    try {/*from w  w w  . j av  a 2  s .c o  m*/
        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) {
                        showScheduleEmailDialog(schedule);
                    }
                });
            }

            @Override
            public void onResponseReceived(Request request, Response response) {
                JSONObject scheduleRequest = (JSONObject) JSONParser.parseStrict(schedule.toString());
                if (scheduleEmailDialog == null) {
                    scheduleEmailDialog = new ScheduleEmailDialog(ScheduleRecurrenceDialog.this, filePath,
                            scheduleRequest, null, editJob);
                    scheduleEmailDialog.setCallback(callback);
                } else {
                    scheduleEmailDialog.setJobSchedule(scheduleRequest);
                }
                scheduleEmailDialog.setNewSchedule(newSchedule);
                scheduleEmailDialog.center();
                hide();
            }

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

}