Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Annotate all the other exception mappers with @Provider to simplify t…
…he WildcardExceptionMapper. Resolves: https://www.pivotaltracker.com/s/projects/684825/stories/78554672
- Loading branch information
Showing
17 changed files
with
675 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...a/org/fcrepo/http/commons/exceptionhandlers/AccessControlJavaSecurityExceptionMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* Copyright 2014 DuraSpace, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.fcrepo.http.commons.exceptionhandlers; | ||
|
||
import static javax.ws.rs.core.Response.status; | ||
import static javax.ws.rs.core.Response.Status.FORBIDDEN; | ||
import static org.slf4j.LoggerFactory.getLogger; | ||
|
||
import java.security.AccessControlException; | ||
|
||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.ext.ExceptionMapper; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
import org.slf4j.Logger; | ||
|
||
/** | ||
* Translate Java Security AccessControlExceptions into HTTP 403 Forbidden errors | ||
* | ||
* @author lsitu | ||
* @author awoods | ||
* @author gregjan | ||
*/ | ||
@Provider | ||
public class AccessControlJavaSecurityExceptionMapper implements | ||
ExceptionMapper<AccessControlException> { | ||
|
||
private static final Logger LOGGER = | ||
getLogger(AccessControlJavaSecurityExceptionMapper.class); | ||
|
||
@Override | ||
public Response toResponse(final AccessControlException e) { | ||
LOGGER.debug("AccessControlJavaSecurityExceptionMapper intercepted exception: \n", | ||
e); | ||
|
||
return status(FORBIDDEN).build(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...src/main/java/org/fcrepo/http/commons/exceptionhandlers/DocumentStoreExceptionMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Copyright 2014 DuraSpace, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.fcrepo.http.commons.exceptionhandlers; | ||
|
||
import static javax.ws.rs.core.Response.status; | ||
import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR; | ||
import static org.slf4j.LoggerFactory.getLogger; | ||
|
||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.ext.ExceptionMapper; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
import org.modeshape.jcr.cache.DocumentStoreException; | ||
import org.slf4j.Logger; | ||
|
||
/** | ||
* Translate Modeshape jcr DocumentStoreException to HTTP 500 Internal Server Error | ||
* | ||
* @author lsitu | ||
*/ | ||
@Provider | ||
public class DocumentStoreExceptionMapper implements | ||
ExceptionMapper<DocumentStoreException> { | ||
|
||
private static final Logger LOGGER = | ||
getLogger(DocumentStoreExceptionMapper.class); | ||
|
||
@Override | ||
public Response toResponse(final DocumentStoreException e) { | ||
LOGGER.debug( | ||
"DocumentStoreException intercepted by DocumentStoreExceptionMapper: \n", e); | ||
return status(INTERNAL_SERVER_ERROR).build(); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
.../src/main/java/org/fcrepo/http/commons/exceptionhandlers/InvalidQueryExceptionMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Copyright 2014 DuraSpace, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.fcrepo.http.commons.exceptionhandlers; | ||
|
||
import static javax.ws.rs.core.Response.status; | ||
import static javax.ws.rs.core.Response.Status.BAD_REQUEST; | ||
import static org.slf4j.LoggerFactory.getLogger; | ||
|
||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.ext.ExceptionMapper; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
import org.modeshape.jcr.query.parse.InvalidQueryException; | ||
import org.slf4j.Logger; | ||
|
||
/** | ||
* Translate Modeshape jcr InvalidQueryException to HTTP 400 Bad Request | ||
* | ||
* @author lsitu | ||
*/ | ||
@Provider | ||
public class InvalidQueryExceptionMapper implements | ||
ExceptionMapper<InvalidQueryException> { | ||
|
||
private static final Logger LOGGER = | ||
getLogger(InvalidQueryExceptionMapper.class); | ||
|
||
@Override | ||
public Response toResponse(final InvalidQueryException e) { | ||
LOGGER.debug( | ||
"InvalidQueryException intercepted by InvalidQueryExceptionMapper: \n", e); | ||
return status(BAD_REQUEST).build(); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
.../src/main/java/org/fcrepo/http/commons/exceptionhandlers/ItemNotFoundExceptionMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Copyright 2014 DuraSpace, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.fcrepo.http.commons.exceptionhandlers; | ||
|
||
import static javax.ws.rs.core.Response.status; | ||
import static javax.ws.rs.core.Response.Status.NOT_FOUND; | ||
import static org.slf4j.LoggerFactory.getLogger; | ||
|
||
import javax.jcr.ItemNotFoundException; | ||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.ext.ExceptionMapper; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
import org.slf4j.Logger; | ||
|
||
/** | ||
* Translate jcr ItemNotFoundException to HTTP 404 Not Found | ||
* | ||
* @author lsitu | ||
*/ | ||
@Provider | ||
public class ItemNotFoundExceptionMapper implements | ||
ExceptionMapper<ItemNotFoundException> { | ||
|
||
private static final Logger LOGGER = | ||
getLogger(ItemNotFoundExceptionMapper.class); | ||
|
||
@Override | ||
public Response toResponse(final ItemNotFoundException e) { | ||
LOGGER.debug( | ||
"ItemNotFoundException intercepted by ItemNotFoundExceptionMapper: \n", e); | ||
return status(NOT_FOUND).build(); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
.../src/main/java/org/fcrepo/http/commons/exceptionhandlers/NodeNotFoundExceptionMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Copyright 2014 DuraSpace, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.fcrepo.http.commons.exceptionhandlers; | ||
|
||
import static javax.ws.rs.core.Response.status; | ||
import static javax.ws.rs.core.Response.Status.NOT_FOUND; | ||
import static org.slf4j.LoggerFactory.getLogger; | ||
|
||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.ext.ExceptionMapper; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
import org.modeshape.jcr.cache.NodeNotFoundException; | ||
import org.slf4j.Logger; | ||
|
||
/** | ||
* Translate Modeshape jcr NodeNotFoundException to HTTP 404 Not Found | ||
* | ||
* @author lsitu | ||
*/ | ||
@Provider | ||
public class NodeNotFoundExceptionMapper implements | ||
ExceptionMapper<NodeNotFoundException> { | ||
|
||
private static final Logger LOGGER = | ||
getLogger(NodeNotFoundExceptionMapper.class); | ||
|
||
@Override | ||
public Response toResponse(final NodeNotFoundException e) { | ||
LOGGER.debug( | ||
"NodeNotFoundException intercepted by NodeNotFoundExceptionMapper: \n", e); | ||
return status(NOT_FOUND).build(); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...s/src/main/java/org/fcrepo/http/commons/exceptionhandlers/ValueFormatExceptionMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Copyright 2014 DuraSpace, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.fcrepo.http.commons.exceptionhandlers; | ||
|
||
import static javax.ws.rs.core.Response.status; | ||
import static javax.ws.rs.core.Response.Status.BAD_REQUEST; | ||
import static org.slf4j.LoggerFactory.getLogger; | ||
|
||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.ext.ExceptionMapper; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
import org.modeshape.jcr.value.ValueFormatException; | ||
import org.slf4j.Logger; | ||
|
||
/** | ||
* Translate Modeshape jcr ValueFormatException to HTTP 400 Bad Request | ||
* | ||
* @author lsitu | ||
*/ | ||
@Provider | ||
public class ValueFormatExceptionMapper implements | ||
ExceptionMapper<ValueFormatException> { | ||
|
||
private static final Logger LOGGER = | ||
getLogger(ValueFormatExceptionMapper.class); | ||
|
||
@Override | ||
public Response toResponse(final ValueFormatException e) { | ||
LOGGER.debug( | ||
"ValueFormatException intercepted by ValueFormatExceptionMapper: \n", e); | ||
return status(BAD_REQUEST).build(); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...rc/main/java/org/fcrepo/http/commons/exceptionhandlers/WebApplicationExceptionMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* Copyright 2014 DuraSpace, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.fcrepo.http.commons.exceptionhandlers; | ||
|
||
import static org.slf4j.LoggerFactory.getLogger; | ||
|
||
import javax.ws.rs.WebApplicationException; | ||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.ext.ExceptionMapper; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
import org.slf4j.Logger; | ||
|
||
/** | ||
* Handle Jersey WebApplicationException | ||
* | ||
* @author lsitu | ||
*/ | ||
@Provider | ||
public class WebApplicationExceptionMapper implements | ||
ExceptionMapper<WebApplicationException> { | ||
|
||
private static final Logger LOGGER = | ||
getLogger(WebApplicationExceptionMapper.class); | ||
|
||
@Override | ||
public Response toResponse(final WebApplicationException e) { | ||
LOGGER.debug( | ||
"WebApplicationException intercepted by WebApplicationExceptionMapper: \n", e); | ||
return e.getResponse(); | ||
} | ||
} |
Oops, something went wrong.