Skip to content

Commit

Permalink
Annotate all the other exception mappers with @Provider to simplify t…
Browse files Browse the repository at this point in the history
  • Loading branch information
lsitu authored and Andrew Woods committed Oct 13, 2014
1 parent 92e3fc2 commit b214e5c
Show file tree
Hide file tree
Showing 17 changed files with 675 additions and 42 deletions.
Expand Up @@ -29,6 +29,7 @@
/**
* Translate JCR AccessControlExceptions into HTTP 403 Forbidden errors
*
* @author lsitu
* @author awoods
* @author gregjan
*/
Expand All @@ -46,16 +47,4 @@ public Response toResponse(final AccessControlException e) {

return status(FORBIDDEN).build();
}

/**
* @param e
* @return forbidden response
*/
public Response toResponse(final java.security.AccessControlException e) {
LOGGER.debug("AccessControlExceptionMapper intercepted exception: \n",
e);

return status(FORBIDDEN).build();
}

}
@@ -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();
}

}
Expand Up @@ -21,13 +21,15 @@
import javax.jcr.AccessDeniedException;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* @author fasseg
*/
@Provider
public class AccessDeniedExceptionMapper implements
ExceptionMapper<AccessDeniedException> {

Expand Down
@@ -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();
}
}
@@ -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();
}
}
@@ -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();
}
}
@@ -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();
}
}
@@ -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();
}
}
@@ -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();
}
}

0 comments on commit b214e5c

Please sign in to comment.