-
Notifications
You must be signed in to change notification settings - Fork 476
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7085 from GlobalDataverseCommunityConsortium/IQSS…
…/7060 Fix for #7060 direct download causes RedirectException
- Loading branch information
Showing
4 changed files
with
78 additions
and
7 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
39 changes: 39 additions & 0 deletions
39
.../java/edu/harvard/iq/dataverse/api/errorhandlers/InternalServerErrorExceptionHandler.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,39 @@ | ||
package edu.harvard.iq.dataverse.api.errorhandlers; | ||
|
||
import java.util.UUID; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
import javax.json.Json; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.ws.rs.InternalServerErrorException; | ||
import javax.ws.rs.core.Context; | ||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.ext.ExceptionMapper; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
/** | ||
* Produces custom 500 messages for the API. | ||
* @author qqmyers | ||
*/ | ||
@Provider | ||
public class InternalServerErrorExceptionHandler implements ExceptionMapper<InternalServerErrorException>{ | ||
|
||
private static final Logger logger = Logger.getLogger(InternalServerErrorExceptionHandler.class.getName()); | ||
|
||
@Context | ||
HttpServletRequest request; | ||
|
||
@Override | ||
public Response toResponse(InternalServerErrorException ex){ | ||
String incidentId = UUID.randomUUID().toString(); | ||
logger.log(Level.SEVERE, "API internal error " + incidentId +": " + ex.getMessage(), ex); | ||
return Response.status(500) | ||
.entity( Json.createObjectBuilder() | ||
.add("status", "ERROR") | ||
.add("code", 500) | ||
.add("message", "Internal server error. More details available at the server logs.") | ||
.add("incidentId", incidentId) | ||
.build()) | ||
.type("application/json").build(); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/edu/harvard/iq/dataverse/api/errorhandlers/RedirectionExceptionHandler.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,32 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package edu.harvard.iq.dataverse.api.errorhandlers; | ||
|
||
import edu.harvard.iq.dataverse.util.BundleUtil; | ||
import javax.json.Json; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.ws.rs.RedirectionException; | ||
import javax.ws.rs.core.Context; | ||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.ext.ExceptionMapper; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
/** | ||
* | ||
* @author qqmyers | ||
*/ | ||
@Provider | ||
public class RedirectionExceptionHandler implements ExceptionMapper<RedirectionException> { | ||
|
||
@Context | ||
HttpServletRequest request; | ||
|
||
@Override | ||
public Response toResponse(RedirectionException ex) { | ||
return ex.getResponse(); | ||
} | ||
|
||
} |