You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2014/05/18 07:06:37 UTC

[09/38] git commit: [OLINGO-196] Added API methods for de-serialize of ODataErrorContext

[OLINGO-196] Added API methods for de-serialize of ODataErrorContext


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

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: 1c2bcda5ad0b76af95cd886cc768bf823ccaca99
Parents: 5f87f64
Author: Michael Bolz <mi...@apache.org>
Authored: Thu Mar 20 13:53:50 2014 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Tue Mar 25 10:52:55 2014 +0100

----------------------------------------------------------------------
 .../olingo/odata2/api/ep/EntityProvider.java    | 24 +++++++++++
 .../odata2/core/ep/AtomEntityProvider.java      |  8 ++++
 .../core/ep/ContentTypeBasedEntityProvider.java |  3 ++
 .../odata2/core/ep/JsonEntityProvider.java      |  6 +++
 .../odata2/core/ep/ProviderFacadeImpl.java      |  6 +++
 .../ep/consumer/JsonErrorDocumentConsumer.java  | 41 +++++++++++++++++++
 .../ep/consumer/XmlErrorDocumentConsumer.java   | 42 ++++++++++++++++++++
 .../core/exception/ODataExceptionTest.java      | 15 +------
 8 files changed, 131 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/1c2bcda5/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ep/EntityProvider.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ep/EntityProvider.java b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ep/EntityProvider.java
index 4ce2dac..8086924 100644
--- a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ep/EntityProvider.java
+++ b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ep/EntityProvider.java
@@ -421,6 +421,16 @@ public final class EntityProvider {
      */
     List<BatchSingleResponse> parseBatchResponse(String contentType, InputStream content) throws BatchException;
 
+    /**
+     * Read (de-serialize) data from error document as {@link InputStream} and provide according
+     * {@link ODataErrorContext}.
+     *
+     * @param errorDocument error document which is read
+     * @param contentType format of content in the given input stream
+     * @return read error document
+     * @throws EntityProviderException if reading of data (de-serialization) fails
+     */
+    ODataErrorContext readErrorDocument(InputStream errorDocument, String contentType) throws  EntityProviderException;
   }
 
   /**
@@ -801,6 +811,20 @@ public final class EntityProvider {
   }
 
   /**
+   * Read (de-serialize) data from error document as {@link InputStream} and provide according
+   * {@link ODataErrorContext}.
+   *
+   * @param errorDocument error document which is read
+   * @param contentType format of content in the given input stream
+   * @return read error document
+   * @throws EntityProviderException if reading of data (de-serialization) fails
+   */
+  public static ODataErrorContext readErrorDocument(final InputStream errorDocument, final String contentType)
+      throws EntityProviderException {
+    return createEntityProvider().readErrorDocument(errorDocument, contentType);
+  }
+
+  /**
    * Read (de-serialize) data from service document <code>inputStream</code> (as {@link InputStream}) and provide
    * ServiceDocument as {@link ServiceDocument}
    * 

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/1c2bcda5/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/AtomEntityProvider.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/AtomEntityProvider.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/AtomEntityProvider.java
index 7024d02..3b6f121 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/AtomEntityProvider.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/AtomEntityProvider.java
@@ -46,6 +46,7 @@ import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties;
 import org.apache.olingo.odata2.api.ep.entry.ODataEntry;
 import org.apache.olingo.odata2.api.ep.feed.ODataDeltaFeed;
 import org.apache.olingo.odata2.api.ep.feed.ODataFeed;
+import org.apache.olingo.odata2.api.processor.ODataErrorContext;
 import org.apache.olingo.odata2.api.processor.ODataResponse;
 import org.apache.olingo.odata2.api.processor.ODataResponse.ODataResponseBuilder;
 import org.apache.olingo.odata2.api.servicedocument.ServiceDocument;
@@ -55,6 +56,7 @@ import org.apache.olingo.odata2.core.ep.aggregator.EntityInfoAggregator;
 import org.apache.olingo.odata2.core.ep.aggregator.EntityPropertyInfo;
 import org.apache.olingo.odata2.core.ep.consumer.AtomServiceDocumentConsumer;
 import org.apache.olingo.odata2.core.ep.consumer.XmlEntityConsumer;
+import org.apache.olingo.odata2.core.ep.consumer.XmlErrorDocumentConsumer;
 import org.apache.olingo.odata2.core.ep.producer.AtomEntryEntityProducer;
 import org.apache.olingo.odata2.core.ep.producer.AtomFeedProducer;
 import org.apache.olingo.odata2.core.ep.producer.AtomServiceDocumentProducer;
@@ -401,4 +403,10 @@ public class AtomEntityProvider implements ContentTypeBasedEntityProvider {
     AtomServiceDocumentConsumer serviceDocConsumer = new AtomServiceDocumentConsumer();
     return serviceDocConsumer.parseXml(serviceDocument);
   }
+
+  @Override
+  public ODataErrorContext readErrorDocument(InputStream errorDocument) throws EntityProviderException {
+    XmlErrorDocumentConsumer xmlErrorDocumentConsumer = new XmlErrorDocumentConsumer();
+    return xmlErrorDocumentConsumer.readError(errorDocument);
+  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/1c2bcda5/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/ContentTypeBasedEntityProvider.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/ContentTypeBasedEntityProvider.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/ContentTypeBasedEntityProvider.java
index 75adf9e..b988039 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/ContentTypeBasedEntityProvider.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/ContentTypeBasedEntityProvider.java
@@ -34,6 +34,7 @@ import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties;
 import org.apache.olingo.odata2.api.ep.entry.ODataEntry;
 import org.apache.olingo.odata2.api.ep.feed.ODataDeltaFeed;
 import org.apache.olingo.odata2.api.ep.feed.ODataFeed;
+import org.apache.olingo.odata2.api.processor.ODataErrorContext;
 import org.apache.olingo.odata2.api.processor.ODataResponse;
 import org.apache.olingo.odata2.api.servicedocument.ServiceDocument;
 
@@ -84,4 +85,6 @@ public interface ContentTypeBasedEntityProvider {
 
   ODataDeltaFeed readDeltaFeed(EdmEntitySet entitySet, InputStream content, EntityProviderReadProperties properties)
       throws EntityProviderException;
+
+  ODataErrorContext readErrorDocument(InputStream errorDocument) throws EntityProviderException;
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/1c2bcda5/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/JsonEntityProvider.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/JsonEntityProvider.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/JsonEntityProvider.java
index d8efe36..32c68a2 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/JsonEntityProvider.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/JsonEntityProvider.java
@@ -43,12 +43,14 @@ import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties;
 import org.apache.olingo.odata2.api.ep.entry.ODataEntry;
 import org.apache.olingo.odata2.api.ep.feed.ODataDeltaFeed;
 import org.apache.olingo.odata2.api.ep.feed.ODataFeed;
+import org.apache.olingo.odata2.api.processor.ODataErrorContext;
 import org.apache.olingo.odata2.api.processor.ODataResponse;
 import org.apache.olingo.odata2.api.processor.ODataResponse.ODataResponseBuilder;
 import org.apache.olingo.odata2.api.servicedocument.ServiceDocument;
 import org.apache.olingo.odata2.core.ep.aggregator.EntityInfoAggregator;
 import org.apache.olingo.odata2.core.ep.aggregator.EntityPropertyInfo;
 import org.apache.olingo.odata2.core.ep.consumer.JsonEntityConsumer;
+import org.apache.olingo.odata2.core.ep.consumer.JsonErrorDocumentConsumer;
 import org.apache.olingo.odata2.core.ep.consumer.JsonServiceDocumentConsumer;
 import org.apache.olingo.odata2.core.ep.producer.JsonCollectionEntityProducer;
 import org.apache.olingo.odata2.core.ep.producer.JsonEntryEntityProducer;
@@ -341,4 +343,8 @@ public class JsonEntityProvider implements ContentTypeBasedEntityProvider {
     return new JsonEntityConsumer().readDeltaFeed(entitySet, content, properties);
   }
 
+  @Override
+  public ODataErrorContext readErrorDocument(InputStream errorDocument) throws EntityProviderException {
+    return new JsonErrorDocumentConsumer().readError(errorDocument);
+  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/1c2bcda5/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/ProviderFacadeImpl.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/ProviderFacadeImpl.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/ProviderFacadeImpl.java
index 128f730..16c5693 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/ProviderFacadeImpl.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/ProviderFacadeImpl.java
@@ -155,6 +155,12 @@ public class ProviderFacadeImpl implements EntityProviderInterface {
   }
 
   @Override
+  public ODataErrorContext readErrorDocument(InputStream errorDocument, String contentType)
+          throws EntityProviderException {
+    return create(contentType).readErrorDocument(errorDocument);
+  }
+
+  @Override
   public ODataFeed readFeed(final String contentType, final EdmEntitySet entitySet, final InputStream content,
       final EntityProviderReadProperties properties) throws EntityProviderException {
     return create(contentType).readFeed(entitySet, content, properties);

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/1c2bcda5/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/JsonErrorDocumentConsumer.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/JsonErrorDocumentConsumer.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/JsonErrorDocumentConsumer.java
new file mode 100644
index 0000000..fad6dd9
--- /dev/null
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/JsonErrorDocumentConsumer.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * 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.odata2.core.ep.consumer;
+
+import org.apache.olingo.odata2.api.ep.EntityProviderException;
+import org.apache.olingo.odata2.api.processor.ODataErrorContext;
+
+import java.io.InputStream;
+
+/**
+ * Consuming (read / deserialization) for OData error document in JSON format.
+ */
+public class JsonErrorDocumentConsumer {
+
+  /**
+   * Deserialize / read OData error document in ODataErrorContext.
+   *
+   * @param errorDocument OData error document in JSON format
+   * @return created ODataErrorContext based on input stream content.
+   * @throws EntityProviderException if an exception during read / deserialization occurs.
+   */
+  public ODataErrorContext readError(InputStream errorDocument) throws EntityProviderException {
+    throw new RuntimeException("Not yet implemented");
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/1c2bcda5/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlErrorDocumentConsumer.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlErrorDocumentConsumer.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlErrorDocumentConsumer.java
new file mode 100644
index 0000000..c7f0a51
--- /dev/null
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlErrorDocumentConsumer.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * 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.odata2.core.ep.consumer;
+
+import org.apache.olingo.odata2.api.ep.EntityProviderException;
+import org.apache.olingo.odata2.api.processor.ODataErrorContext;
+
+import java.io.InputStream;
+
+/**
+ * Consuming (read / deserialization) for OData error document in XML format.
+ */
+public class XmlErrorDocumentConsumer {
+
+
+  /**
+   * Deserialize / read OData error document in ODataErrorContext.
+   *
+   * @param errorDocument OData error document in XML format
+   * @return created ODataErrorContext based on input stream content.
+   * @throws EntityProviderException if an exception during read / deserialization occurs.
+   */
+  public ODataErrorContext readError(InputStream errorDocument) throws EntityProviderException {
+    throw new RuntimeException("Not yet implementedØ");
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/1c2bcda5/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/exception/ODataExceptionTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/exception/ODataExceptionTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/exception/ODataExceptionTest.java
index 6d97d15..4f4dc2b 100644
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/exception/ODataExceptionTest.java
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/exception/ODataExceptionTest.java
@@ -22,20 +22,7 @@ import org.apache.olingo.odata2.api.edm.EdmException;
 import org.apache.olingo.odata2.api.edm.EdmLiteralException;
 import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
 import org.apache.olingo.odata2.api.ep.EntityProviderException;
-import org.apache.olingo.odata2.api.exception.ODataBadRequestException;
-import org.apache.olingo.odata2.api.exception.ODataConflictException;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.exception.ODataForbiddenException;
-import org.apache.olingo.odata2.api.exception.ODataHttpException;
-import org.apache.olingo.odata2.api.exception.ODataMessageException;
-import org.apache.olingo.odata2.api.exception.ODataMethodNotAllowedException;
-import org.apache.olingo.odata2.api.exception.ODataNotAcceptableException;
-import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
-import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
-import org.apache.olingo.odata2.api.exception.ODataPreconditionFailedException;
-import org.apache.olingo.odata2.api.exception.ODataPreconditionRequiredException;
-import org.apache.olingo.odata2.api.exception.ODataServiceUnavailableException;
-import org.apache.olingo.odata2.api.exception.ODataUnsupportedMediaTypeException;
+import org.apache.olingo.odata2.api.exception.*;
 import org.apache.olingo.odata2.api.uri.UriNotMatchingException;
 import org.apache.olingo.odata2.api.uri.UriSyntaxException;
 import org.apache.olingo.odata2.api.uri.expression.ExceptionVisitExpression;