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 2016/02/22 08:54:45 UTC
[21/21] olingo-odata4 git commit: [OLINGO-832] Clean up after merge
[OLINGO-832] Clean up after merge
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/0879bfbe
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/0879bfbe
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/0879bfbe
Branch: refs/heads/master
Commit: 0879bfbe5ed0401872168b3c4478612f42eb75b4
Parents: 47bc730
Author: Michael Bolz <mi...@sap.com>
Authored: Mon Feb 22 08:42:38 2016 +0100
Committer: Michael Bolz <mi...@sap.com>
Committed: Mon Feb 22 08:42:38 2016 +0100
----------------------------------------------------------------------
.../apache/olingo/server/api/ODataContent.java | 24 +++++++++++
.../api/ODataContentWriteErrorCallback.java | 41 ++++++++++++++++++
.../api/ODataContentWriteErrorContext.java | 45 ++++++++++++++++++++
.../server/api/WriteContentErrorCallback.java | 30 -------------
.../server/api/WriteContentErrorContext.java | 27 ------------
.../EntityCollectionSerializerOptions.java | 14 +++---
.../api/serializer/SerializerStreamResult.java | 7 +--
.../server/core/ODataWritableContent.java | 20 ++++++---
.../core/serializer/SerializerResultImpl.java | 16 -------
.../core/serializer/xml/ODataXmlSerializer.java | 1 -
.../json/ODataJsonSerializerTest.java | 9 ++--
11 files changed, 139 insertions(+), 95 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0879bfbe/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContent.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContent.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContent.java
index e237bf3..7f971df 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContent.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContent.java
@@ -21,8 +21,32 @@ package org.apache.olingo.server.api;
import java.io.OutputStream;
import java.nio.channels.WritableByteChannel;
+/**
+ * Contains the response content for the OData request.
+ * <p/>
+ * Because the content is potential streamable an error can occur when the
+ * <code>write</code> methods are used.
+ * If this happens <b>NO</b> exception will be thrown but if registered the
+ * org.apache.olingo.server.api.ODataContentWriteErrorCallback is called.
+ */
public interface ODataContent {
+ /**
+ * Write the available content into the given <code>WritableByteChannel</code>.
+ *
+ * If during write of the content an exception is thrown this exception will be catched
+ * and the org.apache.olingo.server.api.ODataContentWriteErrorCallback is called (if registered).
+ *
+ * @param channel channel in which the content is written.
+ */
void write(WritableByteChannel channel);
+ /**
+ * Write the available content into the given <code>OutputStream</code>.
+ *
+ * If during write of the content an exception is thrown this exception will be catched
+ * and the org.apache.olingo.server.api.ODataContentWriteErrorCallback is called (if registered).
+ *
+ * @param stream stream in which the content is written.
+ */
void write(OutputStream stream);
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0879bfbe/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContentWriteErrorCallback.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContentWriteErrorCallback.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContentWriteErrorCallback.java
new file mode 100644
index 0000000..643d676
--- /dev/null
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContentWriteErrorCallback.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.server.api;
+
+import java.io.OutputStream;
+import java.nio.channels.WritableByteChannel;
+
+/**
+ * The ODataContentWriteErrorCallback is called when during the {@link ODataContent#write(OutputStream)}
+ * or the {@link ODataContent#write(WritableByteChannel)} an error occurs.
+ */
+public interface ODataContentWriteErrorCallback {
+ /**
+ * Is called when during <i>write</i> in the ODataContent an error occurs.
+ * The <code>context:ODataContentWriteErrorContext</code> contains all relevant information
+ * and the <code>channel</code> is the channel (stream) in which before was written.
+ * This channel is at this point not closed and can be used to write additional information.
+ * <b>ATTENTION:</b> This channel MUST NOT be closed by the callback. It will be closed by the
+ * layer responsible for the environment / data transfer (e.g. application server).
+ *
+ * @param context contains all relevant error information
+ * @param channel is the channel (stream) in which before was written
+ */
+ void handleError(ODataContentWriteErrorContext context, WritableByteChannel channel);
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0879bfbe/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContentWriteErrorContext.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContentWriteErrorContext.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContentWriteErrorContext.java
new file mode 100644
index 0000000..5c72b57
--- /dev/null
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContentWriteErrorContext.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;
+
+/**
+ * The WriteContentErrorErrorContext is the parameter for the WriteContentErrorCallback.
+ * and contains all relevant error information
+ */
+public interface ODataContentWriteErrorContext {
+ /**
+ * Get the exception which caused this error (as Java exception).
+ * If the cause exception is a ODataLibraryException this method will
+ * return the same exception as the {@link #getODataLibraryException()} method.
+ *
+ * @return the exception which caused this error (as Java exception).
+ */
+ Exception getException();
+ /**
+ * Get the exception which caused this error (as ODataLibraryException exception).
+ * If the cause exception is an ODataLibraryException this method will
+ * return the same exception as the {@link #getException()} method.
+ * If the cause exception is <b>NOT</b> an ODataLibraryException this method will
+ * return <code>NULL</code>.
+ *
+ * @return the cause exception if it is an ODataLibraryException otherwise
+ * this method will return <code>NULL</code>.
+ */
+ ODataLibraryException getODataLibraryException();
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0879bfbe/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorCallback.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorCallback.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorCallback.java
deleted file mode 100644
index 3132876..0000000
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorCallback.java
+++ /dev/null
@@ -1,30 +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;
-
-import java.io.OutputStream;
-import java.nio.channels.WritableByteChannel;
-
-/**
- * The WriteContentErrorCallback is called when during the {@link ODataContent#write(OutputStream)}
- * or the {@link ODataContent#write(WritableByteChannel)} an error occurs.
- */
-public interface WriteContentErrorCallback {
- void handleError(WriteContentErrorContext context, WritableByteChannel channel);
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0879bfbe/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorContext.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorContext.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorContext.java
deleted file mode 100644
index 837c184..0000000
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorContext.java
+++ /dev/null
@@ -1,27 +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;
-
-/**
- * The WriteContentErrorErrorContext is the parameter for the WriteContentErrorCallback.
- */
-public interface WriteContentErrorContext {
- Exception getException();
- ODataLibraryException getODataLibraryException();
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0879bfbe/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntityCollectionSerializerOptions.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntityCollectionSerializerOptions.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntityCollectionSerializerOptions.java
index 9335829..9578ba7 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntityCollectionSerializerOptions.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntityCollectionSerializerOptions.java
@@ -19,7 +19,7 @@
package org.apache.olingo.server.api.serializer;
import org.apache.olingo.commons.api.data.ContextURL;
-import org.apache.olingo.server.api.WriteContentErrorCallback;
+import org.apache.olingo.server.api.ODataContentWriteErrorCallback;
import org.apache.olingo.server.api.uri.queryoption.CountOption;
import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
import org.apache.olingo.server.api.uri.queryoption.SelectOption;
@@ -33,7 +33,7 @@ public class EntityCollectionSerializerOptions {
private SelectOption select;
private boolean writeOnlyReferences;
private String id;
- private WriteContentErrorCallback writeContentErrorCallback;
+ private ODataContentWriteErrorCallback ODataContentWriteErrorCallback;
private String xml10InvalidCharReplacement;
/** Gets the {@link ContextURL}. */
@@ -74,8 +74,8 @@ public class EntityCollectionSerializerOptions {
* write of the content
*
*/
- public WriteContentErrorCallback getWriteContentErrorCallback() {
- return writeContentErrorCallback;
+ public ODataContentWriteErrorCallback getODataContentWriteErrorCallback() {
+ return ODataContentWriteErrorCallback;
}
/** Gets the replacement string for unicode characters, that is not allowed in XML 1.0 */
public String xml10InvalidCharReplacement() {
@@ -136,11 +136,11 @@ public class EntityCollectionSerializerOptions {
* Set the callback which is used in case of an exception during
* write of the content.
*
- * @param writeContentErrorCallback the callback
+ * @param ODataContentWriteErrorCallback the callback
* @return the builder
*/
- public Builder writeContentErrorCallback(WriteContentErrorCallback writeContentErrorCallback) {
- options.writeContentErrorCallback = writeContentErrorCallback;
+ public Builder writeContentErrorCallback(ODataContentWriteErrorCallback ODataContentWriteErrorCallback) {
+ options.ODataContentWriteErrorCallback = ODataContentWriteErrorCallback;
return this;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0879bfbe/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerStreamResult.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerStreamResult.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerStreamResult.java
index c19c270..54e928d 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerStreamResult.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerStreamResult.java
@@ -22,12 +22,13 @@ import org.apache.olingo.server.api.ODataContent;
/**
* Result type for {@link ODataSerializer} methods
- * which supports stream/write in the future
+ * which supports streaming (write in the future).
*/
public interface SerializerStreamResult {
/**
- * Returns the content as ODataContent
- * @return content
+ * Returns the content as ODataContent instance.
+ *
+ * @return OData response content
*/
ODataContent getODataContent();
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0879bfbe/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataWritableContent.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataWritableContent.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataWritableContent.java
index 7a7c142..f315734 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataWritableContent.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataWritableContent.java
@@ -29,8 +29,8 @@ import org.apache.olingo.commons.api.ex.ODataRuntimeException;
import org.apache.olingo.server.api.ODataContent;
import org.apache.olingo.server.api.ODataLibraryException;
import org.apache.olingo.server.api.ServiceMetadata;
-import org.apache.olingo.server.api.WriteContentErrorCallback;
-import org.apache.olingo.server.api.WriteContentErrorContext;
+import org.apache.olingo.server.api.ODataContentWriteErrorCallback;
+import org.apache.olingo.server.api.ODataContentWriteErrorContext;
import org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions;
import org.apache.olingo.server.api.serializer.ODataSerializer;
import org.apache.olingo.server.api.serializer.SerializerException;
@@ -39,6 +39,14 @@ import org.apache.olingo.server.core.serializer.SerializerStreamResultImpl;
import org.apache.olingo.server.core.serializer.json.ODataJsonSerializer;
import org.apache.olingo.server.core.serializer.xml.ODataXmlSerializer;
+/**
+ * Stream supporting implementation of the ODataContent
+ * and contains the response content for the OData request.
+ * <p/>
+ * If an error occur during a <code>write</code> method <b>NO</b> exception
+ * will be thrown but if registered the
+ * org.apache.olingo.server.api.ODataContentWriteErrorCallback is called.
+ */
public class ODataWritableContent implements ODataContent {
private StreamContent streamContent;
@@ -65,9 +73,9 @@ public class ODataWritableContent implements ODataContent {
try {
writeEntity(iterator, out);
} catch (SerializerException e) {
- final WriteContentErrorCallback errorCallback = options.getWriteContentErrorCallback();
+ final ODataContentWriteErrorCallback errorCallback = options.getODataContentWriteErrorCallback();
if(errorCallback != null) {
- final ErrorContext errorContext = new ErrorContext(e);
+ final WriteErrorContext errorContext = new WriteErrorContext(e);
errorCallback.handleError(errorContext, Channels.newChannel(out));
}
}
@@ -136,9 +144,9 @@ public class ODataWritableContent implements ODataContent {
return new ODataWritableContentBuilder(iterator, entityType, serializer, metadata, options);
}
- public static class ErrorContext implements WriteContentErrorContext {
+ public static class WriteErrorContext implements ODataContentWriteErrorContext {
private ODataLibraryException exception;
- public ErrorContext(ODataLibraryException exception) {
+ public WriteErrorContext(ODataLibraryException exception) {
this.exception = exception;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0879bfbe/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
index 7c7de2f..69287af 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
@@ -20,7 +20,6 @@ package org.apache.olingo.server.core.serializer;
import java.io.InputStream;
-import org.apache.olingo.server.api.ODataContent;
import org.apache.olingo.server.api.serializer.SerializerResult;
public class SerializerResultImpl implements SerializerResult {
@@ -31,21 +30,6 @@ public class SerializerResultImpl implements SerializerResult {
return content;
}
- // @Override
-// public ReadableByteChannel getChannel() {
-// return Channels.newChannel(getContent());
-// }
-//
-// @Override
-// public void write(WritableByteChannel channel) {
-// ResultHelper.copy(Channels.newChannel(content), channel);
-// }
-//
-// @Override
-// public boolean isWriteSupported() {
-// return false;
-// }
-
public static SerializerResultBuilder with() {
return new SerializerResultBuilder();
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0879bfbe/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
index 2fa16ea..399df3d 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
@@ -53,7 +53,6 @@ import org.apache.olingo.commons.api.edm.EdmType;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
import org.apache.olingo.commons.api.ex.ODataErrorDetail;
-import org.apache.olingo.commons.api.ex.ODataRuntimeException;
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
import org.apache.olingo.commons.core.edm.primitivetype.EdmString;
import org.apache.olingo.server.api.ODataServerError;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0879bfbe/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 a7cf057..bc3ac19 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
@@ -26,7 +26,6 @@ import java.nio.channels.WritableByteChannel;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
-import java.util.Locale;
import java.util.TimeZone;
import org.apache.commons.io.IOUtils;
@@ -49,8 +48,8 @@ import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.server.api.OData;
import org.apache.olingo.server.api.ODataContent;
import org.apache.olingo.server.api.ServiceMetadata;
-import org.apache.olingo.server.api.WriteContentErrorCallback;
-import org.apache.olingo.server.api.WriteContentErrorContext;
+import org.apache.olingo.server.api.ODataContentWriteErrorCallback;
+import org.apache.olingo.server.api.ODataContentWriteErrorContext;
import org.apache.olingo.server.api.edmx.EdmxReference;
import org.apache.olingo.server.api.serializer.ComplexSerializerOptions;
import org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions;
@@ -275,9 +274,9 @@ public class ODataJsonSerializerTest {
CountOption countOption = Mockito.mock(CountOption.class);
Mockito.when(countOption.getValue()).thenReturn(true);
- WriteContentErrorCallback errorCallback = new WriteContentErrorCallback() {
+ ODataContentWriteErrorCallback errorCallback = new ODataContentWriteErrorCallback() {
@Override
- public void handleError(WriteContentErrorContext context, WritableByteChannel channel) {
+ public void handleError(ODataContentWriteErrorContext context, WritableByteChannel channel) {
try {
String msgKey = context.getODataLibraryException().getMessageKey().getKey();
String toChannel = "ERROR: " + msgKey;