Skip to content

Commit 0600896

Browse files
ahornaceVladimir Kotal
authored andcommitted
Add generic exception mapper for REST API
1 parent d14d7a6 commit 0600896

File tree

7 files changed

+49
-7
lines changed

7 files changed

+49
-7
lines changed

src/org/opensolaris/opengrok/web/constraints/PositiveDuration.java renamed to src/org/opensolaris/opengrok/web/api/constraints/PositiveDuration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
/*
2121
* Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
2222
*/
23-
package org.opensolaris.opengrok.web.constraints;
23+
package org.opensolaris.opengrok.web.api.constraints;
2424

2525
import javax.validation.Constraint;
2626
import javax.validation.Payload;

src/org/opensolaris/opengrok/web/constraints/PositiveDurationValidator.java renamed to src/org/opensolaris/opengrok/web/api/constraints/PositiveDurationValidator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
/*
2121
* Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
2222
*/
23-
package org.opensolaris.opengrok.web.constraints;
23+
package org.opensolaris.opengrok.web.api.constraints;
2424

2525
import javax.validation.ConstraintValidator;
2626
import javax.validation.ConstraintValidatorContext;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* See LICENSE.txt included in this distribution for the specific
9+
* language governing permissions and limitations under the License.
10+
*
11+
* When distributing Covered Code, include this CDDL HEADER in each
12+
* file and include the License file at LICENSE.txt.
13+
* If applicable, add the following below this CDDL HEADER, with the
14+
* fields enclosed by brackets "[]" replaced with your own identifying
15+
* information: Portions Copyright [yyyy] [name of copyright owner]
16+
*
17+
* CDDL HEADER END
18+
*/
19+
20+
/*
21+
* Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
22+
*/
23+
package org.opensolaris.opengrok.web.api.error;
24+
25+
import javax.ws.rs.core.MediaType;
26+
import javax.ws.rs.core.Response;
27+
import javax.ws.rs.ext.ExceptionMapper;
28+
import javax.ws.rs.ext.Provider;
29+
30+
@Provider
31+
public class GenericExceptionMapper implements ExceptionMapper<Exception> {
32+
33+
@Override
34+
public Response toResponse(final Exception e) {
35+
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
36+
.entity(e.getMessage())
37+
.type(MediaType.TEXT_PLAIN)
38+
.build();
39+
}
40+
41+
}

src/org/opensolaris/opengrok/web/constraints/ValidationExceptionMapper.java renamed to src/org/opensolaris/opengrok/web/api/error/ValidationExceptionMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
/*
2121
* Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
2222
*/
23-
package org.opensolaris.opengrok.web.constraints;
23+
package org.opensolaris.opengrok.web.api.error;
2424

2525
import javax.validation.ValidationException;
2626
import javax.ws.rs.core.MediaType;

src/org/opensolaris/opengrok/web/api/v1/RestApp.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public class RestApp extends ResourceConfig {
3232
public static final String API_PATH = "/api/v1";
3333

3434
public RestApp() {
35-
packages("org.opensolaris.opengrok.web.api.v1.controller", "org.opensolaris.opengrok.web.api.v1.filter");
35+
packages("org.opensolaris.opengrok.web.api.constraints", "org.opensolaris.opengrok.web.api.error");
36+
packages(true, "org.opensolaris.opengrok.web.api.v1");
3637
}
3738

3839
}

src/org/opensolaris/opengrok/web/messages/Message.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
3333
import org.hibernate.validator.constraints.NotBlank;
3434
import org.hibernate.validator.constraints.NotEmpty;
35-
import org.opensolaris.opengrok.web.constraints.PositiveDuration;
35+
import org.opensolaris.opengrok.web.api.constraints.PositiveDuration;
3636

3737
import java.io.IOException;
3838
import java.time.Duration;

test/org/opensolaris/opengrok/web/constraint/PositiveDurationValidatorTest.java renamed to test/org/opensolaris/opengrok/web/api/constraint/PositiveDurationValidatorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
/*
2121
* Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
2222
*/
23-
package org.opensolaris.opengrok.web.constraint;
23+
package org.opensolaris.opengrok.web.api.constraint;
2424

2525
import org.junit.Test;
26-
import org.opensolaris.opengrok.web.constraints.PositiveDurationValidator;
26+
import org.opensolaris.opengrok.web.api.constraints.PositiveDurationValidator;
2727

2828
import java.time.Duration;
2929

0 commit comments

Comments
 (0)