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/08/13 14:59:39 UTC
[2/2] git commit: translatable texts for all server exceptions
translatable texts for all server exceptions
Change-Id: I132aaedb302b7af7ba3457d978569d33a1399d6e
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/0a80d514
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/0a80d514
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/0a80d514
Branch: refs/heads/master
Commit: 0a80d5146b8946e1b87408e07ad00eed73b88f81
Parents: 7be1e99
Author: Klaus Straubinger <kl...@sap.com>
Authored: Wed Aug 13 14:11:25 2014 +0200
Committer: Christian Amend <ch...@apache.org>
Committed: Wed Aug 13 14:35:42 2014 +0200
----------------------------------------------------------------------
.../server/api/ODataTranslatedException.java | 27 +--
.../src/main/resources/i18n.properties | 40 -----
.../server/api/TranslatedExceptionsTest.java | 124 +++++++------
.../src/test/resources/i18n.properties | 21 +++
.../src/test/resources/i18n_de.properties | 3 +-
.../src/test/resources/i18n_en.properties | 6 +-
.../apache/olingo/server/core/ODataHandler.java | 38 ++--
.../server/core/ODataHandlerException.java | 44 +++++
.../server/core/ODataHttpHandlerImpl.java | 16 +-
.../olingo/server/core/uri/parser/Parser.java | 49 ++---
.../core/uri/parser/UriParseTreeVisitor.java | 142 ++++++++-------
.../core/uri/parser/UriParserException.java | 2 +-
.../uri/parser/UriParserSemanticException.java | 30 +++-
.../uri/parser/UriParserSyntaxException.java | 8 +-
.../uri/validator/UriValidationException.java | 2 +-
.../src/main/resources/i18n.properties | 87 +++++++++
.../tecsvc/processor/TechnicalProcessor.java | 20 ++-
.../core/uri/antlr/TestFullResourcePath.java | 177 +++++++++++--------
.../core/uri/antlr/TestUriParserImpl.java | 3 +-
.../core/uri/validator/UriValidatorTest.java | 7 +-
20 files changed, 521 insertions(+), 325 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0a80d514/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataTranslatedException.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataTranslatedException.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataTranslatedException.java
index 1dbb810..b7477b9 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataTranslatedException.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataTranslatedException.java
@@ -29,7 +29,7 @@ import org.apache.olingo.commons.api.ODataException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class ODataTranslatedException extends ODataException {
+public abstract class ODataTranslatedException extends ODataException {
private static final long serialVersionUID = -1210541002198287561L;
private static final Logger log = LoggerFactory.getLogger(ODataTranslatedException.class);
@@ -39,24 +39,16 @@ public class ODataTranslatedException extends ODataException {
protected static interface MessageKey {}
- public static enum MessageKeys implements MessageKey {
- AMBIGUOUS_XHTTP_METHOD,
- HTTP_METHOD_NOT_IMPLEMENTED,
- PROCESSOR_NOT_IMPLEMENTED,
- FUNCTIONALITY_NOT_IMPLEMENTED,
- ODATA_VERSION_NOT_SUPPORTED,
- }
-
private MessageKey messageKey;
private Object[] parameters;
- public ODataTranslatedException(String developmentMessage, MessageKey messageKey, String... parameters) {
+ protected ODataTranslatedException(String developmentMessage, MessageKey messageKey, String... parameters) {
super(developmentMessage);
this.messageKey = messageKey;
this.parameters = parameters;
}
- public ODataTranslatedException(String developmentMessage, Throwable cause, MessageKey messageKey,
+ protected ODataTranslatedException(String developmentMessage, Throwable cause, MessageKey messageKey,
String... parameters) {
super(developmentMessage, cause);
this.messageKey = messageKey;
@@ -90,17 +82,12 @@ public class ODataTranslatedException extends ODataException {
}
private ResourceBundle createResourceBundle(final Locale locale) {
- ResourceBundle bundle = null;
try {
- if (locale == null) {
- bundle = ResourceBundle.getBundle(BUNDLE_NAME, DEFAULT_LOCALE);
- } else {
- bundle = ResourceBundle.getBundle(BUNDLE_NAME, locale);
- }
- } catch (final Exception e) {
+ return ResourceBundle.getBundle(BUNDLE_NAME, locale == null ? DEFAULT_LOCALE : locale);
+ } catch (final MissingResourceException e) {
log.error(e.getMessage(), e);
+ return null;
}
- return bundle;
}
private ODataErrorMessage buildMessage(ResourceBundle bundle, Locale locale) {
@@ -113,7 +100,7 @@ public class ODataTranslatedException extends ODataException {
f.format(message, parameters);
f.close();
Locale usedLocale = bundle.getLocale();
- if (usedLocale == Locale.ROOT || Locale.ROOT.equals(usedLocale)) {
+ if (Locale.ROOT.equals(usedLocale)) {
usedLocale = DEFAULT_LOCALE;
}
return new ODataErrorMessage(builder.toString(), usedLocale);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0a80d514/lib/server-api/src/main/resources/i18n.properties
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/resources/i18n.properties b/lib/server-api/src/main/resources/i18n.properties
deleted file mode 100644
index 7a7fbe9..0000000
--- a/lib/server-api/src/main/resources/i18n.properties
+++ /dev/null
@@ -1,40 +0,0 @@
-#-------------------------------------------------------------------------------
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# 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
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#-------------------------------------------------------------------------------
-# Basic Apache Olingo exception messages
-#
-ODataTranslatedException.AMBIGUOUS_XHTTP_METHOD=x-http-method header '%1$s' and x-http-method-override header '%2$s' are not the same.
-ODataTranslatedException.HTTP_METHOD_NOT_IMPLEMENTED=Invalid HTTP method given: '%1$s'.
-ODataTranslatedException.PROCESSOR_NOT_IMPLEMENTED=No processor for interface '%1$s' registered.
-ODataTranslatedException.FUNCTIONALITY_NOT_IMPLEMENTED=The requested functionality has not been implemented (yet).
-ODataTranslatedException.ODATA_VERSION_NOT_SUPPORTED=OData version '%1$s' is not supported.
-ContentNegotiatorException.WRONG_CHARSET_IN_HEADER=The HTTP header '%1$s' with value '%2$s' contains an invalid character-set specification.
-ContentNegotiatorException.UNSUPPORTED_CONTENT_TYPES=The content-type range '%1$s' is not supported.
-ContentNegotiatorException.UNSUPPORTED_CONTENT_TYPE=The content type '%1$s' is not supported.
-ContentNegotiatorException.UNSUPPORTED_FORMAT_OPTION=The $format option '%1$s' is not supported.
-
-ODataSerializerException.NOT_IMPLEMENTED=The requested serialization method has not been implemented yet.
-ODataSerializerException.UNSUPPORTED_FORMAT=The format '%1$s' is not supported.
-ODataSerializerException.JSON_METADATA=The metadata document cannot be provided in JSON format.
-ODataSerializerException.IO_EXCEPTION=An I/O exception occurred.
-ODataSerializerException.NULL_INPUT=The input 'null' is not allowed here.
-ODataSerializerException.NO_CONTEXT_URL=No context URL has been provided.
-ODataSerializerException.UNSUPPORTED_PROPERTY_TYPE=The type of the property '%1$s' is not yet supported.
-ODataSerializerException.INCONSISTENT_PROPERTY_TYPE=An inconsistency has been detected in the type definition of property '%1$s'.
-ODataSerializerException.MISSING_PROPERTY=The non-nullable property '%1$s' is missing.
-ODataSerializerException.WRONG_PROPERTY_VALUE=The value '%2$s' is not valid for property '%1$s'.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0a80d514/lib/server-api/src/test/java/org/apache/olingo/server/api/TranslatedExceptionsTest.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/test/java/org/apache/olingo/server/api/TranslatedExceptionsTest.java b/lib/server-api/src/test/java/org/apache/olingo/server/api/TranslatedExceptionsTest.java
index ba145b9..5047f3e 100644
--- a/lib/server-api/src/test/java/org/apache/olingo/server/api/TranslatedExceptionsTest.java
+++ b/lib/server-api/src/test/java/org/apache/olingo/server/api/TranslatedExceptionsTest.java
@@ -18,9 +18,10 @@
*/
package org.apache.olingo.server.api;
+import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertThat;
import java.util.Locale;
@@ -30,112 +31,121 @@ import org.junit.Test;
public class TranslatedExceptionsTest {
private static final String DEV = "devMessage";
- private static enum Keys implements ODataTranslatedException.MessageKey {
- BASIC, ONEPARAM, TWOPARAM, NOMESSAGE
- }
- public TranslatedExceptionsTest() {
- // for test reason we assume a system with a default Locale.ENGLISH
- Locale.setDefault(Locale.ENGLISH);
+ private static class TestException extends ODataTranslatedException {
+ private static final long serialVersionUID = -7199975861656921724L;
+ public static enum Keys implements MessageKey {
+ BASIC, ONEPARAM, TWOPARAM, NOMESSAGE, ONLY_ROOT, ONLY_GERMAN
+ }
+ protected TestException(final MessageKey messageKey, final String... parameters) {
+ super(DEV, messageKey, parameters);
+ }
}
@Test
public void basic() {
- ODataTranslatedException exp = new ODataTranslatedException(DEV, Keys.BASIC);
+ TestException exp = new TestException(TestException.Keys.BASIC);
assertEquals(DEV, exp.getMessage());
-
- ODataErrorMessage translatedMessage = exp.getTranslatedMessage(null);
- assertNotNull(translatedMessage);
- assertEquals("Test Default", translatedMessage.getMessage());
-
- translatedMessage = exp.getTranslatedMessage(Locale.ENGLISH);
- assertNotNull(translatedMessage);
- assertEquals("Test Default", translatedMessage.getMessage());
- assertEquals(Locale.ENGLISH, translatedMessage.getLocale());
-
- translatedMessage = exp.getTranslatedMessage(Locale.UK);
- assertNotNull(translatedMessage);
- assertEquals("Test Default", translatedMessage.getMessage());
-
- translatedMessage = exp.getTranslatedMessage(Locale.GERMAN);
- assertNotNull(translatedMessage);
- assertEquals("Test DE", translatedMessage.getMessage());
- assertEquals(Locale.GERMAN, translatedMessage.getLocale());
-
- translatedMessage = exp.getTranslatedMessage(Locale.GERMANY);
- assertNotNull(translatedMessage);
- assertEquals("Test DE", translatedMessage.getMessage());
- assertEquals(Locale.GERMAN, translatedMessage.getLocale());
+ assertEquals(DEV, exp.toString());
+ assertEquals("Test Default", exp.getLocalizedMessage());
+ assertEquals(TestException.Keys.BASIC, exp.getMessageKey());
+
+ checkTranslatedMessage(exp.getTranslatedMessage(null), "Test Default", Locale.ENGLISH);
+ checkTranslatedMessage(exp.getTranslatedMessage(Locale.ENGLISH), "Test Default", Locale.ENGLISH);
+ checkTranslatedMessage(exp.getTranslatedMessage(Locale.UK), "Test Default", Locale.ENGLISH);
+ checkTranslatedMessage(exp.getTranslatedMessage(Locale.GERMAN), "Test DE", Locale.GERMAN);
+ checkTranslatedMessage(exp.getTranslatedMessage(Locale.GERMANY), "Test DE", Locale.GERMAN);
}
@Test
public void unusedParametersMustNotResultInAnException() {
- ODataTranslatedException exp = new ODataTranslatedException(DEV, Keys.BASIC, "unusedParam1", "unusedParam2");
+ TestException exp = new TestException(TestException.Keys.BASIC, "unusedParam1", "unusedParam2");
assertEquals(DEV, exp.getMessage());
-
- ODataErrorMessage translatedMessage = exp.getTranslatedMessage(null);
- assertNotNull(translatedMessage);
- assertEquals("Test Default", translatedMessage.getMessage());
+ checkTranslatedMessage(exp.getTranslatedMessage(null), "Test Default", Locale.ENGLISH);
}
@Test
public void useOneParameter() {
- ODataTranslatedException exp = new ODataTranslatedException(DEV, Keys.ONEPARAM, "usedParam1");
+ TestException exp = new TestException(TestException.Keys.ONEPARAM, "usedParam1");
assertEquals(DEV, exp.getMessage());
-
- ODataErrorMessage translatedMessage = exp.getTranslatedMessage(null);
- assertNotNull(translatedMessage);
- assertEquals("Param1: usedParam1", translatedMessage.getMessage());
+ checkTranslatedMessage(exp.getTranslatedMessage(null), "Param1: usedParam1", Locale.ENGLISH);
}
@Test
public void useOneParameterExpectedButMultipleGiven() {
- ODataTranslatedException exp = new ODataTranslatedException(DEV, Keys.ONEPARAM, "usedParam1", "unusedParam2");
+ TestException exp = new TestException(TestException.Keys.ONEPARAM, "usedParam1", "unusedParam2");
assertEquals(DEV, exp.getMessage());
+ checkTranslatedMessage(exp.getTranslatedMessage(null), "Param1: usedParam1", Locale.ENGLISH);
+ }
- ODataErrorMessage translatedMessage = exp.getTranslatedMessage(null);
- assertNotNull(translatedMessage);
- assertEquals("Param1: usedParam1", translatedMessage.getMessage());
+ @Test
+ public void useTwoParameters() {
+ TestException exp = new TestException(TestException.Keys.TWOPARAM, "usedParam1", "usedParam2");
+ assertEquals(DEV, exp.getMessage());
+ checkTranslatedMessage(exp.getTranslatedMessage(null), "Param1: usedParam1 Param2: usedParam2", Locale.ENGLISH);
}
@Test
- public void useTwoParameter() {
- ODataTranslatedException exp = new ODataTranslatedException(DEV, Keys.TWOPARAM, "usedParam1", "usedParam2");
+ public void parametersNotGivenAlthoughNeeded() {
+ TestException exp = new TestException(TestException.Keys.ONEPARAM);
assertEquals(DEV, exp.getMessage());
ODataErrorMessage translatedMessage = exp.getTranslatedMessage(null);
assertNotNull(translatedMessage);
- assertEquals("Param1: usedParam1 Param2: usedParam2", translatedMessage.getMessage());
+ assertThat(translatedMessage.getMessage(), containsString("Missing replacement for place holder in message"));
}
@Test
- public void parametersNotGivenAltoughNeeded() {
- ODataTranslatedException exp = new ODataTranslatedException(DEV, Keys.ONEPARAM);
+ public void noMessageKey() {
+ TestException exp = new TestException(null);
assertEquals(DEV, exp.getMessage());
ODataErrorMessage translatedMessage = exp.getTranslatedMessage(null);
assertNotNull(translatedMessage);
- assertTrue(translatedMessage.getMessage().contains("Missing replacement for place holder in message"));
+ assertEquals(DEV, translatedMessage.getMessage());
}
@Test
public void noMessageForKey() {
- ODataTranslatedException exp = new ODataTranslatedException(DEV, Keys.NOMESSAGE);
+ TestException exp = new TestException(TestException.Keys.NOMESSAGE);
assertEquals(DEV, exp.getMessage());
ODataErrorMessage translatedMessage = exp.getTranslatedMessage(null);
assertNotNull(translatedMessage);
- assertTrue(translatedMessage.getMessage().contains("Missing message for key"));
+ assertThat(translatedMessage.getMessage(), containsString("Missing message for key"));
}
@Test
public void keyForRootBundleButNotPresentInDerivedBundle() {
- ODataTranslatedException exp =
- new ODataTranslatedException(DEV, ODataTranslatedException.MessageKeys.HTTP_METHOD_NOT_IMPLEMENTED, "param1");
+ TestException exp = new TestException(TestException.Keys.ONLY_ROOT);
+ assertEquals(DEV, exp.getMessage());
+
+ checkTranslatedMessage(exp.getTranslatedMessage(Locale.GERMAN), "Root message", Locale.GERMAN);
+ checkTranslatedMessage(exp.getTranslatedMessage(Locale.ROOT), "Root message", Locale.ENGLISH);
+ }
+
+ @Test
+ public void defaultLocale() {
+ TestException exp = new TestException(TestException.Keys.ONLY_GERMAN);
assertEquals(DEV, exp.getMessage());
- ODataErrorMessage translatedMessage = exp.getTranslatedMessage(Locale.GERMAN);
+ Locale.setDefault(Locale.GERMAN);
+ ODataErrorMessage translatedMessage = exp.getTranslatedMessage(null);
+ assertNotNull(translatedMessage);
+ assertThat(translatedMessage.getMessage(), containsString("Missing message for key"));
+ assertEquals(Locale.ENGLISH, translatedMessage.getLocale());
+
+ Locale.setDefault(Locale.ENGLISH);
+ translatedMessage = exp.getTranslatedMessage(null);
+ assertNotNull(translatedMessage);
+ assertThat(translatedMessage.getMessage(), containsString("Missing message for key"));
+ assertEquals(Locale.ENGLISH, translatedMessage.getLocale());
+ }
+
+ private void checkTranslatedMessage(final ODataErrorMessage translatedMessage,
+ final String expectedText, final Locale expectedLocale) {
assertNotNull(translatedMessage);
- assertEquals("Invalid HTTP method given: 'param1'.", translatedMessage.getMessage());
+ assertEquals(expectedText, translatedMessage.getMessage());
+ assertEquals(expectedLocale, translatedMessage.getLocale());
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0a80d514/lib/server-api/src/test/resources/i18n.properties
----------------------------------------------------------------------
diff --git a/lib/server-api/src/test/resources/i18n.properties b/lib/server-api/src/test/resources/i18n.properties
new file mode 100644
index 0000000..58c31b3
--- /dev/null
+++ b/lib/server-api/src/test/resources/i18n.properties
@@ -0,0 +1,21 @@
+#-------------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# 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
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#-------------------------------------------------------------------------------
+# Basic Apache Olingo exception messages
+#
+TestException.ONLY_ROOT=Root message
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0a80d514/lib/server-api/src/test/resources/i18n_de.properties
----------------------------------------------------------------------
diff --git a/lib/server-api/src/test/resources/i18n_de.properties b/lib/server-api/src/test/resources/i18n_de.properties
index c897e1f..b919483 100644
--- a/lib/server-api/src/test/resources/i18n_de.properties
+++ b/lib/server-api/src/test/resources/i18n_de.properties
@@ -16,4 +16,5 @@
# specific language governing permissions and limitations
# under the License.
#-------------------------------------------------------------------------------
-ODataTranslatedException.BASIC=Test DE
\ No newline at end of file
+TestException.BASIC=Test DE
+TestException.ONLY_GERMAN=Deutsche Nachricht
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0a80d514/lib/server-api/src/test/resources/i18n_en.properties
----------------------------------------------------------------------
diff --git a/lib/server-api/src/test/resources/i18n_en.properties b/lib/server-api/src/test/resources/i18n_en.properties
index 9fdbaaa..84dd9d1 100644
--- a/lib/server-api/src/test/resources/i18n_en.properties
+++ b/lib/server-api/src/test/resources/i18n_en.properties
@@ -18,6 +18,6 @@
#-------------------------------------------------------------------------------
# Basic Apache Olingo exception messages
#
-ODataTranslatedException.BASIC=Test Default
-ODataTranslatedException.ONEPARAM=Param1: %1$s
-ODataTranslatedException.TWOPARAM=Param1: %1$s Param2: %2$s
\ No newline at end of file
+TestException.BASIC=Test Default
+TestException.ONEPARAM=Param1: %1$s
+TestException.TWOPARAM=Param1: %1$s Param2: %2$s
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0a80d514/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 3b9f068..71a69b8 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
@@ -73,8 +73,10 @@ public class ODataHandler {
processInternal(request, requestedContentType, response);
- } catch (UriParserException e) {
- e.printStackTrace();
+ } catch (final UriParserException e) {
+ handleException(request, response,
+ ODataExceptionHelper.createServerErrorObject(e, HttpStatusCode.BAD_REQUEST.getStatusCode()),
+ requestedContentType);
} catch (ContentNegotiatorException e) {
Locale requestedLocale = null;
ODataServerError serverError =
@@ -138,8 +140,8 @@ public class ODataHandler {
break;
default:
response.setStatusCode(HttpStatusCode.NOT_IMPLEMENTED.getStatusCode());
- throw new ODataTranslatedException("not implemented",
- ODataTranslatedException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
+ throw new ODataHandlerException("not implemented",
+ ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
}
}
@@ -176,8 +178,8 @@ public class ODataHandler {
cp.readCollection(request, response, uriInfo, requestedContentType);
} else {
response.setStatusCode(HttpStatusCode.NOT_IMPLEMENTED.getStatusCode());
- throw new ODataTranslatedException("not implemented",
- ODataTranslatedException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
+ throw new ODataHandlerException("not implemented",
+ ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
}
} else {
if (request.getMethod().equals(HttpMethod.GET)) {
@@ -189,8 +191,8 @@ public class ODataHandler {
ep.readEntity(request, response, uriInfo, requestedContentType);
} else {
response.setStatusCode(HttpStatusCode.NOT_IMPLEMENTED.getStatusCode());
- throw new ODataTranslatedException("not implemented",
- ODataTranslatedException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
+ throw new ODataHandlerException("not implemented",
+ ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
}
}
break;
@@ -206,8 +208,8 @@ public class ODataHandler {
cp.readCollection(request, response, uriInfo, requestedContentType);
} else {
response.setStatusCode(HttpStatusCode.NOT_IMPLEMENTED.getStatusCode());
- throw new ODataTranslatedException("not implemented",
- ODataTranslatedException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
+ throw new ODataHandlerException("not implemented",
+ ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
}
} else {
if (request.getMethod().equals(HttpMethod.GET)) {
@@ -219,15 +221,15 @@ public class ODataHandler {
ep.readEntity(request, response, uriInfo, requestedContentType);
} else {
response.setStatusCode(HttpStatusCode.NOT_IMPLEMENTED.getStatusCode());
- throw new ODataTranslatedException("not implemented",
- ODataTranslatedException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
+ throw new ODataHandlerException("not implemented",
+ ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
}
}
break;
default:
response.setStatusCode(HttpStatusCode.NOT_IMPLEMENTED.getStatusCode());
- throw new ODataTranslatedException("not implemented",
- ODataTranslatedException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
+ throw new ODataHandlerException("not implemented",
+ ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
}
}
@@ -239,8 +241,8 @@ public class ODataHandler {
if (maxVersion != null) {
if (ODataServiceVersion.isBiggerThan(ODataServiceVersion.V40.toString(), maxVersion)) {
response.setStatusCode(400);
- throw new ODataTranslatedException("ODataVersion not supported: " + maxVersion,
- ODataTranslatedException.MessageKeys.ODATA_VERSION_NOT_SUPPORTED, maxVersion);
+ throw new ODataHandlerException("ODataVersion not supported: " + maxVersion,
+ ODataHandlerException.MessageKeys.ODATA_VERSION_NOT_SUPPORTED, maxVersion);
}
}
}
@@ -252,8 +254,8 @@ public class ODataHandler {
if (p == null) {
response.setStatusCode(HttpStatusCode.NOT_IMPLEMENTED.getStatusCode());
- throw new ODataTranslatedException("Processor: " + cls.getName() + " not registered.",
- ODataTranslatedException.MessageKeys.PROCESSOR_NOT_IMPLEMENTED, cls.getName());
+ throw new ODataHandlerException("Processor: " + cls.getName() + " not registered.",
+ ODataHandlerException.MessageKeys.PROCESSOR_NOT_IMPLEMENTED, cls.getName());
}
return p;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0a80d514/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandlerException.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandlerException.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandlerException.java
new file mode 100644
index 0000000..589504c
--- /dev/null
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandlerException.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * 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
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core;
+
+import org.apache.olingo.server.api.ODataTranslatedException;
+
+/** Exception thrown during basic request handling. */
+public class ODataHandlerException extends ODataTranslatedException {
+ private static final long serialVersionUID = -907752788975531134L;
+
+ public static enum MessageKeys implements MessageKey {
+ /** parameters: HTTP method, HTTP method */ AMBIGUOUS_XHTTP_METHOD,
+ /** parameter: HTTP method */ HTTP_METHOD_NOT_IMPLEMENTED,
+ /** parameter: processor interface */ PROCESSOR_NOT_IMPLEMENTED,
+ FUNCTIONALITY_NOT_IMPLEMENTED,
+ /** parameter: version */ ODATA_VERSION_NOT_SUPPORTED
+ }
+
+ public ODataHandlerException(final String developmentMessage, final MessageKey messageKey,
+ final String... parameters) {
+ super(developmentMessage, messageKey, parameters);
+ }
+
+ public ODataHandlerException(final String developmentMessage, final Throwable cause, final MessageKey messageKey,
+ final String... parameters) {
+ super(developmentMessage, cause, messageKey, parameters);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0a80d514/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
index 3b7a7a2..436d54f 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
@@ -77,11 +77,11 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler {
private ODataResponse handleException(Exception e) {
ODataResponse resp = new ODataResponse();
- if (e instanceof ODataTranslatedException) {
- ODataTranslatedException exp = (ODataTranslatedException) e;
- if (exp.getMessageKey() == ODataTranslatedException.MessageKeys.AMBIGUOUS_XHTTP_METHOD) {
+ if (e instanceof ODataHandlerException) {
+ ODataHandlerException exp = (ODataHandlerException) e;
+ if (exp.getMessageKey() == ODataHandlerException.MessageKeys.AMBIGUOUS_XHTTP_METHOD) {
resp.setStatusCode(HttpStatusCode.BAD_REQUEST.getStatusCode());
- } else if (exp.getMessageKey() == ODataTranslatedException.MessageKeys.HTTP_METHOD_NOT_IMPLEMENTED) {
+ } else if (exp.getMessageKey() == ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_IMPLEMENTED) {
resp.setStatusCode(HttpStatusCode.NOT_IMPLEMENTED.getStatusCode());
}
}
@@ -156,8 +156,8 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler {
odRequest.setMethod(HttpMethod.valueOf(xHttpMethod));
} else {
if (!xHttpMethod.equalsIgnoreCase(xHttpMethodOverride)) {
- throw new ODataTranslatedException("Ambiguous X-HTTP-Methods",
- ODataTranslatedException.MessageKeys.AMBIGUOUS_XHTTP_METHOD, xHttpMethod, xHttpMethodOverride);
+ throw new ODataHandlerException("Ambiguous X-HTTP-Methods",
+ ODataHandlerException.MessageKeys.AMBIGUOUS_XHTTP_METHOD, xHttpMethod, xHttpMethodOverride);
}
odRequest.setMethod(HttpMethod.valueOf(xHttpMethod));
}
@@ -165,8 +165,8 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler {
odRequest.setMethod(httpRequestMethod);
}
} catch (IllegalArgumentException e) {
- throw new ODataTranslatedException("Invalid http method" + httpRequest.getMethod(),
- ODataTranslatedException.MessageKeys.HTTP_METHOD_NOT_IMPLEMENTED, httpRequest.getMethod());
+ throw new ODataHandlerException("Invalid HTTP method" + httpRequest.getMethod(),
+ ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_IMPLEMENTED, httpRequest.getMethod());
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0a80d514/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 374c108..0c4d92c 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
@@ -23,6 +23,7 @@ import org.antlr.v4.runtime.BailErrorStrategy;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.ParserRuleContext;
+import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.atn.PredictionMode;
import org.antlr.v4.runtime.misc.ParseCancellationException;
@@ -140,7 +141,7 @@ public class Parser {
context.contextUriInfo = new UriInfoImpl().setKind(UriInfoKind.resource);
for (PathSegmentEOFContext ctxPathSegment : ctxPathSegments) {
- // add checks for batcvh entity metadata, all crossjsoin
+ // add checks for batch, entity, metadata, all, crossjoin
uriParseTreeVisitor.visitPathSegmentEOF(ctxPathSegment);
}
@@ -186,8 +187,9 @@ public class Parser {
|| isFormatSyntaxValid(option)) {
formatOption.setFormat(option.value);
} else {
- throw new UriParserSemanticException("Illegal value of $format option!",
- UriParserSemanticException.MessageKeys.TEST);
+ throw new UriParserSyntaxException("Illegal value of $format option!",
+ UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION,
+ option.name, option.value);
}
context.contextUriInfo.setSystemQueryOption(formatOption);
@@ -208,13 +210,13 @@ public class Parser {
context.contextUriInfo.setSystemQueryOption(idOption);
} else if (option.name.equals(SystemQueryOptionKind.LEVELS.toString())) {
throw new UriParserSyntaxException("System query option '$levels' is allowed only inside '$expand'!",
- UriParserSyntaxException.MessageKeys.TEST);
+ UriParserSyntaxException.MessageKeys.SYSTEM_QUERY_OPTION_LEVELS_NOT_ALLOWED_HERE);
} else if (option.name.equals(SystemQueryOptionKind.ORDERBY.toString())) {
- OrderByEOFContext ctxFilterExpression =
+ OrderByEOFContext ctxOrderByExpression =
(OrderByEOFContext) parseRule(option.value, ParserEntryRules.Orderby);
OrderByOptionImpl orderByOption =
- (OrderByOptionImpl) uriParseTreeVisitor.visitOrderByEOF(ctxFilterExpression);
+ (OrderByOptionImpl) uriParseTreeVisitor.visitOrderByEOF(ctxOrderByExpression);
context.contextUriInfo.setSystemQueryOption(orderByOption);
} else if (option.name.equals(SystemQueryOptionKind.SEARCH.toString())) {
@@ -234,8 +236,9 @@ public class Parser {
try {
skipOption.setValue(Integer.parseInt(option.value));
} catch (final NumberFormatException e) {
- throw new UriParserSemanticException("Illegal value of $skip option!", e,
- UriParserSemanticException.MessageKeys.TEST);
+ throw new UriParserSyntaxException("Illegal value of $skip option!", e,
+ UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION,
+ option.name, option.value);
}
context.contextUriInfo.setSystemQueryOption(skipOption);
} else if (option.name.equals(SystemQueryOptionKind.SKIPTOKEN.toString())) {
@@ -251,8 +254,9 @@ public class Parser {
try {
topOption.setValue(Integer.parseInt(option.value));
} catch (final NumberFormatException e) {
- throw new UriParserSemanticException("Illegal value of $top option!", e,
- UriParserSemanticException.MessageKeys.TEST);
+ throw new UriParserSyntaxException("Illegal value of $top option!", e,
+ UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION,
+ option.name, option.value);
}
context.contextUriInfo.setSystemQueryOption(topOption);
} else if (option.name.equals(SystemQueryOptionKind.COUNT.toString())) {
@@ -262,13 +266,14 @@ public class Parser {
if (option.value.equals("true") || option.value.equals("false")) {
inlineCountOption.setValue(Boolean.parseBoolean(option.value));
} else {
- throw new UriParserSemanticException("Illegal value of $count option!",
- UriParserSemanticException.MessageKeys.TEST);
+ throw new UriParserSyntaxException("Illegal value of $count option!",
+ UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION,
+ option.name, option.value);
}
context.contextUriInfo.setSystemQueryOption(inlineCountOption);
} else {
throw new UriParserSyntaxException("Unknown system query option!",
- UriParserSyntaxException.MessageKeys.TEST);
+ UriParserSyntaxException.MessageKeys.UNKNOWN_SYSTEM_QUERY_OPTION, option.name);
}
}
}
@@ -279,12 +284,10 @@ public class Parser {
return context.contextUriInfo;
} catch (ParseCancellationException e) {
- Throwable cause = e.getCause();
- if (cause instanceof UriParserException) {
- throw (UriParserException) cause;
- }
+ throw e.getCause() instanceof UriParserException ?
+ (UriParserException) e.getCause() :
+ new UriParserSyntaxException("Syntax error", e, UriParserSyntaxException.MessageKeys.SYNTAX);
}
- return null;
}
private boolean isFormatSyntaxValid(RawUri.QueryOption option) {
@@ -418,13 +421,15 @@ public class Parser {
break;
}
- } catch (Exception weakException) {
- throw new UriParserSyntaxException("Error in syntax", weakException, UriParserSyntaxException.MessageKeys.TEST);
+ } catch (final RecognitionException weakException) {
+ throw new UriParserSyntaxException("Error in syntax", weakException,
+ UriParserSyntaxException.MessageKeys.SYNTAX);
// exceptionOnStage = 2;
}
- } catch (Exception hardException) {
- throw new UriParserSyntaxException("Error in syntax", hardException, UriParserSyntaxException.MessageKeys.TEST);
+ } catch (final RecognitionException hardException) {
+ throw new UriParserSyntaxException("Error in syntax", hardException,
+ UriParserSyntaxException.MessageKeys.SYNTAX);
}
return ret;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0a80d514/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java
index 13900d6..160cc2a 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java
@@ -343,7 +343,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
tmp += (tmp.length() != 0 ? "," : "") + name;
}
throw wrap(new UriParserSemanticException("Function of functionimport '" + edmFunctionImport.getName()
- + "' with parameters [" + tmp + "] not found", UriParserSemanticException.MessageKeys.TEST));
+ + "' with parameters [" + tmp + "] not found",
+ UriParserSemanticException.MessageKeys.FUNCTION_NOT_FOUND, edmFunctionImport.getName(), tmp));
}
uriResource.setFunction(edmFunctionImport.getUnboundFunction(names));
@@ -358,7 +359,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (lastResourcePart == null) {
if (context.contextTypes.size() == 0) {
throw wrap(new UriParserSemanticException("Resource part '" + odi + "' can only applied on typed "
- + "resource parts", UriParserSemanticException.MessageKeys.TEST));
+ + "resource parts",
+ UriParserSemanticException.MessageKeys.RESOURCE_PART_ONLY_FOR_TYPED_PARTS, odi));
}
source = context.contextTypes.peek();
} else {
@@ -366,7 +368,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (source.type == null) {
throw wrap(new UriParserSemanticException("Resource part '" + odi + "' can only applied on typed "
- + "resource parts", UriParserSemanticException.MessageKeys.TEST));
+ + "resource parts", UriParserSemanticException.MessageKeys.RESOURCE_PART_ONLY_FOR_TYPED_PARTS, odi));
}
}
@@ -385,7 +387,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (!(source.type instanceof EdmStructuredType)) {
throw wrap(new UriParserSemanticException("Can not parse'" + odi
- + "'Previous path segment not a structural type.", UriParserSemanticException.MessageKeys.TEST));
+ + "'Previous path segment not a structural type.",
+ UriParserSemanticException.MessageKeys.RESOURCE_PART_MUST_BE_PRECEDED_BY_STRUCTURAL_TYPE, odi));
}
EdmStructuredType structType = (EdmStructuredType) source.type;
@@ -394,7 +397,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (property == null) {
throw wrap(new UriParserSemanticException("Property '" + odi + "' not found in type '"
+ structType.getNamespace() + "." + structType.getName() + "'",
- UriParserSemanticException.MessageKeys.TEST));
+ UriParserSemanticException.MessageKeys.PROPERTY_NOT_IN_TYPE,
+ structType.getFullQualifiedName().toString(), odi));
}
if (property instanceof EdmProperty) {
@@ -419,7 +423,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
return null;
} else {
throw wrap(new UriParserSemanticException("Unkown type for property '" + property + "'",
- UriParserSemanticException.MessageKeys.TEST));
+ UriParserSemanticException.MessageKeys.UNKNOWN_PROPERTY_TYPE, property.getName()));
}
} else { // with namespace
@@ -435,7 +439,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (!(filterEntityType.compatibleTo(source.type))) {
throw wrap(new UriParserSemanticException(
"Entity typefilter not compatible to previous path segment: " + fullFilterName.toString(),
- UriParserSemanticException.MessageKeys.TEST));
+ UriParserSemanticException.MessageKeys.INCOMPATIBLE_TYPE_FILTER, fullFilterName.toString()));
}
if (lastResourcePart == null) {
@@ -461,7 +465,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
throw wrap(new UriParserSemanticException("Entry typefilters are not chainable, used '"
+ getName(filterEntityType) + "' behind '"
+ getName(lastPartWithKeys.getTypeFilterOnEntry()) + "'",
- UriParserSemanticException.MessageKeys.TEST));
+ UriParserSemanticException.MessageKeys.TYPE_FILTER_NOT_CHAINABLE,
+ getName(lastPartWithKeys.getTypeFilterOnEntry()), getName(filterEntityType)));
}
lastPartWithKeys.setEntryTypeFilter(filterEntityType);
return null;
@@ -470,7 +475,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
throw wrap(new UriParserSemanticException("Collection typefilters are not chainable, used '"
+ getName(filterEntityType) + "' behind '"
+ getName(lastPartWithKeys.getTypeFilterOnCollection()) + "'",
- UriParserSemanticException.MessageKeys.TEST));
+ UriParserSemanticException.MessageKeys.TYPE_FILTER_NOT_CHAINABLE,
+ getName(lastPartWithKeys.getTypeFilterOnCollection()), getName(filterEntityType)));
}
lastPartWithKeys.setCollectionTypeFilter(filterEntityType);
return null;
@@ -480,14 +486,17 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (lastPartTyped.getTypeFilter() != null) {
throw wrap(new UriParserSemanticException("Typefilters are not chainable, used '"
+ getName(filterEntityType) + "' behind '"
- + getName(lastPartTyped.getTypeFilter()) + "'", UriParserSemanticException.MessageKeys.TEST));
+ + getName(lastPartTyped.getTypeFilter()) + "'",
+ UriParserSemanticException.MessageKeys.TYPE_FILTER_NOT_CHAINABLE,
+ getName(lastPartTyped.getTypeFilter()), getName(filterEntityType)));
}
lastPartTyped.setTypeFilter(filterEntityType);
return null;
} else {
throw wrap(new UriParserSemanticException("Path segment before '" + getName(filterEntityType)
- + "' not typed", UriParserSemanticException.MessageKeys.TEST));
+ + "' not typed",
+ UriParserSemanticException.MessageKeys.PREVIOUS_PART_NOT_TYPED, getName(filterEntityType)));
}
}
}
@@ -502,7 +511,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (!(filterComplexType.compatibleTo(source.type))) {
throw wrap(new UriParserSemanticException(
"Complex typefilter '" + getName(source.type) + "'not compatible type of previous path segment '"
- + getName(filterComplexType) + "'", UriParserSemanticException.MessageKeys.TEST));
+ + getName(filterComplexType) + "'",
+ UriParserSemanticException.MessageKeys.INCOMPATIBLE_TYPE_FILTER, getName(source.type)));
}
// is simple complex type cast
@@ -529,7 +539,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
throw wrap(new UriParserSemanticException("Entry typefilters are not chainable, used '"
+ getName(filterComplexType) + "' behind '"
+ getName(lastPartWithKeys.getTypeFilterOnEntry()) + "'",
- UriParserSemanticException.MessageKeys.TEST));
+ UriParserSemanticException.MessageKeys.TYPE_FILTER_NOT_CHAINABLE,
+ getName(lastPartWithKeys.getTypeFilterOnEntry()), getName(filterComplexType)));
}
lastPartWithKeys.setEntryTypeFilter(filterComplexType);
return null;
@@ -538,7 +549,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
throw wrap(new UriParserSemanticException("Collection typefilters are not chainable, used '"
+ getName(filterComplexType) + "' behind '"
+ getName(lastPartWithKeys.getTypeFilterOnCollection()) + "'",
- UriParserSemanticException.MessageKeys.TEST));
+ UriParserSemanticException.MessageKeys.TYPE_FILTER_NOT_CHAINABLE,
+ getName(lastPartWithKeys.getTypeFilterOnCollection()), getName(filterComplexType)));
}
lastPartWithKeys.setCollectionTypeFilter(filterComplexType);
return null;
@@ -549,14 +561,17 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (lastPartTyped.getTypeFilter() != null) {
throw wrap(new UriParserSemanticException("Typefilters are not chainable, used '"
+ getName(filterComplexType) + "' behind '"
- + getName(lastPartTyped.getTypeFilter()) + "'", UriParserSemanticException.MessageKeys.TEST));
+ + getName(lastPartTyped.getTypeFilter()) + "'",
+ UriParserSemanticException.MessageKeys.TYPE_FILTER_NOT_CHAINABLE,
+ getName(lastPartTyped.getTypeFilter()), getName(filterComplexType)));
}
lastPartTyped.setTypeFilter(filterComplexType);
return null;
} else {
throw wrap(new UriParserSemanticException("Path segment before '" + getName(filterComplexType)
- + "' not typed", UriParserSemanticException.MessageKeys.TEST));
+ + "' not typed",
+ UriParserSemanticException.MessageKeys.PREVIOUS_PART_NOT_TYPED, getName(filterComplexType)));
}
}
}
@@ -576,7 +591,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
// do a check for bound functions (which requires a parameter list)
if (ctx.vlNVO.size() == 0) {
throw wrap(new UriParserSemanticException("Expected function parameters for '" + fullBindingTypeName.toString()
- + "'", UriParserSemanticException.MessageKeys.TEST));
+ + "'",
+ UriParserSemanticException.MessageKeys.FUNCTION_PARAMETERS_EXPECTED, fullBindingTypeName.toString()));
}
context.contextReadingFunctionParameters = true;
@@ -618,7 +634,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
}
throw wrap(new UriParserSemanticException("Unknown resource path segment:" + fullFilterName.toString(),
- UriParserSemanticException.MessageKeys.TEST));
+ UriParserSemanticException.MessageKeys.UNKNOWN_PART, fullFilterName.toString()));
}
}
@@ -639,8 +655,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
UriResource obj = context.contextUriInfo.getLastResourcePart();
if (!(obj instanceof UriResourcePartTyped)) {
- throw wrap(new UriParserSemanticException("any only allowed on typed path segments",
- UriParserSemanticException.MessageKeys.TEST));
+ throw wrap(new UriParserSemanticException("all only allowed on typed path segments",
+ UriParserSemanticException.MessageKeys.ONLY_FOR_TYPED_PARTS, "all"));
}
UriContext.LambdaVariables var = new UriContext.LambdaVariables();
@@ -780,7 +796,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
EdmEntityType type = edm.getEntityType(fullName);
if (type == null) {
throw wrap(new UriParserSemanticException("Expected EntityTypeName",
- UriParserSemanticException.MessageKeys.TEST));
+ UriParserSemanticException.MessageKeys.UNKNOWN_ENTITY_TYPE, fullName.toString()));
}
context.contextUriInfo.setEntityTypeCast(type);
@@ -866,7 +882,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
UriResourceImpl lastResourcePart = (UriResourceImpl) context.contextUriInfo.getLastResourcePart();
if (!(lastResourcePart instanceof UriResourcePartTyped)) {
throw wrap(new UriParserSemanticException("any only allowed on typed path segments",
- UriParserSemanticException.MessageKeys.TEST));
+ UriParserSemanticException.MessageKeys.ONLY_FOR_TYPED_PARTS, "any"));
}
UriContext.LambdaVariables var = new UriContext.LambdaVariables();
@@ -969,12 +985,12 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
context.contextUriInfo.addResourcePart(new UriResourceValueImpl());
} else {
throw wrap(new UriParserSemanticException("$value only allowed on typed path segments",
- UriParserSemanticException.MessageKeys.TEST));
+ UriParserSemanticException.MessageKeys.ONLY_FOR_TYPED_PARTS, "$value"));
}
return null;
} else {
throw wrap(new UriParserSemanticException("$value only allowed on typed path segments",
- UriParserSemanticException.MessageKeys.TEST));
+ UriParserSemanticException.MessageKeys.ONLY_FOR_TYPED_PARTS, "$value"));
}
} else if (ctx.vC != null) {
@@ -983,11 +999,11 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
context.contextUriInfo.addResourcePart(new UriResourceCountImpl());
} else {
throw wrap(new UriParserSemanticException("$count only allowed on collection properties",
- UriParserSemanticException.MessageKeys.TEST));
+ UriParserSemanticException.MessageKeys.ONLY_FOR_COLLECTIONS, "$count"));
}
} else {
throw wrap(new UriParserSemanticException("$count only allowed on typed properties",
- UriParserSemanticException.MessageKeys.TEST));
+ UriParserSemanticException.MessageKeys.ONLY_FOR_TYPED_PARTS, "$count"));
}
} else if (ctx.vR != null) {
if (pathInfo instanceof UriResourcePartTyped) {
@@ -995,12 +1011,12 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (type instanceof EdmEntityType) {
context.contextUriInfo.addResourcePart(new UriResourceRefImpl());
} else {
- throw wrap(new UriParserSemanticException("$ref only allowed on endity types",
- UriParserSemanticException.MessageKeys.TEST));
+ throw wrap(new UriParserSemanticException("$ref only allowed on entity types",
+ UriParserSemanticException.MessageKeys.ONLY_FOR_ENTITY_TYPES, "$ref"));
}
} else {
throw wrap(new UriParserSemanticException("$ref only allowed on typed properties",
- UriParserSemanticException.MessageKeys.TEST));
+ UriParserSemanticException.MessageKeys.ONLY_FOR_TYPED_PROPERTIES, "$ref"));
}
} else if (ctx.vAll != null) {
@@ -1411,14 +1427,14 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
expression = (ExpressionImpl) ctx.vVO.accept(this);
} catch (Exception ex) {
throw wrap(new UriParserSemanticException("Invalid key value: " + valueText,
- UriParserSemanticException.MessageKeys.TEST));
+ UriParserSemanticException.MessageKeys.INVALID_KEY_VALUE, valueText));
}
// get type of last resource part
UriResource last = context.contextUriInfo.getLastResourcePart();
if (!(last instanceof UriResourcePartTyped)) {
- throw wrap(new UriParserSemanticException("Paramterslist on untyped resource path segement not allowed",
- UriParserSemanticException.MessageKeys.TEST));
+ throw wrap(new UriParserSemanticException("Parameters list on untyped resource path segment not allowed",
+ UriParserSemanticException.MessageKeys.PARAMETERS_LIST_ONLY_FOR_TYPED_PARTS));
}
EdmEntityType lastType = (EdmEntityType) ((UriResourcePartTyped) last).getType();
@@ -1439,16 +1455,16 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
// key.
// for using referential constrains the last resource part must be a navigation property
if (!(context.contextUriInfo.getLastResourcePart() instanceof UriResourceNavigationPropertyImpl)) {
- throw wrap(new UriParserSemanticException("Not enougth keyproperties defined",
- UriParserSemanticException.MessageKeys.TEST));
+ throw wrap(new UriParserSemanticException("Not enough key properties defined",
+ UriParserSemanticException.MessageKeys.NOT_ENOUGH_KEY_PROPERTIES));
}
UriResourceNavigationPropertyImpl lastNav = (UriResourceNavigationPropertyImpl) last;
// get the partner of the navigation property
EdmNavigationProperty partner = lastNav.getProperty().getPartner();
if (partner == null) {
- throw wrap(new UriParserSemanticException("Not enougth keyproperties defined",
- UriParserSemanticException.MessageKeys.TEST));
+ throw wrap(new UriParserSemanticException("Not enough key properties defined",
+ UriParserSemanticException.MessageKeys.NOT_ENOUGH_KEY_PROPERTIES));
}
// create the keylist
@@ -1466,8 +1482,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
missedKey = item;
} else {
// two of more keys are missing
- throw wrap(new UriParserSemanticException("Not enougth referntial contrains defined",
- UriParserSemanticException.MessageKeys.TEST));
+ throw wrap(new UriParserSemanticException("Not enough referential constraints defined",
+ UriParserSemanticException.MessageKeys.NOT_ENOUGH_REFERENTIAL_CONSTRAINTS));
}
}
}
@@ -1501,8 +1517,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
// get type of last resource part
if (!(last instanceof UriResourcePartTyped)) {
- throw wrap(new UriParserSemanticException("Parameterslist on untyped resource path segement not allowed",
- UriParserSemanticException.MessageKeys.TEST));
+ throw wrap(new UriParserSemanticException("Parameters list on untyped resource path segment not allowed",
+ UriParserSemanticException.MessageKeys.PARAMETERS_LIST_ONLY_FOR_TYPED_PARTS));
}
EdmEntityType lastType = (EdmEntityType) ((UriResourcePartTyped) last).getType();
@@ -1517,16 +1533,16 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
// if not, check if the missing key predicates can be satisfied with help of the defined referential constrains
// for using referential constrains the last resource part must be a navigation property
if (!(context.contextUriInfo.getLastResourcePart() instanceof UriResourceNavigationPropertyImpl)) {
- throw wrap(new UriParserSemanticException("Not enougth keyproperties defined",
- UriParserSemanticException.MessageKeys.TEST));
+ throw wrap(new UriParserSemanticException("Not enough key properties defined",
+ UriParserSemanticException.MessageKeys.NOT_ENOUGH_KEY_PROPERTIES));
}
UriResourceNavigationPropertyImpl lastNav = (UriResourceNavigationPropertyImpl) last;
// get the partner of the navigation property
EdmNavigationProperty partner = lastNav.getProperty().getPartner();
if (partner == null) {
- throw wrap(new UriParserSemanticException("Not enougth keyproperties defined",
- UriParserSemanticException.MessageKeys.TEST));
+ throw wrap(new UriParserSemanticException("Not enough key properties defined",
+ UriParserSemanticException.MessageKeys.NOT_ENOUGH_KEY_PROPERTIES));
}
// fill missing keys from referential constrains
@@ -1553,8 +1569,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
return list;
}
- throw wrap(new UriParserSemanticException("Not enougth keyproperties defined",
- UriParserSemanticException.MessageKeys.TEST));
+ throw wrap(new UriParserSemanticException("Not enough key properties defined",
+ UriParserSemanticException.MessageKeys.NOT_ENOUGH_KEY_PROPERTIES));
}
return new ArrayList<String>();
}
@@ -1658,8 +1674,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
.setKeyPredicates(list);
} else {
throw wrap(new UriParserSemanticException("Key properties not allowed",
- UriParserSemanticException.MessageKeys.TEST));
- // throw UriSemanticError.addKrepredicatesNotAllowed();
+ UriParserSemanticException.MessageKeys.KEY_NOT_ALLOWED));
}
}
@@ -1726,7 +1741,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (!(lastResource instanceof UriResourcePartTyped)) {
throw wrap(new UriParserSemanticException("Resource path not typed",
- UriParserSemanticException.MessageKeys.TEST));
+ UriParserSemanticException.MessageKeys.RESOURCE_PATH_NOT_TYPED));
}
UriResourcePartTyped lastType = (UriResourcePartTyped) lastResource;
@@ -1831,21 +1846,21 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
prevType = getTypeInformation(last).type;
if (prevType == null) {
- throw wrap(new UriParserSemanticException("prev segement not typed",
- UriParserSemanticException.MessageKeys.TEST));
+ throw wrap(new UriParserSemanticException("prev segment not typed",
+ UriParserSemanticException.MessageKeys.ONLY_FOR_TYPED_PARTS, "select"));
}
}
if (!(prevType instanceof EdmStructuredType)) {
throw wrap(new UriParserSemanticException("Previous select item is not a structural type",
- UriParserSemanticException.MessageKeys.TEST));
+ UriParserSemanticException.MessageKeys.ONLY_FOR_STRUCTURAL_TYPES, "select"));
}
EdmStructuredType structType = (EdmStructuredType) prevType;
EdmElement element = structType.getProperty(odi);
if (element == null) {
throw wrap(new UriParserSemanticException("Previous select item has not property: " + odi,
- UriParserSemanticException.MessageKeys.TEST));
+ UriParserSemanticException.MessageKeys.PROPERTY_NOT_IN_TYPE, structType.getName(), odi));
}
// create new segment
@@ -1896,7 +1911,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
}
} else {
throw wrap(new UriParserSemanticException("Only Simple and Complex properties within select allowed",
- UriParserSemanticException.MessageKeys.TEST));
+ UriParserSemanticException.MessageKeys.ONLY_SIMPLE_AND_COMPLEX_PROPERTIES_IN_SELECT));
}
} else {
String namespace = ctx.vNS.getText();
@@ -1948,16 +1963,16 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
}
}
} else {
- throw wrap(new UriParserSemanticException("prev segement must be comlex of entity type",
- UriParserSemanticException.MessageKeys.TEST));
+ throw wrap(new UriParserSemanticException("prev segment must be complex of entity type",
+ UriParserSemanticException.MessageKeys.COMPLEX_PROPERTY_OF_ENTITY_TYPE_EXPECTED));
}
} else {
UriInfoImpl uriInfo = (UriInfoImpl) context.contextSelectItem.getResourcePath();
UriResource last = uriInfo.getLastResourcePart();
if (!(last instanceof UriResourceTypedImpl)) {
- throw wrap(new UriParserSemanticException("prev segement typed",
- UriParserSemanticException.MessageKeys.TEST));
+ throw wrap(new UriParserSemanticException("prev segment typed",
+ UriParserSemanticException.MessageKeys.ONLY_FOR_TYPED_PARTS, "select"));
}
EdmType prevType = getTypeInformation(last).type;
@@ -1973,7 +1988,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
}
}
} else if (prevType instanceof EdmEntityType) {
- throw wrap(new UriParserSemanticException("Error", UriParserSemanticException.MessageKeys.TEST));
+ throw wrap(new UriParserSemanticException("Error",
+ UriParserSemanticException.MessageKeys.NOT_FOR_ENTITY_TYPE));
/*
* EdmEntityType et = edm.getEntityType(fullName);
* if (et != null) {
@@ -1987,8 +2003,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
* }
*/
} else {
- throw wrap(new UriParserSemanticException("prev segement must be comlex of entity type",
- UriParserSemanticException.MessageKeys.TEST));
+ throw wrap(new UriParserSemanticException("prev segment must be complex of entity type",
+ UriParserSemanticException.MessageKeys.COMPLEX_PROPERTY_OF_ENTITY_TYPE_EXPECTED));
}
}
@@ -1999,8 +2015,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
UriInfoImpl uriInfo = (UriInfoImpl) context.contextSelectItem.getResourcePath();
UriResource last = uriInfo.getLastResourcePart();
if (!(last instanceof UriResourceTypedImpl)) {
- throw wrap(new UriParserSemanticException("prev segement typed",
- UriParserSemanticException.MessageKeys.TEST));
+ throw wrap(new UriParserSemanticException("prev segment typed",
+ UriParserSemanticException.MessageKeys.PREVIOUS_PART_TYPED));
}
prevType = getTypeInformation(last).type;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0a80d514/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserException.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserException.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserException.java
index faa3c63..5f509ce 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserException.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserException.java
@@ -20,7 +20,7 @@ package org.apache.olingo.server.core.uri.parser;
import org.apache.olingo.server.api.ODataTranslatedException;
-public class UriParserException extends ODataTranslatedException {
+abstract public class UriParserException extends ODataTranslatedException {
private static final long serialVersionUID = -6438700016830955949L;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0a80d514/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSemanticException.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSemanticException.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSemanticException.java
index 41d178f..7d742bc 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSemanticException.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSemanticException.java
@@ -18,12 +18,38 @@
*/
package org.apache.olingo.server.core.uri.parser;
+/** Exception thrown during URI parsing in cases where an URI part is invalid according to the Entity Data Model. */
public class UriParserSemanticException extends UriParserException {
private static final long serialVersionUID = 3850285860949809622L;
-
+
public static enum MessageKeys implements MessageKey {
- TEST
+ /** parameters: function-import name, function parameters */ FUNCTION_NOT_FOUND,
+ /** parameter: resource part */ RESOURCE_PART_ONLY_FOR_TYPED_PARTS,
+ /** parameter: resource part */ RESOURCE_PART_MUST_BE_PRECEDED_BY_STRUCTURAL_TYPE,
+ /** parameters: type name, property name */ PROPERTY_NOT_IN_TYPE,
+ /** parameter: property name */ UNKNOWN_PROPERTY_TYPE,
+ /** parameter: type filter */ INCOMPATIBLE_TYPE_FILTER,
+ /** parameters: previous type filter, last type filter */ TYPE_FILTER_NOT_CHAINABLE,
+ /** parameter: type filter */ PREVIOUS_PART_NOT_TYPED,
+ /** parameter: type */ FUNCTION_PARAMETERS_EXPECTED,
+ /** parameter: resource part */ UNKNOWN_PART,
+ /** parameter: expression */ ONLY_FOR_TYPED_PARTS,
+ /** parameter: entity type name */ UNKNOWN_ENTITY_TYPE,
+ /** parameter: expression */ ONLY_FOR_COLLECTIONS,
+ /** parameter: expression */ ONLY_FOR_ENTITY_TYPES,
+ /** parameter: expression */ ONLY_FOR_STRUCTURAL_TYPES,
+ /** parameter: expression */ ONLY_FOR_TYPED_PROPERTIES,
+ /** parameter: value */ INVALID_KEY_VALUE,
+ PARAMETERS_LIST_ONLY_FOR_TYPED_PARTS,
+ NOT_ENOUGH_KEY_PROPERTIES,
+ NOT_ENOUGH_REFERENTIAL_CONSTRAINTS,
+ KEY_NOT_ALLOWED,
+ RESOURCE_PATH_NOT_TYPED,
+ ONLY_SIMPLE_AND_COMPLEX_PROPERTIES_IN_SELECT,
+ COMPLEX_PROPERTY_OF_ENTITY_TYPE_EXPECTED,
+ NOT_FOR_ENTITY_TYPE,
+ PREVIOUS_PART_TYPED
}
public UriParserSemanticException(String developmentMessage, MessageKey messageKey, String... parameters) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0a80d514/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 a7dfdd9..393855b 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
@@ -18,14 +18,18 @@
*/
package org.apache.olingo.server.core.uri.parser;
+/** Exception thrown during URI parsing in cases where the URI violates the URI construction rules. */
public class UriParserSyntaxException extends UriParserException {
private static final long serialVersionUID = 5887744747812478226L;
public static enum MessageKeys implements MessageKey {
- TEST
+ /** parameter: query-option name */ UNKNOWN_SYSTEM_QUERY_OPTION,
+ /** parameters: query-option name, query-option value */ WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION,
+ SYNTAX,
+ SYSTEM_QUERY_OPTION_LEVELS_NOT_ALLOWED_HERE
}
-
+
public UriParserSyntaxException(String developmentMessage, MessageKey messageKey, String... parameters) {
super(developmentMessage, messageKey, parameters);
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0a80d514/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidationException.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidationException.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidationException.java
index f175483..d5c7c0a 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidationException.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidationException.java
@@ -50,7 +50,7 @@ public class UriValidationException extends ODataTranslatedException {
/** parameter: unallowed kind before $value */
UNALLOWED_KIND_BEFORE_VALUE,
/** parameter: unallowed kind before $count */
- UNALLOWED_KIND_BEFORE_COUNT,
+ UNALLOWED_KIND_BEFORE_COUNT
}
public UriValidationException(String developmentMessage, MessageKey messageKey, String... parameters) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0a80d514/lib/server-core/src/main/resources/i18n.properties
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/resources/i18n.properties b/lib/server-core/src/main/resources/i18n.properties
new file mode 100644
index 0000000..1b603f4
--- /dev/null
+++ b/lib/server-core/src/main/resources/i18n.properties
@@ -0,0 +1,87 @@
+#-------------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# 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
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#-------------------------------------------------------------------------------
+# Basic Apache Olingo exception messages
+#
+ODataHandlerException.AMBIGUOUS_XHTTP_METHOD=x-http-method header '%1$s' and x-http-method-override header '%2$s' are not the same.
+ODataHandlerException.HTTP_METHOD_NOT_IMPLEMENTED=Invalid HTTP method given: '%1$s'.
+ODataHandlerException.PROCESSOR_NOT_IMPLEMENTED=No processor for interface '%1$s' registered.
+ODataHandlerException.FUNCTIONALITY_NOT_IMPLEMENTED=The requested functionality has not been implemented (yet).
+ODataHandlerException.ODATA_VERSION_NOT_SUPPORTED=OData version '%1$s' is not supported.
+
+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.SYNTAX=The URI is malformed.
+UriParserSyntaxException.SYSTEM_QUERY_OPTION_LEVELS_NOT_ALLOWED_HERE=The system query option '$levels' is not allowed here.
+
+UriParserSemanticException.FUNCTION_NOT_FOUND=The function import '%1$s' has no function with parameters '%2$s'.
+UriParserSemanticException.RESOURCE_PART_ONLY_FOR_TYPED_PARTS='%1%s' is only allowed for typed parts.
+UriParserSemanticException.RESOURCE_PART_MUST_BE_PRECEDED_BY_STRUCTURAL_TYPE=The resource part '%1$s' must be preceded by a structural type.
+UriParserSemanticException.PROPERTY_NOT_IN_TYPE=The type '%1$s' has no property '%2$s'.
+UriParserSemanticException.UNKNOWN_PROPERTY_TYPE=The type of the property '%1$s' is unknown.
+UriParserSemanticException.INCOMPATIBLE_TYPE_FILTER=The type filter '%1$s' is incompatible.
+UriParserSemanticException.TYPE_FILTER_NOT_CHAINABLE=The type filter '%2$s' can not be chained with '%1$s'.
+UriParserSemanticException.PREVIOUS_PART_NOT_TYPED=The previous part of the type filter '%1$s' is not typed.
+UriParserSemanticException.FUNCTION_PARAMETERS_EXPECTED=Function parameters expected for type '%1$s'.
+UriParserSemanticException.UNKNOWN_PART=The part '%1%s' is not defined.
+UriParserSemanticException.ONLY_FOR_TYPED_PARTS='%1%s' is only allowed for typed parts.
+UriParserSemanticException.UNKNOWN_ENTITY_TYPE=The entity type '%1%s' is not defined.
+UriParserSemanticException.ONLY_FOR_COLLECTIONS='%1%s' is only allowed for collections.
+UriParserSemanticException.ONLY_FOR_ENTITY_TYPES='%1%s' is only allowed for entity types.
+UriParserSemanticException.ONLY_FOR_STRUCTURAL_TYPES='%1%s' is only allowed for structural types.
+UriParserSemanticException.ONLY_FOR_TYPED_PROPERTIES='%1%s' is only allowed for typed properties.
+UriParserSemanticException.INVALID_KEY_VALUE=The key value '%1$s' is invalid.
+UriParserSemanticException.PARAMETERS_LIST_ONLY_FOR_TYPED_PARTS=A list of parameters is only allowed for typed parts.
+UriParserSemanticException.NOT_ENOUGH_KEY_PROPERTIES=There are not enough key properties.
+UriParserSemanticException.NOT_ENOUGH_REFERENTIAL_CONSTRAINTS=There are not enough referential constraints.
+UriParserSemanticException.KEY_NOT_ALLOWED=A key is not allowed.
+UriParserSemanticException.RESOURCE_PATH_NOT_TYPED=The resource path is not typed.
+UriParserSemanticException.ONLY_SIMPLE_AND_COMPLEX_PROPERTIES_IN_SELECT=Only simple and complex properties are allowed in selection.
+UriParserSemanticException.COMPLEX_PROPERTY_OF_ENTITY_TYPE_EXPECTED=A complex property of an entity type is expected.
+UriParserSemanticException.NOT_FOR_ENTITY_TYPE=Not allowed for entity type.
+UriParserSemanticException.PREVIOUS_PART_TYPED=The previous part is typed.
+
+UriValidationException.UNSUPPORTED_QUERY_OPTION=The query option '%1$s' is not supported.
+UriValidationException.UNSUPPORTED_URI_KIND=The URI kind '%1$s' is not supported.
+UriValidationException.UNSUPPORTED_URI_RESOURCE_KIND=The URI resource kind '%1$s' is not supported.
+UriValidationException.UNSUPPORTED_FUNCTION_RETURN_TYPE=The function return type '%1$s' is not supported.
+UriValidationException.UNSUPPORTED_ACTION_RETURN_TYPE=The action return type '%1$s' is not supported.
+UriValidationException.UNSUPPORTED_HTTP_METHOD=The HTTP method '%1$s' is not supported.
+UriValidationException.SYSTEM_QUERY_OPTION_NOT_ALLOWED=The system query option '%1$s' is not allowed.
+UriValidationException.SYSTEM_QUERY_OPTION_NOT_ALLOWED_FOR_HTTP_METHOD=The system query option '%1$s' is not allowed for HTTP method '%2$s'.
+UriValidationException.INVALID_KEY_PROPERTY=The key property '%1$s' is invalid.
+UriValidationException.LAST_SEGMENT_NOT_TYPED=The last segment '%1$s' is not typed.
+UriValidationException.SECOND_LAST_SEGMENT_NOT_TYPED=The second last segment '%1$s' is not typed.
+UriValidationException.UNALLOWED_KIND_BEFORE_VALUE=The kind '%1$s' is not allowed before '$value'.
+UriValidationException.UNALLOWED_KIND_BEFORE_COUNT=The kind '%1$s' is not allowed before '$count'.
+
+ContentNegotiatorException.WRONG_CHARSET_IN_HEADER=The HTTP header '%1$s' with value '%2$s' contains an invalid character-set specification.
+ContentNegotiatorException.UNSUPPORTED_CONTENT_TYPES=The content-type range '%1$s' is not supported.
+ContentNegotiatorException.UNSUPPORTED_CONTENT_TYPE=The content type '%1$s' is not supported.
+ContentNegotiatorException.UNSUPPORTED_FORMAT_OPTION=The $format option '%1$s' is not supported.
+
+ODataSerializerException.NOT_IMPLEMENTED=The requested serialization method has not been implemented yet.
+ODataSerializerException.UNSUPPORTED_FORMAT=The format '%1$s' is not supported.
+ODataSerializerException.JSON_METADATA=The metadata document cannot be provided in JSON format.
+ODataSerializerException.IO_EXCEPTION=An I/O exception occurred.
+ODataSerializerException.NULL_INPUT=The input 'null' is not allowed here.
+ODataSerializerException.NO_CONTEXT_URL=No context URL has been provided.
+ODataSerializerException.UNSUPPORTED_PROPERTY_TYPE=The type of the property '%1$s' is not yet supported.
+ODataSerializerException.INCONSISTENT_PROPERTY_TYPE=An inconsistency has been detected in the type definition of property '%1$s'.
+ODataSerializerException.MISSING_PROPERTY=The non-nullable property '%1$s' is missing.
+ODataSerializerException.WRONG_PROPERTY_VALUE=The value '%2$s' is not valid for property '%1$s'.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0a80d514/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java
index 3e4dde4..b35e40d 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java
@@ -29,6 +29,7 @@ import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.api.http.HttpHeader;
import org.apache.olingo.commons.api.http.HttpStatusCode;
import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.ODataApplicationException;
import org.apache.olingo.server.api.ODataRequest;
import org.apache.olingo.server.api.ODataResponse;
import org.apache.olingo.server.api.ODataTranslatedException;
@@ -42,6 +43,7 @@ import org.apache.olingo.server.api.uri.UriResourceEntitySet;
import org.apache.olingo.server.tecsvc.data.DataProvider;
import java.util.List;
+import java.util.Locale;
public class TechnicalProcessor implements EntityCollectionProcessor, EntityProcessor {
@@ -81,6 +83,8 @@ public class TechnicalProcessor implements EntityCollectionProcessor, EntityProc
response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
} catch (final ODataTranslatedException e) {
response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
+ } catch (final ODataApplicationException e) {
+ response.setStatusCode(e.getStatusCode());
}
}
@@ -106,6 +110,8 @@ public class TechnicalProcessor implements EntityCollectionProcessor, EntityProc
response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
} catch (final ODataTranslatedException e) {
response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
+ } catch (final ODataApplicationException e) {
+ response.setStatusCode(e.getStatusCode());
}
}
@@ -136,20 +142,20 @@ public class TechnicalProcessor implements EntityCollectionProcessor, EntityProc
&& uriInfo.getTopOption() == null;
}
- private EdmEntitySet getEdmEntitySet(final UriInfoResource uriInfo) throws ODataTranslatedException {
+ private EdmEntitySet getEdmEntitySet(final UriInfoResource uriInfo) throws ODataApplicationException {
final List<UriResource> resourcePaths = uriInfo.getUriResourceParts();
if (resourcePaths.size() != 1) {
- throw new ODataTranslatedException("Invalid resource path.",
- ODataTranslatedException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
+ throw new ODataApplicationException("Invalid resource path.",
+ HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT);
}
if (!(resourcePaths.get(0) instanceof UriResourceEntitySet)) {
- throw new ODataTranslatedException("Invalid resource type.",
- ODataTranslatedException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
+ throw new ODataApplicationException("Invalid resource type.",
+ HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT);
}
final UriResourceEntitySet uriResource = (UriResourceEntitySet) resourcePaths.get(0);
if (uriResource.getTypeFilterOnCollection() != null || uriResource.getTypeFilterOnEntry() != null) {
- throw new ODataTranslatedException("Type filters are not supported.",
- ODataTranslatedException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
+ throw new ODataApplicationException("Type filters are not supported.",
+ HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT);
}
return uriResource.getEntitySet();
}