Example usage for com.google.gwt.http.client URL encode

List of usage examples for com.google.gwt.http.client URL encode

Introduction

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

Prototype

public static String encode(String decodedURL) 

Source Link

Document

Returns a string where all characters that are not valid for a complete URL have been escaped.

Usage

From source file:org.eclipse.che.ide.ext.datasource.client.ssl.SslKeyStoreClientServiceImpl.java

License:Open Source License

@Override
public void deleteServerCert(SslKeyStoreEntry entry, AsyncRequestCallback<Void> callback) {
    asyncRequestFactory/*w ww.jav a 2  s.  c  o m*/
            .createGetRequest(baseUrl + "/ssl-keystore/truststore/" + URL.encode(entry.getAlias()) + "/remove")
            .loader(loader, "Deleting SSL server cert entries for " + entry.getAlias()).send(callback);
}

From source file:org.eclipse.che.ide.ext.runner.client.manager.RunnerManagerPresenter.java

License:Open Source License

/** {@inheritDoc} */
@Override/*  w  w w.  ja  va  2 s .  c om*/
public Runner launchRunner() {
    CurrentProject currentProject = appContext.getCurrentProject();
    if (currentProject == null) {
        throw new IllegalStateException(
                "Can't launch runner for current project. Current project is absent...");
    }

    int ram = DEFAULT.getValue();

    RunnersDescriptor runnersDescriptor = currentProject.getProjectDescription().getRunners();
    String defaultRunner = runnersDescriptor.getDefault();

    if (!EnvironmentIdValidator.isValid(defaultRunner)) {
        defaultRunner = URL.encode(defaultRunner);
    }

    RunnerConfiguration defaultConfigs = runnersDescriptor.getConfigs().get(defaultRunner);

    if (defaultRunner != null && defaultConfigs != null) {
        ram = defaultConfigs.getRam();
    }

    RunOptions runOptions = dtoFactory.createDto(RunOptions.class)
            .withSkipBuild(Boolean.valueOf(currentProject.getAttributeValue("runner:skipBuild")))
            .withEnvironmentId(defaultRunner).withMemorySize(ram);

    Environment environment = chooseRunnerAction.selectEnvironment();
    if (environment != null) {
        if (defaultRunner != null && defaultRunner.equals(environment.getId())) {
            return launchRunner(modelsFactory.createRunner(runOptions));
        }
        runOptions = runOptions.withOptions(environment.getOptions()).withMemorySize(environment.getRam())
                .withEnvironmentId(environment.getId());
        return launchRunner(modelsFactory.createRunner(runOptions, environment.getName()));
    }

    return launchRunner(modelsFactory.createRunner(runOptions));
}

From source file:org.eclipse.che.ide.ext.runner.client.runneractions.impl.RunAction.java

License:Open Source License

/** {@inheritDoc} */
@Override/*from ww w.j a v  a2s  .  co  m*/
public void perform(@Nonnull final Runner runner) {
    eventLogger.log(this);
    final CurrentProject project = appContext.getCurrentProject();
    if (project == null) {
        return;
    }

    presenter.setActive();

    AsyncRequestCallback<ApplicationProcessDescriptor> callback = callbackBuilderProvider.get()
            .unmarshaller(ApplicationProcessDescriptor.class)
            .success(new SuccessCallback<ApplicationProcessDescriptor>() {
                @Override
                public void onSuccess(ApplicationProcessDescriptor descriptor) {
                    runner.setProcessDescriptor(descriptor);
                    runner.setRAM(descriptor.getMemorySize());

                    presenter.addRunnerId(descriptor.getProcessId());

                    presenter.update(runner);

                    launchAction.perform(runner);
                }
            }).failure(new FailureCallback() {
                @Override
                public void onFailure(@Nonnull Throwable reason) {

                    if (project.getRunner() == null) {
                        runnerUtil.showError(runner, locale.defaultRunnerAbsent(), null);
                        return;
                    }

                    runnerUtil.showError(runner,
                            locale.startApplicationFailed(project.getProjectDescription().getName()), null);
                }
            }).build();

    String encodedEnvironmentId = runner.getOptions().getEnvironmentId();
    if (encodedEnvironmentId != null && !EnvironmentIdValidator.isValid(encodedEnvironmentId)) {
        runner.getOptions().setEnvironmentId(URL.encode(encodedEnvironmentId));
    }

    service.run(project.getProjectDescription().getPath(), runner.getOptions(), callback);
}

From source file:org.eclipse.che.ide.ext.runner.client.tabs.properties.panel.impl.PropertiesEnvironmentPanel.java

License:Open Source License

/**
 * Gets the type of an environment. First we check if type is not defined by a runner configuration. If there is not, use type of the
 * environment//  w w  w.  ja v a2 s. co m
 *
 * @param environment
 *         the environment to check
 * @return the type of the provided environment
 */
private String getType(@Nonnull Environment environment) {
    String envId = URL.encode(environment.getId());
    RunnerConfiguration runnerConfiguration = runnerConfigs.get(envId);
    if (runnerConfiguration != null) {
        return runnerConfiguration.getVariables().get(CONFIGURATION_TYPE);
    } else {
        return environment.getType();
    }
}

From source file:org.eclipse.che.ide.ext.runner.client.tabs.properties.panel.impl.PropertiesEnvironmentPanel.java

License:Open Source License

private String generateEnvironmentId(@Nonnull String environmentName) {
    String newName = URL.encode(ENVIRONMENT_ID_PREFIX + environmentName);
    // with GWT mocks, native methods can be empty
    if (newName.isEmpty()) {
        return ENVIRONMENT_ID_PREFIX + environmentName;
    }//from  w ww  .  j a  v a  2  s.  c o  m
    return newName;
}

From source file:org.eclipse.che.ide.ext.runner.client.tabs.properties.panel.impl.PropertiesEnvironmentPanel.java

License:Open Source License

/** {@inheritDoc} */
@Override// ww  w .  j  av a 2  s . com
public void onSaveButtonClicked() {
    isParameterChanged = false;

    final String newEnvironmentName = view.getName();
    final String environmentName = environment.getName();
    final String environmentId = environment.getId();
    final String encodedEnvironmentId = URL.encode(environmentId);

    final String pathToProject = projectDescriptor.getPath();
    final String path = pathToProject + ROOT_FOLDER + environmentName;

    final AsyncRequestCallback<Void> renameAsyncRequestCallback = voidAsyncCallbackBuilder
            .success(new SuccessCallback<Void>() {
                @Override
                public void onSuccess(Void result) {
                    RunnerConfiguration config = runnerConfigs.get(encodedEnvironmentId);
                    runnerConfigs.remove(encodedEnvironmentId);

                    runnerConfigs.put(generateEnvironmentId(newEnvironmentName), config);

                    String defaultRunner = currentProject.getRunner();

                    if (defaultRunner != null && defaultRunner.equals(environmentId)) {
                        projectDescriptor.getRunners().setDefault(generateEnvironmentId(newEnvironmentName));
                    }

                    updateProject();
                }
            }).failure(new FailureCallback() {
                @Override
                public void onFailure(@Nonnull Throwable reason) {
                    notificationManager.showError(reason.getMessage());
                }
            }).build();

    // we save before trying to rename the file
    if (editor.isDirty()) {
        editor.doSave(new AsyncCallback<EditorInput>() {
            @Override
            public void onSuccess(EditorInput editorInput) {
                view.setEnableSaveButton(false);
                view.setEnableCancelButton(false);
                // rename file
                if (!environmentName.equals(newEnvironmentName)) {
                    projectService.rename(path, newEnvironmentName, null, renameAsyncRequestCallback);
                }

            }

            @Override
            public void onFailure(Throwable throwable) {
                Log.error(getClass(), throwable.getMessage());
            }
        });
    } else {
        // rename directly as nothing to save
        if (!environmentName.equals(newEnvironmentName)) {
            projectService.rename(path, newEnvironmentName, null, renameAsyncRequestCallback);
        }

    }

    Map<String, String> variables = new HashMap<>();
    variables.put(CONFIGURATION_TYPE, environment.getType());
    RunnerConfiguration config = dtoFactory.createDto(RunnerConfiguration.class).withRam(environment.getRam())
            .withVariables(variables);

    runnerConfigs.put(encodedEnvironmentId, config);

    updateProject();

    projectEnvironmentsAction.perform();
}

From source file:org.eclipse.che.ide.ext.runner.client.tabs.properties.panel.impl.PropertiesEnvironmentPanel.java

License:Open Source License

/** {@inheritDoc} */
@Override/*from ww w .  j  a v a2s .  co  m*/
public void update(@Nonnull Environment environment) {
    view.setEnableCancelButton(isParameterChanged);
    view.setEnableSaveButton(isParameterChanged);

    Scope scope = environment.getScope();

    view.setEnableDeleteButton(PROJECT.equals(scope));

    String environmentName = environment.getName();
    String environmentId = URL.encode(environment.getId());

    boolean isConfigExist = runnerConfigs.containsKey(environmentId);

    RAM ram = RAM.detect(isConfigExist && !isParameterChanged ? getRam(environmentId) : environment.getRam());

    this.environment.setRam(ram.getValue());

    view.selectShutdown(getTimeout());
    view.selectMemory(ram);
    view.setName(environmentName);
    String type = getType(environment);
    view.setType(type);
    view.selectScope(scope);

    String defaultRunner = currentProject.getRunner();

    view.changeSwitcherState(environment.getId().equals(defaultRunner));
}

From source file:org.eclipse.kura.web.client.ui.EntryClassUi.java

License:Open Source License

private void installMarketplaceDp(final String uri) {
    String url = "/" + GWT.getModuleName() + "/file/deploy/url";
    final RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(url));

    this.gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {

        @Override/*ww  w. j  a  v  a 2s  . c  o m*/
        public void onFailure(Throwable ex) {
            EntryClassUi.hideWaitModal();
            FailureHandler.handle(ex, EntryClassUi.class.getName());
        }

        @Override
        public void onSuccess(GwtXSRFToken token) {
            StringBuilder sb = new StringBuilder();
            sb.append("xsrfToken=" + token.getToken());
            sb.append("&packageUrl=" + uri);

            builder.setHeader("Content-type", "application/x-www-form-urlencoded");
            try {
                builder.sendRequest(sb.toString(), new RequestCallback() {

                    @Override
                    public void onResponseReceived(Request request, Response response) {
                        logger.info(response.getText());
                    }

                    @Override
                    public void onError(Request request, Throwable ex) {
                        logger.log(Level.SEVERE, ex.getMessage(), ex);
                        FailureHandler.handle(ex, EntryClassUi.class.getName());
                    }

                });
            } catch (RequestException e) {
                logger.log(Level.SEVERE, e.getMessage(), e);
                FailureHandler.handle(e, EntryClassUi.class.getName());
            }
        }
    });
}

From source file:org.eclipselabs.emfjson.gwt.handlers.HttpHandler.java

License:Open Source License

@Override
public void createInputStream(URI uri, Map<?, ?> options, final Callback<Map<?, ?>> callback) {
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(uri.toString()));

    try {//from   ww  w .  ja  va 2s  . c  o m
        builder.sendRequest(null, new RequestCallback() {
            @Override
            public void onResponseReceived(Request request, Response response) {
                Map<String, Object> resultMap = new HashMap<String, Object>();
                Map<String, Object> responseMap = new HashMap<String, Object>();
                resultMap.put(URIConverter.OPTION_RESPONSE, responseMap);

                if (200 == response.getStatusCode()) {
                    String responseText = response.getText();
                    if (responseText != null) {
                        InputStream stream = new ByteArrayInputStream(responseText.getBytes());
                        responseMap.put(URIConverter.RESPONSE_RESULT, stream);
                    }
                } else {
                    responseMap.put(URIConverter.RESPONSE_RESULT, null);
                }
                callback.onSuccess(resultMap);
            }

            @Override
            public void onError(Request request, Throwable exception) {
                callback.onFailure(exception);
            }
        });
    } catch (RequestException e) {
        e.printStackTrace();
    }
}

From source file:org.eclipselabs.emfjson.gwt.handlers.HttpHandler.java

License:Open Source License

@Override
public void delete(URI uri, Map<?, ?> options, final Callback<Map<?, ?>> callback) {
    RequestBuilder builder = new RequestBuilder(RequestBuilder.DELETE, URL.encode(uri.toString()));

    try {/*w w w  . ja v a2  s  .  c  om*/
        builder.sendRequest(null, new RequestCallback() {
            @Override
            public void onResponseReceived(Request request, Response response) {
                Map<String, Object> resultMap = new HashMap<String, Object>();
                Map<String, Object> responseMap = new HashMap<String, Object>();
                resultMap.put(URIConverter.OPTION_RESPONSE, responseMap);

                int code = response.getStatusCode();
                if (code >= 200 && code < 300) {
                    responseMap.put(URIConverter.RESPONSE_RESULT, null);
                    responseMap.put(URIConverter.RESPONSE_TIME_STAMP_PROPERTY, null);
                    responseMap.put(URIConverter.RESPONSE_URI, null);
                }

                callback.onSuccess(resultMap);
            }

            @Override
            public void onError(Request request, Throwable exception) {
                callback.onFailure(exception);
            }
        });
    } catch (RequestException e) {
        e.printStackTrace();
    }
}