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/10/02 17:09:44 UTC
[1/2] [OLINGO-447] Improve ODataHttpHandler and ODataHandler
Repository: olingo-odata4
Updated Branches:
refs/heads/master eacc63c67 -> 5af9f46d4
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5af9f46d/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 540119e..621f4eb 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
@@ -19,7 +19,8 @@
# 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.INVALID_HTTP_METHOD=Invalid HTTP method given: '%1$s'.
+ODataHandlerException.HTTP_METHOD_NOT_ALLOWED=HTTP method '%1$s' not allowed for this resource.
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.
@@ -79,13 +80,13 @@ ContentNegotiatorException.UNSUPPORTED_CONTENT_TYPES=The content-type range '%1$
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'.
+SerializerException.NOT_IMPLEMENTED=The requested serialization method has not been implemented yet.
+SerializerException.UNSUPPORTED_FORMAT=The format '%1$s' is not supported.
+SerializerException.JSON_METADATA=The metadata document cannot be provided in JSON format.
+SerializerException.IO_EXCEPTION=An I/O exception occurred.
+SerializerException.NULL_INPUT=The input 'null' is not allowed here.
+SerializerException.NO_CONTEXT_URL=No context URL has been provided.
+SerializerException.UNSUPPORTED_PROPERTY_TYPE=The type of the property '%1$s' is not yet supported.
+SerializerException.INCONSISTENT_PROPERTY_TYPE=An inconsistency has been detected in the type definition of property '%1$s'.
+SerializerException.MISSING_PROPERTY=The non-nullable property '%1$s' is missing.
+SerializerException.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/5af9f46d/lib/server-core/src/test/java/org/apache/olingo/server/core/ContentNegotiatorTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/ContentNegotiatorTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/ContentNegotiatorTest.java
index 21db4a4..6230a9e 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/ContentNegotiatorTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/ContentNegotiatorTest.java
@@ -35,7 +35,7 @@ import org.apache.olingo.commons.api.http.HttpMethod;
import org.apache.olingo.server.api.OData;
import org.apache.olingo.server.api.ODataRequest;
import org.apache.olingo.server.api.ODataResponse;
-import org.apache.olingo.server.api.processor.CustomContentTypeSupportProcessor;
+import org.apache.olingo.server.api.processor.CustomContentTypeSupport;
import org.apache.olingo.server.api.processor.EntitySetProcessor;
import org.apache.olingo.server.api.processor.MetadataProcessor;
import org.apache.olingo.server.api.processor.Processor;
@@ -190,7 +190,7 @@ public class ContentNegotiatorTest {
}
private class ProcessorStub implements ServiceDocumentProcessor, MetadataProcessor,
- EntitySetProcessor, CustomContentTypeSupportProcessor {
+ EntitySetProcessor, CustomContentTypeSupport {
List<ContentType> customTypes;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5af9f46d/lib/server-core/src/test/java/org/apache/olingo/server/core/TranslatedExceptionSubclassesTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/TranslatedExceptionSubclassesTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/TranslatedExceptionSubclassesTest.java
index 3b8bc87..5460d9f 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/TranslatedExceptionSubclassesTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/TranslatedExceptionSubclassesTest.java
@@ -19,7 +19,7 @@
package org.apache.olingo.server.core;
import org.apache.olingo.server.api.ODataTranslatedException;
-import org.apache.olingo.server.api.serializer.ODataSerializerException;
+import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.core.uri.parser.UriParserSemanticException;
import org.apache.olingo.server.core.uri.parser.UriParserSyntaxException;
import org.apache.olingo.server.core.uri.validator.UriValidationException;
@@ -54,7 +54,7 @@ public class TranslatedExceptionSubclassesTest {
testException(UriParserSemanticException.class, UriParserSemanticException.MessageKeys.values());
testException(UriParserSyntaxException.class, UriParserSyntaxException.MessageKeys.values());
testException(ContentNegotiatorException.class, ContentNegotiatorException.MessageKeys.values());
- testException(ODataSerializerException.class, ODataSerializerException.MessageKeys.values());
+ testException(SerializerException.class, SerializerException.MessageKeys.values());
testException(UriValidationException.class, UriValidationException.MessageKeys.values());
testException(UriParserSyntaxException.class, UriParserSyntaxException.MessageKeys.values());
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5af9f46d/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataErrorSerializerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataErrorSerializerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataErrorSerializerTest.java
index 3e210e4..4e44db4 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataErrorSerializerTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataErrorSerializerTest.java
@@ -31,7 +31,7 @@ import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.server.api.OData;
import org.apache.olingo.server.api.ODataServerError;
import org.apache.olingo.server.api.serializer.ODataSerializer;
-import org.apache.olingo.server.api.serializer.ODataSerializerException;
+import org.apache.olingo.server.api.serializer.SerializerException;
import org.junit.Before;
import org.junit.Test;
@@ -75,7 +75,7 @@ public class ODataErrorSerializerTest {
assertEquals("{\"error\":{\"code\":\"Code\",\"message\":\"ErrorMessage\",\"target\":\"Target\"}}", jsonString);
}
- @Test(expected = ODataSerializerException.class)
+ @Test(expected = SerializerException.class)
public void nullErrorResultsInException() throws Exception {
ser.error(null);
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5af9f46d/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 c8de547..06ccf53 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
@@ -35,7 +35,7 @@ import org.apache.olingo.server.api.ODataResponse;
import org.apache.olingo.server.api.processor.EntitySetProcessor;
import org.apache.olingo.server.api.processor.EntityProcessor;
import org.apache.olingo.server.api.serializer.ODataSerializer;
-import org.apache.olingo.server.api.serializer.ODataSerializerException;
+import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.api.serializer.ODataSerializerOptions;
import org.apache.olingo.server.api.uri.UriInfo;
import org.apache.olingo.server.api.uri.UriInfoResource;
@@ -93,7 +93,7 @@ public class TechnicalProcessor implements EntitySetProcessor, EntityProcessor {
}
} catch (final DataProvider.DataProviderException e) {
response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
- } catch (final ODataSerializerException e) {
+ } catch (final SerializerException e) {
response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
} catch (final ODataApplicationException e) {
response.setStatusCode(e.getStatusCode());
@@ -129,7 +129,7 @@ public class TechnicalProcessor implements EntitySetProcessor, EntityProcessor {
}
} catch (final DataProvider.DataProviderException e) {
response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
- } catch (final ODataSerializerException e) {
+ } catch (final SerializerException e) {
response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
} catch (final ODataApplicationException e) {
response.setStatusCode(e.getStatusCode());
@@ -225,7 +225,7 @@ public class TechnicalProcessor implements EntitySetProcessor, EntityProcessor {
private ContextURL getContextUrl(final ODataSerializer serializer,
final EdmEntitySet entitySet, final boolean isSingleEntity,
- final ExpandOption expand, final SelectOption select) throws ODataSerializerException {
+ final ExpandOption expand, final SelectOption select) throws SerializerException {
return ContextURL.with().entitySet(entitySet)
.selectList(serializer.buildContextURLSelectList(entitySet, expand, select))
.suffix(isSingleEntity ? Suffix.ENTITY : null).build();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5af9f46d/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerExceptionHandlingTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerExceptionHandlingTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerExceptionHandlingTest.java
index 0f40d19..f227f29 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerExceptionHandlingTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerExceptionHandlingTest.java
@@ -26,7 +26,6 @@ import static org.mockito.Mockito.mock;
import java.util.Locale;
-import org.apache.commons.io.IOUtils;
import org.apache.olingo.commons.api.ODataException;
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
@@ -57,6 +56,92 @@ public class ODataHandlerExceptionHandlingTest {
}
@Test
+ public void wrongHttpMethodForMetadataDocument() throws Exception {
+ ODataRequest request = new ODataRequest();
+ request.setMethod(HttpMethod.POST);
+ request.setRawODataPath("$metadata");
+ ODataResponse response = handler.process(request);
+ assertNotNull(response);
+ assertEquals(HttpStatusCode.METHOD_NOT_ALLOWED.getStatusCode(), response.getStatusCode());
+ assertNotNull(response.getContent());
+
+ request = new ODataRequest();
+ request.setMethod(HttpMethod.PUT);
+ request.setRawODataPath("$metadata");
+ response = handler.process(request);
+ assertNotNull(response);
+ assertEquals(HttpStatusCode.METHOD_NOT_ALLOWED.getStatusCode(), response.getStatusCode());
+ assertNotNull(response.getContent());
+
+ request = new ODataRequest();
+ request.setMethod(HttpMethod.PATCH);
+ request.setRawODataPath("$metadata");
+ response = handler.process(request);
+ assertNotNull(response);
+ assertEquals(HttpStatusCode.METHOD_NOT_ALLOWED.getStatusCode(), response.getStatusCode());
+ assertNotNull(response.getContent());
+
+ request = new ODataRequest();
+ request.setMethod(HttpMethod.MERGE);
+ request.setRawODataPath("$metadata");
+ response = handler.process(request);
+ assertNotNull(response);
+ assertEquals(HttpStatusCode.METHOD_NOT_ALLOWED.getStatusCode(), response.getStatusCode());
+ assertNotNull(response.getContent());
+
+ request = new ODataRequest();
+ request.setMethod(HttpMethod.DELETE);
+ request.setRawODataPath("$metadata");
+ response = handler.process(request);
+ assertNotNull(response);
+ assertEquals(HttpStatusCode.METHOD_NOT_ALLOWED.getStatusCode(), response.getStatusCode());
+ assertNotNull(response.getContent());
+ }
+
+ @Test
+ public void wrongHttpMethodForServiceDocument() throws Exception {
+ ODataRequest request = new ODataRequest();
+ request.setMethod(HttpMethod.POST);
+ request.setRawODataPath("");
+ ODataResponse response = handler.process(request);
+ assertNotNull(response);
+ assertEquals(HttpStatusCode.METHOD_NOT_ALLOWED.getStatusCode(), response.getStatusCode());
+ assertNotNull(response.getContent());
+
+ request = new ODataRequest();
+ request.setMethod(HttpMethod.PUT);
+ request.setRawODataPath("");
+ response = handler.process(request);
+ assertNotNull(response);
+ assertEquals(HttpStatusCode.METHOD_NOT_ALLOWED.getStatusCode(), response.getStatusCode());
+ assertNotNull(response.getContent());
+
+ request = new ODataRequest();
+ request.setMethod(HttpMethod.PATCH);
+ request.setRawODataPath("");
+ response = handler.process(request);
+ assertNotNull(response);
+ assertEquals(HttpStatusCode.METHOD_NOT_ALLOWED.getStatusCode(), response.getStatusCode());
+ assertNotNull(response.getContent());
+
+ request = new ODataRequest();
+ request.setMethod(HttpMethod.MERGE);
+ request.setRawODataPath("");
+ response = handler.process(request);
+ assertNotNull(response);
+ assertEquals(HttpStatusCode.METHOD_NOT_ALLOWED.getStatusCode(), response.getStatusCode());
+ assertNotNull(response.getContent());
+
+ request = new ODataRequest();
+ request.setMethod(HttpMethod.DELETE);
+ request.setRawODataPath("");
+ response = handler.process(request);
+ assertNotNull(response);
+ assertEquals(HttpStatusCode.METHOD_NOT_ALLOWED.getStatusCode(), response.getStatusCode());
+ assertNotNull(response.getContent());
+ }
+
+ @Test
public void testUriParserExceptionResultsInRightResponseNotFound() throws Exception {
ODataRequest request = new ODataRequest();
@@ -100,8 +185,6 @@ public class ODataHandlerExceptionHandlingTest {
ODataResponse response = localHandler.process(request);
assertNotNull(response);
assertEquals(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode());
- // TODO: Check for message in case of EdmException
- System.out.println(IOUtils.toString(response.getContent()));
}
@Test
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5af9f46d/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
index 83e2173..3d8243e 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
@@ -35,7 +35,7 @@ import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.server.api.OData;
import org.apache.olingo.server.api.serializer.ODataSerializer;
-import org.apache.olingo.server.api.serializer.ODataSerializerException;
+import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.api.serializer.ODataSerializerOptions;
import org.apache.olingo.server.api.uri.queryoption.CountOption;
import org.apache.olingo.server.api.uri.queryoption.ExpandItem;
@@ -110,7 +110,7 @@ public class ODataJsonSerializerTest {
Assert.assertEquals(expectedResult, resultString);
}
- @Test(expected = ODataSerializerException.class)
+ @Test(expected = SerializerException.class)
public void entityAllPrimKeyNull() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");
Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
@@ -132,8 +132,8 @@ public class ODataJsonSerializerTest {
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.build());
Assert.fail("Expected exception not thrown!");
- } catch (final ODataSerializerException e) {
- Assert.assertEquals(ODataSerializerException.MessageKeys.WRONG_PROPERTY_VALUE, e.getMessageKey());
+ } catch (final SerializerException e) {
+ Assert.assertEquals(SerializerException.MessageKeys.WRONG_PROPERTY_VALUE, e.getMessageKey());
final String message = e.getLocalizedMessage();
Assert.assertThat(message, CoreMatchers.containsString("PropertyInt16"));
Assert.assertThat(message, CoreMatchers.containsString("false"));
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5af9f46d/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java
index 609d33e..2dbce10 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java
@@ -55,14 +55,14 @@ import org.apache.olingo.server.api.edm.provider.Schema;
import org.apache.olingo.server.api.edm.provider.Singleton;
import org.apache.olingo.server.api.edm.provider.TypeDefinition;
import org.apache.olingo.server.api.serializer.ODataSerializer;
-import org.apache.olingo.server.api.serializer.ODataSerializerException;
+import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.core.edm.provider.EdmProviderImpl;
import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
import org.junit.Test;
public class MetadataDocumentTest {
- @Test(expected = ODataSerializerException.class)
+ @Test(expected = SerializerException.class)
public void metadataOnJsonResultsInException() throws Exception {
ODataSerializer serializer = OData.newInstance().createSerializer(ODataFormat.JSON);
serializer.metadataDocument(mock(Edm.class));
[2/2] git commit: [OLINGO-447] Improve ODataHttpHandler and
ODataHandler
Posted by ch...@apache.org.
[OLINGO-447] Improve ODataHttpHandler and ODataHandler
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/5af9f46d
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/5af9f46d
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/5af9f46d
Branch: refs/heads/master
Commit: 5af9f46d416d209125950b327149cd1892009c69
Parents: eacc63c
Author: Christian Amend <ch...@apache.org>
Authored: Thu Oct 2 17:08:53 2014 +0200
Committer: Christian Amend <ch...@apache.org>
Committed: Thu Oct 2 17:08:53 2014 +0200
----------------------------------------------------------------------
.../client/BasicHttpExceptionHandling.java | 56 ++++++++++++
.../org/apache/olingo/server/api/OData.java | 4 +-
.../apache/olingo/server/api/ODataResponse.java | 3 +-
.../api/processor/CustomContentTypeSupport.java | 45 +++++++++
.../CustomContentTypeSupportProcessor.java | 45 ---------
.../server/api/processor/DefaultProcessor.java | 15 ++-
.../server/api/processor/EntityProcessor.java | 15 ++-
.../api/processor/EntitySetProcessor.java | 36 +++++---
.../api/processor/ExceptionProcessor.java | 2 +-
.../server/api/processor/MetadataProcessor.java | 5 +-
.../api/processor/ServiceDocumentProcessor.java | 4 +-
.../server/api/serializer/ODataSerializer.java | 12 +--
.../serializer/ODataSerializerException.java | 74 ---------------
.../api/serializer/SerializerException.java | 74 +++++++++++++++
.../olingo/server/core/ContentNegotiator.java | 6 +-
.../server/core/ODataExceptionHelper.java | 30 ++++--
.../apache/olingo/server/core/ODataHandler.java | 58 +++++++-----
.../server/core/ODataHandlerException.java | 3 +-
.../server/core/ODataHttpHandlerImpl.java | 72 +++++----------
.../apache/olingo/server/core/ODataImpl.java | 8 +-
.../core/serializer/ODataXmlSerializerImpl.java | 38 ++++----
.../serializer/json/ODataErrorSerializer.java | 8 +-
.../serializer/json/ODataJsonSerializer.java | 96 ++++++++++----------
.../core/serializer/utils/ContextURLHelper.java | 8 +-
.../serializer/utils/ExpandSelectHelper.java | 8 +-
.../server-core-exceptions-i18n.properties | 23 ++---
.../server/core/ContentNegotiatorTest.java | 4 +-
.../core/TranslatedExceptionSubclassesTest.java | 4 +-
.../json/ODataErrorSerializerTest.java | 4 +-
.../tecsvc/processor/TechnicalProcessor.java | 8 +-
.../core/ODataHandlerExceptionHandlingTest.java | 89 +++++++++++++++++-
.../json/ODataJsonSerializerTest.java | 8 +-
.../serializer/xml/MetadataDocumentTest.java | 4 +-
33 files changed, 516 insertions(+), 353 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5af9f46d/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicHttpExceptionHandling.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicHttpExceptionHandling.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicHttpExceptionHandling.java
new file mode 100644
index 0000000..df208c5
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicHttpExceptionHandling.java
@@ -0,0 +1,56 @@
+/*
+ * 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.fit.tecsvc.client;
+
+import static org.junit.Assert.assertEquals;
+
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import org.apache.olingo.client.api.CommonODataClient;
+import org.apache.olingo.commons.api.http.HttpHeader;
+import org.apache.olingo.fit.AbstractBaseTestITCase;
+import org.apache.olingo.fit.tecsvc.TecSvcConst;
+import org.junit.Test;
+
+public class BasicHttpExceptionHandling extends AbstractBaseTestITCase {
+
+ private static final String SERVICE_URI = TecSvcConst.BASE_URI + "/";
+
+ @Test
+ public void ambigiousXHTTPMethod() throws Exception{
+ URL url = new URL(SERVICE_URI + "?$format=json");
+
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+ connection.setRequestMethod("POST");
+ connection.setRequestProperty(HttpHeader.ACCEPT, "application/json");
+ connection.setRequestProperty(HttpHeader.X_HTTP_METHOD, "value");
+ connection.setRequestProperty(HttpHeader.X_HTTP_METHOD_OVERRIDE, "differentValue");
+ connection.connect();
+
+ int code = connection.getResponseCode();
+ assertEquals(400, code);
+ }
+
+ @Override
+ protected CommonODataClient<?> getClient() {
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5af9f46d/lib/server-api/src/main/java/org/apache/olingo/server/api/OData.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/OData.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/OData.java
index 6087d89..34d79fe 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/OData.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/OData.java
@@ -23,7 +23,7 @@ import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.server.api.edm.provider.EdmProvider;
import org.apache.olingo.server.api.serializer.ODataSerializer;
-import org.apache.olingo.server.api.serializer.ODataSerializerException;
+import org.apache.olingo.server.api.serializer.SerializerException;
/**
* Root object for serving factory tasks and support loose coupling of implementation (core) from the API.
@@ -56,7 +56,7 @@ public abstract class OData {
* Serializers are used in Processor implementations.
* @param format - any format supported by Olingo (XML, JSON ...)
*/
- public abstract ODataSerializer createSerializer(ODataFormat format) throws ODataSerializerException;
+ public abstract ODataSerializer createSerializer(ODataFormat format) throws SerializerException;
/**
* Creates a new ODataHttpHandler for handling OData requests in an HTTP context.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5af9f46d/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataResponse.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataResponse.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataResponse.java
index d701e0b..d629112 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataResponse.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataResponse.java
@@ -34,6 +34,7 @@ public class ODataResponse {
private Map<String, String> headers = new HashMap<String, String>();
private InputStream content;
+
/**
* Sets the status code.
* @see HttpStatusCode
@@ -52,7 +53,7 @@ public class ODataResponse {
/**
* Sets a header.
- * @param name the name
+ * @param name the name
* @param value the value
*/
public void setHeader(final String name, final String value) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5af9f46d/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/CustomContentTypeSupport.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/CustomContentTypeSupport.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/CustomContentTypeSupport.java
new file mode 100644
index 0000000..4759919
--- /dev/null
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/CustomContentTypeSupport.java
@@ -0,0 +1,45 @@
+/*
+ * 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.api.processor;
+
+import java.util.List;
+
+import org.apache.olingo.commons.api.format.ContentType;
+
+/**
+ * A processor which supports custom content types can implement this interface.
+ * The processor can also remove default content types if the default serializers
+ * of Olingo are not used. By default this interface is not implemented and
+ * a processor supports content types implemented by Olingo's default serializer
+ * (e.g., <code>application/xml</code> for the metadata and
+ * </code>application/json</code> for the service document).
+ * Requesting a content type that is not supported results in an HTTP error
+ * 406 (Not Acceptable).
+ */
+public interface CustomContentTypeSupport {
+
+ /**
+ * Returns a list of supported content types.
+ * @param defaultContentTypes content types supported by Olingo's serializer
+ * @param processorClass the {@link Processor} of the current request
+ * @return modified list of supported content types
+ */
+ public List<ContentType> modifySupportedContentTypes(
+ List<ContentType> defaultContentTypes, Class<? extends Processor> processorClass);
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5af9f46d/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/CustomContentTypeSupportProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/CustomContentTypeSupportProcessor.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/CustomContentTypeSupportProcessor.java
deleted file mode 100644
index 7969bc8..0000000
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/CustomContentTypeSupportProcessor.java
+++ /dev/null
@@ -1,45 +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.
- */
-package org.apache.olingo.server.api.processor;
-
-import java.util.List;
-
-import org.apache.olingo.commons.api.format.ContentType;
-
-/**
- * A processor which supports custom content types can implement this interface.
- * The processor can also remove default content types if the default serializers
- * of Olingo are not used. By default this interface is not implemented and
- * a processor supports content types implemented by Olingo's default serializer
- * (e.g., <code>application/xml</code> for the metadata and
- * </code>application/json</code> for the service document).
- * Requesting a content type that is not supported results in an HTTP error
- * 406 (Not Acceptable).
- */
-public interface CustomContentTypeSupportProcessor {
-
- /**
- * Returns a list of supported content types.
- * @param defaultContentTypes content types supported by Olingo's serializer
- * @param processorClass the {@link Processor} of the current request
- * @return modified list of supported content types
- */
- public List<ContentType> modifySupportedContentTypes(
- List<ContentType> defaultContentTypes, Class<? extends Processor> processorClass);
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5af9f46d/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/DefaultProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/DefaultProcessor.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/DefaultProcessor.java
index 7e8e9fb..b674e02 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/DefaultProcessor.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/DefaultProcessor.java
@@ -22,16 +22,18 @@ import java.io.ByteArrayInputStream;
import java.io.InputStream;
import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.apache.olingo.commons.api.format.ContentType;
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.ODataServerError;
import org.apache.olingo.server.api.serializer.ODataSerializer;
-import org.apache.olingo.server.api.serializer.ODataSerializerException;
+import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.api.uri.UriInfo;
/**
@@ -55,26 +57,26 @@ public class DefaultProcessor implements MetadataProcessor, ServiceDocumentProce
@Override
public void readServiceDocument(final ODataRequest request, final ODataResponse response, final UriInfo uriInfo,
- final ContentType requestedContentType) {
+ final ContentType requestedContentType) throws ODataApplicationException, SerializerException {
try {
ODataSerializer serializer = odata.createSerializer(ODataFormat.fromContentType(requestedContentType));
response.setContent(serializer.serviceDocument(edm, request.getRawBaseUri()));
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());
- } catch (final ODataSerializerException e) {
+ } catch (final SerializerException e) {
response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
}
}
@Override
public void readMetadata(final ODataRequest request, final ODataResponse response, final UriInfo uriInfo,
- final ContentType requestedContentType) {
+ final ContentType requestedContentType) throws ODataApplicationException, SerializerException {
try {
ODataSerializer serializer = odata.createSerializer(ODataFormat.fromContentType(requestedContentType));
response.setContent(serializer.metadataDocument(edm));
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());
- } catch (final ODataSerializerException e) {
+ } catch (final SerializerException e) {
response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
}
}
@@ -83,6 +85,9 @@ public class DefaultProcessor implements MetadataProcessor, ServiceDocumentProce
public void processException(ODataRequest request, ODataResponse response, ODataServerError serverError,
ContentType requestedContentType) {
try {
+ if(ContentType.APPLICATION_XML.equals(requestedContentType)){
+ requestedContentType = ODataFormat.JSON.getContentType(ODataServiceVersion.V40);
+ }
ODataSerializer serializer = odata.createSerializer(ODataFormat.fromContentType(requestedContentType));
InputStream responseEntity = serializer.error(serverError);
response.setStatusCode(serverError.getStatusCode());
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5af9f46d/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/EntityProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/EntityProcessor.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/EntityProcessor.java
index a277fa9..1d2075b 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/EntityProcessor.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/EntityProcessor.java
@@ -19,8 +19,10 @@
package org.apache.olingo.server.api.processor;
import org.apache.olingo.commons.api.format.ContentType;
+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.serializer.SerializerException;
import org.apache.olingo.server.api.uri.UriInfo;
/**
@@ -30,10 +32,13 @@ public interface EntityProcessor extends Processor {
/**
* Reads entity data from persistency and puts serialized content and status into the response.
- * @param request - OData request object containing raw HTTP information
- * @param response - OData response object for collecting response data
- * @param uriInfo - information of a parsed OData URI
- * @param requestedContentType - requested content type after content negotiation
+ * @param request - OData request object containing raw HTTP information
+ * @param response - OData response object for collecting response data
+ * @param uriInfo - information of a parsed OData URI
+ * @param requestedContentType - requested content type after content negotiation
+ * @throws ODataApplicationException
+ * @throws SerializerException
*/
- void readEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType format);
+ void readEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType requestedContentType)
+ throws ODataApplicationException, SerializerException;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5af9f46d/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/EntitySetProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/EntitySetProcessor.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/EntitySetProcessor.java
index e23823c..fbb3faf 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/EntitySetProcessor.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/EntitySetProcessor.java
@@ -19,8 +19,10 @@
package org.apache.olingo.server.api.processor;
import org.apache.olingo.commons.api.format.ContentType;
+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.serializer.SerializerException;
import org.apache.olingo.server.api.uri.UriInfo;
/**
@@ -29,22 +31,28 @@ import org.apache.olingo.server.api.uri.UriInfo;
public interface EntitySetProcessor extends Processor {
/**
- * Reads entities data from persistence and puts serialized content and status into the response.
- *
- * @param request - OData request object containing raw HTTP information
- * @param response - OData response object for collecting response data
- * @param uriInfo - information of a parsed OData URI
- * @param requestedContentType - requested content type after content negotiation
+ * Reads entities data from persistence and puts serialized content and status into the response.
+ *
+ * @param request - OData request object containing raw HTTP information
+ * @param response - OData response object for collecting response data
+ * @param uriInfo - information of a parsed OData URI
+ * @param requestedContentType - requested content type after content negotiation
+ * @throws ODataApplicationException
+ * @throws SerializerException
*/
- void readEntitySet(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType requestedContentType);
+ void readEntitySet(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType requestedContentType)
+ throws ODataApplicationException, SerializerException;
/**
- * Count entities from persistence and puts serialized content and status into the response.
- * Response content type is <code>text/plain</code> by default.
- *
- * @param request - OData request object containing raw http information.
- * @param response - OData response object for collecting response data
- * @param uriInfo - information of a parsed OData uri
+ * Count entities from persistence and puts serialized content and status into the response.
+ * Response content type is <code>text/plain</code> by default.
+ *
+ * @param request - OData request object containing raw http information.
+ * @param response - OData response object for collecting response data
+ * @param uriInfo - information of a parsed OData uri
+ * @throws ODataApplicationException
+ * @throws SerializerException
*/
- void countEntitySet(ODataRequest request, ODataResponse response, UriInfo uriInfo);
+ void countEntitySet(ODataRequest request, ODataResponse response, UriInfo uriInfo) throws ODataApplicationException,
+ SerializerException;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5af9f46d/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/ExceptionProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/ExceptionProcessor.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/ExceptionProcessor.java
index 967052b..170d6a4 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/ExceptionProcessor.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/ExceptionProcessor.java
@@ -29,7 +29,7 @@ import org.apache.olingo.server.api.ODataServerError;
public interface ExceptionProcessor extends Processor{
/**
- * Processes an exception.
+ * Processes an exception. MUST NOT throw an exception!
* @param request the request
* @param response the response
* @param serverError the server error
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5af9f46d/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/MetadataProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/MetadataProcessor.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/MetadataProcessor.java
index 5abfe67..33d1551 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/MetadataProcessor.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/MetadataProcessor.java
@@ -22,6 +22,7 @@ import org.apache.olingo.commons.api.format.ContentType;
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.serializer.SerializerException;
import org.apache.olingo.server.api.uri.UriInfo;
/**
@@ -35,7 +36,9 @@ public interface MetadataProcessor extends Processor {
* @param response - OData response object for collecting response data
* @param uriInfo - information of a parsed OData URI
* @param requestedContentType - requested content type after content negotiation
+ * @throws ODataApplicationException
+ * @throws SerializerException
*/
void readMetadata(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType requestedContentType)
- throws ODataApplicationException;
+ throws ODataApplicationException, SerializerException;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5af9f46d/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/ServiceDocumentProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/ServiceDocumentProcessor.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/ServiceDocumentProcessor.java
index 784b288..ac2e4d5 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/ServiceDocumentProcessor.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/ServiceDocumentProcessor.java
@@ -19,8 +19,10 @@
package org.apache.olingo.server.api.processor;
import org.apache.olingo.commons.api.format.ContentType;
+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.serializer.SerializerException;
import org.apache.olingo.server.api.uri.UriInfo;
/**
@@ -36,5 +38,5 @@ public interface ServiceDocumentProcessor extends Processor {
* @param requestedContentType - requested content type after content negotiation
*/
void readServiceDocument(ODataRequest request, ODataResponse response, UriInfo uriInfo,
- ContentType requestedContentType);
+ ContentType requestedContentType) throws ODataApplicationException, SerializerException;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5af9f46d/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
index 8d11ee4..e78f56c 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
@@ -39,13 +39,13 @@ public interface ODataSerializer {
* @param edm the Entity Data Model
* @param serviceRoot the service-root URI of this OData service
*/
- InputStream serviceDocument(Edm edm, String serviceRoot) throws ODataSerializerException;
+ InputStream serviceDocument(Edm edm, String serviceRoot) throws SerializerException;
/**
* Writes the metadata document into an InputStream.
* @param edm the Entity Data Model
*/
- InputStream metadataDocument(Edm edm) throws ODataSerializerException;
+ InputStream metadataDocument(Edm edm) throws SerializerException;
/**
* Writes entity data into an InputStream.
@@ -54,7 +54,7 @@ public interface ODataSerializer {
* @param options options for the serializer
*/
InputStream entity(EdmEntitySet edmEntitySet, Entity entity, ODataSerializerOptions options)
- throws ODataSerializerException;
+ throws SerializerException;
/**
* Writes entity-set data into an InputStream.
@@ -63,14 +63,14 @@ public interface ODataSerializer {
* @param options options for the serializer
*/
InputStream entitySet(EdmEntitySet edmEntitySet, EntitySet entitySet, ODataSerializerOptions options)
- throws ODataSerializerException;
+ throws SerializerException;
/**
* Writes an ODataError into an InputStream.
* @param error the main error
* @return inputStream containing the OData-formatted error
*/
- InputStream error(ODataServerError error) throws ODataSerializerException;
+ InputStream error(ODataServerError error) throws SerializerException;
/**
* Builds the select-list part of a {@link org.apache.olingo.commons.api.data.ContextURL ContextURL}.
@@ -80,5 +80,5 @@ public interface ODataSerializer {
* @return a String with the select list
*/
String buildContextURLSelectList(EdmEntitySet edmEntitySet, ExpandOption expand, SelectOption select)
- throws ODataSerializerException;
+ throws SerializerException;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5af9f46d/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializerException.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializerException.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializerException.java
deleted file mode 100644
index 809be07..0000000
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializerException.java
+++ /dev/null
@@ -1,74 +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.
- */
-package org.apache.olingo.server.api.serializer;
-
-import org.apache.olingo.server.api.ODataTranslatedException;
-
-/** Exception thrown by the {@link ODataSerializer}. */
-public class ODataSerializerException extends ODataTranslatedException {
-
- private static final long serialVersionUID = 5358683245923127425L;
-
- /** Keys for exception texts in the resource bundle. */
- public static enum MessageKeys implements MessageKey {
- NOT_IMPLEMENTED,
- /** parameter: format */ UNSUPPORTED_FORMAT,
- JSON_METADATA,
- IO_EXCEPTION,
- NULL_INPUT,
- NO_CONTEXT_URL,
- /** parameter: property name */ UNSUPPORTED_PROPERTY_TYPE,
- /** parameter: property name */ INCONSISTENT_PROPERTY_TYPE,
- /** parameter: property name */ MISSING_PROPERTY,
- /** parameters: property name, property value */ WRONG_PROPERTY_VALUE;
-
- @Override
- public String getKey() {
- return name();
- }
- }
-
- /**
- * Creates serializer exception.
- * @param developmentMessage message text as fallback and for debugging purposes
- * @param messageKey one of the {@link MessageKeys} for the exception text in the resource bundle
- * @param parameters parameters for the exception text
- */
- public ODataSerializerException(final String developmentMessage,
- final MessageKey messageKey, final String... parameters) {
- super(developmentMessage, messageKey, parameters);
- }
-
- /**
- * Creates serializer exception.
- * @param developmentMessage message text as fallback and for debugging purposes
- * @param cause the cause of this exception
- * @param messageKey one of the {@link MessageKeys} for the exception text in the resource bundle
- * @param parameters parameters for the exception text
- */
- public ODataSerializerException(final String developmentMessage, final Throwable cause,
- final MessageKey messageKey, final String... parameters) {
- super(developmentMessage, cause, messageKey, parameters);
- }
-
- @Override
- protected String getBundleName() {
- return DEFAULT_SERVER_BUNDLE_NAME;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5af9f46d/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerException.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerException.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerException.java
new file mode 100644
index 0000000..5617a79
--- /dev/null
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerException.java
@@ -0,0 +1,74 @@
+/*
+ * 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.api.serializer;
+
+import org.apache.olingo.server.api.ODataTranslatedException;
+
+/** Exception thrown by the {@link ODataSerializer}. */
+public class SerializerException extends ODataTranslatedException {
+
+ private static final long serialVersionUID = 5358683245923127425L;
+
+ /** Keys for exception texts in the resource bundle. */
+ public static enum MessageKeys implements MessageKey {
+ NOT_IMPLEMENTED,
+ /** parameter: format */ UNSUPPORTED_FORMAT,
+ JSON_METADATA,
+ IO_EXCEPTION,
+ NULL_INPUT,
+ NO_CONTEXT_URL,
+ /** parameter: property name */ UNSUPPORTED_PROPERTY_TYPE,
+ /** parameter: property name */ INCONSISTENT_PROPERTY_TYPE,
+ /** parameter: property name */ MISSING_PROPERTY,
+ /** parameters: property name, property value */ WRONG_PROPERTY_VALUE;
+
+ @Override
+ public String getKey() {
+ return name();
+ }
+ }
+
+ /**
+ * Creates serializer exception.
+ * @param developmentMessage message text as fallback and for debugging purposes
+ * @param messageKey one of the {@link MessageKeys} for the exception text in the resource bundle
+ * @param parameters parameters for the exception text
+ */
+ public SerializerException(final String developmentMessage,
+ final MessageKey messageKey, final String... parameters) {
+ super(developmentMessage, messageKey, parameters);
+ }
+
+ /**
+ * Creates serializer exception.
+ * @param developmentMessage message text as fallback and for debugging purposes
+ * @param cause the cause of this exception
+ * @param messageKey one of the {@link MessageKeys} for the exception text in the resource bundle
+ * @param parameters parameters for the exception text
+ */
+ public SerializerException(final String developmentMessage, final Throwable cause,
+ final MessageKey messageKey, final String... parameters) {
+ super(developmentMessage, cause, messageKey, parameters);
+ }
+
+ @Override
+ protected String getBundleName() {
+ return DEFAULT_SERVER_BUNDLE_NAME;
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5af9f46d/lib/server-core/src/main/java/org/apache/olingo/server/core/ContentNegotiator.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ContentNegotiator.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ContentNegotiator.java
index c6fb1bf..a4952ad 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ContentNegotiator.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ContentNegotiator.java
@@ -27,7 +27,7 @@ import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.api.http.HttpHeader;
import org.apache.olingo.server.api.ODataRequest;
-import org.apache.olingo.server.api.processor.CustomContentTypeSupportProcessor;
+import org.apache.olingo.server.api.processor.CustomContentTypeSupport;
import org.apache.olingo.server.api.processor.MetadataProcessor;
import org.apache.olingo.server.api.processor.Processor;
import org.apache.olingo.server.api.uri.queryoption.FormatOption;
@@ -54,8 +54,8 @@ public class ContentNegotiator {
List<ContentType> supportedContentTypes = getDefaultSupportedContentTypes(processorClass);
- if (processor instanceof CustomContentTypeSupportProcessor) {
- supportedContentTypes = ((CustomContentTypeSupportProcessor) processor)
+ if (processor instanceof CustomContentTypeSupport) {
+ supportedContentTypes = ((CustomContentTypeSupport) processor)
.modifySupportedContentTypes(supportedContentTypes, processorClass);
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5af9f46d/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 9b0ddfd..4caceab 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
@@ -25,31 +25,32 @@ import org.apache.olingo.server.api.ODataApplicationException;
import org.apache.olingo.server.api.ODataServerError;
import org.apache.olingo.server.api.ODataTranslatedException;
import org.apache.olingo.server.api.ODataTranslatedException.ODataErrorMessage;
+import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.core.uri.parser.UriParserException;
import org.apache.olingo.server.core.uri.parser.UriParserSemanticException;
import org.apache.olingo.server.core.uri.parser.UriParserSyntaxException;
import org.apache.olingo.server.core.uri.validator.UriValidationException;
public class ODataExceptionHelper {
-
+
public static ODataServerError createServerErrorObject(UriValidationException e, Locale requestedLocale) {
ODataServerError serverError = basicTranslatedError(e, requestedLocale);
serverError.setStatusCode(HttpStatusCode.BAD_REQUEST.getStatusCode());
return serverError;
}
-
+
public static ODataServerError createServerErrorObject(UriParserSemanticException e, Locale requestedLocale) {
ODataServerError serverError = basicTranslatedError(e, requestedLocale);
- if(UriParserSemanticException.MessageKeys.RESOURCE_NOT_FOUND.equals(e.getMessageKey())
+ if (UriParserSemanticException.MessageKeys.RESOURCE_NOT_FOUND.equals(e.getMessageKey())
|| UriParserSemanticException.MessageKeys.FUNCTION_NOT_FOUND.equals(e.getMessageKey())
- || UriParserSemanticException.MessageKeys.PROPERTY_NOT_IN_TYPE.equals(e.getMessageKey())){
+ || UriParserSemanticException.MessageKeys.PROPERTY_NOT_IN_TYPE.equals(e.getMessageKey())) {
serverError.setStatusCode(HttpStatusCode.NOT_FOUND.getStatusCode());
- }else{
+ } else {
serverError.setStatusCode(HttpStatusCode.BAD_REQUEST.getStatusCode());
}
return serverError;
}
-
+
public static ODataServerError createServerErrorObject(UriParserSyntaxException e, Locale requestedLocale) {
ODataServerError serverError = basicTranslatedError(e, requestedLocale);
serverError.setStatusCode(
@@ -58,13 +59,13 @@ public class ODataExceptionHelper {
HttpStatusCode.BAD_REQUEST.getStatusCode());
return serverError;
}
-
+
public static ODataServerError createServerErrorObject(UriParserException e, Locale requestedLocale) {
ODataServerError serverError = basicTranslatedError(e, requestedLocale);
serverError.setStatusCode(HttpStatusCode.BAD_REQUEST.getStatusCode());
return serverError;
}
-
+
public static ODataServerError createServerErrorObject(ContentNegotiatorException e, Locale requestedLocale) {
ODataServerError serverError = basicTranslatedError(e, requestedLocale);
serverError.setStatusCode(HttpStatusCode.NOT_ACCEPTABLE.getStatusCode());
@@ -74,16 +75,25 @@ public class ODataExceptionHelper {
public static ODataServerError createServerErrorObject(ODataHandlerException e, Locale requestedLocale) {
ODataServerError serverError = basicTranslatedError(e, requestedLocale);
if (ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED.equals(e.getMessageKey())
- || ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_IMPLEMENTED.equals(e.getMessageKey())
|| ODataHandlerException.MessageKeys.PROCESSOR_NOT_IMPLEMENTED.equals(e.getMessageKey())) {
serverError.setStatusCode(HttpStatusCode.NOT_IMPLEMENTED.getStatusCode());
- } else if (ODataHandlerException.MessageKeys.ODATA_VERSION_NOT_SUPPORTED.equals(e.getMessageKey())) {
+ } else if (ODataHandlerException.MessageKeys.ODATA_VERSION_NOT_SUPPORTED.equals(e.getMessageKey())
+ || ODataHandlerException.MessageKeys.INVALID_HTTP_METHOD.equals(e.getMessageKey())
+ || ODataHandlerException.MessageKeys.AMBIGUOUS_XHTTP_METHOD.equals(e.getMessageKey())) {
serverError.setStatusCode(HttpStatusCode.BAD_REQUEST.getStatusCode());
+ } else if (ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED.equals(e.getMessageKey())) {
+ serverError.setStatusCode(HttpStatusCode.METHOD_NOT_ALLOWED.getStatusCode());
}
return serverError;
}
+ public static ODataServerError createServerErrorObject(SerializerException e, Locale requestedLocale) {
+ ODataServerError serverError = basicTranslatedError(e, requestedLocale);
+ serverError.setStatusCode(HttpStatusCode.BAD_REQUEST.getStatusCode());
+ return serverError;
+ }
+
public static ODataServerError createServerErrorObject(ODataTranslatedException e, Locale requestedLocale) {
return basicTranslatedError(e, requestedLocale);
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5af9f46d/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 5527607..1f09b21 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
@@ -40,6 +40,7 @@ import org.apache.olingo.server.api.processor.ExceptionProcessor;
import org.apache.olingo.server.api.processor.MetadataProcessor;
import org.apache.olingo.server.api.processor.Processor;
import org.apache.olingo.server.api.processor.ServiceDocumentProcessor;
+import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.api.uri.UriInfo;
import org.apache.olingo.server.api.uri.UriResource;
import org.apache.olingo.server.api.uri.UriResourceNavigation;
@@ -57,6 +58,7 @@ public class ODataHandler {
private final Edm edm;
private final Map<Class<? extends Processor>, Processor> processors =
new HashMap<Class<? extends Processor>, Processor>();
+ private ContentType requestedContentType;
public ODataHandler(final OData server, final Edm edm) {
odata = server;
@@ -67,11 +69,10 @@ public class ODataHandler {
}
public ODataResponse process(final ODataRequest request) {
- ContentType requestedContentType = null;
ODataResponse response = new ODataResponse();
try {
- processInternal(request, requestedContentType, response);
+ processInternal(request, response);
} catch (final UriValidationException e) {
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
@@ -88,6 +89,9 @@ public class ODataHandler {
} catch (ContentNegotiatorException e) {
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
handleException(request, response, serverError, null);
+ } catch (SerializerException e) {
+ ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
+ handleException(request, response, serverError, requestedContentType);
} catch (ODataHandlerException e) {
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
handleException(request, response, serverError, requestedContentType);
@@ -101,10 +105,9 @@ public class ODataHandler {
return response;
}
- private void processInternal(final ODataRequest request, ContentType requestedContentType,
- final ODataResponse response)
+ private void processInternal(final ODataRequest request, final ODataResponse response)
throws ODataHandlerException, UriParserException, UriValidationException, ContentNegotiatorException,
- ODataApplicationException {
+ ODataApplicationException, SerializerException {
validateODataVersion(request, response);
Parser parser = new Parser();
@@ -115,25 +118,34 @@ public class ODataHandler {
switch (uriInfo.getKind()) {
case metadata:
- MetadataProcessor mp = selectProcessor(MetadataProcessor.class);
-
- requestedContentType =
- ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request, mp, MetadataProcessor.class);
+ if (request.getMethod().equals(HttpMethod.GET)) {
+ MetadataProcessor mp = selectProcessor(MetadataProcessor.class);
- mp.readMetadata(request, response, uriInfo, requestedContentType);
+ requestedContentType =
+ ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request, mp, MetadataProcessor.class);
+ mp.readMetadata(request, response, uriInfo, requestedContentType);
+ } else {
+ throw new ODataHandlerException("HttpMethod " + request.getMethod() + " not allowed for metadata document",
+ ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, request.getMethod().toString());
+ }
break;
case service:
- if ("".equals(request.getRawODataPath())) {
- RedirectProcessor rdp = selectProcessor(RedirectProcessor.class);
- rdp.redirect(request, response);
- } else {
- ServiceDocumentProcessor sdp = selectProcessor(ServiceDocumentProcessor.class);
+ if (request.getMethod().equals(HttpMethod.GET)) {
+ if ("".equals(request.getRawODataPath())) {
+ RedirectProcessor rdp = selectProcessor(RedirectProcessor.class);
+ rdp.redirect(request, response);
+ } else {
+ ServiceDocumentProcessor sdp = selectProcessor(ServiceDocumentProcessor.class);
- requestedContentType =
- ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request, sdp,
- ServiceDocumentProcessor.class);
+ requestedContentType =
+ ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request, sdp,
+ ServiceDocumentProcessor.class);
- sdp.readServiceDocument(request, response, uriInfo, requestedContentType);
+ sdp.readServiceDocument(request, response, uriInfo, requestedContentType);
+ }
+ } else {
+ throw new ODataHandlerException("HttpMethod " + request.getMethod() + " not allowed for service document",
+ ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, request.getMethod().toString());
}
break;
case resource:
@@ -145,12 +157,13 @@ public class ODataHandler {
}
}
- private void handleException(ODataRequest request, ODataResponse response, ODataServerError serverError,
+ public void handleException(ODataRequest request, ODataResponse response, ODataServerError serverError,
ContentType requestedContentType) {
ExceptionProcessor exceptionProcessor;
try {
exceptionProcessor = selectProcessor(ExceptionProcessor.class);
} catch (ODataTranslatedException e) {
+ // This cannot happen since there is always an ExceptionProcessor registered
exceptionProcessor = new DefaultProcessor();
}
if (requestedContentType == null) {
@@ -160,7 +173,8 @@ public class ODataHandler {
}
private void handleResourceDispatching(final ODataRequest request, final ODataResponse response,
- final UriInfo uriInfo) throws ODataHandlerException, ContentNegotiatorException {
+ final UriInfo uriInfo) throws ODataHandlerException, ContentNegotiatorException, ODataApplicationException,
+ SerializerException {
int lastPathSegmentIndex = uriInfo.getUriResourceParts().size() - 1;
UriResource lastPathSegment = uriInfo.getUriResourceParts().get(lastPathSegmentIndex);
ContentType requestedContentType = null;
@@ -225,7 +239,7 @@ public class ODataHandler {
case count:
if (request.getMethod().equals(HttpMethod.GET)) {
EntitySetProcessor cp = selectProcessor(EntitySetProcessor.class);
- cp.countEntitySet(request, response, uriInfo);
+ cp.countEntitySet(request, response, uriInfo);
} else {
throw new ODataHandlerException("not implemented",
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5af9f46d/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
index 01048a6..cc4d662 100644
--- 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
@@ -26,7 +26,8 @@ public class ODataHandlerException extends ODataTranslatedException {
public static enum MessageKeys implements MessageKey {
/** parameters: HTTP method, HTTP method */ AMBIGUOUS_XHTTP_METHOD,
- /** parameter: HTTP method */ HTTP_METHOD_NOT_IMPLEMENTED,
+ /** parameter: HTTP method */ INVALID_HTTP_METHOD,
+ /** parameter: HTTP method */ HTTP_METHOD_NOT_ALLOWED,
/** parameter: processor interface */ PROCESSOR_NOT_IMPLEMENTED,
FUNCTIONALITY_NOT_IMPLEMENTED,
/** parameter: version */ ODATA_VERSION_NOT_SUPPORTED;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5af9f46d/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 4e1f90c..3b77bfd 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
@@ -18,13 +18,21 @@
*/
package org.apache.olingo.server.core;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Map.Entry;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
import org.apache.olingo.commons.api.ODataRuntimeException;
import org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.format.ContentType;
-import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.api.http.HttpHeader;
import org.apache.olingo.commons.api.http.HttpMethod;
-import org.apache.olingo.commons.api.http.HttpStatusCode;
import org.apache.olingo.server.api.OData;
import org.apache.olingo.server.api.ODataHttpHandler;
import org.apache.olingo.server.api.ODataRequest;
@@ -32,24 +40,10 @@ import org.apache.olingo.server.api.ODataResponse;
import org.apache.olingo.server.api.ODataServerError;
import org.apache.olingo.server.api.ODataTranslatedException;
import org.apache.olingo.server.api.processor.Processor;
-import org.apache.olingo.server.api.serializer.ODataSerializer;
-import org.apache.olingo.server.api.serializer.ODataSerializerException;
+import org.apache.olingo.server.api.serializer.SerializerException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map.Entry;
-
public class ODataHttpHandlerImpl implements ODataHttpHandler {
private static final Logger LOG = LoggerFactory.getLogger(ODataHttpHandlerImpl.class);
@@ -70,7 +64,7 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler {
odResponse = handler.process(odRequest);
// ALL future methods after process must not throw exceptions!
} catch (Exception e) {
- odResponse = handleException(e);
+ odResponse = handleException(odRequest, e);
}
convertToHttp(response, odResponse);
@@ -81,37 +75,17 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler {
this.split = split;
}
- private ODataResponse handleException(Exception e) {
+ private ODataResponse handleException(ODataRequest odRequest, Exception e) {
ODataResponse resp = new ODataResponse();
+ ODataServerError serverError;
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() == ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_IMPLEMENTED) {
- resp.setStatusCode(HttpStatusCode.NOT_IMPLEMENTED.getStatusCode());
- }
- }
-
- ODataServerError error = new ODataServerError();
- if (e instanceof ODataTranslatedException) {
- error.setMessage(((ODataTranslatedException) e).getTranslatedMessage(Locale.ENGLISH).getMessage());
+ serverError = ODataExceptionHelper.createServerErrorObject((ODataHandlerException) e, null);
+ } else if (e instanceof ODataTranslatedException) {
+ serverError = ODataExceptionHelper.createServerErrorObject((ODataTranslatedException) e, null);
} else {
- error.setMessage(e.getMessage());
- }
-
- try {
- ODataSerializer serializer = OData.newInstance().createSerializer(ODataFormat.JSON);
- resp.setContent(serializer.error(error));
- } catch (final ODataSerializerException e1) {
- // This should never happen but to be sure we have this catch here to prevent sending a stacktrace to a client.
- String responseContent =
- "{\"error\":{\"code\":null,\"message\":\"An unexpected exception occurred in the ODataHttpHandler during " +
- "error processing with message: " + e.getMessage() + "\"}}";
- resp.setContent(new ByteArrayInputStream(responseContent.getBytes()));
- resp.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
+ serverError = ODataExceptionHelper.createServerErrorObject(e);
}
- // Set header
- resp.setHeader(HttpHeader.CONTENT_TYPE, ContentType.APPLICATION_JSON.toContentTypeString());
+ handler.handleException(odRequest, resp, serverError, null);
return resp;
}
@@ -159,8 +133,8 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler {
return odRequest;
} catch (final IOException e) {
- throw new ODataSerializerException("An I/O exception occurred.", e,
- ODataSerializerException.MessageKeys.IO_EXCEPTION);
+ throw new SerializerException("An I/O exception occurred.", e,
+ SerializerException.MessageKeys.IO_EXCEPTION);
}
}
@@ -191,7 +165,7 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler {
}
} catch (IllegalArgumentException e) {
throw new ODataHandlerException("Invalid HTTP method" + httpRequest.getMethod(),
- ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_IMPLEMENTED, httpRequest.getMethod());
+ ODataHandlerException.MessageKeys.INVALID_HTTP_METHOD, httpRequest.getMethod());
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5af9f46d/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java
index 8c1032b..4c80676 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java
@@ -24,7 +24,7 @@ import org.apache.olingo.server.api.OData;
import org.apache.olingo.server.api.ODataHttpHandler;
import org.apache.olingo.server.api.edm.provider.EdmProvider;
import org.apache.olingo.server.api.serializer.ODataSerializer;
-import org.apache.olingo.server.api.serializer.ODataSerializerException;
+import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.core.edm.provider.EdmProviderImpl;
import org.apache.olingo.server.core.serializer.ODataXmlSerializerImpl;
import org.apache.olingo.server.core.serializer.json.ODataJsonSerializer;
@@ -32,7 +32,7 @@ import org.apache.olingo.server.core.serializer.json.ODataJsonSerializer;
public class ODataImpl extends OData {
@Override
- public ODataSerializer createSerializer(final ODataFormat format) throws ODataSerializerException {
+ public ODataSerializer createSerializer(final ODataFormat format) throws SerializerException {
ODataSerializer serializer;
switch (format) {
case JSON:
@@ -44,8 +44,8 @@ public class ODataImpl extends OData {
serializer = new ODataXmlSerializerImpl();
break;
default:
- throw new ODataSerializerException("Unsupported format: " + format,
- ODataSerializerException.MessageKeys.UNSUPPORTED_FORMAT, format.toString());
+ throw new SerializerException("Unsupported format: " + format,
+ SerializerException.MessageKeys.UNSUPPORTED_FORMAT, format.toString());
}
return serializer;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5af9f46d/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ODataXmlSerializerImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ODataXmlSerializerImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ODataXmlSerializerImpl.java
index 580833a..d327808 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ODataXmlSerializerImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ODataXmlSerializerImpl.java
@@ -30,7 +30,7 @@ import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmEntitySet;
import org.apache.olingo.server.api.ODataServerError;
import org.apache.olingo.server.api.serializer.ODataSerializer;
-import org.apache.olingo.server.api.serializer.ODataSerializerException;
+import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.api.serializer.ODataSerializerOptions;
import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
import org.apache.olingo.server.api.uri.queryoption.SelectOption;
@@ -45,13 +45,13 @@ public class ODataXmlSerializerImpl implements ODataSerializer {
private static final Logger log = LoggerFactory.getLogger(ODataXmlSerializerImpl.class);
@Override
- public InputStream serviceDocument(final Edm edm, final String serviceRoot) throws ODataSerializerException {
- throw new ODataSerializerException("Service Document not implemented for XML format",
- ODataSerializerException.MessageKeys.NOT_IMPLEMENTED);
+ public InputStream serviceDocument(final Edm edm, final String serviceRoot) throws SerializerException {
+ throw new SerializerException("Service Document not implemented for XML format",
+ SerializerException.MessageKeys.NOT_IMPLEMENTED);
}
@Override
- public InputStream metadataDocument(final Edm edm) throws ODataSerializerException {
+ public InputStream metadataDocument(final Edm edm) throws SerializerException {
CircleStreamBuffer buffer;
XMLStreamWriter xmlStreamWriter = null;
@@ -67,15 +67,15 @@ public class ODataXmlSerializerImpl implements ODataSerializer {
return buffer.getInputStream();
} catch (final XMLStreamException e) {
log.error(e.getMessage(), e);
- throw new ODataSerializerException("An I/O exception occurred.", e,
- ODataSerializerException.MessageKeys.IO_EXCEPTION);
+ throw new SerializerException("An I/O exception occurred.", e,
+ SerializerException.MessageKeys.IO_EXCEPTION);
} finally {
if (xmlStreamWriter != null) {
try {
xmlStreamWriter.close();
} catch (XMLStreamException e) {
- throw new ODataSerializerException("An I/O exception occurred.", e,
- ODataSerializerException.MessageKeys.IO_EXCEPTION);
+ throw new SerializerException("An I/O exception occurred.", e,
+ SerializerException.MessageKeys.IO_EXCEPTION);
}
}
}
@@ -83,27 +83,27 @@ public class ODataXmlSerializerImpl implements ODataSerializer {
@Override
public InputStream entity(final EdmEntitySet edmEntitySet, final Entity entity,
- final ODataSerializerOptions options) throws ODataSerializerException {
- throw new ODataSerializerException("Entity serialization not implemented for XML format",
- ODataSerializerException.MessageKeys.NOT_IMPLEMENTED);
+ final ODataSerializerOptions options) throws SerializerException {
+ throw new SerializerException("Entity serialization not implemented for XML format",
+ SerializerException.MessageKeys.NOT_IMPLEMENTED);
}
@Override
public InputStream entitySet(final EdmEntitySet edmEntitySet, final EntitySet entitySet,
- final ODataSerializerOptions options) throws ODataSerializerException {
- throw new ODataSerializerException("Entityset serialization not implemented for XML format",
- ODataSerializerException.MessageKeys.NOT_IMPLEMENTED);
+ final ODataSerializerOptions options) throws SerializerException {
+ throw new SerializerException("Entityset serialization not implemented for XML format",
+ SerializerException.MessageKeys.NOT_IMPLEMENTED);
}
@Override
- public InputStream error(ODataServerError error) throws ODataSerializerException {
- throw new ODataSerializerException("error serialization not implemented for XML format",
- ODataSerializerException.MessageKeys.NOT_IMPLEMENTED);
+ public InputStream error(ODataServerError error) throws SerializerException {
+ throw new SerializerException("error serialization not implemented for XML format",
+ SerializerException.MessageKeys.NOT_IMPLEMENTED);
}
@Override
public String buildContextURLSelectList(final EdmEntitySet edmEntitySet,
- final ExpandOption expand, final SelectOption select) throws ODataSerializerException {
+ final ExpandOption expand, final SelectOption select) throws SerializerException {
return ContextURLHelper.buildSelectList(edmEntitySet.getEntityType(), expand, select);
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5af9f46d/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataErrorSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataErrorSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataErrorSerializer.java
index 39c44ea..14381bb 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataErrorSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataErrorSerializer.java
@@ -23,17 +23,17 @@ import java.io.IOException;
import org.apache.olingo.commons.api.Constants;
import org.apache.olingo.commons.api.domain.ODataError;
import org.apache.olingo.commons.api.domain.ODataErrorDetail;
-import org.apache.olingo.server.api.serializer.ODataSerializerException;
+import org.apache.olingo.server.api.serializer.SerializerException;
import com.fasterxml.jackson.core.JsonGenerator;
public class ODataErrorSerializer {
public void writeErrorDocument(JsonGenerator json, final ODataError error)
- throws IOException, ODataSerializerException {
+ throws IOException, SerializerException {
if (error == null) {
- throw new ODataSerializerException("ODataError object MUST NOT be null!",
- ODataSerializerException.MessageKeys.NULL_INPUT);
+ throw new SerializerException("ODataError object MUST NOT be null!",
+ SerializerException.MessageKeys.NULL_INPUT);
}
json.writeStartObject();
json.writeFieldName(Constants.JSON_ERROR);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5af9f46d/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
index 1d5e549..6f2ff36 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
@@ -43,7 +43,7 @@ import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
import org.apache.olingo.server.api.ODataServerError;
import org.apache.olingo.server.api.serializer.ODataSerializer;
-import org.apache.olingo.server.api.serializer.ODataSerializerException;
+import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.api.serializer.ODataSerializerOptions;
import org.apache.olingo.server.api.uri.queryoption.ExpandItem;
import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
@@ -70,7 +70,7 @@ public class ODataJsonSerializer implements ODataSerializer {
}
@Override
- public InputStream serviceDocument(final Edm edm, final String serviceRoot) throws ODataSerializerException {
+ public InputStream serviceDocument(final Edm edm, final String serviceRoot) throws SerializerException {
CircleStreamBuffer buffer;
JsonGenerator gen = null;
@@ -92,51 +92,51 @@ public class ODataJsonSerializer implements ODataSerializer {
} catch (final IOException e) {
log.error(e.getMessage(), e);
- throw new ODataSerializerException("An I/O exception occurred.", e,
- ODataSerializerException.MessageKeys.IO_EXCEPTION);
+ throw new SerializerException("An I/O exception occurred.", e,
+ SerializerException.MessageKeys.IO_EXCEPTION);
} finally {
if (gen != null) {
try {
gen.close();
} catch (IOException e) {
- throw new ODataSerializerException("An I/O exception occurred.", e,
- ODataSerializerException.MessageKeys.IO_EXCEPTION);
+ throw new SerializerException("An I/O exception occurred.", e,
+ SerializerException.MessageKeys.IO_EXCEPTION);
}
}
}
}
@Override
- public InputStream metadataDocument(final Edm edm) throws ODataSerializerException {
- throw new ODataSerializerException("Metadata in JSON format not supported!",
- ODataSerializerException.MessageKeys.JSON_METADATA);
+ public InputStream metadataDocument(final Edm edm) throws SerializerException {
+ throw new SerializerException("Metadata in JSON format not supported!",
+ SerializerException.MessageKeys.JSON_METADATA);
}
@Override
- public InputStream error(final ODataServerError error) throws ODataSerializerException {
+ public InputStream error(final ODataServerError error) throws SerializerException {
CircleStreamBuffer buffer = new CircleStreamBuffer();
try {
JsonGenerator json = new JsonFactory().createGenerator(buffer.getOutputStream());
new ODataErrorSerializer().writeErrorDocument(json, error);
json.close();
} catch (final IOException e) {
- throw new ODataSerializerException("An I/O exception occurred.", e,
- ODataSerializerException.MessageKeys.IO_EXCEPTION);
+ throw new SerializerException("An I/O exception occurred.", e,
+ SerializerException.MessageKeys.IO_EXCEPTION);
}
return buffer.getInputStream();
}
@Override
public InputStream entitySet(final EdmEntitySet edmEntitySet, final EntitySet entitySet,
- final ODataSerializerOptions options) throws ODataSerializerException {
+ final ODataSerializerOptions options) throws SerializerException {
CircleStreamBuffer buffer = new CircleStreamBuffer();
try {
JsonGenerator json = new JsonFactory().createGenerator(buffer.getOutputStream());
json.writeStartObject();
if (format != ODataFormat.JSON_NO_METADATA) {
if (options == null || options.getContextURL() == null) {
- throw new ODataSerializerException("ContextURL null!",
- ODataSerializerException.MessageKeys.NO_CONTEXT_URL);
+ throw new SerializerException("ContextURL null!",
+ SerializerException.MessageKeys.NO_CONTEXT_URL);
} else {
json.writeStringField(Constants.JSON_CONTEXT,
ContextURLBuilder.create(options.getContextURL()).toASCIIString());
@@ -154,19 +154,19 @@ public class ODataJsonSerializer implements ODataSerializer {
}
json.close();
} catch (final IOException e) {
- throw new ODataSerializerException("An I/O exception occurred.", e,
- ODataSerializerException.MessageKeys.IO_EXCEPTION);
+ throw new SerializerException("An I/O exception occurred.", e,
+ SerializerException.MessageKeys.IO_EXCEPTION);
}
return buffer.getInputStream();
}
@Override
public InputStream entity(final EdmEntitySet edmEntitySet, final Entity entity,
- final ODataSerializerOptions options) throws ODataSerializerException {
+ final ODataSerializerOptions options) throws SerializerException {
final ContextURL contextURL = options == null ? null : options.getContextURL();
if (format != ODataFormat.JSON_NO_METADATA && contextURL == null) {
- throw new ODataSerializerException("ContextURL null!",
- ODataSerializerException.MessageKeys.NO_CONTEXT_URL);
+ throw new SerializerException("ContextURL null!",
+ SerializerException.MessageKeys.NO_CONTEXT_URL);
}
CircleStreamBuffer buffer = new CircleStreamBuffer();
try {
@@ -175,15 +175,15 @@ public class ODataJsonSerializer implements ODataSerializer {
options == null ? null : options.getExpand(), options == null ? null : options.getSelect(), json);
json.close();
} catch (final IOException e) {
- throw new ODataSerializerException("An I/O exception occurred.", e,
- ODataSerializerException.MessageKeys.IO_EXCEPTION);
+ throw new SerializerException("An I/O exception occurred.", e,
+ SerializerException.MessageKeys.IO_EXCEPTION);
}
return buffer.getInputStream();
}
protected void writeEntitySet(final EdmEntityType entityType, final EntitySet entitySet,
final ExpandOption expand, final SelectOption select, final JsonGenerator json)
- throws IOException, ODataSerializerException {
+ throws IOException, SerializerException {
json.writeStartArray();
for (final Entity entity : entitySet.getEntities()) {
writeEntity(entityType, entity, null, expand, select, json);
@@ -193,7 +193,7 @@ public class ODataJsonSerializer implements ODataSerializer {
protected void writeEntity(final EdmEntityType entityType, final Entity entity, final ContextURL contextURL,
final ExpandOption expand, final SelectOption select, final JsonGenerator json)
- throws IOException, ODataSerializerException {
+ throws IOException, SerializerException {
json.writeStartObject();
if (format != ODataFormat.JSON_NO_METADATA) {
if (contextURL != null) {
@@ -217,7 +217,7 @@ public class ODataJsonSerializer implements ODataSerializer {
}
protected void writeProperties(final EdmEntityType entityType, final Entity entity, final SelectOption select,
- JsonGenerator json) throws IOException, ODataSerializerException {
+ JsonGenerator json) throws IOException, SerializerException {
final boolean all = ExpandSelectHelper.isAll(select);
final Set<String> selected = all ? null :
ExpandSelectHelper.getSelectedPropertyNames(select.getSelectItems());
@@ -233,7 +233,7 @@ public class ODataJsonSerializer implements ODataSerializer {
}
protected void writeNavigationProperties(final EdmEntityType entityType, final Entity entity,
- final ExpandOption expand, final JsonGenerator json) throws ODataSerializerException, IOException {
+ final ExpandOption expand, final JsonGenerator json) throws SerializerException, IOException {
if (ExpandSelectHelper.hasExpand(expand)) {
final boolean expandAll = ExpandSelectHelper.isExpandAll(expand);
final Set<String> expanded = expandAll ? null :
@@ -245,8 +245,8 @@ public class ODataJsonSerializer implements ODataSerializer {
final ExpandItem innerOptions = expandAll ? null :
ExpandSelectHelper.getExpandItem(expand.getExpandItems(), propertyName);
if (innerOptions != null && (innerOptions.isRef() || innerOptions.getLevelsOption() != null)) {
- throw new ODataSerializerException("Expand options $ref and $levels are not supported.",
- ODataSerializerException.MessageKeys.NOT_IMPLEMENTED);
+ throw new SerializerException("Expand options $ref and $levels are not supported.",
+ SerializerException.MessageKeys.NOT_IMPLEMENTED);
}
writeExpandedNavigationProperty(property, navigationLink,
innerOptions == null ? null : innerOptions.getExpandOption(),
@@ -259,7 +259,7 @@ public class ODataJsonSerializer implements ODataSerializer {
protected void writeExpandedNavigationProperty(final EdmNavigationProperty property, final Link navigationLink,
final ExpandOption innerExpand, final SelectOption innerSelect, JsonGenerator json)
- throws IOException, ODataSerializerException {
+ throws IOException, SerializerException {
json.writeFieldName(property.getName());
if (property.isCollection()) {
if (navigationLink == null || navigationLink.getInlineEntitySet() == null) {
@@ -278,12 +278,12 @@ public class ODataJsonSerializer implements ODataSerializer {
}
protected void writeProperty(final EdmProperty edmProperty, final Property property,
- final Set<List<String>> selectedPaths, final JsonGenerator json) throws IOException, ODataSerializerException {
+ final Set<List<String>> selectedPaths, final JsonGenerator json) throws IOException, SerializerException {
json.writeFieldName(edmProperty.getName());
if (property == null || property.isNull()) {
if (edmProperty.isNullable() == Boolean.FALSE) {
- throw new ODataSerializerException("Non-nullable property not present!",
- ODataSerializerException.MessageKeys.MISSING_PROPERTY, edmProperty.getName());
+ throw new SerializerException("Non-nullable property not present!",
+ SerializerException.MessageKeys.MISSING_PROPERTY, edmProperty.getName());
} else {
json.writeNull();
}
@@ -298,12 +298,12 @@ public class ODataJsonSerializer implements ODataSerializer {
} else if (property.isComplex()) {
writeComplexValue(edmProperty, property.asComplex(), selectedPaths, json);
} else {
- throw new ODataSerializerException("Property type not yet supported!",
- ODataSerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, edmProperty.getName());
+ throw new SerializerException("Property type not yet supported!",
+ SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, edmProperty.getName());
}
} catch (final EdmPrimitiveTypeException e) {
- throw new ODataSerializerException("Wrong value for property!", e,
- ODataSerializerException.MessageKeys.WRONG_PROPERTY_VALUE,
+ throw new SerializerException("Wrong value for property!", e,
+ SerializerException.MessageKeys.WRONG_PROPERTY_VALUE,
edmProperty.getName(), property.getValue().toString());
}
}
@@ -311,7 +311,7 @@ public class ODataJsonSerializer implements ODataSerializer {
private void writeCollection(final EdmProperty edmProperty, final Property property,
final Set<List<String>> selectedPaths, JsonGenerator json)
- throws IOException, EdmPrimitiveTypeException, ODataSerializerException {
+ throws IOException, EdmPrimitiveTypeException, SerializerException {
json.writeStartArray();
for (Object value : property.asCollection()) {
switch (property.getValueType()) {
@@ -319,8 +319,8 @@ public class ODataJsonSerializer implements ODataSerializer {
writePrimitiveValue(edmProperty, value, json);
break;
case COLLECTION_GEOSPATIAL:
- throw new ODataSerializerException("Property type not yet supported!",
- ODataSerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, edmProperty.getName());
+ throw new SerializerException("Property type not yet supported!",
+ SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, edmProperty.getName());
case COLLECTION_ENUM:
json.writeString(value.toString());
break;
@@ -331,25 +331,25 @@ public class ODataJsonSerializer implements ODataSerializer {
writeComplexValue(edmProperty, property.asComplex(), selectedPaths, json);
break;
default:
- throw new ODataSerializerException("Property type not yet supported!",
- ODataSerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, edmProperty.getName());
+ throw new SerializerException("Property type not yet supported!",
+ SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, edmProperty.getName());
}
}
json.writeEndArray();
}
private void writePrimitive(EdmProperty edmProperty, Property property, JsonGenerator json)
- throws EdmPrimitiveTypeException, IOException, ODataSerializerException {
+ throws EdmPrimitiveTypeException, IOException, SerializerException {
if (property.isPrimitive()) {
writePrimitiveValue(edmProperty, property.asPrimitive(), json);
} else if (property.isGeospatial()) {
- throw new ODataSerializerException("Property type not yet supported!",
- ODataSerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, edmProperty.getName());
+ throw new SerializerException("Property type not yet supported!",
+ SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, edmProperty.getName());
} else if (property.isEnum()) {
writePrimitiveValue(edmProperty, property.asEnum(), json);
} else {
- throw new ODataSerializerException("Inconsistent property type!",
- ODataSerializerException.MessageKeys.INCONSISTENT_PROPERTY_TYPE, edmProperty.getName());
+ throw new SerializerException("Inconsistent property type!",
+ SerializerException.MessageKeys.INCONSISTENT_PROPERTY_TYPE, edmProperty.getName());
}
}
@@ -377,7 +377,7 @@ public class ODataJsonSerializer implements ODataSerializer {
protected void writeComplexValue(final EdmProperty edmProperty, final List<Property> properties,
final Set<List<String>> selectedPaths, JsonGenerator json)
- throws IOException, EdmPrimitiveTypeException, ODataSerializerException {
+ throws IOException, EdmPrimitiveTypeException, SerializerException {
final EdmComplexType type = (EdmComplexType) edmProperty.getType();
json.writeStartObject();
for (final String propertyName : type.getPropertyNames()) {
@@ -402,7 +402,7 @@ public class ODataJsonSerializer implements ODataSerializer {
@Override
public String buildContextURLSelectList(final EdmEntitySet edmEntitySet,
- final ExpandOption expand, final SelectOption select) throws ODataSerializerException {
+ final ExpandOption expand, final SelectOption select) throws SerializerException {
return ContextURLHelper.buildSelectList(edmEntitySet.getEntityType(), expand, select);
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5af9f46d/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLHelper.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLHelper.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLHelper.java
index 5c7d3a6..099055e 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLHelper.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLHelper.java
@@ -27,7 +27,7 @@ import org.apache.olingo.commons.api.edm.EdmComplexType;
import org.apache.olingo.commons.api.edm.EdmEntityType;
import org.apache.olingo.commons.api.edm.EdmProperty;
import org.apache.olingo.commons.core.Encoder;
-import org.apache.olingo.server.api.serializer.ODataSerializerException;
+import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.api.uri.queryoption.ExpandItem;
import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
import org.apache.olingo.server.api.uri.queryoption.SelectItem;
@@ -42,10 +42,10 @@ public final class ContextURLHelper {
* @param expand the Expand option (from the URL's $expand query option)
* @param select the Select option (from the URL's $select query option)
* @return a select-list String
- * @throws ODataSerializerException if an unsupported feature is used
+ * @throws SerializerException if an unsupported feature is used
*/
public static String buildSelectList(final EdmEntityType entityType,
- final ExpandOption expand, final SelectOption select) throws ODataSerializerException {
+ final ExpandOption expand, final SelectOption select) throws SerializerException {
StringBuilder result = new StringBuilder();
if (ExpandSelectHelper.hasSelect(select)) {
handleSelect(entityType, select, result);
@@ -98,7 +98,7 @@ public final class ContextURLHelper {
}
private static void handleExpand(final EdmEntityType entityType, final ExpandOption expand, StringBuilder result)
- throws ODataSerializerException {
+ throws SerializerException {
final Set<String> expandedPropertyNames = ExpandSelectHelper.getExpandedPropertyNames(expand.getExpandItems());
for (final String propertyName : entityType.getNavigationPropertyNames()) {
if (expandedPropertyNames.contains(propertyName)) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5af9f46d/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ExpandSelectHelper.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ExpandSelectHelper.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ExpandSelectHelper.java
index 37dbbac..c537fbd 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ExpandSelectHelper.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ExpandSelectHelper.java
@@ -23,7 +23,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
-import org.apache.olingo.server.api.serializer.ODataSerializerException;
+import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.api.uri.UriResource;
import org.apache.olingo.server.api.uri.UriResourceNavigation;
import org.apache.olingo.server.api.uri.UriResourceProperty;
@@ -124,7 +124,7 @@ public abstract class ExpandSelectHelper {
}
public static Set<String> getExpandedPropertyNames(final List<ExpandItem> expandItems)
- throws ODataSerializerException {
+ throws SerializerException {
Set<String> expanded = new HashSet<String>();
for (final ExpandItem item : expandItems) {
final List<UriResource> resourceParts = item.getResourcePath().getUriResourceParts();
@@ -134,8 +134,8 @@ public abstract class ExpandSelectHelper {
expanded.add(((UriResourceNavigation) resource).getProperty().getName());
}
} else {
- throw new ODataSerializerException("Expand is not supported within complex properties.",
- ODataSerializerException.MessageKeys.NOT_IMPLEMENTED);
+ throw new SerializerException("Expand is not supported within complex properties.",
+ SerializerException.MessageKeys.NOT_IMPLEMENTED);
}
}
return expanded;