Repository: olingo-odata4
Updated Branches:
  refs/heads/master 29b169def -> ea89f7213


[OLINGO-663] Add new exceptiontext and right status code


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/ea89f721
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/ea89f721
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/ea89f721

Branch: refs/heads/master
Commit: ea89f7213e6cc0189a020f5161f0c1fb653b8597
Parents: 29b169d
Author: Christian Amend <[email protected]>
Authored: Thu May 28 11:02:18 2015 +0200
Committer: Christian Amend <[email protected]>
Committed: Thu May 28 11:02:18 2015 +0200

----------------------------------------------------------------------
 .../apache/olingo/server/api/CustomETagSupport.java |  2 +-
 .../olingo/server/core/ODataExceptionHelper.java    | 16 +++++++++++-----
 .../org/apache/olingo/server/core/ODataHandler.java |  5 ++++-
 .../server/core/PreconditionRequiredException.java  |  3 +--
 .../olingo/server/core/PreconditionsValidator.java  |  2 +-
 .../server-core-exceptions-i18n.properties          |  4 +++-
 .../server/core/PreconditionsValidatorTest.java     |  8 ++++----
 7 files changed, 25 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ea89f721/lib/server-api/src/main/java/org/apache/olingo/server/api/CustomETagSupport.java
----------------------------------------------------------------------
diff --git 
a/lib/server-api/src/main/java/org/apache/olingo/server/api/CustomETagSupport.java
 
b/lib/server-api/src/main/java/org/apache/olingo/server/api/CustomETagSupport.java
index 1cca8ab..2644b28 100644
--- 
a/lib/server-api/src/main/java/org/apache/olingo/server/api/CustomETagSupport.java
+++ 
b/lib/server-api/src/main/java/org/apache/olingo/server/api/CustomETagSupport.java
@@ -19,7 +19,7 @@
 package org.apache.olingo.server.api;
 
 /**
- * <p>Processors that would like to support concurrency control for certain 
entity sets can implement this
+ * <p>Processors that would like to support etags for certain entity sets can 
implement this
  * interface.</p>
  * <p>If implemented this interface can be registered at the ODataHttpHandler. 
This will result in change request to
  * require an if-match/if-none-match or an 
if-modified-since/if-unmodified-since header. Otherwise the request will

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ea89f721/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataExceptionHelper.java
----------------------------------------------------------------------
diff --git 
a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataExceptionHelper.java
 
b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataExceptionHelper.java
index 78a27ea..f7c2fe4 100644
--- 
a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataExceptionHelper.java
+++ 
b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataExceptionHelper.java
@@ -6,9 +6,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License. You may obtain a copy of the License at
- *
+ * 
  * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * 
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -54,12 +54,12 @@ public class ODataExceptionHelper {
   }
 
   public static ODataServerError
-  createServerErrorObject(final UriParserSyntaxException e, final Locale 
requestedLocale) {
+      createServerErrorObject(final UriParserSyntaxException e, final Locale 
requestedLocale) {
     ODataServerError serverError = basicTranslatedError(e, requestedLocale);
     serverError.setStatusCode(
         
UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT.equals(e.getMessageKey())
 ?
             HttpStatusCode.NOT_ACCEPTABLE.getStatusCode() :
-              HttpStatusCode.BAD_REQUEST.getStatusCode());
+            HttpStatusCode.BAD_REQUEST.getStatusCode());
     return serverError;
   }
 
@@ -103,8 +103,14 @@ public class ODataExceptionHelper {
         .setStatusCode(HttpStatusCode.BAD_REQUEST.getStatusCode());
   }
 
+  public static ODataServerError createServerErrorObject(final 
PreconditionRequiredException e,
+      final Locale requestedLocale) {
+    return basicTranslatedError(e, requestedLocale)
+        .setStatusCode(HttpStatusCode.PRECONDITION_REQUIRED.getStatusCode());
+  }
+
   public static ODataServerError
-  createServerErrorObject(final ODataTranslatedException e, final Locale 
requestedLocale) {
+      createServerErrorObject(final ODataTranslatedException e, final Locale 
requestedLocale) {
     return basicTranslatedError(e, requestedLocale);
   }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ea89f721/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java
----------------------------------------------------------------------
diff --git 
a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java 
b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java
index b1beaea..b43497f 100644
--- 
a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java
+++ 
b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java
@@ -93,7 +93,10 @@ public class ODataHandler {
     } catch (DeserializerException e) {
       ODataServerError serverError = 
ODataExceptionHelper.createServerErrorObject(e, null);
       handleException(request, response, serverError);
-    } catch (ODataHandlerException e) {
+    } catch (PreconditionRequiredException e) {
+      ODataServerError serverError = 
ODataExceptionHelper.createServerErrorObject(e, null);
+      handleException(request, response, serverError);
+    }catch (ODataHandlerException e) {
       ODataServerError serverError = 
ODataExceptionHelper.createServerErrorObject(e, null);
       handleException(request, response, serverError);
     } catch (ODataApplicationException e) {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ea89f721/lib/server-core/src/main/java/org/apache/olingo/server/core/PreconditionRequiredException.java
----------------------------------------------------------------------
diff --git 
a/lib/server-core/src/main/java/org/apache/olingo/server/core/PreconditionRequiredException.java
 
b/lib/server-core/src/main/java/org/apache/olingo/server/core/PreconditionRequiredException.java
index a9b6754..4fb527f 100644
--- 
a/lib/server-core/src/main/java/org/apache/olingo/server/core/PreconditionRequiredException.java
+++ 
b/lib/server-core/src/main/java/org/apache/olingo/server/core/PreconditionRequiredException.java
@@ -24,8 +24,7 @@ public class PreconditionRequiredException extends 
ODataTranslatedException {
   private static final long serialVersionUID = -8112658467394158700L;
 
   public static enum MessageKeys implements MessageKey {
-    /** parameter: required header */
-    PRECONDITION_REQUIRED;
+    MISSING_HEADER;
 
     @Override
     public String getKey() {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ea89f721/lib/server-core/src/main/java/org/apache/olingo/server/core/PreconditionsValidator.java
----------------------------------------------------------------------
diff --git 
a/lib/server-core/src/main/java/org/apache/olingo/server/core/PreconditionsValidator.java
 
b/lib/server-core/src/main/java/org/apache/olingo/server/core/PreconditionsValidator.java
index fe1875e..81be05b 100644
--- 
a/lib/server-core/src/main/java/org/apache/olingo/server/core/PreconditionsValidator.java
+++ 
b/lib/server-core/src/main/java/org/apache/olingo/server/core/PreconditionsValidator.java
@@ -60,7 +60,7 @@ public class PreconditionsValidator {
   private void checkETagHeaderPresent() throws PreconditionRequiredException {
     if (ifMatch == null && ifNoneMatch == null) {
       throw new PreconditionRequiredException("Expected an if-match or 
if-none-match header",
-          PreconditionRequiredException.MessageKeys.PRECONDITION_REQUIRED);
+          PreconditionRequiredException.MessageKeys.MISSING_HEADER);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ea89f721/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
----------------------------------------------------------------------
diff --git 
a/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties 
b/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
index 2bca286..9455c05 100644
--- a/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
+++ b/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
@@ -142,4 +142,6 @@ BatchDeserializerException.MISSING_CONTENT_TYPE=Missing 
content-type at line '%1
 BatchDeserializerException.MISSING_MANDATORY_HEADER=Missing mandatory header 
at line '%1$s'.
 BatchDeserializerException.INVALID_BASE_URI=The base URI do not match the 
service base URI  at line '%1$s'.
  
-BatchSerializerExecption.MISSING_CONTENT_ID=Each request within a change set 
required exactly one content id.
\ No newline at end of file
+BatchSerializerExecption.MISSING_CONTENT_ID=Each request within a change set 
required exactly one content id.
+
+PreconditionRequiredException.MISSING_HEADER=The Operation you requested on 
this Entity requires an if-match or if-none-match header.
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ea89f721/lib/server-test/src/test/java/org/apache/olingo/server/core/PreconditionsValidatorTest.java
----------------------------------------------------------------------
diff --git 
a/lib/server-test/src/test/java/org/apache/olingo/server/core/PreconditionsValidatorTest.java
 
b/lib/server-test/src/test/java/org/apache/olingo/server/core/PreconditionsValidatorTest.java
index 3a1c131..3dc07c7 100644
--- 
a/lib/server-test/src/test/java/org/apache/olingo/server/core/PreconditionsValidatorTest.java
+++ 
b/lib/server-test/src/test/java/org/apache/olingo/server/core/PreconditionsValidatorTest.java
@@ -69,7 +69,7 @@ public class PreconditionsValidatorTest {
       new PreconditionsValidator(new ETagSupport(), uriInfo, null, 
null).validatePreconditions(false);
       fail("Expected a PreconditionRequiredException but was not thrown");
     } catch (PreconditionRequiredException e) {
-      
assertEquals(PreconditionRequiredException.MessageKeys.PRECONDITION_REQUIRED, 
e.getMessageKey());
+      assertEquals(PreconditionRequiredException.MessageKeys.MISSING_HEADER, 
e.getMessageKey());
     }
   }
 
@@ -81,7 +81,7 @@ public class PreconditionsValidatorTest {
       new PreconditionsValidator(new ETagSupport("ESKeyNav"), uriInfo, null, 
null).validatePreconditions(false);
       fail("Expected a PreconditionRequiredException but was not thrown");
     } catch (PreconditionRequiredException e) {
-      
assertEquals(PreconditionRequiredException.MessageKeys.PRECONDITION_REQUIRED, 
e.getMessageKey());
+      assertEquals(PreconditionRequiredException.MessageKeys.MISSING_HEADER, 
e.getMessageKey());
     }
   }
 
@@ -92,7 +92,7 @@ public class PreconditionsValidatorTest {
       new PreconditionsValidator(new ETagSupport(), uriInfo, null, 
null).validatePreconditions(true);
       fail("Expected a PreconditionRequiredException but was not thrown");
     } catch (PreconditionRequiredException e) {
-      
assertEquals(PreconditionRequiredException.MessageKeys.PRECONDITION_REQUIRED, 
e.getMessageKey());
+      assertEquals(PreconditionRequiredException.MessageKeys.MISSING_HEADER, 
e.getMessageKey());
     }
   }
 
@@ -103,7 +103,7 @@ public class PreconditionsValidatorTest {
       new PreconditionsValidator(new ETagSupport(), uriInfo, null, 
null).validatePreconditions(false);
       fail("Expected a PreconditionRequiredException but was not thrown");
     } catch (PreconditionRequiredException e) {
-      
assertEquals(PreconditionRequiredException.MessageKeys.PRECONDITION_REQUIRED, 
e.getMessageKey());
+      assertEquals(PreconditionRequiredException.MessageKeys.MISSING_HEADER, 
e.getMessageKey());
     }
   }
 

Reply via email to