You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ch...@apache.org on 2014/09/25 15:32:41 UTC

[2/3] git commit: better server error messages in case of $format errors

better server error messages in case of $format errors

Change-Id: If4495f5c91086618ee7d3824339aa5e7b99ff76c

Signed-off-by: Christian Amend <ch...@apache.org>


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

Branch: refs/heads/master
Commit: 788036db25637f9872c55346df208d4a0d4b93d4
Parents: f947afc
Author: Klaus Straubinger <kl...@sap.com>
Authored: Thu Sep 25 13:47:38 2014 +0200
Committer: Christian Amend <ch...@apache.org>
Committed: Thu Sep 25 15:26:24 2014 +0200

----------------------------------------------------------------------
 .../apache/olingo/server/core/ODataExceptionHelper.java   |  9 ++++-----
 .../org/apache/olingo/server/core/uri/parser/Parser.java  |  3 +--
 .../server/core/uri/parser/UriParserSyntaxException.java  |  2 +-
 .../main/resources/server-core-exceptions-i18n.properties |  2 +-
 .../server/core/uri/antlr/TestFullResourcePath.java       | 10 +++++-----
 5 files changed, 12 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/788036db/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 d0f248f..9b0ddfd 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
@@ -52,11 +52,10 @@ public class ODataExceptionHelper {
   
   public static ODataServerError createServerErrorObject(UriParserSyntaxException e, Locale requestedLocale) {
     ODataServerError serverError = basicTranslatedError(e, requestedLocale);
-    if(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_VALUE.equals(e.getMessageKey())){
-      serverError.setStatusCode(HttpStatusCode.NOT_ACCEPTABLE.getStatusCode());
-    }else{
-      serverError.setStatusCode(HttpStatusCode.BAD_REQUEST.getStatusCode());
-    }
+    serverError.setStatusCode(
+        UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT.equals(e.getMessageKey()) ?
+            HttpStatusCode.NOT_ACCEPTABLE.getStatusCode() :
+            HttpStatusCode.BAD_REQUEST.getStatusCode());
     return serverError;
   }
   

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/788036db/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java
index 016aeb9..c2be438 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java
@@ -188,8 +188,7 @@ public class Parser {
               formatOption.setFormat(option.value);
             } else {
               throw new UriParserSyntaxException("Illegal value of $format option!",
-                  UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_VALUE,
-                  option.name, option.value);
+                  UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT, option.value);
             }
             context.contextUriInfo.setSystemQueryOption(formatOption);
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/788036db/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSyntaxException.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSyntaxException.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSyntaxException.java
index e1506ee..454ed3b 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSyntaxException.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSyntaxException.java
@@ -28,7 +28,7 @@ public class UriParserSyntaxException extends UriParserException {
     /** parameters: query-option name, query-option value */ WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION,
     SYNTAX,
     SYSTEM_QUERY_OPTION_LEVELS_NOT_ALLOWED_HERE, 
-    /** parameter: query-option value */ WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_VALUE;
+    /** parameter: $format option value */ WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT;
 
     @Override
     public String getKey() {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/788036db/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 4695c73..57e805c 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
@@ -26,7 +26,7 @@ ODataHandlerException.ODATA_VERSION_NOT_SUPPORTED=OData version '%1$s' is not su
 
 UriParserSyntaxException.UNKNOWN_SYSTEM_QUERY_OPTION=The system query option '%1$s' is not defined.
 UriParserSyntaxException.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION=The system query option '%1$s' has the not-allowed value '%2$s'.
-UriParserSyntaxException.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_VALUE=The system query option $value must be either json, xml, atom or a valid content-type. The value '%1$s' is neither.
+UriParserSyntaxException.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT=The system query option '$format' must be either 'json', 'xml', 'atom', or a valid content type; the value '%1$s' is neither.
 UriParserSyntaxException.SYNTAX=The URI is malformed.
 UriParserSyntaxException.SYSTEM_QUERY_OPTION_LEVELS_NOT_ALLOWED_HERE=The system query option '$levels' is not allowed here.
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/788036db/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
index 5d7325b..856be6b 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
@@ -2553,15 +2553,15 @@ public class TestFullResourcePath {
         .isKind(UriInfoKind.resource).goPath()
         .isFormatText(HttpContentType.APPLICATION_ATOM_XML_ENTRY_UTF8);
     testUri.runEx("ESKeyNav(1)?$format=noSlash")
-        .isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_VALUE);
+        .isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT);
     testUri.runEx("ESKeyNav(1)?$format=slashAtEnd/")
-        .isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_VALUE);
+        .isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT);
     testUri.runEx("ESKeyNav(1)?$format=/startsWithSlash")
-        .isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_VALUE);
+        .isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT);
     testUri.runEx("ESKeyNav(1)?$format=two/Slashes/tooMuch")
-        .isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_VALUE);
+        .isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT);
     testUri.runEx("ESKeyNav(1)?$format=")
-        .isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_VALUE);
+        .isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT);
   }
 
   @Test