Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Improve error responses Resolves: https://www.pivotaltracker.com/story/show/82429414
- Loading branch information
1 parent
cd2d11c
commit 024b9b3
Showing
13 changed files
with
253 additions
and
18 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
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
54 changes: 54 additions & 0 deletions
54
.../org/fcrepo/http/commons/exceptionhandlers/InvalidSerializationFormatExceptionMapper.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,54 @@ | ||
/** | ||
* 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 org.fcrepo.serialization.InvalidSerializationFormatException; | ||
import org.slf4j.Logger; | ||
|
||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.ext.ExceptionMapper; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
import static javax.ws.rs.core.Response.Status.BAD_REQUEST; | ||
import static javax.ws.rs.core.Response.status; | ||
import static org.slf4j.LoggerFactory.getLogger; | ||
|
||
/** | ||
* Translate InvalidSerializationFormatException errors into reasonable | ||
* HTTP error codes | ||
* | ||
* @author md5wz | ||
* @since 11/17/14 | ||
*/ | ||
@Provider | ||
public class InvalidSerializationFormatExceptionMapper implements | ||
ExceptionMapper<InvalidSerializationFormatException> { | ||
|
||
private static final Logger LOGGER = | ||
getLogger(InvalidSerializationFormatExceptionMapper.class); | ||
|
||
@Override | ||
public Response toResponse(final InvalidSerializationFormatException e) { | ||
if (LOGGER.isDebugEnabled()) { | ||
LOGGER.debug("InvalidSerializationFormatException intercepted by InvalidSerializationFormatExceptionMapper" | ||
+ (e.getMessage() != null ? ": " + e.getMessage() : "."), e); | ||
} else { | ||
LOGGER.info("InvalidSerializationFormatException intercepted by InvalidSerializationFormatExceptionMapper" | ||
+ (e.getMessage() != null ? ": " + 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
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
37 changes: 37 additions & 0 deletions
37
...alization/src/main/java/org/fcrepo/serialization/InvalidSerializationFormatException.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,37 @@ | ||
/** | ||
* 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.serialization; | ||
|
||
/** | ||
* Exception thrown when during deserialization it becomes obvious that the | ||
* InputStream is not in the expected format. | ||
* | ||
* @author md5wz | ||
* @since November 2014 | ||
*/ | ||
public class InvalidSerializationFormatException extends Exception { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
/** | ||
* Exception with message | ||
* @param message | ||
*/ | ||
public InvalidSerializationFormatException(final String message) { | ||
super(message); | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<different> | ||
<xml /> | ||
</different> |
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 @@ | ||
<?xml version="1.0" encoding="UTF-8"?><sv:node xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:fedoraconfig="http://fedora.info/definitions/v4/config#" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:image="http://www.modeshape.org/images/1.0" xmlns:premis="http://www.loc.gov/premis/rdf/v1#" xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:mode="http://www.modeshape.org/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:sv="http://www.jcp.org/jcr/sv/1.0" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:fedora="http://fedora.info/definitions/v4/repository#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ldp="http://www.w3.org/ns/ldp#" sv:name="test"><sv:property sv:name="jcr:primaryType" sv:type="Name"><sv:value>nt:folder</sv:value></sv:property><sv:property sv:name="jcr:mixinTypes" sv:type="Name" sv:multiple="true"><sv:value>fedora:Container</sv:value><sv:value>fedora:Resource</sv:value></sv:property><sv:property sv:name="jcr:uuid" sv:type="String"><sv:value>bfb75d10-b5a1-4422-b137-6199043ef70b</sv:value></sv:property><sv:property sv:name="jcr:created" sv:type="Date"><sv:value>2014-11-14T09:19:01.049-05:00</sv:value></sv:property><sv:property sv:name="jcr:lastModified" sv:type="Date"><sv:value>2014-11-14T09:19:01.049-05:00</sv:value></sv:property><sv:property sv:name="jcr:lastModifiedBy" sv:type="String"><sv:value>bypassAdmin</sv:value></sv:property><sv:property sv:name="jcr:createdBy" sv:type="String"><sv:value>bypassAdmin</sv:value></sv:property></sv:node> |
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