directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject [1/2] directory-fortress-core git commit: o mapping exception to a suitable HTTP status code (FC-258) o updated FortResponse to contain a HTTP status code
Date Mon, 19 Nov 2018 16:14:27 GMT
Repository: directory-fortress-core
Updated Branches:
  refs/heads/master 64ff72730 -> 48d825b9f


o mapping exception to a suitable HTTP status code (FC-258)
o updated FortResponse to contain a HTTP status code


Project: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/commit/60301eca
Tree: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/tree/60301eca
Diff: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/diff/60301eca

Branch: refs/heads/master
Commit: 60301ecae59960e83a39443b5037e8e5b5c25a85
Parents: 9ee0748
Author: Kiran Ayyagari <kayyagari@apache.org>
Authored: Mon Nov 19 21:43:00 2018 +0530
Committer: Kiran Ayyagari <kayyagari@apache.org>
Committed: Mon Nov 19 21:43:00 2018 +0530

----------------------------------------------------------------------
 .../fortress/core/AuthorizationException.java   |  1 +
 .../directory/fortress/core/BaseException.java  | 17 ++++++++++++
 .../fortress/core/FinderException.java          |  2 ++
 .../fortress/core/PasswordException.java        |  1 +
 .../fortress/core/ValidationException.java      |  1 +
 .../fortress/core/model/FortResponse.java       | 28 ++++++++++++++++++++
 6 files changed, 50 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/60301eca/src/main/java/org/apache/directory/fortress/core/AuthorizationException.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/AuthorizationException.java
b/src/main/java/org/apache/directory/fortress/core/AuthorizationException.java
index bef290c..4ca4873 100755
--- a/src/main/java/org/apache/directory/fortress/core/AuthorizationException.java
+++ b/src/main/java/org/apache/directory/fortress/core/AuthorizationException.java
@@ -42,5 +42,6 @@ public class AuthorizationException extends SecurityException
     public AuthorizationException( int errorId, String msg )
     {
         super( errorId, msg );
+        setHttpStatus(403);
     }
 }

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/60301eca/src/main/java/org/apache/directory/fortress/core/BaseException.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/BaseException.java b/src/main/java/org/apache/directory/fortress/core/BaseException.java
index ff6aa84..d08838a 100755
--- a/src/main/java/org/apache/directory/fortress/core/BaseException.java
+++ b/src/main/java/org/apache/directory/fortress/core/BaseException.java
@@ -35,6 +35,7 @@ public abstract class BaseException extends Exception implements StandardExcepti
 
     private final int errorId;
 
+    private int httpStatus = 500; // default is mapped to server error
 
     /**
      * Create exception containing error code and message.
@@ -72,4 +73,20 @@ public abstract class BaseException extends Exception implements StandardExcepti
     {
         return errorId;
     }
+
+
+    /**
+     * Returns the HTTP Status code mapped to represent this error
+     * @return HTTP status code assigned for this exception
+     */
+    public int getHttpStatus()
+    {
+        return httpStatus;
+    }
+
+
+    public void setHttpStatus(int httpStatus)
+    {
+        this.httpStatus = httpStatus;
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/60301eca/src/main/java/org/apache/directory/fortress/core/FinderException.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/FinderException.java b/src/main/java/org/apache/directory/fortress/core/FinderException.java
index 4355b79..bacd5c1 100755
--- a/src/main/java/org/apache/directory/fortress/core/FinderException.java
+++ b/src/main/java/org/apache/directory/fortress/core/FinderException.java
@@ -42,6 +42,7 @@ public class FinderException extends SecurityException
     public FinderException( int errorId, String msg )
     {
         super( errorId, msg );
+        setHttpStatus(404);
     }
 
 
@@ -55,5 +56,6 @@ public class FinderException extends SecurityException
     public FinderException( int errorId, String msg, Exception previousException )
     {
         super( errorId, msg, previousException );
+        setHttpStatus(404);
     }
 }

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/60301eca/src/main/java/org/apache/directory/fortress/core/PasswordException.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/PasswordException.java b/src/main/java/org/apache/directory/fortress/core/PasswordException.java
index 224cf4a..1d1cb09 100755
--- a/src/main/java/org/apache/directory/fortress/core/PasswordException.java
+++ b/src/main/java/org/apache/directory/fortress/core/PasswordException.java
@@ -42,5 +42,6 @@ public class PasswordException extends SecurityException
     public PasswordException( int errorId, String msg )
     {
         super( errorId, msg );
+        setHttpStatus(400);
     }
 }

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/60301eca/src/main/java/org/apache/directory/fortress/core/ValidationException.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/ValidationException.java b/src/main/java/org/apache/directory/fortress/core/ValidationException.java
index a05646f..a69c05d 100755
--- a/src/main/java/org/apache/directory/fortress/core/ValidationException.java
+++ b/src/main/java/org/apache/directory/fortress/core/ValidationException.java
@@ -42,5 +42,6 @@ public class ValidationException extends SecurityException
     public ValidationException( int errorId, String msg )
     {
         super( errorId, msg );
+        setHttpStatus(400);
     }
 }

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/60301eca/src/main/java/org/apache/directory/fortress/core/model/FortResponse.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/model/FortResponse.java b/src/main/java/org/apache/directory/fortress/core/model/FortResponse.java
index bea185c..854a999 100755
--- a/src/main/java/org/apache/directory/fortress/core/model/FortResponse.java
+++ b/src/main/java/org/apache/directory/fortress/core/model/FortResponse.java
@@ -20,6 +20,9 @@
 package org.apache.directory.fortress.core.model;
 
 import javax.xml.bind.annotation.*;
+
+import org.apache.directory.fortress.core.GlobalErrIds;
+
 import java.util.List;
 import java.util.Set;
 
@@ -53,6 +56,7 @@ public class FortResponse
     private List<String> values;
     private Set<String> valueSet;
     private Session session;
+    private int httpStatus = -1; // the default value is set to an invalid value see #getHttpStatus()
for details
 
     public FortEntity getEntity()
     {
@@ -133,5 +137,29 @@ public class FortResponse
     {
         this.session = session;
     }
+
+    public int getHttpStatus()
+    {
+        // if this is not an error response and
+        // http status code is not set by the creator
+        // of this response then assume the status as
+        // http Success i.e 200 OK
+        if( errorCode == GlobalErrIds.NO_ERROR && httpStatus == -1 )
+        {
+            httpStatus = 200;
+        }
+        // if the errorCode is set but httpStatus is not then assume server error
+        else if( errorCode != GlobalErrIds.NO_ERROR && httpStatus == -1 )
+        {
+            httpStatus = 500;
+        }
+
+        return httpStatus;
+    }
+
+    public void setHttpStatus(int httpStatus)
+    {
+        this.httpStatus = httpStatus;
+    }
 }
 


Mime
View raw message