Example usage for com.google.gwt.http.client Response SC_CONFLICT

List of usage examples for com.google.gwt.http.client Response SC_CONFLICT

Introduction

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

Prototype

int SC_CONFLICT

To view the source code for com.google.gwt.http.client Response SC_CONFLICT.

Click Source Link

Usage

From source file:com.google.appinventor.client.explorer.commands.BuildCommand.java

License:Open Source License

@Override
public void execute(final ProjectNode node) {
    final Ode ode = Ode.getInstance();
    final MessagesOutput messagesOutput = MessagesOutput.getMessagesOutput();
    messagesOutput.clear();/*from www . ja v  a  2s  .c o m*/
    messagesOutput.addMessages(MESSAGES.buildRequestedMessage(node.getName(),
            DateTimeFormat.getMediumDateTimeFormat().format(new Date())));

    OdeAsyncCallback<RpcResult> callback = new OdeAsyncCallback<RpcResult>(
            // failure message
            MESSAGES.buildError()) {
        @Override
        public void onSuccess(RpcResult result) {
            messagesOutput.addMessages(result.getOutput());
            messagesOutput.addMessages(result.getError());
            Tracking.trackEvent(Tracking.PROJECT_EVENT, Tracking.PROJECT_SUBACTION_BUILD_YA, node.getName(),
                    getElapsedMillis());
            if (result.succeeded()) {
                executeNextCommand(node);
            } else {
                // The result is the HTTP response code from the build server.
                int responseCode = result.getResult();
                switch (responseCode) {
                case Response.SC_SERVICE_UNAVAILABLE:
                    // SC_SERVICE_UNAVAILABLE (response code 503), means that the build server is too busy
                    // at this time to accept this build request.
                    // We use ErrorReporter.reportInfo so that the message has yellow background instead of
                    // red background.
                    ErrorReporter.reportInfo(MESSAGES.buildServerBusyError());
                    break;
                case Response.SC_CONFLICT:
                    // SC_CONFLICT (response code 409), means that the build server is running a
                    // different version of the App Inventor code.
                    // We use ErrorReporter.reportInfo so that the message has yellow background instead
                    // of red background.
                    ErrorReporter.reportInfo(MESSAGES.buildServerDifferentVersion());
                    break;
                default:
                    String errorMsg = result.getError();
                    // This is not an internal App Inventor bug. The error is reported as info so that
                    // the red background is not shown.
                    ErrorReporter.reportInfo(
                            MESSAGES.buildFailedError() + (errorMsg.isEmpty() ? "" : " " + errorMsg));
                    break;
                }
                executionFailedOrCanceled();
            }
        }

        @Override
        public void onFailure(Throwable caught) {
            super.onFailure(caught);
            executionFailedOrCanceled();
        }
    };

    String nonce = ode.generateNonce();
    ode.getProjectService().build(node.getProjectId(), nonce, target, callback);
}

From source file:com.google.appinventor.client.explorer.commands.BuildEclipseProjectCommand.java

License:Open Source License

@Override
public void execute(final ProjectNode node) {
    final Ode ode = Ode.getInstance();
    final MessagesOutput messagesOutput = MessagesOutput.getMessagesOutput();
    messagesOutput.clear();/*from w ww .  ja va  2 s  .  co  m*/
    messagesOutput.addMessages(MESSAGES.buildRequestedMessage(node.getName(),
            DateTimeFormat.getMediumDateTimeFormat().format(new Date())));

    OdeAsyncCallback<RpcResult> callback = new OdeAsyncCallback<RpcResult>(
            // failure message
            MESSAGES.buildError()) {
        @Override
        public void onSuccess(RpcResult result) {
            messagesOutput.addMessages(result.getOutput());
            messagesOutput.addMessages(result.getError());
            Tracking.trackEvent(Tracking.PROJECT_EVENT, Tracking.PROJECT_SUBACTION_BUILD_YA, node.getName(),
                    getElapsedMillis());
            if (result.succeeded()) {
                executeNextCommand(node);
            } else {
                // The result is the HTTP response code from the build server.
                int responseCode = result.getResult();
                switch (responseCode) {
                case Response.SC_SERVICE_UNAVAILABLE:
                    // SC_SERVICE_UNAVAILABLE (response code 503), means that the build server is too busy
                    // at this time to accept this build request.
                    // We use ErrorReporter.reportInfo so that the message has yellow background instead of
                    // red background.
                    ErrorReporter.reportInfo(MESSAGES.buildServerBusyError());
                    break;
                case Response.SC_CONFLICT:
                    // SC_CONFLICT (response code 409), means that the build server is running a
                    // different version of the App Inventor code.
                    // We use ErrorReporter.reportInfo so that the message has yellow background instead
                    // of red background.
                    ErrorReporter.reportInfo(MESSAGES.buildServerDifferentVersion());
                    break;
                default:
                    String errorMsg = result.getError();
                    // This is not an internal App Inventor bug. The error is reported as info so that
                    // the red background is not shown.
                    ErrorReporter.reportInfo(
                            MESSAGES.buildFailedError() + (errorMsg.isEmpty() ? "" : " " + errorMsg));
                    break;
                }
                executionFailedOrCanceled();
            }
        }

        @Override
        public void onFailure(Throwable caught) {
            super.onFailure(caught);
            executionFailedOrCanceled();
        }
    };

    ode.getProjectService().buildEclipseProject(node.getProjectId(), target, buildOption, callback);
}

From source file:com.google.appinventor.client.explorer.commands.BuildWebCommand.java

License:Open Source License

@Override
public void execute(final ProjectNode node) {
    final Ode ode = Ode.getInstance();
    final MessagesOutput messagesOutput = MessagesOutput.getMessagesOutput();
    messagesOutput.clear();/*from   w w  w .  j a v  a2s  .c o  m*/
    messagesOutput.addMessages(MESSAGES.buildRequestedMessage(node.getName(),
            DateTimeFormat.getMediumDateTimeFormat().format(new Date())));

    OdeAsyncCallback<RpcResult> callback = new OdeAsyncCallback<RpcResult>(
            // failure message
            MESSAGES.buildError()) {
        @Override
        public void onSuccess(RpcResult result) {
            messagesOutput.addMessages(result.getOutput());
            messagesOutput.addMessages(result.getError());
            Tracking.trackEvent(Tracking.PROJECT_EVENT, Tracking.PROJECT_SUBACTION_BUILD_YA, node.getName(),
                    getElapsedMillis());
            if (result.succeeded()) {
                executeNextCommand(node);
            } else {
                // The result is the HTTP response code from the build server.
                int responseCode = result.getResult();
                switch (responseCode) {
                case Response.SC_SERVICE_UNAVAILABLE:
                    // SC_SERVICE_UNAVAILABLE (response code 503), means that the build server is too busy
                    // at this time to accept this build request.
                    // We use ErrorReporter.reportInfo so that the message has yellow background instead of
                    // red background.
                    ErrorReporter.reportInfo(MESSAGES.buildServerBusyError());
                    break;
                case Response.SC_CONFLICT:
                    // SC_CONFLICT (response code 409), means that the build server is running a
                    // different version of the App Inventor code.
                    // We use ErrorReporter.reportInfo so that the message has yellow background instead
                    // of red background.
                    ErrorReporter.reportInfo(MESSAGES.buildServerDifferentVersion());
                    break;
                default:
                    String errorMsg = result.getError();
                    // This is not an internal App Inventor bug. The error is reported as info so that
                    // the red background is not shown.
                    ErrorReporter.reportInfo(
                            MESSAGES.buildFailedError() + (errorMsg.isEmpty() ? "" : " " + errorMsg));
                    break;
                }
                executionFailedOrCanceled();
            }
        }

        @Override
        public void onFailure(Throwable caught) {
            super.onFailure(caught);
            executionFailedOrCanceled();
        }
    };

    String nonce = ode.generateNonce();
    ode.getProjectService().buildDemo(node.getProjectId(), nonce, target, callback);
}

From source file:com.google.collide.client.communication.FrontendRestApi.java

License:Open Source License

private static FailureReason getFailureReason(Response response, ServerError responseData) {
    switch (response.getStatusCode()) {
    case Response.SC_OK:
        return null;
    case Response.SC_UNAUTHORIZED:
        if (responseData != null) {
            return responseData.getFailureReason();
        }// ww  w  .  j  a  v a2  s .  com
        return FailureReason.UNAUTHORIZED;
    // TODO: Make this a server dto error.
    case Response.SC_CONFLICT:
        return FailureReason.STALE_CLIENT;
    case Response.SC_NOT_FOUND:
        if (responseData != null) {
            return responseData.getFailureReason();
        }
        return FailureReason.UNKNOWN;
    case Response.SC_NOT_IMPLEMENTED:
        if (responseData != null) {
            return responseData.getFailureReason();
        }
        return FailureReason.UNKNOWN;
    default:
        return FailureReason.SERVER_ERROR;
    }
}

From source file:com.google.gerrit.client.account.MyGpgKeysScreen.java

License:Apache License

private void doAddKey() {
    if (keyText.getText().isEmpty()) {
        return;//from  w ww.j av a  2 s  .com
    }
    addButton.setEnabled(false);
    keyText.setEnabled(false);
    AccountApi.addGpgKey("self", keyText.getText(), new AsyncCallback<NativeMap<GpgKeyInfo>>() {
        @Override
        public void onSuccess(NativeMap<GpgKeyInfo> result) {
            keyText.setEnabled(true);
            refreshKeys();
        }

        @Override
        public void onFailure(Throwable caught) {
            keyText.setEnabled(true);
            addButton.setEnabled(true);
            if (caught instanceof StatusCodeException) {
                StatusCodeException sce = (StatusCodeException) caught;
                if (sce.getStatusCode() == Response.SC_CONFLICT
                        || sce.getStatusCode() == Response.SC_BAD_REQUEST) {
                    errorText.setText(sce.getEncodedResponse());
                } else {
                    errorText.setText(sce.getMessage());
                }
            } else {
                errorText.setText("Unexpected error saving key: " + caught.getMessage());
            }
            errorPanel.setVisible(true);
        }
    });
}

From source file:org.fusesource.restygwt.client.callback.RestfulCachingCallbackFilter.java

License:Apache License

@Override
protected boolean isCachingStatusCode(final int code) {
    return code == Response.SC_CONFLICT || super.isCachingStatusCode(code);
}

From source file:org.fusesource.restygwt.client.callback.RestfulCachingCallbackFilter.java

License:Apache License

@Override
protected void cacheResult(Method method, Response response) {
    final CacheKey cacheKey;
    if (response.getStatusCode() == Response.SC_CREATED && response.getHeader("Location") != null) {
        final String uri;
        if (response.getHeader("Location").startsWith("http")) {
            uri = response.getHeader("Location");
        } else {//  w ww.j  ava2 s  . co  m
            // TODO very fragile way of getting the URL
            uri = method.builder.getUrl().replaceFirst("/[^/]*$", "") + response.getHeader("Location");
        }
        cacheKey = new UrlCacheKey(uri);
    } else {
        cacheKey = cacheKey(method.builder);
    }
    if (RequestBuilder.DELETE.toString().equalsIgnoreCase(method.builder.getHTTPMethod()) ||
    // in case of a conflict the next GET request needs to
    // go remote !!
            response.getStatusCode() == Response.SC_CONFLICT) {
        cache.remove(cacheKey);
    } else if (method.builder.getUrl().matches(".*/[0-9]+$")) {
        // if url has an ID at the end then treat it as single entity
        // otherwise assume a collection which are not cached.
        cache.putResult(cacheKey, response);
    }
}

From source file:org.jbpm.formbuilder.client.RestyFormBuilderModel.java

License:Apache License

@Override
public void saveForm(final FormRepresentation form) {
    Resource resource = new Resource(URLBuilder.saveFormURL(this.contextPath, this.packageName));
    try {//www . j a  v  a 2 s. c  o  m
        String json = FormEncodingFactory.getEncoder().encode(form);
        resource.post().text(json).send(new SimpleTextCallback(i18n.CouldntSaveForm()) {
            @Override
            public void onSuccess(Method method, String response) {
                int code = method.getResponse().getStatusCode();
                if (code == Response.SC_CONFLICT) {
                    bus.fireEvent(new NotificationEvent(Level.WARN, i18n.FormAlreadyUpdated()));
                } else if (code != Response.SC_CREATED) {
                    bus.fireEvent(new NotificationEvent(Level.WARN,
                            i18n.SaveFormUnkwnownStatus(String.valueOf(code))));
                } else {
                    String name = helper.getFormId(response);
                    form.setLastModified(System.currentTimeMillis());
                    form.setSaved(true);
                    form.setName(name);
                    bus.fireEvent(new FormSavedEvent(form));
                }
            }
        });
    } catch (FormEncodingException e) {
        bus.fireEvent(new NotificationEvent(Level.ERROR, i18n.CouldntDecodeForm(), e));
    }
}

From source file:org.jbpm.formbuilder.client.RestyFormBuilderModel.java

License:Apache License

@Override
public void saveFormItem(FormItemRepresentation formItem, String formItemName) {
    Resource resource = new Resource(
            URLBuilder.saveFormItemURL(this.contextPath, this.packageName, formItemName));
    try {/*from   w  w  w. j a v a2 s  .  c  o  m*/
        String xml = helper.asXml(formItemName, formItem);
        resource.post().xml(XMLParser.parse(xml)).send(new SimpleTextCallback(i18n.CouldntSaveFormItem()) {
            @Override
            public void onSuccess(Method method, String response) {
                int code = method.getResponse().getStatusCode();
                if (code == Response.SC_CONFLICT) {
                    bus.fireEvent(new NotificationEvent(Level.WARN, i18n.FormItemAlreadyUpdated()));
                } else if (code != Response.SC_CREATED) {
                    bus.fireEvent(new NotificationEvent(Level.WARN,
                            i18n.SaveFormItemUnknownStatus(String.valueOf(code))));
                } else {
                    String name = helper.getFormItemId(response);
                    bus.fireEvent(new NotificationEvent(Level.INFO, i18n.FormItemSaved(name)));
                }
            }
        });
    } catch (FormEncodingException e) {
        bus.fireEvent(new NotificationEvent(Level.ERROR, i18n.CouldntDecodeFormItem(formItemName), e));
    }
}

From source file:org.openremote.model.http.ConflictRequestError.java

License:Open Source License

public ConflictRequestError() {
    super(Response.SC_CONFLICT, "Conflicting resource state (concurrent updates?)");
}