olingo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject [1/2] olingo-odata2 git commit: [OLINGO-193] Reuse as much code as possible in the spring extension (Extend the core ODataRootLocator and override the setters)
Date Wed, 07 Jan 2015 14:02:08 GMT
Repository: olingo-odata2
Updated Branches:
  refs/heads/OLINGO-193_SpringSupport 7a596e207 -> 92531140b


[OLINGO-193] Reuse as much code as possible in the spring extension (Extend the core ODataRootLocator
and override the setters)

Signed-off-by: Michael Bolz <michael.bolz@sap.com>


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

Branch: refs/heads/OLINGO-193_SpringSupport
Commit: 5b632779b992c151478d8333c19489740c8255b9
Parents: 7a596e2
Author: Lior Okman <lior.okman@gmail.com>
Authored: Wed Dec 24 20:43:44 2014 +0200
Committer: Michael Bolz <michael.bolz@sap.com>
Committed: Wed Jan 7 14:52:24 2015 +0100

----------------------------------------------------------------------
 .../odata2/core/rest/ODataRootLocator.java      | 21 +++++--
 .../olingo/odata2/spring/OlingoRootLocator.java | 64 ++------------------
 2 files changed, 19 insertions(+), 66 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/5b632779/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/rest/ODataRootLocator.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/rest/ODataRootLocator.java
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/rest/ODataRootLocator.java
index 3ff5984..e75ef5d 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/rest/ODataRootLocator.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/rest/ODataRootLocator.java
@@ -102,13 +102,9 @@ public class ODataRootLocator {
       return handleRedirect();
     }
 
-    ODataServiceFactory serviceFactory = createServiceFactoryFromContext(app, servletRequest,
servletConfig);
+    ODataServiceFactory serviceFactory = getServiceFactory();
 
-    int pathSplit = 0;
-    final String pathSplitAsString = servletConfig.getInitParameter(ODataServiceFactory.PATH_SPLIT_LABEL);
-    if (pathSplitAsString != null) {
-      pathSplit = Integer.parseInt(pathSplitAsString);
-    }
+    int pathSplit = getPathSplit();
 
     final SubLocatorParameter param = new SubLocatorParameter();
     param.setServiceFactory(serviceFactory);
@@ -122,6 +118,19 @@ public class ODataRootLocator {
     return ODataSubLocator.create(param);
   }
 
+  public ODataServiceFactory getServiceFactory() {
+    return createServiceFactoryFromContext(app, servletRequest, servletConfig);
+  }
+
+  public int getPathSplit() {
+    int pathSplit = 0;
+    final String pathSplitAsString = servletConfig.getInitParameter(ODataServiceFactory.PATH_SPLIT_LABEL);
+    if (pathSplitAsString != null) {
+      pathSplit = Integer.parseInt(pathSplitAsString);
+    }
+    return pathSplit;
+  }
+
   public static ODataServiceFactory createServiceFactoryFromContext(final Application app,
       final HttpServletRequest servletRequest,
       final ServletConfig servletConfig) {

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/5b632779/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoRootLocator.java
----------------------------------------------------------------------
diff --git a/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoRootLocator.java
b/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoRootLocator.java
index bf60cb6..4cfceea 100644
--- a/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoRootLocator.java
+++ b/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoRootLocator.java
@@ -24,6 +24,7 @@ import org.apache.olingo.odata2.api.exception.ODataException;
 import org.apache.olingo.odata2.core.rest.ODataRedirectLocator;
 import org.apache.olingo.odata2.core.rest.ODataSubLocator;
 import org.apache.olingo.odata2.core.rest.SubLocatorParameter;
+import org.apache.olingo.odata2.core.rest.ODataRootLocator;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.Encoded;
@@ -51,71 +52,13 @@ import java.util.List;
  *
  */
 @Path("/")
-public class OlingoRootLocator {
-
-  @Context
-  private HttpHeaders httpHeaders;
-  @Context
-  private UriInfo uriInfo;
-  @Context
-  private Request request;
-  @Context
-  private HttpServletRequest servletRequest;
+public class OlingoRootLocator extends ODataRootLocator {
 
   // These next two members are exposed so that they can be injected with Spring
   private ODataServiceFactory serviceFactory;
   private int pathSplit = 0;
 
-  /**
-   * Default root behavior which will delegate all paths to a ODataLocator.
-   * @param pathSegments URI path segments - all segments have to be OData
-   * @param xHttpMethod HTTP Header X-HTTP-Method for tunneling through POST
-   * @param xHttpMethodOverride HTTP Header X-HTTP-Method-Override for tunneling through
POST
-   * @return a locator handling OData protocol
-   * @throws org.apache.olingo.odata2.api.exception.ODataException
-   * @throws ClassNotFoundException
-   * @throws IllegalAccessException
-   * @throws InstantiationException
-   */
-  @Path("/{pathSegments: .*}")
-  public Object handleRequest(
-      @Encoded @PathParam("pathSegments") final List<PathSegment> pathSegments,
-      @HeaderParam("X-HTTP-Method") final String xHttpMethod,
-      @HeaderParam("X-HTTP-Method-Override") final String xHttpMethodOverride)
-      throws ODataException, ClassNotFoundException, InstantiationException, IllegalAccessException
{
-
-    if (xHttpMethod != null && xHttpMethodOverride != null) {
-
-      /*
-       * X-HTTP-Method-Override : implemented by CXF
-       * X-HTTP-Method : implemented in ODataSubLocator:handlePost
-       */
-
-      if (!xHttpMethod.equalsIgnoreCase(xHttpMethodOverride)) {
-        throw new ODataBadRequestException(ODataBadRequestException.AMBIGUOUS_XMETHOD);
-      }
-    }
-
-    if (servletRequest.getPathInfo() == null) {
-      return handleRedirect();
-    }
-
-    final SubLocatorParameter param = new SubLocatorParameter();
-    param.setServiceFactory(getServiceFactory());
-    param.setPathSegments(pathSegments);
-    param.setHttpHeaders(httpHeaders);
-    param.setUriInfo(uriInfo);
-    param.setRequest(request);
-    param.setServletRequest(servletRequest);
-    param.setPathSplit(getPathSplit());
-
-    return ODataSubLocator.create(param);
-  }
-
-  private Object handleRedirect() {
-    return new ODataRedirectLocator();
-  }
-
+  @Override
   public ODataServiceFactory getServiceFactory() {
     return serviceFactory;
   }
@@ -124,6 +67,7 @@ public class OlingoRootLocator {
     this.serviceFactory = serviceFactory;
   }
 
+  @Override
   public int getPathSplit() {
     return pathSplit;
   }


Mime
View raw message