Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Pre-validate paths for unregistered namespaces
- Add FedoraInvalidNamespaceException type - Add FedoraInvalidNamespaceExceptionMapper - Add new validatePath method to AbstractService - Fix Unit Test that require a mock NamespaceRegistry Resolves: https://www.pivotaltracker.com/story/show/61500426
- Loading branch information
Jared Whiklo
authored and
Andrew Woods
committed
Sep 19, 2014
1 parent
4762faa
commit f374560
Showing
5 changed files
with
175 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
...java/org/fcrepo/http/commons/exceptionhandlers/FedoraInvalidNamespaceExceptionMapper.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.fcrepo.kernel.exception.FedoraInvalidNamespaceException; | ||
|
||
import org.slf4j.Logger; | ||
|
||
/** | ||
* For invalid namespace exceptions on CRUD actions for nodes/datastreams | ||
* | ||
* @author whikloj | ||
* @since September 12, 2014 | ||
*/ | ||
@Provider | ||
public class FedoraInvalidNamespaceExceptionMapper implements ExceptionMapper<FedoraInvalidNamespaceException> { | ||
|
||
private static final Logger LOGGER = getLogger(FedoraInvalidNamespaceExceptionMapper.class); | ||
|
||
@Override | ||
public Response toResponse(final FedoraInvalidNamespaceException e) { | ||
LOGGER.trace("NamespaceExceptionMapper caught an exception: {}", e.getMessage()); | ||
return status(BAD_REQUEST).entity(e.getMessage()).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
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
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
48 changes: 48 additions & 0 deletions
48
fcrepo-kernel/src/main/java/org/fcrepo/kernel/exception/FedoraInvalidNamespaceException.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,48 @@ | ||
/** | ||
* 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.kernel.exception; | ||
|
||
|
||
/** | ||
* Indicates a namespace used in a CRUD request has not been registered in the repository | ||
* | ||
* @author whikloj | ||
* @since September 12, 2014 | ||
*/ | ||
public class FedoraInvalidNamespaceException extends RepositoryRuntimeException { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
/** | ||
* Ordinary constructor | ||
* | ||
* @param msg | ||
*/ | ||
public FedoraInvalidNamespaceException(final String msg) { | ||
super(msg); | ||
} | ||
|
||
/** | ||
* Ordinary constructor | ||
* | ||
* @param msg | ||
* @param rootCause | ||
*/ | ||
public FedoraInvalidNamespaceException(final String msg, final Throwable rootCause) { | ||
super(msg, rootCause); | ||
} | ||
|
||
} |