From f8a5acfed995c46a853e4ddc6c3efe55b8b30c90 Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Wed, 20 Aug 2014 09:01:09 -0400 Subject: [PATCH] Exception enhancements --- .../exceptions/AuthenticationException.java | 4 +- .../BaseServerResponseException.java | 64 ++++++++++++++----- 2 files changed, 49 insertions(+), 19 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/exceptions/AuthenticationException.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/exceptions/AuthenticationException.java index c863964832e..ca8a931e68c 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/exceptions/AuthenticationException.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/exceptions/AuthenticationException.java @@ -1,7 +1,5 @@ package ca.uhn.fhir.rest.server.exceptions; -import java.text.ParseException; - import ca.uhn.fhir.rest.server.Constants; /* @@ -41,7 +39,7 @@ public class AuthenticationException extends BaseServerResponseException { super(STATUS_CODE, theMessage); } - public AuthenticationException(String theMessage, ParseException theCause) { + public AuthenticationException(String theMessage, Throwable theCause) { super(STATUS_CODE, theMessage, theCause); } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/exceptions/BaseServerResponseException.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/exceptions/BaseServerResponseException.java index c8a1dd95ea8..4725ef95c2b 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/exceptions/BaseServerResponseException.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/exceptions/BaseServerResponseException.java @@ -27,9 +27,8 @@ import ca.uhn.fhir.model.dstu.resource.OperationOutcome; */ /** - * Base class for RESTful client and server exceptions. RESTful client methods - * will only throw exceptions which are subclasses of this exception type, and - * RESTful server methods should also only call subclasses of this exception + * Base class for RESTful client and server exceptions. RESTful client methods will only throw exceptions which are + * subclasses of this exception type, and RESTful server methods should also only call subclasses of this exception * type. */ public abstract class BaseServerResponseException extends RuntimeException { @@ -50,10 +49,8 @@ public abstract class BaseServerResponseException extends RuntimeException { } private final OperationOutcome myOperationOutcome; - private String myResponseBody; private String myResponseMimeType; - private int myStatusCode; /** @@ -77,6 +74,9 @@ public abstract class BaseServerResponseException extends RuntimeException { * The HTTP status code corresponding to this problem * @param theMessage * The message + * @param theOperationOutcome + * An OperationOutcome resource to return to the calling client (in a server) or the OperationOutcome + * that was returned from the server (in a client) */ public BaseServerResponseException(int theStatusCode, String theMessage, OperationOutcome theOperationOutcome) { super(theMessage); @@ -100,6 +100,25 @@ public abstract class BaseServerResponseException extends RuntimeException { myOperationOutcome = null; } + /** + * Constructor + * + * @param theStatusCode + * The HTTP status code corresponding to this problem + * @param theMessage + * The message + * @param theCause + * The underlying cause exception + * @param theOperationOutcome + * An OperationOutcome resource to return to the calling client (in a server) or the OperationOutcome + * that was returned from the server (in a client) + */ + public BaseServerResponseException(int theStatusCode, String theMessage, Throwable theCause, OperationOutcome theOperationOutcome) { + super(theMessage, theCause); + myStatusCode = theStatusCode; + myOperationOutcome = theOperationOutcome; + } + /** * Constructor * @@ -115,17 +134,32 @@ public abstract class BaseServerResponseException extends RuntimeException { } /** - * Returns the {@link OperationOutcome} resource if any which was supplied - * in the response, or null + * Constructor + * + * @param theStatusCode + * The HTTP status code corresponding to this problem + * @param theCause + * The underlying cause exception + * @param theOperationOutcome + * An OperationOutcome resource to return to the calling client (in a server) or the OperationOutcome + * that was returned from the server (in a client) + */ + public BaseServerResponseException(int theStatusCode, Throwable theCause, OperationOutcome theOperationOutcome) { + super(theCause.toString(), theCause); + myStatusCode = theStatusCode; + myOperationOutcome = theOperationOutcome; + } + + /** + * Returns the {@link OperationOutcome} resource if any which was supplied in the response, or null */ public OperationOutcome getOperationOutcome() { return myOperationOutcome; } /** - * In a RESTful client, this method will be populated with the body of the - * HTTP respone if one was provided by the server, or null - * otherwise. + * In a RESTful client, this method will be populated with the body of the HTTP respone if one was provided by the + * server, or null otherwise. *

* In a restful server, this method is currently ignored. *

@@ -135,8 +169,8 @@ public abstract class BaseServerResponseException extends RuntimeException { } /** - * In a RESTful client, this method will be populated with the HTTP status - * code that was returned with the HTTP response. + * In a RESTful client, this method will be populated with the HTTP status code that was returned with the HTTP + * response. *

* In a restful server, this method is currently ignored. *

@@ -153,16 +187,14 @@ public abstract class BaseServerResponseException extends RuntimeException { } /** - * This method is currently only called internally by HAPI, it should not be - * called by user code. + * This method is currently only called internally by HAPI, it should not be called by user code. */ public void setResponseBody(String theResponseBody) { myResponseBody = theResponseBody; } /** - * This method is currently only called internally by HAPI, it should not be - * called by user code. + * This method is currently only called internally by HAPI, it should not be called by user code. */ public void setResponseMimeType(String theResponseMimeType) { myResponseMimeType = theResponseMimeType;