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

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

Introduction

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

Prototype

int SC_INTERNAL_SERVER_ERROR

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

Click Source Link

Usage

From source file:com.google.gerrit.client.ErrorDialog.java

License:Apache License

/** Create a dialog box to nicely format an exception. */
public ErrorDialog(final Throwable what) {
    this();/*from  w w  w  .  java  2s. c o  m*/

    String hdr;
    String msg;

    if (what instanceof StatusCodeException) {
        StatusCodeException sc = (StatusCodeException) what;
        if (RestApi.isExpected(sc.getStatusCode())) {
            hdr = null;
            msg = sc.getEncodedResponse();
        } else if (sc.getStatusCode() == Response.SC_INTERNAL_SERVER_ERROR) {
            hdr = null;
            msg = what.getMessage();
        } else {
            hdr = RpcConstants.C.errorServerUnavailable();
            msg = what.getMessage();
        }

    } else if (what instanceof RemoteJsonException) {
        // TODO Remove RemoteJsonException from Gerrit sources.
        hdr = RpcConstants.C.errorRemoteJsonException();
        msg = what.getMessage();

    } else {
        // TODO Fix callers of ErrorDialog to stop passing random types.
        hdr = what.getClass().getName();
        if (hdr.startsWith("java.lang.")) {
            hdr = hdr.substring("java.lang.".length());
        } else if (hdr.startsWith("com.google.gerrit.")) {
            hdr = hdr.substring(hdr.lastIndexOf('.') + 1);
        }
        if (hdr.endsWith("Exception")) {
            hdr = hdr.substring(0, hdr.length() - "Exception".length());
        } else if (hdr.endsWith("Error")) {
            hdr = hdr.substring(0, hdr.length() - "Error".length());
        }
        msg = what.getMessage();
    }

    if (hdr != null) {
        final Label r = new Label(hdr);
        r.setStyleName(Gerrit.RESOURCES.css().errorDialogErrorType());
        body.add(r);
    }

    if (msg != null) {
        final Label m = new Label(msg);
        DOM.setStyleAttribute(m.getElement(), "whiteSpace", "pre");
        body.add(m);
    }
}

From source file:org.glom.web.server.OnlineGlomImagesServlet.java

License:Open Source License

/** Get the image from a specific field of a specific record in a specific table in the database.
 * /*from  ww w.  j  a v  a2  s  . c om*/
 * @param resp
 * @param attrDocumentID
 * @param attrTableName
 * @param attrPrimaryKeyValue
 * @param attrFieldName
 * @param configuredDocument
 * @param document
 * @return
 * @throws IOException
 */
private byte[] getImageFromDatabase(final HttpServletRequest request, final HttpServletResponse resp,
        final String attrDocumentID, final String attrTableName, final String attrPrimaryKeyValue,
        final String attrFieldName, final ConfiguredDocument configuredDocument, final Document document)
        throws IOException {
    final Field field = document.getField(attrTableName, attrFieldName);
    if (field == null) {
        doError(resp, Response.SC_NOT_FOUND, "The specified field was not found: field=" + attrFieldName,
                attrDocumentID);
        return null;
    }

    final Field fieldPrimaryKey = document.getTablePrimaryKeyField(attrTableName);

    TypedDataItem primaryKeyValue = new TypedDataItem();
    primaryKeyValue.setNumber(Double.parseDouble(attrPrimaryKeyValue));

    final LayoutItemField layoutItemField = new LayoutItemField();
    layoutItemField.setFullFieldDetails(field);
    final List<LayoutItemField> fieldsToGet = new ArrayList<LayoutItemField>();
    fieldsToGet.add(layoutItemField);
    final String query = SqlUtils.buildSqlSelectWithKey(attrTableName, fieldsToGet, fieldPrimaryKey,
            primaryKeyValue, document.getSqlDialect());

    final ComboPooledDataSource authenticatedConnection = getConnection(request, attrDocumentID);
    if (authenticatedConnection == null) {
        return null;
    }

    ResultSet rs = null;
    try {
        rs = SqlUtils.executeQuery(authenticatedConnection, query);
    } catch (SQLException e) {
        doError(resp, Response.SC_INTERNAL_SERVER_ERROR, "SQL exception: " + e.getMessage(), attrDocumentID);
        return null;
    }

    if (rs == null) {
        doError(resp, Response.SC_INTERNAL_SERVER_ERROR, "The SQL result set is null.", attrDocumentID);
        return null;
    }

    byte[] bytes = null;
    try {
        rs.next();
        bytes = rs.getBytes(1); //This is 1-indexed, not 0-indexed.
    } catch (SQLException e) {
        doError(resp, Response.SC_INTERNAL_SERVER_ERROR, "SQL exception: " + e.getMessage(), attrDocumentID);
        return null;
    }

    if (bytes == null) {
        doError(resp, Response.SC_INTERNAL_SERVER_ERROR, "The database contained null.", attrDocumentID);
        return null;
    }

    return bytes;
}

From source file:org.obiba.opal.web.gwt.app.client.administration.configuration.edit.GeneralConfModalPresenter.java

License:Open Source License

@Override
public void save() {
    getView().clearErrors();/*  w  w w .  ja  v  a  2s.c  o m*/
    if (validationHandler.validate()) {
        GeneralConf dto = GeneralConf.create();
        dto.setName(getView().getName().getText());
        dto.setDefaultCharSet(getView().getDefaultCharSet().getText());
        dto.setLanguagesArray(getView().getLanguages());
        dto.setPublicURL(getView().getPublicUrl().getText());

        ResourceRequestBuilderFactory.<GeneralConf>newBuilder().forResource("/system/conf/general")
                .withResourceBody(GeneralConf.stringify(dto)).withCallback(new ResponseCodeCallback() {
                    @Override
                    public void onResponseCode(Request request, Response response) {
                        if (response.getStatusCode() == Response.SC_OK) {
                            getView().hide();
                            fireEvent(new GeneralConfigSavedEvent());
                        } else {
                            fireEvent(NotificationEvent.newBuilder().error(response.getText()).build());
                        }
                    }
                }, Response.SC_OK, Response.SC_INTERNAL_SERVER_ERROR, Response.SC_NOT_FOUND).put().send();
    }
}

From source file:org.obiba.opal.web.gwt.app.client.administration.identifiers.presenter.CopySystemIdentifiersModalPresenter.java

License:Open Source License

@Override
public void onSubmit(TableDto selection) {
    if (!validationHandler.validate())
        return;/*from www. j  a  v a 2 s.com*/

    GWT.log(selection.getDatasourceName() + " " + table.getName());

    getView().setBusy(true);
    String uri = UriBuilder.create().segment("identifiers", "mappings", "entities", "_sync")
            .query("datasource", selection.getDatasourceName(), "table", selection.getName()).build();
    ResourceRequestBuilderFactory.newBuilder().forResource(uri) //
            .post() //
            .withCallback(new ResponseCodeCallback() {
                @Override
                public void onResponseCode(Request request, Response response) {
                    getView().setBusy(false);
                    if (response.getStatusCode() == Response.SC_OK) {
                        getView().hide();
                        fireEvent(new IdentifiersTableSelectionEvent.Builder().dto(table).build());
                    } else {
                        getView().showError(response.getText(), null);
                    }
                }
            }, Response.SC_BAD_REQUEST, Response.SC_INTERNAL_SERVER_ERROR, Response.SC_OK).send();
}

From source file:org.obiba.opal.web.gwt.app.client.administration.identifiers.presenter.GenerateIdentifiersModalPresenter.java

License:Open Source License

public void initialize(VariableDto variable, final TableDto table) {
    this.variable = variable;
    this.table = table;

    String prefix = variable.getName().toUpperCase() + "-";
    getView().setDefault(10, prefix);/*www.ja  va2  s.  c o m*/

    UriBuilder ub = UriBuilder.create().segment("identifiers", "mapping", "{}", "_count").query("type",
            table.getEntityType());
    ResourceRequestBuilderFactory.newBuilder().forResource(ub.build(variable.getName())).get()//
            .withCallback(new ResponseCodeCallback() {
                @Override
                public void onResponseCode(Request request, Response response) {
                    try {
                        getView().setAffectedEntities(
                                table.getValueSetCount() - Integer.parseInt(response.getText()));
                    } catch (Exception e) {
                        GWT.log("Unable to get identifiers mapping count: " + e.getMessage());
                    }
                }
            }, Response.SC_OK, Response.SC_INTERNAL_SERVER_ERROR, Response.SC_NOT_FOUND,
                    Response.SC_BAD_REQUEST)
            .send();
}

From source file:org.obiba.opal.web.gwt.app.client.administration.identifiers.presenter.GenerateIdentifiersModalPresenter.java

License:Open Source License

@Override
public void generateIdentifiers(Number size, boolean allowZeros, String prefix) {
    getView().setBusy(true);//from ww w .  j av a 2  s .c o  m

    ResponseCodeCallback callbackHandler = new ResponseCodeCallback() {

        @Override
        public void onResponseCode(Request request, Response response) {
            if (response.getStatusCode() == Response.SC_OK) {
                int count = 0;
                try {
                    count = Integer.parseInt(response.getText());
                } catch (NumberFormatException ignored) {
                }
                if (count > 0) {
                    fireEvent(NotificationEvent.newBuilder().info("IdentifiersGenerationCompleted")
                            .args(variable.getName(), response.getText()).build());
                } else {
                    fireEvent(NotificationEvent.newBuilder().info("NoIdentifiersGenerated")
                            .args(variable.getName()).build());
                }
            } else {
                fireEvent(NotificationEvent.newBuilder().error("IdentifiersGenerationFailed")
                        .args(variable.getName()).build());
            }
            getView().hideDialog();
            fireEvent(new IdentifiersTableSelectionEvent.Builder().dto(table).build());
        }

    };

    UriBuilder ub = UriBuilder.create().segment("identifiers", "mapping", "{}", "_generate").query("type",
            table.getEntityType(), "size", String.valueOf(size), "zeros", String.valueOf(allowZeros), "prefix",
            prefix);
    ResourceRequestBuilderFactory.newBuilder().forResource(ub.build(variable.getName())).post()//
            .withCallback(callbackHandler, Response.SC_OK, Response.SC_INTERNAL_SERVER_ERROR, //
                    Response.SC_NOT_FOUND) //
            .send();
}

From source file:org.obiba.opal.web.gwt.app.client.administration.identifiers.presenter.IdentifiersMappingModalPresenter.java

License:Open Source License

public void onUpdate(VariableDto updatedVariable) {
    UriBuilder uriBuilder = UriBuilders.IDENTIFIERS_TABLE_VARIABLE.create();
    ResourceRequestBuilderFactory.newBuilder()
            .forResource(uriBuilder.build(tableDto.getName(), variable.getName())) //
            .put() //
            .withResourceBody(VariableDto.stringify(updatedVariable)) //
            .withCallback(new VariableUpdateCallback(updatedVariable), Response.SC_BAD_REQUEST,
                    Response.SC_INTERNAL_SERVER_ERROR, Response.SC_OK)
            .send();//from w  ww.  j a v a2  s .c om
}

From source file:org.obiba.opal.web.gwt.app.client.administration.identifiers.presenter.IdentifiersMappingModalPresenter.java

License:Open Source License

public void doCreate(VariableDto newVariable) {
    UriBuilder uriBuilder;/*from   w  ww . ja  va2 s  .c o m*/
    uriBuilder = UriBuilders.IDENTIFIERS_TABLE_VARIABLES.create();

    ResourceRequestBuilderFactory.newBuilder().forResource(uriBuilder.build(tableDto.getName())) //
            .post() //
            .withResourceBody("[" + VariableDto.stringify(newVariable) + "]") //
            .withCallback(new VariableCreateCallback(newVariable), Response.SC_BAD_REQUEST,
                    Response.SC_INTERNAL_SERVER_ERROR, Response.SC_OK)
            .send();
}

From source file:org.obiba.opal.web.gwt.app.client.administration.identifiers.presenter.IdentifiersTableModalPresenter.java

License:Open Source License

public void doCreate(TableDto newTable) {
    ResourceRequestBuilderFactory.newBuilder().forResource(UriBuilders.IDENTIFIERS_TABLES.create().build()) //
            .post() //
            .withResourceBody(TableDto.stringify(newTable)) //
            .withCallback(new TableCreateCallback(newTable), Response.SC_BAD_REQUEST,
                    Response.SC_INTERNAL_SERVER_ERROR, Response.SC_CREATED)
            .send();/*from ww  w .jav  a 2s. c o  m*/
}

From source file:org.obiba.opal.web.gwt.app.client.administration.identifiers.presenter.ImportIdentifiersMappingModalPresenter.java

License:Open Source License

private void doCreateAndImport(final String name, final String systemIdentifiers, final String identifiers) {
    VariableDto newVariable = VariableDto.create();
    newVariable.setName(name);//w ww.  j  a v  a2  s  .  co m
    newVariable.setIsNewVariable(true);
    newVariable.setEntityType(table.getEntityType());
    newVariable.setIsRepeatable(false);
    newVariable.setValueType("text");

    UriBuilder uriBuilder = UriBuilders.IDENTIFIERS_TABLE_VARIABLES.create();
    ResourceRequestBuilderFactory.newBuilder().forResource(uriBuilder.build(table.getName())) //
            .post() //
            .withResourceBody("[" + VariableDto.stringify(newVariable) + "]") //
            .withCallback(new ResponseCodeCallback() {
                @Override
                public void onResponseCode(Request request, Response response) {
                    if (response.getStatusCode() == Response.SC_OK) {
                        doImport(name, systemIdentifiers, identifiers);
                    } else {
                        getView().showError(response.getText(), null);
                    }
                }
            }, Response.SC_BAD_REQUEST, Response.SC_INTERNAL_SERVER_ERROR, Response.SC_OK).send();
}