You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by il...@apache.org on 2014/07/16 10:14:21 UTC

[09/12] [OLINGO-362] OAuth2 supporting abstract class provided + concrete CXF-based IT

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c541d925/fit/src/main/java/org/apache/olingo/fit/V3KeyAsSegment.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/V3KeyAsSegment.java b/fit/src/main/java/org/apache/olingo/fit/V3KeyAsSegment.java
index fb6a446..01d9086 100644
--- a/fit/src/main/java/org/apache/olingo/fit/V3KeyAsSegment.java
+++ b/fit/src/main/java/org/apache/olingo/fit/V3KeyAsSegment.java
@@ -20,6 +20,7 @@ package org.apache.olingo.fit;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.io.InputStream;
 
 import javax.ws.rs.Consumes;
@@ -51,14 +52,14 @@ public class V3KeyAsSegment {
 
   private final V3Services services;
 
-  public V3KeyAsSegment() throws Exception {
+  public V3KeyAsSegment() throws IOException {
     services = new V3Services();
   }
 
   private Response replaceServiceName(final Response response) {
     try {
       final String content = IOUtils.toString((InputStream) response.getEntity(), Constants.ENCODING).
-          replaceAll("Static\\.svc", "KeyAsSegment.svc");
+              replaceAll("Static\\.svc", "KeyAsSegment.svc");
 
       final Response.ResponseBuilder builder = Response.status(response.getStatus());
       for (String headerName : response.getHeaders().keySet()) {
@@ -84,91 +85,91 @@ public class V3KeyAsSegment {
   @GET
   @Path("/{entitySetName}/{entityId}")
   public Response getEntity(
-      @Context final UriInfo uriInfo,
-      @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
-      @PathParam("entitySetName") final String entitySetName,
-      @PathParam("entityId") final String entityId,
-      @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format,
-      @QueryParam("$expand") @DefaultValue(StringUtils.EMPTY) final String expand,
-      @QueryParam("$select") @DefaultValue(StringUtils.EMPTY) final String select) {
+          @Context final UriInfo uriInfo,
+          @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
+          @PathParam("entitySetName") final String entitySetName,
+          @PathParam("entityId") final String entityId,
+          @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format,
+          @QueryParam("$expand") @DefaultValue(StringUtils.EMPTY) final String expand,
+          @QueryParam("$select") @DefaultValue(StringUtils.EMPTY) final String select) {
 
     return replaceServiceName(services.getEntityInternal(uriInfo.getRequestUri().toASCIIString(),
-        accept, entitySetName, entityId, format, expand, select, true));
+            accept, entitySetName, entityId, format, expand, select, true));
   }
 
   @DELETE
   @Path("/{entitySetName}/{entityId}")
   public Response removeEntity(
-      @PathParam("entitySetName") final String entitySetName,
-      @PathParam("entityId") final String entityId) {
+          @PathParam("entitySetName") final String entitySetName,
+          @PathParam("entityId") final String entityId) {
 
     return replaceServiceName(services.removeEntity(entitySetName, entityId));
   }
 
   @MERGE
   @Path("/{entitySetName}/{entityId}")
-  @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
-  @Consumes({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
+  @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
+  @Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
   public Response mergeEntity(
-      @Context final UriInfo uriInfo,
-      @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
-      @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
-      @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
-      @HeaderParam("If-Match") @DefaultValue(StringUtils.EMPTY) final String ifMatch,
-      @PathParam("entitySetName") final String entitySetName,
-      @PathParam("entityId") final String entityId,
-      final String changes) {
+          @Context final UriInfo uriInfo,
+          @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
+          @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
+          @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
+          @HeaderParam("If-Match") @DefaultValue(StringUtils.EMPTY) final String ifMatch,
+          @PathParam("entitySetName") final String entitySetName,
+          @PathParam("entityId") final String entityId,
+          final String changes) {
 
     return replaceServiceName(services.patchEntity(uriInfo, accept, contentType, prefer, ifMatch, entitySetName,
-        entityId, changes));
+            entityId, changes));
   }
 
   @PATCH
   @Path("/{entitySetName}/{entityId}")
-  @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
-  @Consumes({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
+  @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
+  @Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
   public Response patchEntity(
-      @Context final UriInfo uriInfo,
-      @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
-      @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
-      @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
-      @HeaderParam("If-Match") @DefaultValue(StringUtils.EMPTY) final String ifMatch,
-      @PathParam("entitySetName") final String entitySetName,
-      @PathParam("entityId") final String entityId,
-      final String changes) {
+          @Context final UriInfo uriInfo,
+          @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
+          @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
+          @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
+          @HeaderParam("If-Match") @DefaultValue(StringUtils.EMPTY) final String ifMatch,
+          @PathParam("entitySetName") final String entitySetName,
+          @PathParam("entityId") final String entityId,
+          final String changes) {
 
     return replaceServiceName(services.patchEntity(uriInfo, accept, contentType, prefer, ifMatch, entitySetName,
-        entityId, changes));
+            entityId, changes));
   }
 
   @PUT
   @Path("/{entitySetName}/{entityId}")
-  @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
-  @Consumes({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
+  @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
+  @Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
   public Response putNewEntity(
-      @Context final UriInfo uriInfo,
-      @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
-      @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
-      @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
-      @PathParam("entitySetName") final String entitySetName,
-      @PathParam("entityId") final String entityId,
-      final String entity) {
+          @Context final UriInfo uriInfo,
+          @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
+          @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
+          @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
+          @PathParam("entitySetName") final String entitySetName,
+          @PathParam("entityId") final String entityId,
+          final String entity) {
 
     return replaceServiceName(services.replaceEntity(uriInfo, accept, contentType, prefer, entitySetName, entityId,
-        entity));
+            entity));
   }
 
   @POST
   @Path("/{entitySetName}")
-  @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
-  @Consumes({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM })
+  @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
+  @Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM})
   public Response postNewEntity(
-      @Context final UriInfo uriInfo,
-      @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
-      @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
-      @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
-      @PathParam("entitySetName") final String entitySetName,
-      final String entity) {
+          @Context final UriInfo uriInfo,
+          @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
+          @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
+          @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
+          @PathParam("entitySetName") final String entitySetName,
+          final String entity) {
 
     return replaceServiceName(services.postNewEntity(uriInfo, accept, contentType, prefer, entitySetName, entity));
   }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c541d925/fit/src/main/java/org/apache/olingo/fit/V3OpenType.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/V3OpenType.java b/fit/src/main/java/org/apache/olingo/fit/V3OpenType.java
index 55abc3b..9452739 100644
--- a/fit/src/main/java/org/apache/olingo/fit/V3OpenType.java
+++ b/fit/src/main/java/org/apache/olingo/fit/V3OpenType.java
@@ -20,6 +20,7 @@ package org.apache.olingo.fit;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.io.InputStream;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -55,16 +56,16 @@ public class V3OpenType extends V3Services {
 
   private static final Pattern GUID = Pattern.compile("guid'(.*)'");
 
-  public V3OpenType() throws Exception {
+  public V3OpenType() throws IOException {
     super(new Metadata(FSManager.instance(ODataServiceVersion.V30).
-        readRes("openType" + StringUtils.capitalize(Constants.get(ODataServiceVersion.V30, ConstantKey.METADATA)),
-            Accept.XML), ODataServiceVersion.V30));
+            readRes("openType" + StringUtils.capitalize(Constants.get(ODataServiceVersion.V30, ConstantKey.METADATA)),
+                    Accept.XML), ODataServiceVersion.V30));
   }
 
   private Response replaceServiceName(final Response response) {
     try {
       final String content = IOUtils.toString((InputStream) response.getEntity(), Constants.ENCODING).
-          replaceAll("Static\\.svc", "OpenType.svc");
+              replaceAll("Static\\.svc", "OpenType.svc");
 
       final Response.ResponseBuilder builder = Response.status(response.getStatus());
       for (String headerName : response.getHeaders().keySet()) {
@@ -89,7 +90,7 @@ public class V3OpenType extends V3Services {
 
   /**
    * Provide sample large metadata.
-   * 
+   *
    * @return metadata.
    */
   @GET
@@ -98,39 +99,39 @@ public class V3OpenType extends V3Services {
   @Override
   public Response getMetadata() {
     return super.getMetadata("openType" + StringUtils.capitalize(
-        Constants.get(ODataServiceVersion.V30, ConstantKey.METADATA)));
+            Constants.get(ODataServiceVersion.V30, ConstantKey.METADATA)));
   }
 
   @GET
   @Path("/{entitySetName}({entityId})")
   @Override
   public Response getEntity(
-      @Context final UriInfo uriInfo,
-      @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
-      @PathParam("entitySetName") final String entitySetName,
-      @PathParam("entityId") final String entityId,
-      @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format,
-      @QueryParam("$expand") @DefaultValue(StringUtils.EMPTY) final String expand,
-      @QueryParam("$select") @DefaultValue(StringUtils.EMPTY) final String select) {
+          @Context final UriInfo uriInfo,
+          @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
+          @PathParam("entitySetName") final String entitySetName,
+          @PathParam("entityId") final String entityId,
+          @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format,
+          @QueryParam("$expand") @DefaultValue(StringUtils.EMPTY) final String expand,
+          @QueryParam("$select") @DefaultValue(StringUtils.EMPTY) final String select) {
 
     final Matcher matcher = GUID.matcher(entityId);
     return replaceServiceName(super.getEntityInternal(
-        uriInfo.getRequestUri().toASCIIString(), accept, entitySetName,
-        matcher.matches() ? matcher.group(1) : entityId, format, expand, select, false));
+            uriInfo.getRequestUri().toASCIIString(), accept, entitySetName,
+            matcher.matches() ? matcher.group(1) : entityId, format, expand, select, false));
   }
 
   @POST
   @Path("/{entitySetName}")
-  @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
-  @Consumes({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM })
+  @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
+  @Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM})
   @Override
   public Response postNewEntity(
-      @Context final UriInfo uriInfo,
-      @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
-      @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
-      @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
-      @PathParam("entitySetName") final String entitySetName,
-      final String entity) {
+          @Context final UriInfo uriInfo,
+          @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
+          @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
+          @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
+          @PathParam("entitySetName") final String entitySetName,
+          final String entity) {
 
     return replaceServiceName(super.postNewEntity(uriInfo, accept, contentType, prefer, entitySetName, entity));
   }
@@ -139,11 +140,11 @@ public class V3OpenType extends V3Services {
   @Path("/{entitySetName}({entityId})")
   @Override
   public Response removeEntity(
-      @PathParam("entitySetName") final String entitySetName,
-      @PathParam("entityId") final String entityId) {
+          @PathParam("entitySetName") final String entitySetName,
+          @PathParam("entityId") final String entityId) {
 
     final Matcher matcher = GUID.matcher(entityId);
     return replaceServiceName(super.removeEntity(entitySetName,
-        matcher.matches() ? matcher.group(1) : entityId));
+            matcher.matches() ? matcher.group(1) : entityId));
   }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c541d925/fit/src/main/java/org/apache/olingo/fit/V3PrimitiveKeys.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/V3PrimitiveKeys.java b/fit/src/main/java/org/apache/olingo/fit/V3PrimitiveKeys.java
index 2368b13..6231303 100644
--- a/fit/src/main/java/org/apache/olingo/fit/V3PrimitiveKeys.java
+++ b/fit/src/main/java/org/apache/olingo/fit/V3PrimitiveKeys.java
@@ -18,6 +18,7 @@
  */
 package org.apache.olingo.fit;
 
+import java.io.IOException;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
@@ -32,15 +33,10 @@ import org.springframework.stereotype.Service;
 @Path("/V30/PrimitiveKeys.svc")
 public class V3PrimitiveKeys extends V3Services {
 
-  public V3PrimitiveKeys() throws Exception {
+  public V3PrimitiveKeys() throws IOException {
     super();
   }
 
-  /**
-   * Provide sample large metadata.
-   * 
-   * @return metadata.
-   */
   @GET
   @Path("/$metadata")
   @Produces(MediaType.APPLICATION_XML)
@@ -48,7 +44,7 @@ public class V3PrimitiveKeys extends V3Services {
   public Response getMetadata() {
     try {
       return xml.createResponse(
-          null, FSManager.instance(version).readRes("primitiveKeysMetadata", Accept.XML), null, Accept.XML);
+              null, FSManager.instance(version).readRes("primitiveKeysMetadata", Accept.XML), null, Accept.XML);
     } catch (Exception e) {
       return xml.createFaultResponse(Accept.XML.toString(version), e);
     }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c541d925/fit/src/main/java/org/apache/olingo/fit/V3Services.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/V3Services.java b/fit/src/main/java/org/apache/olingo/fit/V3Services.java
index be2a297..975b3d3 100644
--- a/fit/src/main/java/org/apache/olingo/fit/V3Services.java
+++ b/fit/src/main/java/org/apache/olingo/fit/V3Services.java
@@ -62,7 +62,7 @@ import org.apache.olingo.fit.utils.ConstantKey;
 import org.apache.olingo.fit.utils.Constants;
 import org.apache.olingo.fit.utils.FSManager;
 import org.apache.olingo.fit.utils.LinkInfo;
-import org.apache.olingo.fit.utils.XHTTPMethodInterceptor;
+import org.apache.olingo.fit.rest.XHTTPMethodInterceptor;
 import org.springframework.stereotype.Service;
 
 @Service
@@ -70,19 +70,19 @@ import org.springframework.stereotype.Service;
 @InInterceptors(classes = XHTTPMethodInterceptor.class)
 public class V3Services extends AbstractServices {
 
-  public V3Services() throws Exception {
+  public V3Services() throws IOException {
     super(ODataServiceVersion.V30, Commons.getMetadata(ODataServiceVersion.V30));
   }
 
-  protected V3Services(final Metadata metadata) throws Exception {
+  protected V3Services(final Metadata metadata) throws IOException {
     super(ODataServiceVersion.V30, metadata);
   }
 
   @GET
   @Path("/InStreamErrorGetCustomer")
   public Response instreamErrorGetCustomer(
-      @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
-      @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format) {
+          @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
+          @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format) {
 
     final Accept acceptType;
     if (StringUtils.isNotBlank(format)) {
@@ -95,9 +95,9 @@ public class V3Services extends AbstractServices {
       final InputStream error = FSManager.instance(version).readFile("InStreamErrorGetCustomer", acceptType);
 
       return Response.ok(error).
-          header(Constants.get(version, ConstantKey.ODATA_SERVICE_VERSION), version + ";").
-          header("Content-Type", acceptType.toString(version)).
-          build();
+              header(Constants.get(version, ConstantKey.ODATA_SERVICE_VERSION), version + ";").
+              header("Content-Type", acceptType.toString(version)).
+              build();
     } catch (Exception e) {
       if (acceptType == Accept.XML || acceptType == Accept.TEXT) {
         throw new UnsupportedMediaTypeException("Unsupported media type");
@@ -109,7 +109,7 @@ public class V3Services extends AbstractServices {
 
   /**
    * Provide sample large metadata.
-   * 
+   *
    * @return metadata.
    */
   @GET
@@ -128,8 +128,9 @@ public class V3Services extends AbstractServices {
 
   @Override
   public InputStream exploreMultipart(
-      final List<Attachment> attachments, final String boundary, final boolean contineOnError)
-      throws IOException {
+          final List<Attachment> attachments, final String boundary, final boolean contineOnError)
+          throws IOException {
+
     final ByteArrayOutputStream bos = new ByteArrayOutputStream();
 
     Response res = null;
@@ -197,7 +198,6 @@ public class V3Services extends AbstractServices {
 
           addSingleBatchResponse(res, bos);
         }
-
       } catch (Exception e) {
         if (res == null || res.getStatus() < 400) {
           addErrorBatchResponse(e, bos);
@@ -215,15 +215,15 @@ public class V3Services extends AbstractServices {
   @GET
   @Path("/Car/{type:.*}")
   public Response filterCar(
-      @Context final UriInfo uriInfo,
-      @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
-      @QueryParam("$top") @DefaultValue(StringUtils.EMPTY) final String top,
-      @QueryParam("$skip") @DefaultValue(StringUtils.EMPTY) final String skip,
-      @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format,
-      @QueryParam("$inlinecount") @DefaultValue(StringUtils.EMPTY) final String count,
-      @QueryParam("$filter") @DefaultValue(StringUtils.EMPTY) final String filter,
-      @QueryParam("$orderby") @DefaultValue(StringUtils.EMPTY) final String orderby,
-      @QueryParam("$skiptoken") @DefaultValue(StringUtils.EMPTY) final String skiptoken) {
+          @Context final UriInfo uriInfo,
+          @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
+          @QueryParam("$top") @DefaultValue(StringUtils.EMPTY) final String top,
+          @QueryParam("$skip") @DefaultValue(StringUtils.EMPTY) final String skip,
+          @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format,
+          @QueryParam("$inlinecount") @DefaultValue(StringUtils.EMPTY) final String count,
+          @QueryParam("$filter") @DefaultValue(StringUtils.EMPTY) final String filter,
+          @QueryParam("$orderby") @DefaultValue(StringUtils.EMPTY) final String orderby,
+          @QueryParam("$skiptoken") @DefaultValue(StringUtils.EMPTY) final String skiptoken) {
 
     return super.getEntitySet(uriInfo, accept, "Car", top, skip, format, count, filter, orderby, skiptoken);
   }
@@ -231,27 +231,27 @@ public class V3Services extends AbstractServices {
   @GET
   @Path("/Login({entityId})")
   public Response getLogin(
-      @Context final UriInfo uriInfo,
-      @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
-      @PathParam("entityId") final String entityId,
-      @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format,
-      @QueryParam("$expand") @DefaultValue(StringUtils.EMPTY) final String expand,
-      @QueryParam("$select") @DefaultValue(StringUtils.EMPTY) final String select) {
+          @Context final UriInfo uriInfo,
+          @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
+          @PathParam("entityId") final String entityId,
+          @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format,
+          @QueryParam("$expand") @DefaultValue(StringUtils.EMPTY) final String expand,
+          @QueryParam("$select") @DefaultValue(StringUtils.EMPTY) final String select) {
 
     return super.getEntityInternal(uriInfo.getRequestUri().toASCIIString(), accept,
-        "Login", StringUtils.remove(entityId, "'"), format, expand, select, false);
+            "Login", StringUtils.remove(entityId, "'"), format, expand, select, false);
   }
 
   @POST
   @Path("/Login")
-  @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
-  @Consumes({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM })
+  @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
+  @Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM})
   public Response postLogin(
-      @Context final UriInfo uriInfo,
-      @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
-      @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
-      @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
-      final String entity) {
+          @Context final UriInfo uriInfo,
+          @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
+          @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
+          @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
+          final String entity) {
 
     if ("{\"odata.type\":\"Microsoft.Test.OData.Services.AstoriaDefaultService.Login\"}".equals(entity)) {
       return xml.createFaultResponse(accept, new BadRequestException());
@@ -263,14 +263,14 @@ public class V3Services extends AbstractServices {
   @DELETE
   @Path("/Login({entityId})")
   public Response removeLogin(
-      @PathParam("entityId") final String entityId) {
+          @PathParam("entityId") final String entityId) {
 
     return super.removeEntity("Login", StringUtils.remove(entityId, "'"));
   }
 
   /**
    * Retrieve links sample.
-   * 
+   *
    * @param accept Accept header.
    * @param entitySetName Entity set name.
    * @param entityId entity id.
@@ -281,11 +281,11 @@ public class V3Services extends AbstractServices {
   @GET
   @Path("/{entitySetName}({entityId})/$links/{linkName}")
   public Response getLinks(
-      @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
-      @PathParam("entitySetName") final String entitySetName,
-      @PathParam("entityId") final String entityId,
-      @PathParam("linkName") final String linkName,
-      @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format) {
+          @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
+          @PathParam("entitySetName") final String entitySetName,
+          @PathParam("entityId") final String entityId,
+          @PathParam("linkName") final String linkName,
+          @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format) {
     try {
       final Accept acceptType;
       if (StringUtils.isNotBlank(format)) {
@@ -301,9 +301,9 @@ public class V3Services extends AbstractServices {
       final LinkInfo links = xml.readLinks(entitySetName, entityId, linkName, acceptType);
 
       return xml.createResponse(
-          links.getLinks(),
-          links.getEtag(),
-          acceptType);
+              links.getLinks(),
+              links.getEtag(),
+              acceptType);
     } catch (Exception e) {
       return xml.createFaultResponse(accept, e);
     }
@@ -312,13 +312,13 @@ public class V3Services extends AbstractServices {
   @POST
   @Path("/{entitySetName}({entityId})/$links/{linkName}")
   public Response postLink(
-      @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
-      @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
-      @PathParam("entitySetName") final String entitySetName,
-      @PathParam("entityId") final String entityId,
-      @PathParam("linkName") final String linkName,
-      final String link,
-      @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format) {
+          @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
+          @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
+          @PathParam("entitySetName") final String entitySetName,
+          @PathParam("entityId") final String entityId,
+          @PathParam("linkName") final String linkName,
+          final String link,
+          @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format) {
     try {
       final Accept acceptType;
       if (StringUtils.isNotBlank(format)) {
@@ -348,11 +348,11 @@ public class V3Services extends AbstractServices {
       }
 
       utils.putLinksInMemory(
-          Commons.getEntityBasePath(entitySetName, entityId),
-          entitySetName,
-          entityId,
-          linkName,
-          links);
+              Commons.getEntityBasePath(entitySetName, entityId),
+              entitySetName,
+              entityId,
+              linkName,
+              links);
 
       return xml.createResponse(null, null, null, Response.Status.NO_CONTENT);
     } catch (Exception e) {
@@ -363,39 +363,39 @@ public class V3Services extends AbstractServices {
   @MERGE
   @Path("/{entitySetName}({entityId})/$links/{linkName}")
   public Response mergeLink(
-      @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
-      @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
-      @PathParam("entitySetName") final String entitySetName,
-      @PathParam("entityId") final String entityId,
-      @PathParam("linkName") final String linkName,
-      final String link,
-      @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format) {
+          @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
+          @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
+          @PathParam("entitySetName") final String entitySetName,
+          @PathParam("entityId") final String entityId,
+          @PathParam("linkName") final String linkName,
+          final String link,
+          @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format) {
     return putLink(accept, contentType, entitySetName, entityId, linkName, link, format);
   }
 
   @PATCH
   @Path("/{entitySetName}({entityId})/$links/{linkName}")
   public Response patchLink(
-      @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
-      @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
-      @PathParam("entitySetName") final String entitySetName,
-      @PathParam("entityId") final String entityId,
-      @PathParam("linkName") final String linkName,
-      final String link,
-      @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format) {
+          @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
+          @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
+          @PathParam("entitySetName") final String entitySetName,
+          @PathParam("entityId") final String entityId,
+          @PathParam("linkName") final String linkName,
+          final String link,
+          @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format) {
     return putLink(accept, contentType, entitySetName, entityId, linkName, link, format);
   }
 
   @PUT
   @Path("/{entitySetName}({entityId})/$links/{linkName}")
   public Response putLink(
-      @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
-      @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
-      @PathParam("entitySetName") final String entitySetName,
-      @PathParam("entityId") final String entityId,
-      @PathParam("linkName") final String linkName,
-      final String link,
-      @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format) {
+          @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
+          @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
+          @PathParam("entitySetName") final String entitySetName,
+          @PathParam("entityId") final String entityId,
+          @PathParam("linkName") final String linkName,
+          final String link,
+          @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format) {
     try {
       final Accept acceptType;
       if (StringUtils.isNotBlank(format)) {
@@ -425,10 +425,10 @@ public class V3Services extends AbstractServices {
       }
 
       utils.putLinksInMemory(
-          Commons.getEntityBasePath(entitySetName, entityId),
-          entitySetName,
-          linkName,
-          links);
+              Commons.getEntityBasePath(entitySetName, entityId),
+              entitySetName,
+              linkName,
+              links);
 
       return xml.createResponse(null, null, null, Response.Status.NO_CONTENT);
     } catch (Exception e) {
@@ -439,13 +439,13 @@ public class V3Services extends AbstractServices {
   @DELETE
   @Path("/{entitySetName}({entityId})/$links/{linkName}({linkId})")
   public Response deleteLink(
-      @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
-      @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
-      @PathParam("entitySetName") final String entitySetName,
-      @PathParam("entityId") final String entityId,
-      @PathParam("linkName") final String linkName,
-      @PathParam("linkId") final String linkId,
-      @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format) {
+          @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
+          @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
+          @PathParam("entitySetName") final String entitySetName,
+          @PathParam("entityId") final String entityId,
+          @PathParam("linkName") final String linkName,
+          @PathParam("linkId") final String linkId,
+          @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format) {
     try {
       final Accept acceptType;
       if (StringUtils.isNotBlank(format)) {
@@ -461,19 +461,19 @@ public class V3Services extends AbstractServices {
       final AbstractUtilities utils = getUtilities(acceptType);
 
       final Map.Entry<String, List<String>> currents = json.extractLinkURIs(utils.readLinks(
-          entitySetName, entityId, linkName, Accept.JSON_FULLMETA).getLinks());
+              entitySetName, entityId, linkName, Accept.JSON_FULLMETA).getLinks());
 
       final Map.Entry<String, List<String>> toBeRemoved = json.extractLinkURIs(utils.readLinks(
-          entitySetName, entityId, linkName + "(" + linkId + ")", Accept.JSON_FULLMETA).getLinks());
+              entitySetName, entityId, linkName + "(" + linkId + ")", Accept.JSON_FULLMETA).getLinks());
 
       final List<String> remains = currents.getValue();
       remains.removeAll(toBeRemoved.getValue());
 
       utils.putLinksInMemory(
-          Commons.getEntityBasePath(entitySetName, entityId),
-          entitySetName,
-          linkName,
-          remains);
+              Commons.getEntityBasePath(entitySetName, entityId),
+              entitySetName,
+              linkName,
+              remains);
 
       return xml.createResponse(null, null, null, Response.Status.NO_CONTENT);
     } catch (Exception e) {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c541d925/fit/src/main/java/org/apache/olingo/fit/V4Demo.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/V4Demo.java b/fit/src/main/java/org/apache/olingo/fit/V4Demo.java
index 1c6f501..18e7deb 100644
--- a/fit/src/main/java/org/apache/olingo/fit/V4Demo.java
+++ b/fit/src/main/java/org/apache/olingo/fit/V4Demo.java
@@ -20,6 +20,7 @@ package org.apache.olingo.fit;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.io.InputStream;
 
 import javax.ws.rs.Consumes;
@@ -52,16 +53,16 @@ import org.springframework.stereotype.Service;
 @Path("/V40/Demo.svc")
 public class V4Demo extends V4Services {
 
-  public V4Demo() throws Exception {
+  public V4Demo() throws IOException {
     super(new Metadata(FSManager.instance(ODataServiceVersion.V40).
-        readRes("demo" + StringUtils.capitalize(Constants.get(ODataServiceVersion.V40, ConstantKey.METADATA)),
-            Accept.XML), ODataServiceVersion.V40));
+            readRes("demo" + StringUtils.capitalize(Constants.get(ODataServiceVersion.V40, ConstantKey.METADATA)),
+                    Accept.XML), ODataServiceVersion.V40));
   }
 
   private Response replaceServiceName(final Response response) {
     try {
       final String content = IOUtils.toString((InputStream) response.getEntity(), Constants.ENCODING).
-          replaceAll("Static\\.svc", "Demo.svc");
+              replaceAll("Static\\.svc", "Demo.svc");
 
       final Response.ResponseBuilder builder = Response.status(response.getStatus());
       for (String headerName : response.getHeaders().keySet()) {
@@ -90,84 +91,84 @@ public class V4Demo extends V4Services {
   @Override
   public Response getMetadata() {
     return super.getMetadata(
-        "demo" + StringUtils.capitalize(Constants.get(ODataServiceVersion.V40, ConstantKey.METADATA)));
+            "demo" + StringUtils.capitalize(Constants.get(ODataServiceVersion.V40, ConstantKey.METADATA)));
   }
 
   @GET
   @Path("/{entitySetName}({entityId})")
   @Override
   public Response getEntity(
-      @Context final UriInfo uriInfo,
-      @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
-      @PathParam("entitySetName") final String entitySetName,
-      @PathParam("entityId") final String entityId,
-      @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format,
-      @QueryParam("$expand") @DefaultValue(StringUtils.EMPTY) final String expand,
-      @QueryParam("$select") @DefaultValue(StringUtils.EMPTY) final String select) {
+          @Context final UriInfo uriInfo,
+          @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
+          @PathParam("entitySetName") final String entitySetName,
+          @PathParam("entityId") final String entityId,
+          @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format,
+          @QueryParam("$expand") @DefaultValue(StringUtils.EMPTY) final String expand,
+          @QueryParam("$select") @DefaultValue(StringUtils.EMPTY) final String select) {
 
     return replaceServiceName(super.getEntityInternal(uriInfo.getRequestUri().toASCIIString(),
-        accept, entitySetName, entityId, format, expand, select, false));
+            accept, entitySetName, entityId, format, expand, select, false));
   }
 
   @GET
   @Path("/{entitySetName}({entityId})/$value")
   @Override
   public Response getMediaEntity(
-      @Context final UriInfo uriInfo,
-      @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
-      @PathParam("entitySetName") final String entitySetName,
-      @PathParam("entityId") final String entityId) {
+          @Context final UriInfo uriInfo,
+          @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
+          @PathParam("entitySetName") final String entitySetName,
+          @PathParam("entityId") final String entityId) {
 
     return super.getMediaEntity(uriInfo, accept, entitySetName, entityId);
   }
 
   @POST
   @Path("/{entitySetName}")
-  @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
-  @Consumes({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM })
+  @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
+  @Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM})
   @Override
   public Response postNewEntity(
-      @Context final UriInfo uriInfo,
-      @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
-      @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
-      @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
-      @PathParam("entitySetName") final String entitySetName,
-      final String entity) {
+          @Context final UriInfo uriInfo,
+          @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
+          @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
+          @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
+          @PathParam("entitySetName") final String entitySetName,
+          final String entity) {
 
     return replaceServiceName(super.postNewEntity(uriInfo, accept, contentType, prefer, entitySetName, entity));
   }
 
   @PATCH
   @Path("/{entitySetName}({entityId})")
-  @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
-  @Consumes({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
+  @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
+  @Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
   @Override
   public Response patchEntity(
-      @Context final UriInfo uriInfo,
-      @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
-      @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
-      @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
-      @HeaderParam("If-Match") @DefaultValue(StringUtils.EMPTY) final String ifMatch,
-      @PathParam("entitySetName") final String entitySetName,
-      @PathParam("entityId") final String entityId,
-      final String changes) {
+          @Context final UriInfo uriInfo,
+          @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
+          @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
+          @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
+          @HeaderParam("If-Match") @DefaultValue(StringUtils.EMPTY) final String ifMatch,
+          @PathParam("entitySetName") final String entitySetName,
+          @PathParam("entityId") final String entityId,
+          final String changes) {
 
     return replaceServiceName(super.patchEntity(uriInfo, accept, contentType, prefer, ifMatch, entitySetName, entityId,
-        changes));
+            changes));
   }
 
   @PUT
-  @Produces({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
-  @Consumes({ MediaType.WILDCARD, MediaType.APPLICATION_OCTET_STREAM })
+  @Produces({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
+  @Consumes({MediaType.WILDCARD, MediaType.APPLICATION_OCTET_STREAM})
   @Path("/{entitySetName}({entityId})/$value")
   @Override
   public Response replaceMediaEntity(
-      @Context final UriInfo uriInfo,
-      @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
-      @PathParam("entitySetName") final String entitySetName,
-      @PathParam("entityId") final String entityId,
-      @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format,
-      final String value) {
+          @Context final UriInfo uriInfo,
+          @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
+          @PathParam("entitySetName") final String entitySetName,
+          @PathParam("entityId") final String entityId,
+          @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format,
+          final String value) {
 
     return super.replaceMediaEntity(uriInfo, prefer, entitySetName, entityId, format, value);
   }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c541d925/fit/src/main/java/org/apache/olingo/fit/V4KeyAsSegment.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/V4KeyAsSegment.java b/fit/src/main/java/org/apache/olingo/fit/V4KeyAsSegment.java
index 1474c1f..858bc01 100644
--- a/fit/src/main/java/org/apache/olingo/fit/V4KeyAsSegment.java
+++ b/fit/src/main/java/org/apache/olingo/fit/V4KeyAsSegment.java
@@ -20,6 +20,7 @@ package org.apache.olingo.fit;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.io.InputStream;
 
 import javax.ws.rs.Consumes;
@@ -49,14 +50,14 @@ public class V4KeyAsSegment extends V4Services {
   @Context
   private UriInfo uriInfo;
 
-  public V4KeyAsSegment() throws Exception {
+  public V4KeyAsSegment() throws IOException {
     super();
   }
 
   private Response replaceServiceName(final Response response) {
     try {
       final String content = IOUtils.toString((InputStream) response.getEntity(), Constants.ENCODING).
-          replaceAll("Static\\.svc", "KeyAsSegment.svc");
+              replaceAll("Static\\.svc", "KeyAsSegment.svc");
 
       final Response.ResponseBuilder builder = Response.status(response.getStatus());
       for (String headerName : response.getHeaders().keySet()) {
@@ -82,68 +83,69 @@ public class V4KeyAsSegment extends V4Services {
   @Override
   public Response getEntitySet(final String accept, final String name, final String type) {
     return replaceServiceName(super.getEntityInternal(uriInfo.getRequestUri().toASCIIString(),
-        accept, name, type, null, null, null, true));
+            accept, name, type, null, null, null, true));
   }
 
   @DELETE
   @Path("/{entitySetName}/{entityId}")
   @Override
   public Response removeEntity(
-      @PathParam("entitySetName") final String entitySetName,
-      @PathParam("entityId") final String entityId) {
+          @PathParam("entitySetName") final String entitySetName,
+          @PathParam("entityId") final String entityId) {
 
     return replaceServiceName(super.removeEntity(entitySetName, entityId));
   }
 
   @PATCH
   @Path("/{entitySetName}/{entityId}")
-  @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
-  @Consumes({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
+  @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
+  @Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
   @Override
   public Response patchEntity(
-      @Context final UriInfo uriInfo,
-      @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
-      @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
-      @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
-      @HeaderParam("If-Match") @DefaultValue(StringUtils.EMPTY) final String ifMatch,
-      @PathParam("entitySetName") final String entitySetName,
-      @PathParam("entityId") final String entityId,
-      final String changes) {
-
-    return replaceServiceName(super.patchEntity(uriInfo, accept, contentType, prefer, ifMatch, entitySetName, entityId,
-        changes));
+          @Context final UriInfo uriInfo,
+          @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
+          @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
+          @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
+          @HeaderParam("If-Match") @DefaultValue(StringUtils.EMPTY) final String ifMatch,
+          @PathParam("entitySetName") final String entitySetName,
+          @PathParam("entityId") final String entityId,
+          final String changes) {
+
+    return replaceServiceName(
+            super.patchEntity(uriInfo, accept, contentType, prefer, ifMatch, entitySetName, entityId, changes));
   }
 
   @PUT
   @Path("/{entitySetName}/{entityId}")
-  @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
-  @Consumes({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
+  @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
+  @Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
   public Response putNewEntity(
-      @Context final UriInfo uriInfo,
-      @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
-      @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
-      @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
-      @PathParam("entitySetName") final String entitySetName,
-      @PathParam("entityId") final String entityId,
-      final String entity) {
-
-    return replaceServiceName(super
-        .replaceEntity(uriInfo, accept, contentType, prefer, entitySetName, entityId, entity));
+          @Context final UriInfo uriInfo,
+          @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
+          @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
+          @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
+          @PathParam("entitySetName") final String entitySetName,
+          @PathParam("entityId") final String entityId,
+          final String entity) {
+
+    return replaceServiceName(
+            super.replaceEntity(uriInfo, accept, contentType, prefer, entitySetName, entityId, entity));
   }
 
   @POST
   @Path("/{entitySetName}")
-  @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
-  @Consumes({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM })
+  @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
+  @Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM})
   @Override
   public Response postNewEntity(
-      @Context final UriInfo uriInfo,
-      @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
-      @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
-      @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
-      @PathParam("entitySetName") final String entitySetName,
-      final String entity) {
-
-    return replaceServiceName(super.postNewEntity(uriInfo, accept, contentType, prefer, entitySetName, entity));
+          @Context final UriInfo uriInfo,
+          @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
+          @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
+          @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
+          @PathParam("entitySetName") final String entitySetName,
+          final String entity) {
+
+    return replaceServiceName(
+            super.postNewEntity(uriInfo, accept, contentType, prefer, entitySetName, entity));
   }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c541d925/fit/src/main/java/org/apache/olingo/fit/V4NorthWind.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/V4NorthWind.java b/fit/src/main/java/org/apache/olingo/fit/V4NorthWind.java
index 1fc5eab..2a922c5 100644
--- a/fit/src/main/java/org/apache/olingo/fit/V4NorthWind.java
+++ b/fit/src/main/java/org/apache/olingo/fit/V4NorthWind.java
@@ -18,13 +18,14 @@
  */
 package org.apache.olingo.fit;
 
+import java.io.IOException;
 import javax.ws.rs.Path;
 import javax.ws.rs.core.Response;
 
 import org.apache.cxf.interceptor.InInterceptors;
 import org.apache.olingo.fit.utils.ConstantKey;
 import org.apache.olingo.fit.utils.Constants;
-import org.apache.olingo.fit.utils.XHTTPMethodInterceptor;
+import org.apache.olingo.fit.rest.XHTTPMethodInterceptor;
 import org.springframework.stereotype.Service;
 
 @Service
@@ -32,7 +33,7 @@ import org.springframework.stereotype.Service;
 @InInterceptors(classes = XHTTPMethodInterceptor.class)
 public class V4NorthWind extends V4Services {
 
-  public V4NorthWind() throws Exception {
+  public V4NorthWind() throws IOException {
     super();
   }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c541d925/fit/src/main/java/org/apache/olingo/fit/V4NorthWindExt.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/V4NorthWindExt.java b/fit/src/main/java/org/apache/olingo/fit/V4NorthWindExt.java
index 7daddf8..92c9b8e 100644
--- a/fit/src/main/java/org/apache/olingo/fit/V4NorthWindExt.java
+++ b/fit/src/main/java/org/apache/olingo/fit/V4NorthWindExt.java
@@ -18,22 +18,23 @@
  */
 package org.apache.olingo.fit;
 
+import java.io.IOException;
 import javax.ws.rs.Path;
 import javax.ws.rs.core.Response;
 
 import org.apache.cxf.interceptor.InInterceptors;
 import org.apache.olingo.fit.utils.ConstantKey;
 import org.apache.olingo.fit.utils.Constants;
-import org.apache.olingo.fit.utils.ResolvingReferencesInterceptor;
-import org.apache.olingo.fit.utils.XHTTPMethodInterceptor;
+import org.apache.olingo.fit.rest.ResolvingReferencesInterceptor;
+import org.apache.olingo.fit.rest.XHTTPMethodInterceptor;
 import org.springframework.stereotype.Service;
 
 @Service
 @Path("/V40/NorthWindExt.svc")
-@InInterceptors(classes = { XHTTPMethodInterceptor.class, ResolvingReferencesInterceptor.class })
+@InInterceptors(classes = {XHTTPMethodInterceptor.class, ResolvingReferencesInterceptor.class})
 public class V4NorthWindExt extends V4Services {
 
-  public V4NorthWindExt() throws Exception {
+  public V4NorthWindExt() throws IOException {
     super();
   }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c541d925/fit/src/main/java/org/apache/olingo/fit/V4OAuth2.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/V4OAuth2.java b/fit/src/main/java/org/apache/olingo/fit/V4OAuth2.java
new file mode 100644
index 0000000..b43b034
--- /dev/null
+++ b/fit/src/main/java/org/apache/olingo/fit/V4OAuth2.java
@@ -0,0 +1,37 @@
+/*
+ * 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;
+
+import java.io.IOException;
+
+import javax.ws.rs.Path;
+import org.apache.cxf.interceptor.InInterceptors;
+import org.apache.olingo.fit.rest.OAuth2InInterceptor;
+import org.springframework.stereotype.Service;
+
+@Service
+@Path("/V40/OAuth2.svc")
+@InInterceptors(classes = {OAuth2InInterceptor.class})
+public class V4OAuth2 extends V4Services {
+
+  public V4OAuth2() throws IOException {
+    super();
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c541d925/fit/src/main/java/org/apache/olingo/fit/V4OpenType.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/V4OpenType.java b/fit/src/main/java/org/apache/olingo/fit/V4OpenType.java
index aac908a..b19916b 100644
--- a/fit/src/main/java/org/apache/olingo/fit/V4OpenType.java
+++ b/fit/src/main/java/org/apache/olingo/fit/V4OpenType.java
@@ -20,6 +20,7 @@ package org.apache.olingo.fit;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.io.InputStream;
 
 import javax.ws.rs.Consumes;
@@ -51,16 +52,16 @@ import org.springframework.stereotype.Service;
 @Path("/V40/OpenType.svc")
 public class V4OpenType extends V4Services {
 
-  public V4OpenType() throws Exception {
+  public V4OpenType() throws IOException {
     super(new Metadata(FSManager.instance(ODataServiceVersion.V40).
-        readRes("openType" + StringUtils.capitalize(Constants.get(ODataServiceVersion.V40, ConstantKey.METADATA)),
-            Accept.XML), ODataServiceVersion.V40));
+            readRes("openType" + StringUtils.capitalize(Constants.get(ODataServiceVersion.V40, ConstantKey.METADATA)),
+                    Accept.XML), ODataServiceVersion.V40));
   }
 
   private Response replaceServiceName(final Response response) {
     try {
       final String content = IOUtils.toString((InputStream) response.getEntity(), Constants.ENCODING).
-          replaceAll("Static\\.svc", "OpenType.svc");
+              replaceAll("Static\\.svc", "OpenType.svc");
 
       final Response.ResponseBuilder builder = Response.status(response.getStatus());
       for (String headerName : response.getHeaders().keySet()) {
@@ -85,7 +86,7 @@ public class V4OpenType extends V4Services {
 
   /**
    * Provide sample large metadata.
-   * 
+   *
    * @return metadata.
    */
   @GET
@@ -94,37 +95,37 @@ public class V4OpenType extends V4Services {
   @Override
   public Response getMetadata() {
     return super.getMetadata("openType" + StringUtils.capitalize(
-        Constants.get(ODataServiceVersion.V40, ConstantKey.METADATA)));
+            Constants.get(ODataServiceVersion.V40, ConstantKey.METADATA)));
   }
 
   @GET
   @Path("/{entitySetName}({entityId})")
   @Override
   public Response getEntity(
-      @Context final UriInfo uriInfo,
-      @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
-      @PathParam("entitySetName") final String entitySetName,
-      @PathParam("entityId") final String entityId,
-      @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format,
-      @QueryParam("$expand") @DefaultValue(StringUtils.EMPTY) final String expand,
-      @QueryParam("$select") @DefaultValue(StringUtils.EMPTY) final String select) {
+          @Context final UriInfo uriInfo,
+          @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
+          @PathParam("entitySetName") final String entitySetName,
+          @PathParam("entityId") final String entityId,
+          @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format,
+          @QueryParam("$expand") @DefaultValue(StringUtils.EMPTY) final String expand,
+          @QueryParam("$select") @DefaultValue(StringUtils.EMPTY) final String select) {
 
     return replaceServiceName(super.getEntityInternal(
-        uriInfo.getRequestUri().toASCIIString(), accept, entitySetName, entityId, format, expand, select, false));
+            uriInfo.getRequestUri().toASCIIString(), accept, entitySetName, entityId, format, expand, select, false));
   }
 
   @POST
   @Path("/{entitySetName}")
-  @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
-  @Consumes({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM })
+  @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
+  @Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM})
   @Override
   public Response postNewEntity(
-      @Context final UriInfo uriInfo,
-      @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
-      @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
-      @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
-      @PathParam("entitySetName") final String entitySetName,
-      final String entity) {
+          @Context final UriInfo uriInfo,
+          @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
+          @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
+          @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
+          @PathParam("entitySetName") final String entitySetName,
+          final String entity) {
 
     return replaceServiceName(super.postNewEntity(uriInfo, accept, contentType, prefer, entitySetName, entity));
   }
@@ -133,8 +134,8 @@ public class V4OpenType extends V4Services {
   @Path("/{entitySetName}({entityId})")
   @Override
   public Response removeEntity(
-      @PathParam("entitySetName") final String entitySetName,
-      @PathParam("entityId") final String entityId) {
+          @PathParam("entitySetName") final String entitySetName,
+          @PathParam("entityId") final String entityId) {
 
     return replaceServiceName(super.removeEntity(entitySetName, entityId));
   }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c541d925/fit/src/main/java/org/apache/olingo/fit/V4Services.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/V4Services.java b/fit/src/main/java/org/apache/olingo/fit/V4Services.java
index 978bf5a..5e32230 100644
--- a/fit/src/main/java/org/apache/olingo/fit/V4Services.java
+++ b/fit/src/main/java/org/apache/olingo/fit/V4Services.java
@@ -81,8 +81,8 @@ import org.apache.olingo.fit.utils.ConstantKey;
 import org.apache.olingo.fit.utils.Constants;
 import org.apache.olingo.fit.utils.FSManager;
 import org.apache.olingo.fit.utils.LinkInfo;
-import org.apache.olingo.fit.utils.ResolvingReferencesInterceptor;
-import org.apache.olingo.fit.utils.XHTTPMethodInterceptor;
+import org.apache.olingo.fit.rest.ResolvingReferencesInterceptor;
+import org.apache.olingo.fit.rest.XHTTPMethodInterceptor;
 import org.springframework.stereotype.Service;
 
 @Service
@@ -102,11 +102,11 @@ public class V4Services extends AbstractServices {
 
   private final Map<String, String> providedAsync = new HashMap<String, String>();
 
-  public V4Services() throws Exception {
+  public V4Services() throws IOException {
     super(ODataServiceVersion.V40, Commons.getMetadata(ODataServiceVersion.V40));
   }
 
-  protected V4Services(final Metadata metadata) throws Exception {
+  protected V4Services(final Metadata metadata) throws IOException {
     super(ODataServiceVersion.V40, metadata);
   }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c541d925/fit/src/main/java/org/apache/olingo/fit/V4Vocabularies.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/V4Vocabularies.java b/fit/src/main/java/org/apache/olingo/fit/V4Vocabularies.java
index cf20fba..0691b27 100644
--- a/fit/src/main/java/org/apache/olingo/fit/V4Vocabularies.java
+++ b/fit/src/main/java/org/apache/olingo/fit/V4Vocabularies.java
@@ -18,6 +18,7 @@
  */
 package org.apache.olingo.fit;
 
+import java.io.IOException;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
@@ -42,10 +43,10 @@ public class V4Vocabularies {
 
   private final XMLUtilities xml;
 
-  public V4Vocabularies() throws Exception {
+  public V4Vocabularies() throws IOException {
     metadata = new Metadata(FSManager.instance(ODataServiceVersion.V40).readRes(
-        "vocabularies-" + Constants.get(ODataServiceVersion.V40, ConstantKey.METADATA), Accept.XML),
-        ODataServiceVersion.V40);
+            "vocabularies-" + Constants.get(ODataServiceVersion.V40, ConstantKey.METADATA), Accept.XML),
+            ODataServiceVersion.V40);
     xml = new XMLUtilities(ODataServiceVersion.V40, metadata);
   }
 
@@ -55,11 +56,11 @@ public class V4Vocabularies {
   public Response getMetadata() {
     try {
       return xml.createResponse(
-          null,
-          FSManager.instance(ODataServiceVersion.V40).readRes(
-              "vocabularies-" + Constants.get(ODataServiceVersion.V40, ConstantKey.METADATA), Accept.XML),
-          null,
-          Accept.XML);
+              null,
+              FSManager.instance(ODataServiceVersion.V40).readRes(
+                      "vocabularies-" + Constants.get(ODataServiceVersion.V40, ConstantKey.METADATA), Accept.XML),
+              null,
+              Accept.XML);
     } catch (Exception e) {
       return xml.createFaultResponse(Accept.XML.toString(ODataServiceVersion.V40), e);
     }
@@ -71,10 +72,10 @@ public class V4Vocabularies {
   public Response getVocabulary(@PathParam("vocabulary") final String vocabulary) {
     try {
       return xml.createResponse(
-          null,
-          FSManager.instance(ODataServiceVersion.V40).readFile(vocabulary, null),
-          null,
-          Accept.XML);
+              null,
+              FSManager.instance(ODataServiceVersion.V40).readFile(vocabulary, null),
+              null,
+              Accept.XML);
     } catch (Exception e) {
       return xml.createFaultResponse(Accept.XML.toString(ODataServiceVersion.V40), e);
     }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c541d925/fit/src/main/java/org/apache/olingo/fit/rest/OAuth2InInterceptor.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/rest/OAuth2InInterceptor.java b/fit/src/main/java/org/apache/olingo/fit/rest/OAuth2InInterceptor.java
new file mode 100644
index 0000000..bddc642
--- /dev/null
+++ b/fit/src/main/java/org/apache/olingo/fit/rest/OAuth2InInterceptor.java
@@ -0,0 +1,97 @@
+/*
+ * 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.rest;
+
+import java.net.URI;
+import java.util.List;
+import java.util.Map;
+import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.rs.security.oauth2.client.OAuthClientUtils;
+import org.apache.cxf.rs.security.oauth2.common.ClientAccessToken;
+import org.apache.cxf.rs.security.oauth2.grants.code.AuthorizationCodeGrant;
+import org.apache.cxf.rs.security.oauth2.provider.OAuthServiceException;
+import org.apache.cxf.transport.http.AbstractHTTPDestination;
+
+public class OAuth2InInterceptor extends AbstractPhaseInterceptor<Message> {
+
+  private static final OAuthClientUtils.Consumer OAUTH2_CONSUMER =
+          new OAuthClientUtils.Consumer(OAuth2Provider.CLIENT_ID, OAuth2Provider.CLIENT_SECRET);
+
+  public OAuth2InInterceptor() {
+    super(Phase.PRE_INVOKE);
+  }
+
+  @Override
+  public void handleMessage(final Message message) throws Fault {
+    final String requestURL = (String) message.get(Message.REQUEST_URL);
+    if (requestURL.contains("V40/OAuth2.svc")) {
+      @SuppressWarnings("unchecked")
+      final Map<String, List<String>> headers = (Map<String, List<String>>) message.get(Message.PROTOCOL_HEADERS);
+      final List<String> oauth2CodeHeader = headers.get(OAuth2Provider.OAUTH2_CODE_HEADER);
+      if (oauth2CodeHeader == null || oauth2CodeHeader.isEmpty()) {
+        message.put(AbstractHTTPDestination.REQUEST_REDIRECTED, Boolean.TRUE);
+
+        final HttpServletResponse response = (HttpServletResponse) message.get(AbstractHTTPDestination.HTTP_RESPONSE);
+        try {
+          final String authorizationServiceURI =
+                  StringUtils.substringBefore(requestURL, "V40/OAuth2.svc") + "oauth/authorize";
+
+          final URI authorizationURI = OAuthClientUtils.getAuthorizationURI(
+                  authorizationServiceURI,
+                  OAuth2Provider.CLIENT_ID,
+                  OAuth2Provider.REDIRECT_URI,
+                  null,
+                  null);
+          response.addHeader("Location", authorizationURI.toASCIIString());
+          response.sendError(303);
+        } catch (Exception e) {
+          throw new Fault(e);
+        }
+      } else {
+        try {
+          final JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
+          bean.setAddress(StringUtils.substringBefore(requestURL, "V40/OAuth2.svc") + "oauth/token");
+          bean.setUsername("odatajclient");
+          bean.setPassword("odatajclient");
+          final WebClient accessTokenService = bean.createWebClient().
+                  type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).
+                  accept(MediaType.APPLICATION_JSON_TYPE);
+
+          final AuthorizationCodeGrant codeGrant = new AuthorizationCodeGrant(oauth2CodeHeader.get(0));
+          final ClientAccessToken accessToken =
+                  OAuthClientUtils.getAccessToken(accessTokenService, OAUTH2_CONSUMER, codeGrant);
+          if (accessToken == null) {
+            throw new WebApplicationException("No OAuth2 access token");
+          }
+        } catch (OAuthServiceException e) {
+          throw new Fault(e);
+        }
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c541d925/fit/src/main/java/org/apache/olingo/fit/rest/OAuth2Provider.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/rest/OAuth2Provider.java b/fit/src/main/java/org/apache/olingo/fit/rest/OAuth2Provider.java
new file mode 100644
index 0000000..bd35515
--- /dev/null
+++ b/fit/src/main/java/org/apache/olingo/fit/rest/OAuth2Provider.java
@@ -0,0 +1,133 @@
+/*
+ * 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.rest;
+
+import java.util.Collections;
+import java.util.List;
+import org.apache.cxf.rs.security.oauth2.common.AccessTokenRegistration;
+import org.apache.cxf.rs.security.oauth2.common.Client;
+import org.apache.cxf.rs.security.oauth2.common.OAuthPermission;
+import org.apache.cxf.rs.security.oauth2.common.ServerAccessToken;
+import org.apache.cxf.rs.security.oauth2.common.UserSubject;
+import org.apache.cxf.rs.security.oauth2.grants.code.AuthorizationCodeDataProvider;
+import org.apache.cxf.rs.security.oauth2.grants.code.AuthorizationCodeRegistration;
+import org.apache.cxf.rs.security.oauth2.grants.code.ServerAuthorizationCodeGrant;
+import org.apache.cxf.rs.security.oauth2.provider.OAuthServiceException;
+import org.apache.cxf.rs.security.oauth2.tokens.bearer.BearerAccessToken;
+
+public class OAuth2Provider implements AuthorizationCodeDataProvider {
+
+  public static final String CLIENT_ID = "odataOAuth2SVC";
+
+  public static final String CLIENT_SECRET = "1234567890";
+
+  public static final String REDIRECT_URI = "/stub/StaticService/V40/OAuth2.svc/";
+
+  public static final String OAUTH2_CODE_HEADER = "oauth2.token";
+
+  private Client client;
+
+  private ServerAuthorizationCodeGrant grant;
+
+  private ServerAccessToken token;
+
+  @Override
+  public Client getClient(final String string) throws OAuthServiceException {
+    if (client == null) {
+      client = new Client(CLIENT_ID, CLIENT_SECRET, true);
+      client.getRedirectUris().add(REDIRECT_URI);
+    }
+    return client;
+  }
+
+  @Override
+  public ServerAccessToken getPreauthorizedToken(
+          final Client client, final List<String> list, final UserSubject us, final String string)
+          throws OAuthServiceException {
+
+    return null;
+  }
+
+  @Override
+  public List<OAuthPermission> convertScopeToPermissions(final Client client, final List<String> list) {
+    return Collections.singletonList(new OAuthPermission());
+  }
+
+  @Override
+  public ServerAuthorizationCodeGrant createCodeGrant(final AuthorizationCodeRegistration acr)
+          throws OAuthServiceException {
+
+    grant = new ServerAuthorizationCodeGrant(client, 3600L);
+    grant.setRedirectUri(acr.getRedirectUri());
+    grant.setSubject(acr.getSubject());
+    final List<String> scope = acr.getApprovedScope().isEmpty()
+            ? acr.getRequestedScope()
+            : acr.getApprovedScope();
+    grant.setApprovedScopes(scope);
+
+    return grant;
+  }
+
+  @Override
+  public ServerAuthorizationCodeGrant removeCodeGrant(final String code) throws OAuthServiceException {
+    return grant == null || !grant.getCode().equals(code)
+            ? null
+            : grant;
+  }
+
+  @Override
+  public ServerAccessToken createAccessToken(final AccessTokenRegistration atr) throws OAuthServiceException {
+    token = new BearerAccessToken(atr.getClient(), 3600L);
+
+    final List<String> scope = atr.getApprovedScope().isEmpty()
+            ? atr.getRequestedScope()
+            : atr.getApprovedScope();
+    token.setScopes(convertScopeToPermissions(atr.getClient(), scope));
+    token.setSubject(atr.getSubject());
+    token.setGrantType(atr.getGrantType());
+
+    return token;
+  }
+
+  @Override
+  public ServerAccessToken getAccessToken(final String tokenId) throws OAuthServiceException {
+    return token == null || token.getTokenKey().equals(tokenId) ? token : null;
+  }
+
+  @Override
+  public ServerAccessToken refreshAccessToken(
+          final Client client, final String string, final List<String> list)
+          throws OAuthServiceException {
+
+    throw new UnsupportedOperationException("Not supported yet.");
+  }
+
+  @Override
+  public void removeAccessToken(final ServerAccessToken sat) throws OAuthServiceException {
+    if (token != null && token.getTokenKey().equals(sat.getTokenKey())) {
+      token = null;
+    }
+  }
+
+  @Override
+  public void revokeToken(final Client client, final String string, final String string1) throws OAuthServiceException {
+    throw new UnsupportedOperationException("Not supported yet.");
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c541d925/fit/src/main/java/org/apache/olingo/fit/rest/ResolvingReferencesInterceptor.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/rest/ResolvingReferencesInterceptor.java b/fit/src/main/java/org/apache/olingo/fit/rest/ResolvingReferencesInterceptor.java
new file mode 100644
index 0000000..b4cecbe
--- /dev/null
+++ b/fit/src/main/java/org/apache/olingo/fit/rest/ResolvingReferencesInterceptor.java
@@ -0,0 +1,59 @@
+/*
+ * 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.rest;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URLDecoder;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+
+public class ResolvingReferencesInterceptor extends AbstractPhaseInterceptor<Message> {
+
+  public ResolvingReferencesInterceptor() {
+    super(Phase.PRE_PROTOCOL);
+  }
+
+  @Override
+  public void handleMessage(final Message message) throws Fault {
+    final String path = (String) message.get(Message.PATH_INFO);
+    final String query = (String) message.get(Message.QUERY_STRING);
+
+    try {
+      if (path.endsWith("$entity") && StringUtils.isNotBlank(query)
+              && URLDecoder.decode(query, "UTF-8").contains("$id=")) {
+
+        final String id = URLDecoder.decode(query, "UTF-8");
+        final String newURL = id.substring(id.indexOf("$id=") + 4);
+
+        final URI uri = URI.create(newURL);
+
+        message.put(Message.REQUEST_URL, uri.toASCIIString());
+        message.put(Message.REQUEST_URI, uri.getPath());
+        message.put(Message.PATH_INFO, uri.getPath());
+      }
+    } catch (UnsupportedEncodingException ignore) {
+      // ignore
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c541d925/fit/src/main/java/org/apache/olingo/fit/rest/ServiceNameResponseFilter.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/rest/ServiceNameResponseFilter.java b/fit/src/main/java/org/apache/olingo/fit/rest/ServiceNameResponseFilter.java
new file mode 100644
index 0000000..70b9c3e
--- /dev/null
+++ b/fit/src/main/java/org/apache/olingo/fit/rest/ServiceNameResponseFilter.java
@@ -0,0 +1,55 @@
+/*
+ * 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.rest;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerResponseContext;
+import javax.ws.rs.container.ContainerResponseFilter;
+import javax.ws.rs.ext.Provider;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.olingo.fit.utils.Constants;
+
+@Provider
+public class ServiceNameResponseFilter implements ContainerResponseFilter {
+
+  @Override
+  public void filter(final ContainerRequestContext requestContext, final ContainerResponseContext responseContext)
+          throws IOException {
+
+    final String svcName =
+            StringUtils.substringBefore(StringUtils.substringAfter(requestContext.getUriInfo().getPath(), "/"), "/");
+
+    if ("OAuth2.svc".equals(svcName) && responseContext.getEntity() != null) {
+      final String content = IOUtils.toString((InputStream) responseContext.getEntity(), Constants.ENCODING).
+              replaceAll("Static\\.svc", svcName);
+
+      final InputStream toBeStreamedBack = IOUtils.toInputStream(content, Constants.ENCODING);
+      final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+      IOUtils.copy(toBeStreamedBack, baos);
+      IOUtils.closeQuietly(toBeStreamedBack);
+
+      responseContext.setEntity(new ByteArrayInputStream(baos.toByteArray()));
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c541d925/fit/src/main/java/org/apache/olingo/fit/rest/StaticSecurityInterceptor.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/rest/StaticSecurityInterceptor.java b/fit/src/main/java/org/apache/olingo/fit/rest/StaticSecurityInterceptor.java
new file mode 100644
index 0000000..1959cc2
--- /dev/null
+++ b/fit/src/main/java/org/apache/olingo/fit/rest/StaticSecurityInterceptor.java
@@ -0,0 +1,85 @@
+/*
+ * 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.rest;
+
+import java.security.Principal;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+import org.apache.cxf.common.security.SimplePrincipal;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.security.SecurityContext;
+import org.apache.geronimo.mail.util.Base64;
+
+public class StaticSecurityInterceptor extends AbstractPhaseInterceptor<Message> {
+
+  private static final String AUTHORIZATION_PROPERTY = "Authorization";
+
+  private static final String AUTHENTICATION_SCHEME = "Basic";
+
+  public StaticSecurityInterceptor() {
+    super(Phase.PRE_PROTOCOL);
+  }
+
+  @Override
+  public void handleMessage(final Message message) throws Fault {
+    final SecurityContext sc = message.get(SecurityContext.class);
+    if (sc == null || sc.getUserPrincipal() == null) {
+      @SuppressWarnings("unchecked")
+      final Map<String, List<String>> headers = (Map<String, List<String>>) message.get(Message.PROTOCOL_HEADERS);
+
+      final List<String> auth = headers.get(AUTHORIZATION_PROPERTY);
+      if (auth == null || auth.isEmpty()) {
+        throw new WebApplicationException(Response.Status.UNAUTHORIZED);
+      }
+
+      final String encodedUserPassword = auth.get(0).replaceFirst(AUTHENTICATION_SCHEME + " ", "");
+      final String usernameAndPassword = new String(Base64.decode(encodedUserPassword));
+
+      //Split username and password tokens
+      final StringTokenizer tokenizer = new StringTokenizer(usernameAndPassword, ":");
+      final String username = tokenizer.nextToken();
+      final String password = tokenizer.nextToken();
+
+      if (!"odatajclient".equals(username) || !"odatajclient".equals(password)) {
+        throw new WebApplicationException(Response.Status.UNAUTHORIZED);
+      }
+
+      final SecurityContext newSc = new SecurityContext() {
+
+        @Override
+        public Principal getUserPrincipal() {
+          return new SimplePrincipal("odatajclient");
+        }
+
+        @Override
+        public boolean isUserInRole(final String role) {
+          return false;
+        }
+      };
+      message.put(SecurityContext.class, newSc);
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c541d925/fit/src/main/java/org/apache/olingo/fit/rest/XHTTPMethodInterceptor.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/rest/XHTTPMethodInterceptor.java b/fit/src/main/java/org/apache/olingo/fit/rest/XHTTPMethodInterceptor.java
new file mode 100644
index 0000000..cacb0ea
--- /dev/null
+++ b/fit/src/main/java/org/apache/olingo/fit/rest/XHTTPMethodInterceptor.java
@@ -0,0 +1,47 @@
+/*
+ * 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.rest;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+import org.apache.olingo.fit.utils.ConstantKey;
+import org.apache.olingo.fit.utils.Constants;
+
+public class XHTTPMethodInterceptor extends AbstractPhaseInterceptor<Message> {
+
+  public XHTTPMethodInterceptor() {
+    super(Phase.PRE_PROTOCOL);
+  }
+
+  @Override
+  public void handleMessage(final Message message) throws Fault {
+    @SuppressWarnings("unchecked")
+    final Map<String, List<String>> headers = (Map<String, List<String>>) message.get(Message.PROTOCOL_HEADERS);
+
+    if (headers.containsKey(Constants.get(ConstantKey.XHTTP_HEADER_NAME))) {
+      message.put(Message.HTTP_REQUEST_METHOD,
+              headers.get(Constants.get(ConstantKey.XHTTP_HEADER_NAME)).iterator().next());
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c541d925/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java b/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java
index 55d6733..baf2fac 100644
--- a/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java
+++ b/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java
@@ -94,7 +94,7 @@ public abstract class AbstractUtilities {
   protected final ODataSerializer atomSerializer;
   protected final ODataSerializer jsonSerializer;
 
-  public AbstractUtilities(final ODataServiceVersion version, final Metadata metadata) throws Exception {
+  public AbstractUtilities(final ODataServiceVersion version, final Metadata metadata) throws IOException {
     this.version = version;
     this.metadata = metadata;
     fsManager = FSManager.instance(version);