directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r1538881 - in /directory/escimo/trunk: common/src/main/java/org/apache/directory/scim/ schema/src/main/java/org/apache/directory/scim/schema/ server/src/main/java/org/apache/directory/scim/rest/
Date Tue, 05 Nov 2013 07:09:07 GMT
Author: kayyagari
Date: Tue Nov  5 07:09:07 2013
New Revision: 1538881

URL: http://svn.apache.org/r1538881
Log:
improved error handling

Modified:
    directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/ScimUtil.java
    directory/escimo/trunk/schema/src/main/java/org/apache/directory/scim/schema/ErrorResponse.java
    directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/GroupService.java
    directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/UserService.java

Modified: directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/ScimUtil.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/ScimUtil.java?rev=1538881&r1=1538880&r2=1538881&view=diff
==============================================================================
--- directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/ScimUtil.java (original)
+++ directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/ScimUtil.java Tue
Nov  5 07:09:07 2013
@@ -33,6 +33,7 @@ import javax.ws.rs.core.Response.Respons
 import org.apache.directory.scim.json.ResourceSerializer;
 import org.apache.directory.scim.schema.ErrorCode;
 import org.apache.directory.scim.schema.ErrorResponse;
+import org.apache.directory.scim.schema.ErrorResponse.ScimError;
 
 /**
  * 
@@ -95,7 +96,7 @@ public class ScimUtil
             desc = ec.getDesc();
         }
         
-        ErrorResponse.Error error = new ErrorResponse.Error( ec.getVal(), desc );
+        ErrorResponse.ScimError error = new ErrorResponse.ScimError( ec.getVal(), desc );
         
         error.setStackTrace( exceptionToStr( e ) );
         
@@ -107,4 +108,17 @@ public class ScimUtil
         
         return rb;
     }
+
+    
+    public static Response sendBadRequest( String message )
+    {
+        ScimError err = new ScimError( ErrorCode.BAD_REQUEST, message );
+        
+        ErrorResponse resp = new ErrorResponse( err );
+        String json = ResourceSerializer.serialize( resp );
+        ResponseBuilder rb = Response.status( err.getCode() ).entity( json );
+        
+        return rb.build();
+    }
+    
 }

Modified: directory/escimo/trunk/schema/src/main/java/org/apache/directory/scim/schema/ErrorResponse.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/schema/src/main/java/org/apache/directory/scim/schema/ErrorResponse.java?rev=1538881&r1=1538880&r2=1538881&view=diff
==============================================================================
--- directory/escimo/trunk/schema/src/main/java/org/apache/directory/scim/schema/ErrorResponse.java
(original)
+++ directory/escimo/trunk/schema/src/main/java/org/apache/directory/scim/schema/ErrorResponse.java
Tue Nov  5 07:09:07 2013
@@ -31,14 +31,14 @@ import java.util.List;
  */
 public class ErrorResponse
 {
-    public static final String SCHEMA_ID = "urn:scim:schemas:core:2.0:Error";
+    public static final String SCHEMA_ID = "urn:scim:schemas:core:2.0:ScimError";
 
     // named the variable with uppercase 'E'
     // to allow direct serialization using Gson
-    private List<Error> Errors;
+    private List<ScimError> Errors;
 
 
-    public ErrorResponse( Error error )
+    public ErrorResponse( ScimError error )
     {
         addError( error );
     }
@@ -54,11 +54,11 @@ public class ErrorResponse
         return Errors.get( 0 ).getDescription();
     }
 
-    public void addError( Error error )
+    public void addError( ScimError error )
     {
         if ( Errors == null )
         {
-            Errors = new ArrayList<Error>();
+            Errors = new ArrayList<ScimError>();
         }
 
         Errors.add( error );
@@ -68,7 +68,7 @@ public class ErrorResponse
     /**
      * @return the errors
      */
-    public List<Error> getErrors()
+    public List<ScimError> getErrors()
     {
         return Errors;
     }
@@ -77,12 +77,12 @@ public class ErrorResponse
     /**
      * @param errors the errors to set
      */
-    public void setErrors( List<Error> errors )
+    public void setErrors( List<ScimError> errors )
     {
         this.Errors = errors;
     }
 
-    public static class Error
+    public static class ScimError
     {
         private String description;
         
@@ -92,7 +92,12 @@ public class ErrorResponse
         // debugging purpose
         private String stackTrace;
 
-        public Error( int code, String description )
+        public ScimError( ErrorCode code, String description )
+        {
+            this( code.getVal(), description );
+        }
+        
+        public ScimError( int code, String description )
         {
             this.code = code;
             this.description = description;

Modified: directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/GroupService.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/GroupService.java?rev=1538881&r1=1538880&r2=1538881&view=diff
==============================================================================
--- directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/GroupService.java
(original)
+++ directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/GroupService.java
Tue Nov  5 07:09:07 2013
@@ -20,7 +20,7 @@
 package org.apache.directory.scim.rest;
 
 
-import static org.apache.directory.scim.ScimUtil.exceptionToStr;
+import static org.apache.directory.scim.ScimUtil.*;
 
 import java.net.URI;
 
@@ -78,7 +78,7 @@ public class GroupService
         }
         catch( ResourceNotFoundException e )
         {
-            rb = Response.status( Status.INTERNAL_SERVER_ERROR ).entity( exceptionToStr(
e ) );
+            rb = buildError( e );
         }
         
         return rb.build();
@@ -97,7 +97,7 @@ public class GroupService
         }
         catch( Exception e )
         {
-            rb = Response.status( Status.INTERNAL_SERVER_ERROR ).entity( exceptionToStr(
e ) );
+            rb = buildError( e );
         }
         
         return rb.build();
@@ -112,8 +112,7 @@ public class GroupService
 
         if( ( jsonData == null ) || ( jsonData.trim().length() == 0 ) )
         {
-            rb = Response.status( Status.BAD_REQUEST ).entity( "No data is present with the
call to " + uriInfo.getAbsolutePath() );
-            return rb.build();
+            return sendBadRequest( "No data is present with the call to " + uriInfo.getAbsolutePath()
);
         }
         
         LOG.debug( "Data received at the URI {}\n{}", uriInfo.getAbsolutePath(), jsonData
);
@@ -134,7 +133,7 @@ public class GroupService
         }
         catch( Exception e )
         {
-            rb = Response.status( Status.INTERNAL_SERVER_ERROR ).entity( exceptionToStr(
e ) );
+            rb = buildError( e );
         }
         
         return rb.build();
@@ -150,8 +149,7 @@ public class GroupService
 
         if( ( jsonData == null ) || ( jsonData.trim().length() == 0 ) )
         {
-            rb = Response.status( Status.BAD_REQUEST ).entity( "No data is present with the
call to " + uriInfo.getAbsolutePath() );
-            return rb.build();
+            return sendBadRequest( "No data is present with the call to " + uriInfo.getAbsolutePath()
);
         }
         
         LOG.debug( "Data received at the URI {}\n{}", uriInfo.getAbsolutePath(), jsonData
);
@@ -170,7 +168,7 @@ public class GroupService
         }
         catch( Exception e )
         {
-            rb = Response.status( Status.INTERNAL_SERVER_ERROR ).entity( exceptionToStr(
e ) );
+            rb = buildError( e );
         }
         
         return rb.build();
@@ -185,8 +183,7 @@ public class GroupService
 
         if( ( jsonData == null ) || ( jsonData.trim().length() == 0 ) )
         {
-            rb = Response.status( Status.BAD_REQUEST ).entity( "No data is present with the
call to " + uriInfo.getAbsolutePath() );
-            return rb.build();
+            return sendBadRequest( "No data is present with the call to " + uriInfo.getAbsolutePath()
);
         }
         
         LOG.debug( "Data received at the URI {}\n{}", uriInfo.getAbsolutePath(), jsonData
);
@@ -207,13 +204,9 @@ public class GroupService
                 rb = Response.ok().entity( json );
             }
         }
-        catch( AttributeNotFoundException e )
-        {
-            rb = Response.status( Status.NOT_FOUND ).entity( exceptionToStr( e ) );
-        }
         catch( Exception e )
         {
-            rb = Response.status( Status.INTERNAL_SERVER_ERROR ).entity( exceptionToStr(
e ) );
+            rb = buildError( e );
         }
         
         return rb.build();

Modified: directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/UserService.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/UserService.java?rev=1538881&r1=1538880&r2=1538881&view=diff
==============================================================================
--- directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/UserService.java
(original)
+++ directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/UserService.java
Tue Nov  5 07:09:07 2013
@@ -18,6 +18,8 @@
  */
 package org.apache.directory.scim.rest;
 
+import static org.apache.directory.scim.ScimUtil.*;
+
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -45,7 +47,6 @@ import org.apache.directory.scim.ListRes
 import org.apache.directory.scim.MissingParameterException;
 import org.apache.directory.scim.ProviderService;
 import org.apache.directory.scim.RequestContext;
-import org.apache.directory.scim.ScimUtil;
 import org.apache.directory.scim.ServerResource;
 import org.apache.directory.scim.UserResource;
 import org.apache.directory.scim.json.ResourceSerializer;
@@ -81,7 +82,7 @@ public class UserService
         }
         catch( Exception e )
         {
-            rb = ScimUtil.buildError( e );
+            rb = buildError( e );
         }
         
         return rb.build();
@@ -100,7 +101,7 @@ public class UserService
         }
         catch( Exception e )
         {
-            rb = ScimUtil.buildError( e );
+            rb = buildError( e );
         }
         
         return rb.build();
@@ -115,8 +116,7 @@ public class UserService
 
         if( ( jsonData == null ) || ( jsonData.trim().length() == 0 ) )
         {
-            rb = Response.status( Status.BAD_REQUEST ).entity( "No data is present with the
call to " + uriInfo.getAbsolutePath() );
-            return rb.build();
+            return sendBadRequest( "No data is present with the call to " + uriInfo.getAbsolutePath()
);
         }
         
         LOG.debug( "Data received at the URI {}\n{}", uriInfo.getAbsolutePath(), jsonData
);
@@ -137,7 +137,7 @@ public class UserService
         }
         catch( Exception e )
         {
-            rb = ScimUtil.buildError( e );
+            rb = buildError( e );
         }
         
         return rb.build();
@@ -153,8 +153,7 @@ public class UserService
 
         if( ( jsonData == null ) || ( jsonData.trim().length() == 0 ) )
         {
-            rb = Response.status( Status.BAD_REQUEST ).entity( "No data is present with the
call to " + uriInfo.getAbsolutePath() );
-            return rb.build();
+            return sendBadRequest( "No data is present with the call to " + uriInfo.getAbsolutePath()
);
         }
         
         LOG.debug( "Data received at the URI {}\n{}", uriInfo.getAbsolutePath(), jsonData
);
@@ -173,7 +172,7 @@ public class UserService
         }
         catch( Exception e )
         {
-            rb = ScimUtil.buildError( e );
+            rb = buildError( e );
         }
         
         return rb.build();
@@ -189,8 +188,7 @@ public class UserService
 
         if( ( jsonData == null ) || ( jsonData.trim().length() == 0 ) )
         {
-            rb = Response.status( Status.BAD_REQUEST ).entity( "No data is present with the
call to " + uriInfo.getAbsolutePath() );
-            return rb.build();
+            return sendBadRequest( "No data is present with the call to " + uriInfo.getAbsolutePath()
);
         }
         
         LOG.debug( "Data received at the URI {}\n{}", uriInfo.getAbsolutePath(), jsonData
);
@@ -213,7 +211,7 @@ public class UserService
         }
         catch( Exception e )
         {
-            rb = ScimUtil.buildError( e );
+            rb = buildError( e );
         }
         
         return rb.build();
@@ -229,8 +227,7 @@ public class UserService
         if( ( ( filter == null ) || ( filter.trim().length() == 0 ) ) &&
             ( ( attributes == null ) || ( attributes.trim().length() == 0 ) ) )
         {
-            rb = Response.status( Status.BAD_REQUEST ).entity( "Neither filter nor attributes
parameters are present with the call to " + uriInfo.getAbsolutePath() );
-            return rb.build();
+            return sendBadRequest( "Neither filter nor attributes parameters are present
with the call to " + uriInfo.getAbsolutePath() );
         }
         
         LOG.debug( "Filter : {}", filter );
@@ -246,7 +243,7 @@ public class UserService
         }
         catch( Exception e )
         {
-            rb = ScimUtil.buildError( e );
+            rb = buildError( e );
         }
 
         return rb.build();
@@ -301,10 +298,9 @@ public class UserService
         }
         catch( MissingParameterException e )
         {
-            rb = ScimUtil.buildError( e );
+            rb = buildError( e );
         }
         
         return rb.build();
-
     }
 }



Mime
View raw message