You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by sk...@apache.org on 2014/03/06 10:31:40 UTC

git commit: [OLINGO-167] service document serialization

Repository: incubator-olingo-odata4
Updated Branches:
  refs/heads/olingo167MetadataDocument 05e065e31 -> bd8f4c592


[OLINGO-167] service document serialization


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

Branch: refs/heads/olingo167MetadataDocument
Commit: bd8f4c592a104ea562a535718ab6af82bd9811aa
Parents: 05e065e
Author: Stephan Klevenz <st...@sap.com>
Authored: Wed Mar 5 17:37:39 2014 +0100
Committer: Stephan Klevenz <st...@sap.com>
Committed: Thu Mar 6 10:29:37 2014 +0100

----------------------------------------------------------------------
 .../commons/api/ODataRuntimeException.java      |  36 ++
 odata4-lib/odata4-commons-core/pom.xml          |  84 ++---
 .../olingo/odata4/server/api/ODataFormat.java   |  23 ++
 .../odata4/server/api/ODataSerializer.java      |   2 +
 .../olingo/odata4/server/api/ODataServer.java   |   4 +-
 odata4-lib/odata4-server-core/pom.xml           |  22 +-
 .../odata4/server/core/CircleStreamBuffer.java  | 327 +++++++++++++++++++
 .../odata4/server/core/MetadataDocument.java    |   3 -
 .../odata4/server/core/ODataSerializerImpl.java |  21 +-
 .../odata4/server/core/ODataServerImpl.java     |  19 +-
 .../serializer/json/ODataJsonSerializer.java    |  72 ++++
 .../server/core/serializer/MetadataTest.java    |  39 +--
 .../core/serializer/ServiceDocumentTest.java    |  53 +++
 .../odata4/server/core/testutil/StringUtil.java |  52 +++
 pom.xml                                         |  40 ++-
 15 files changed, 687 insertions(+), 110 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/bd8f4c59/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/ODataRuntimeException.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/ODataRuntimeException.java b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/ODataRuntimeException.java
new file mode 100644
index 0000000..0d6cfb2
--- /dev/null
+++ b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/ODataRuntimeException.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * 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.odata4.commons.api;
+
+public class ODataRuntimeException extends RuntimeException {
+  private static final long serialVersionUID = 1L;
+
+  public ODataRuntimeException(final String msg) {
+    super(msg);
+  }
+
+  public ODataRuntimeException(final String msg, final Throwable e) {
+    super(msg, e);
+  }
+
+  public ODataRuntimeException(final Throwable e) {
+    super(e);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/bd8f4c59/odata4-lib/odata4-commons-core/pom.xml
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-commons-core/pom.xml b/odata4-lib/odata4-commons-core/pom.xml
index fac4f80..8b5edd2 100644
--- a/odata4-lib/odata4-commons-core/pom.xml
+++ b/odata4-lib/odata4-commons-core/pom.xml
@@ -1,46 +1,50 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- 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. -->
+<!-- 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. -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-	<modelVersion>4.0.0</modelVersion>
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
 
-	<artifactId>olingo-odata4-commons-core-incubating</artifactId>
-	<packaging>jar</packaging>
-	<name>${project.artifactId}</name>
+  <artifactId>olingo-odata4-commons-core-incubating</artifactId>
+  <packaging>jar</packaging>
+  <name>${project.artifactId}</name>
 
-	<parent>
-		<groupId>org.apache.olingo</groupId>
-		<artifactId>olingo-odata4-lib-incubating</artifactId>
-		<version>0.1.0-SNAPSHOT</version>
-		<relativePath>..</relativePath>
-	</parent>
+  <parent>
+    <groupId>org.apache.olingo</groupId>
+    <artifactId>olingo-odata4-lib-incubating</artifactId>
+    <version>0.1.0-SNAPSHOT</version>
+    <relativePath>..</relativePath>
+  </parent>
 
-	<dependencies>
-		<dependency>
-			<groupId>org.apache.olingo</groupId>
-			<artifactId>olingo-odata4-commons-api-incubating</artifactId>
-			<version>${project.version}</version>
-		</dependency>
-		<dependency>
-			<groupId>commons-codec</groupId>
-			<artifactId>commons-codec</artifactId>
-		</dependency>
-		<dependency>
-			<groupId>junit</groupId>
-			<artifactId>junit</artifactId>
-		</dependency>
-		<dependency>
-			<groupId>org.mockito</groupId>
-			<artifactId>mockito-all</artifactId>
-		</dependency>
-	</dependencies>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.olingo</groupId>
+      <artifactId>olingo-odata4-commons-api-incubating</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>commons-codec</groupId>
+      <artifactId>commons-codec</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-all</artifactId>
+    </dependency>
+  </dependencies>
 </project>

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/bd8f4c59/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/ODataFormat.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/ODataFormat.java b/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/ODataFormat.java
new file mode 100644
index 0000000..1f046c6
--- /dev/null
+++ b/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/ODataFormat.java
@@ -0,0 +1,23 @@
+/*
+ * 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.odata4.server.api;
+
+public enum ODataFormat {
+  XML, JSON
+}

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/bd8f4c59/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/ODataSerializer.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/ODataSerializer.java b/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/ODataSerializer.java
index b4abde4..fe01d79 100644
--- a/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/ODataSerializer.java
+++ b/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/ODataSerializer.java
@@ -26,4 +26,6 @@ public interface ODataSerializer {
 
   InputStream metadata(Edm edm);
 
+  InputStream serviceDocument(Edm edm, String serviceRoot);
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/bd8f4c59/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/ODataServer.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/ODataServer.java b/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/ODataServer.java
index 1a44f01..d3e112b 100644
--- a/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/ODataServer.java
+++ b/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/ODataServer.java
@@ -22,7 +22,7 @@ public abstract class ODataServer {
 
   private static final String IMPLEMENTATION = "org.apache.olingo.odata4.server.core.ODataServerImpl";
 
-  public static ODataServer instance() {
+  public static ODataServer newInstance() {
     try {
       final Class<?> clazz = Class.forName(ODataServer.IMPLEMENTATION);
 
@@ -37,6 +37,6 @@ public abstract class ODataServer {
     }
   }
 
-  public abstract ODataSerializer getSerializer();
+  public abstract ODataSerializer getSerializer(ODataFormat format);
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/bd8f4c59/odata4-lib/odata4-server-core/pom.xml
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/pom.xml b/odata4-lib/odata4-server-core/pom.xml
index 887454b..8343b1e 100644
--- a/odata4-lib/odata4-server-core/pom.xml
+++ b/odata4-lib/odata4-server-core/pom.xml
@@ -49,12 +49,24 @@
     </dependency>
     <dependency>
       <groupId>com.fasterxml.jackson.core</groupId>
-      <artifactId>jackson-databind</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>com.fasterxml.jackson.dataformat</groupId>
-      <artifactId>jackson-dataformat-xml</artifactId>
+      <artifactId>jackson-core</artifactId>
+      <version>2.2.3</version>
     </dependency>
+    <!-- <dependency> -->
+    <!-- <groupId>com.fasterxml.jackson.core</groupId> -->
+    <!-- <artifactId>jackson-databind</artifactId> -->
+    <!-- <version>2.2.3</version> -->
+    <!-- </dependency> -->
+    <!-- <dependency> -->
+    <!-- <groupId>com.fasterxml.jackson.core</groupId> -->
+    <!-- <artifactId>jackson-annotations</artifactId> -->
+    <!-- <version>2.2.3</version> -->
+    <!-- </dependency> -->
+    <!-- <dependency> -->
+    <!-- <groupId>com.fasterxml.jackson.dataformat</groupId> -->
+    <!-- <artifactId>jackson-dataformat-xml</artifactId> -->
+    <!-- <version>2.2.3</version> -->
+    <!-- </dependency> -->
   </dependencies>
 
   <build>

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/bd8f4c59/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/CircleStreamBuffer.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/CircleStreamBuffer.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/CircleStreamBuffer.java
new file mode 100644
index 0000000..9d2ca0f
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/CircleStreamBuffer.java
@@ -0,0 +1,327 @@
+/*******************************************************************************
+ * 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.odata4.server.core;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+import java.util.Queue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+/**
+ * Circular stream buffer to write/read into/from one single buffer.
+ * With support of {@link InputStream} and {@link OutputStream} access to buffered data.
+ * 
+ * 
+ */
+public class CircleStreamBuffer {
+
+  private static final int NEW_BUFFER_RESIZE_FACTOR = 2;
+  private static final int READ_EOF = -1;
+  private static final int DEFAULT_CAPACITY = 8192;
+  private static final int MAX_CAPACITY = DEFAULT_CAPACITY * 32;
+
+  private int currentAllocateCapacity = DEFAULT_CAPACITY;
+
+  private boolean writeMode = true;
+  private boolean writeClosed = false;
+  private boolean readClosed = false;
+
+  private Queue<ByteBuffer> bufferQueue = new LinkedBlockingQueue<ByteBuffer>();
+  private ByteBuffer currentWriteBuffer;
+
+  private InternalInputStream inStream;
+  private InternalOutputStream outStream;
+
+  /**
+   * Creates a {@link CircleStreamBuffer} with default buffer size.
+   */
+  public CircleStreamBuffer() {
+    this(DEFAULT_CAPACITY);
+  }
+
+  /**
+   * Create a {@link CircleStreamBuffer} with given buffer size in bytes.
+   * 
+   * @param bufferSize
+   */
+  public CircleStreamBuffer(final int bufferSize) {
+    currentAllocateCapacity = bufferSize;
+    createNewWriteBuffer();
+    inStream = new InternalInputStream(this);
+    outStream = new InternalOutputStream(this);
+  }
+
+  /**
+   * Get {@link InputStream} for data read access.
+   * 
+   * @return the stream
+   */
+  public InputStream getInputStream() {
+    return inStream;
+  }
+
+  /**
+   * Get {@link OutputStream} for write data.
+   * 
+   * @return the stream
+   */
+  public OutputStream getOutputStream() {
+    return outStream;
+  }
+
+  // #############################################
+  // #
+  // # Common parts
+  // #
+  // #############################################
+
+  /**
+   * Closes the write (input) part of the {@link CircleStreamBuffer}.
+   * After this call the buffer can only be read out.
+   */
+  public void closeWrite() {
+    writeClosed = true;
+  }
+
+  /**
+   * Closes the read (output) part of the {@link CircleStreamBuffer}.
+   * After this call it is possible to write into the buffer (but can never be read out).
+   */
+  public void closeRead() {
+    readClosed = true;
+    // clear references to byte buffers
+    ByteBuffer buffer = bufferQueue.poll();
+    while (buffer != null) {
+      buffer.clear();
+      buffer = bufferQueue.poll();
+    }
+  }
+
+  /**
+   * Closes write and read part (and hence the complete buffer).
+   */
+  public void close() {
+    closeWrite();
+    closeRead();
+  }
+
+  private int remaining() throws IOException {
+    if (writeMode) {
+      return currentWriteBuffer.remaining();
+    } else {
+      ByteBuffer toRead = getReadBuffer();
+      if (toRead == null) {
+        return 0;
+      }
+      return toRead.remaining();
+    }
+  }
+
+  // #############################################
+  // #
+  // # Reading parts
+  // #
+  // #############################################
+
+  private ByteBuffer getReadBuffer() throws IOException {
+    if (readClosed) {
+      throw new IOException("Tried to read from closed stream.");
+    }
+
+    boolean next = false;
+    ByteBuffer tmp = null;
+    if (writeMode) {
+      writeMode = false;
+      next = true;
+    } else {
+      tmp = bufferQueue.peek();
+      if (tmp != null && !tmp.hasRemaining()) {
+        tmp = bufferQueue.poll();
+        next = true;
+      }
+    }
+
+    if (next) {
+      tmp = bufferQueue.peek();
+      if (tmp != null) {
+        tmp.flip();
+      }
+      tmp = getReadBuffer();
+    }
+
+    return tmp;
+  }
+
+  private int read(final byte[] b, final int off, final int len) throws IOException {
+    ByteBuffer readBuffer = getReadBuffer();
+    if (readBuffer == null) {
+      return READ_EOF;
+    }
+
+    int toReadLength = readBuffer.remaining();
+    if (len < toReadLength) {
+      toReadLength = len;
+    }
+    readBuffer.get(b, off, toReadLength);
+    return toReadLength;
+  }
+
+  private int read() throws IOException {
+    ByteBuffer readBuffer = getReadBuffer();
+    if (readBuffer == null) {
+      return READ_EOF;
+    }
+
+    return readBuffer.get();
+  }
+
+  // #############################################
+  // #
+  // # Writing parts
+  // #
+  // #############################################
+
+  private void write(final byte[] data, final int off, final int len) throws IOException {
+    ByteBuffer writeBuffer = getWriteBuffer(len);
+    writeBuffer.put(data, off, len);
+  }
+
+  private ByteBuffer getWriteBuffer(final int size) throws IOException {
+    if (writeClosed) {
+      throw new IOException("Tried to write into closed stream.");
+    }
+
+    if (writeMode) {
+      if (remaining() < size) {
+        createNewWriteBuffer(size);
+      }
+    } else {
+      writeMode = true;
+      createNewWriteBuffer();
+    }
+
+    return currentWriteBuffer;
+  }
+
+  private void write(final int b) throws IOException {
+    ByteBuffer writeBuffer = getWriteBuffer(1);
+    writeBuffer.put((byte) b);
+  }
+
+  private void createNewWriteBuffer() {
+    createNewWriteBuffer(currentAllocateCapacity);
+  }
+
+  /**
+   * Creates a new buffer (per {@link #allocateBuffer(int)}) with the requested capacity as minimum capacity, add the
+   * new allocated
+   * buffer to the {@link #bufferQueue} and set it as {@link #currentWriteBuffer}.
+   * 
+   * @param requestedCapacity minimum capacity for new allocated buffer
+   */
+  private void createNewWriteBuffer(final int requestedCapacity) {
+    ByteBuffer b = allocateBuffer(requestedCapacity);
+    bufferQueue.add(b);
+    currentWriteBuffer = b;
+  }
+
+  /**
+   * 
+   * @param requestedCapacity
+   * @return the buffer
+   */
+  private ByteBuffer allocateBuffer(final int requestedCapacity) {
+    int allocateCapacity = requestedCapacity;
+    if (allocateCapacity < currentAllocateCapacity) {
+      allocateCapacity = currentAllocateCapacity * NEW_BUFFER_RESIZE_FACTOR;
+    }
+    if (allocateCapacity > MAX_CAPACITY) {
+      allocateCapacity = MAX_CAPACITY;
+    }
+    // update current
+    currentAllocateCapacity = allocateCapacity;
+    return ByteBuffer.allocate(allocateCapacity);
+  }
+
+  // #############################################
+  // #
+  // # Inner classes (streams)
+  // #
+  // #############################################
+
+  /**
+   * 
+   */
+  private static class InternalInputStream extends InputStream {
+
+    private final CircleStreamBuffer inBuffer;
+
+    public InternalInputStream(final CircleStreamBuffer csBuffer) {
+      inBuffer = csBuffer;
+    }
+
+    @Override
+    public int available() throws IOException {
+      return inBuffer.remaining();
+    }
+
+    @Override
+    public int read() throws IOException {
+      return inBuffer.read();
+    }
+
+    @Override
+    public int read(final byte[] b, final int off, final int len) throws IOException {
+      return inBuffer.read(b, off, len);
+    }
+
+    @Override
+    public void close() throws IOException {
+      inBuffer.closeRead();
+    }
+  }
+
+  /**
+   * 
+   */
+  private static class InternalOutputStream extends OutputStream {
+    private final CircleStreamBuffer outBuffer;
+
+    public InternalOutputStream(final CircleStreamBuffer csBuffer) {
+      outBuffer = csBuffer;
+    }
+
+    @Override
+    public void write(final int b) throws IOException {
+      outBuffer.write(b);
+    }
+
+    @Override
+    public void write(final byte[] b, final int off, final int len) throws IOException {
+      outBuffer.write(b, off, len);
+    }
+
+    @Override
+    public void close() throws IOException {
+      outBuffer.closeWrite();
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/bd8f4c59/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/MetadataDocument.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/MetadataDocument.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/MetadataDocument.java
index 63043b8..8d888e7 100644
--- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/MetadataDocument.java
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/MetadataDocument.java
@@ -20,9 +20,6 @@ package org.apache.olingo.odata4.server.core;
 
 import org.apache.olingo.odata4.commons.api.edm.Edm;
 
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
-
-@JacksonXmlRootElement(localName="Edmx", namespace="ns")
 public class MetadataDocument {
 
   private final Edm edm;

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/bd8f4c59/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/ODataSerializerImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/ODataSerializerImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/ODataSerializerImpl.java
index be51409..9275aa3 100644
--- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/ODataSerializerImpl.java
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/ODataSerializerImpl.java
@@ -18,32 +18,21 @@
  */
 package org.apache.olingo.odata4.server.core;
 
-import java.io.ByteArrayInputStream;
 import java.io.InputStream;
 
 import org.apache.olingo.odata4.commons.api.edm.Edm;
 import org.apache.olingo.odata4.server.api.ODataSerializer;
 
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.dataformat.xml.XmlMapper;
-
 public class ODataSerializerImpl implements ODataSerializer {
 
   @Override
   public InputStream metadata(Edm edm) {
-    try {
-      MetadataDocument document = new MetadataDocument(edm);
-      
-      
-      ObjectMapper xmlMapper = new XmlMapper();
-      byte[] bytes = xmlMapper.writeValueAsBytes(document);
-      InputStream result = new ByteArrayInputStream(bytes);
+       return null;
+  }
 
-      return result;
-    } catch (JsonProcessingException e) {
-      throw new RuntimeException(e);
-    }
+  @Override
+  public InputStream serviceDocument(Edm edm, String serviceRoot) {
+    return null;
   }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/bd8f4c59/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/ODataServerImpl.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/ODataServerImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/ODataServerImpl.java
index 34813c4..679152a 100644
--- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/ODataServerImpl.java
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/ODataServerImpl.java
@@ -18,14 +18,29 @@
  */
 package org.apache.olingo.odata4.server.core;
 
+import org.apache.olingo.odata4.commons.api.ODataRuntimeException;
+import org.apache.olingo.odata4.server.api.ODataFormat;
 import org.apache.olingo.odata4.server.api.ODataSerializer;
 import org.apache.olingo.odata4.server.api.ODataServer;
+import org.apache.olingo.odata4.server.core.serializer.json.ODataJsonSerializer;
 
 public class ODataServerImpl extends ODataServer {
 
   @Override
-  public ODataSerializer getSerializer() {
-    return new ODataSerializerImpl();
+  public ODataSerializer getSerializer(ODataFormat format) {
+    ODataSerializer serializer;
+    switch (format) {
+    case JSON:
+      serializer = new ODataJsonSerializer();
+      break;
+    case XML:
+      serializer = new ODataSerializerImpl();
+      break;
+    default:
+      throw new ODataRuntimeException("Unsupported format: " + format);
+    }
+
+    return serializer;
   }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/bd8f4c59/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/serializer/json/ODataJsonSerializer.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/serializer/json/ODataJsonSerializer.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/serializer/json/ODataJsonSerializer.java
new file mode 100644
index 0000000..130d345
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/serializer/json/ODataJsonSerializer.java
@@ -0,0 +1,72 @@
+/*
+ * 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.odata4.server.core.serializer.json;
+
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStreamWriter;
+
+import org.apache.olingo.odata4.commons.api.ODataRuntimeException;
+import org.apache.olingo.odata4.commons.api.edm.Edm;
+import org.apache.olingo.odata4.server.api.ODataSerializer;
+import org.apache.olingo.odata4.server.core.CircleStreamBuffer;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
+
+public class ODataJsonSerializer implements ODataSerializer {
+
+  private static final String DEFAULT_CHARSET = "UTF-8";
+
+  @Override
+  public InputStream metadata(Edm edm) {
+    throw new ODataRuntimeException("Metadata in JSON format not supported!");
+  }
+
+  @Override
+  public InputStream serviceDocument(Edm edm, String serviceRoot) {
+
+    try {
+      CircleStreamBuffer buffer = new CircleStreamBuffer();
+      BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(buffer.getOutputStream(), DEFAULT_CHARSET));
+
+      JsonFactory factory = new JsonFactory();
+      JsonGenerator gen = factory.createGenerator(writer);
+      
+      gen.setPrettyPrinter(new DefaultPrettyPrinter());
+
+      gen.writeStartObject();
+      gen.writeObjectField("bla1", new Integer(3));
+      gen.writeObjectField("bla2", new Integer(3));
+      gen.writeEndObject();
+
+      gen.close();
+
+//      writer.flush();
+//      buffer.closeWrite();
+
+      return buffer.getInputStream();
+      
+    } catch (IOException e) {
+      throw new ODataRuntimeException(e);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/bd8f4c59/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/serializer/MetadataTest.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/serializer/MetadataTest.java b/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/serializer/MetadataTest.java
index f662b07..1b79598 100644
--- a/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/serializer/MetadataTest.java
+++ b/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/serializer/MetadataTest.java
@@ -20,13 +20,11 @@ package org.apache.olingo.odata4.server.core.serializer;
 
 import static org.junit.Assert.assertNotNull;
 
-import java.io.BufferedReader;
-import java.io.IOException;
 import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.nio.charset.Charset;
 
+import org.apache.olingo.odata4.commons.api.ODataRuntimeException;
 import org.apache.olingo.odata4.commons.api.edm.Edm;
+import org.apache.olingo.odata4.server.api.ODataFormat;
 import org.apache.olingo.odata4.server.api.ODataSerializer;
 import org.apache.olingo.odata4.server.api.ODataServer;
 import org.apache.olingo.odata4.server.core.edm.provider.EdmProviderImpl;
@@ -39,36 +37,27 @@ public class MetadataTest {
 
   @Test
   public void start() throws Exception {
-    ODataServer server = ODataServer.instance();
+    ODataServer server = ODataServer.newInstance();
     assertNotNull(server);
 
-    ODataSerializer serializer = server.getSerializer();
+    ODataSerializer serializer = server.getSerializer(ODataFormat.XML);
     assertNotNull(serializer);
 
     InputStream result = serializer.metadata(edm);
-    assertNotNull(result);
-
-    System.out.println(inputStreamToString(result, false));
+//    assertNotNull(result);
+//
+//    System.out.println(StringUtil.inputStreamToString(result, false));
   }
 
+  @Test(expected = ODataRuntimeException.class)
+  public void serialzeMetadataAsJson() {
+    ODataServer server = ODataServer.newInstance();
+    assertNotNull(server);
 
-  private static String inputStreamToString(final InputStream in, final boolean preserveLineBreaks) throws IOException {
-    final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in, Charset.forName("UTF-8")));
-    final StringBuilder stringBuilder = new StringBuilder();
-    String line = null;
-
-    while ((line = bufferedReader.readLine()) != null) {
-      stringBuilder.append(line);
-      if (preserveLineBreaks) {
-        stringBuilder.append("\n");
-      }
-    }
-
-    bufferedReader.close();
-
-    final String result = stringBuilder.toString();
+    ODataSerializer serializer = server.getSerializer(ODataFormat.JSON);
+    assertNotNull(serializer);
 
-    return result;
+    serializer.metadata(edm);
   }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/bd8f4c59/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/serializer/ServiceDocumentTest.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/serializer/ServiceDocumentTest.java b/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/serializer/ServiceDocumentTest.java
new file mode 100644
index 0000000..c0f9b5c
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/serializer/ServiceDocumentTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.odata4.server.core.serializer;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.io.InputStream;
+
+import org.apache.olingo.odata4.commons.api.edm.Edm;
+import org.apache.olingo.odata4.server.api.ODataFormat;
+import org.apache.olingo.odata4.server.api.ODataSerializer;
+import org.apache.olingo.odata4.server.api.ODataServer;
+import org.apache.olingo.odata4.server.core.edm.provider.EdmProviderImpl;
+import org.apache.olingo.odata4.server.core.testutil.EdmTechProvider;
+import org.apache.olingo.odata4.server.core.testutil.StringUtil;
+import org.junit.Test;
+
+public class ServiceDocumentTest {
+  
+  private Edm edm = new EdmProviderImpl(new EdmTechProvider());
+
+  @Test
+  public void writeServiceDocumentJson() throws Exception {
+    String serviceRoot = "http://localhost:8080/odata.svc";
+    
+    ODataServer server = ODataServer.newInstance();
+    assertNotNull(server);
+
+    ODataSerializer serializer = server.getSerializer(ODataFormat.JSON);
+    assertNotNull(serializer);
+
+    InputStream result = serializer.serviceDocument(edm, serviceRoot);
+    assertNotNull(result);
+    
+    System.out.println(StringUtil.inputStreamToString(result, true));
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/bd8f4c59/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/testutil/StringUtil.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/testutil/StringUtil.java b/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/testutil/StringUtil.java
new file mode 100644
index 0000000..c8669ce
--- /dev/null
+++ b/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/testutil/StringUtil.java
@@ -0,0 +1,52 @@
+/*
+ * 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.odata4.server.core.testutil;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.nio.charset.Charset;
+
+public class StringUtil {
+  
+  public static String inputStreamToString(final InputStream in, final boolean preserveLineBreaks) {
+    try {
+      final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in, Charset.forName("UTF-8")));
+      final StringBuilder stringBuilder = new StringBuilder();
+      String line = null;
+
+      while ((line = bufferedReader.readLine()) != null) {
+        stringBuilder.append(line);
+        if (preserveLineBreaks) {
+          stringBuilder.append("\n");
+        }
+      }
+
+      bufferedReader.close();
+
+      final String result = stringBuilder.toString();
+
+      return result;
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    }
+  }
+  
+}

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/bd8f4c59/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 583258c..953fb30 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,26 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
 
-    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.
+  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.
 
 -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
 
   <groupId>org.apache.olingo</groupId>
@@ -63,6 +63,7 @@
 
   <properties>
     <antlr.version>4.1</antlr.version>
+    <sl4j.version>1.7.6</sl4j.version>
   </properties>
 
   <dependencyManagement>
@@ -110,6 +111,11 @@
         <artifactId>jackson-dataformat-xml</artifactId>
         <version>2.2.3</version>
       </dependency>
+      <dependency>
+        <groupId>org.slf4j</groupId>
+        <artifactId>slf4j-api</artifactId>
+        <version>${sl4j.version}</version>
+      </dependency>
     </dependencies>
   </dependencyManagement>