Return-Path: X-Original-To: apmail-directory-commits-archive@www.apache.org Delivered-To: apmail-directory-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3D1ED10187 for ; Tue, 5 Nov 2013 07:09:37 +0000 (UTC) Received: (qmail 11200 invoked by uid 500); 5 Nov 2013 07:09:35 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 11133 invoked by uid 500); 5 Nov 2013 07:09:31 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 11126 invoked by uid 99); 5 Nov 2013 07:09:29 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Nov 2013 07:09:29 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Nov 2013 07:09:28 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 288D523888A6; Tue, 5 Nov 2013 07:09:08 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@directory.apache.org From: kayyagari@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20131105070908.288D523888A6@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 Errors; + private List 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(); + Errors = new ArrayList(); } Errors.add( error ); @@ -68,7 +68,7 @@ public class ErrorResponse /** * @return the errors */ - public List getErrors() + public List getErrors() { return Errors; } @@ -77,12 +77,12 @@ public class ErrorResponse /** * @param errors the errors to set */ - public void setErrors( List errors ) + public void setErrors( List 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(); - } }