/**
* Request is not valid and can not be processed.
*/
-public class BadRequestException extends HttpException {
+public class BadRequestException extends ServerException {
private static final int BAD_REQUEST = 400;
/**
* Permission denied. User does not have the required permissions.
*/
-public class ForbiddenException extends HttpException {
+public class ForbiddenException extends ServerException {
private static final int FORBIDDEN = 403;
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.exceptions;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-
-import java.util.Collection;
-import java.util.Collections;
-
-import static com.google.common.collect.Lists.newArrayList;
-
-public class HttpException extends RuntimeException {
- private final int httpCode;
-
- private final String l10nKey;
- private final Collection<Object> l10nParams;
-
- public HttpException(int httpCode) {
- this.httpCode = httpCode;
- this.l10nKey = null;
- this.l10nParams = null;
- }
-
- public HttpException(int httpCode, String message) {
- super(message);
- this.httpCode = httpCode;
- this.l10nKey = null;
- this.l10nParams = null;
- }
-
- public HttpException(int httpCode, @Nullable String message, @Nullable String l10nKey, @Nullable Object[] l10nParams) {
- super(message);
- this.httpCode = httpCode;
- this.l10nKey = l10nKey;
- this.l10nParams = l10nParams == null ? Collections.emptyList() : Collections.unmodifiableCollection(newArrayList(l10nParams));
- }
-
- public int httpCode() {
- return httpCode;
- }
-
- @CheckForNull
- public String l10nKey() {
- return l10nKey;
- }
-
- @CheckForNull
- public Collection<Object> l10nParams() {
- return l10nParams;
- }
-}
*/
package org.sonar.server.exceptions;
-public class NotFoundException extends HttpException {
+public class NotFoundException extends ServerException {
private static final int NOT_FOUND = 404;
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.exceptions;
-
-public class ServerErrorException extends HttpException {
-
- private static final int SERVER_ERROR = 500;
-
- public ServerErrorException(String message) {
- super(SERVER_ERROR, message);
- }
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.exceptions;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import static com.google.common.collect.Lists.newArrayList;
+
+public class ServerException extends RuntimeException {
+ private final int httpCode;
+
+ private final String l10nKey;
+ private final Collection<Object> l10nParams;
+
+ public ServerException(int httpCode) {
+ this.httpCode = httpCode;
+ this.l10nKey = null;
+ this.l10nParams = null;
+ }
+
+ public ServerException(int httpCode, String message) {
+ super(message);
+ this.httpCode = httpCode;
+ this.l10nKey = null;
+ this.l10nParams = null;
+ }
+
+ public ServerException(int httpCode, @Nullable String message, @Nullable String l10nKey, @Nullable Object[] l10nParams) {
+ super(message);
+ this.httpCode = httpCode;
+ this.l10nKey = l10nKey;
+ this.l10nParams = l10nParams == null ? Collections.emptyList() : Collections.unmodifiableCollection(newArrayList(l10nParams));
+ }
+
+ public int httpCode() {
+ return httpCode;
+ }
+
+ @CheckForNull
+ public String l10nKey() {
+ return l10nKey;
+ }
+
+ @CheckForNull
+ public Collection<Object> l10nParams() {
+ return l10nParams;
+ }
+}
/**
* User needs to be authenticated. HTTP request is generally redirected to login form.
*/
-public class UnauthorizedException extends HttpException {
+public class UnauthorizedException extends ServerException {
private static final int UNAUTHORIZED = 401;
import org.sonar.core.permission.PermissionTemplateDto;
import org.sonar.core.user.UserDao;
import org.sonar.server.exceptions.BadRequestException;
-import org.sonar.server.exceptions.ServerErrorException;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
+
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
validateTemplateName(null, name);
validateKeyPattern(keyPattern);
PermissionTemplateDto permissionTemplateDto = permissionTemplateDao.createPermissionTemplate(name, description, keyPattern);
- if (permissionTemplateDto.getId() == null) {
- String errorMsg = "Template creation failed";
- LOG.error(errorMsg);
- throw new ServerErrorException(errorMsg);
- }
return PermissionTemplate.create(permissionTemplateDto);
}
render_native_access_denied(error)
elsif error.java_kind_of? Java::OrgSonarServerExceptions::ForbiddenException
render_native_access_denied(error)
- elsif error.java_kind_of? Java::OrgSonarServerExceptions::HttpException
+ elsif error.java_kind_of? Java::OrgSonarServerExceptions::ServerException
render_server_exception(error)
else
render_error(error)
Api.users.deactivate(user.login)
flash[:notice] = 'User is deleted.'
rescue NativeException => exception
- if exception.cause.java_kind_of? Java::OrgSonarServerExceptions::HttpException
+ if exception.cause.java_kind_of? Java::OrgSonarServerExceptions::ServerException
error = exception.cause
flash[:error] = (error.getMessage ? error.getMessage : Api::Utils.message(error.l10nKey, :params => error.l10nParams.to_a))
else
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.exceptions;
-
-import org.junit.Test;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class HttpExceptionTest {
-
- @Test
- public void should_create_exception_with_status(){
- HttpException exception = new HttpException(400);
- assertThat(exception.httpCode()).isEqualTo(400);
- }
-
- @Test
- public void should_create_exception_with_status_and_message(){
- HttpException exception = new HttpException(404, "Not found");
- assertThat(exception.httpCode()).isEqualTo(404);
- assertThat(exception.getMessage()).isEqualTo("Not found");
- }
-
- @Test
- public void should_create_exception_with_status_and_l10n_message_with_param(){
- HttpException exception = new HttpException(404, null, "key", new String[]{"value"});
- assertThat(exception.httpCode()).isEqualTo(404);
- assertThat(exception.l10nKey()).isEqualTo("key");
- assertThat(exception.l10nParams()).containsOnly("value");
- }
-
- @Test
- public void should_create_exception_with_status_and_l10n_message_without_param(){
- HttpException exception = new HttpException(404, null, "key", null);
- assertThat(exception.httpCode()).isEqualTo(404);
- assertThat(exception.l10nKey()).isEqualTo("key");
- assertThat(exception.l10nParams()).isEmpty();
- }
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.exceptions;
+
+import org.junit.Test;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class ServerExceptionTest {
+
+ @Test
+ public void should_create_exception_with_status(){
+ ServerException exception = new ServerException(400);
+ assertThat(exception.httpCode()).isEqualTo(400);
+ }
+
+ @Test
+ public void should_create_exception_with_status_and_message(){
+ ServerException exception = new ServerException(404, "Not found");
+ assertThat(exception.httpCode()).isEqualTo(404);
+ assertThat(exception.getMessage()).isEqualTo("Not found");
+ }
+
+ @Test
+ public void should_create_exception_with_status_and_l10n_message_with_param(){
+ ServerException exception = new ServerException(404, null, "key", new String[]{"value"});
+ assertThat(exception.httpCode()).isEqualTo(404);
+ assertThat(exception.l10nKey()).isEqualTo("key");
+ assertThat(exception.l10nParams()).containsOnly("value");
+ }
+
+ @Test
+ public void should_create_exception_with_status_and_l10n_message_without_param(){
+ ServerException exception = new ServerException(404, null, "key", null);
+ assertThat(exception.httpCode()).isEqualTo(404);
+ assertThat(exception.l10nKey()).isEqualTo("key");
+ assertThat(exception.l10nParams()).isEmpty();
+ }
+}