olingo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sklev...@apache.org
Subject [10/19] git commit: [OLINGO-260] provided authenticated entity creation on proxy
Date Thu, 22 May 2014 10:35:53 GMT
[OLINGO-260] provided authenticated entity creation on proxy


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

Branch: refs/heads/olingo-266-tecsvc
Commit: 377ddb95985273369cc191b76ccf4fe1229b6115
Parents: 84203da
Author: fmartelli <fabio.martelli@gmail.com>
Authored: Wed May 21 11:59:53 2014 +0200
Committer: fmartelli <fabio.martelli@gmail.com>
Committed: Wed May 21 11:59:53 2014 +0200

----------------------------------------------------------------------
 .../org/apache/olingo/fit/AbstractServices.java |  5 +-
 .../org/apache/olingo/fit/utils/FSManager.java  | 64 +++++++++++++-------
 .../apache/olingo/fit/utils/XMLUtilities.java   |  2 +-
 .../olingo/fit/proxy/v3/AbstractTestITCase.java |  3 -
 .../proxy/v3/AuthEntityRetrieveTestITCase.java  | 48 ---------------
 .../proxy/v4/AuthEntityCreateTestITCase.java    | 50 +++++++++++++++
 .../proxy/v4/AuthEntityRetrieveTestITCase.java  |  4 +-
 .../fit/proxy/v4/EntityCreateTestITCase.java    |  6 +-
 8 files changed, 101 insertions(+), 81 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/377ddb95/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java b/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
index 4ccea54..973833e 100644
--- a/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
+++ b/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
@@ -1306,10 +1306,9 @@ public abstract class AbstractServices {
           @PathParam("entityId") String entityId) {
 
     try {
-      final String basePath =
-              entitySetName + File.separatorChar + Commons.getEntityKey(entityId) + File.separatorChar;
+      final String basePath = entitySetName + File.separatorChar + Commons.getEntityKey(entityId);
 
-      FSManager.instance(version).deleteFile(basePath + Constants.get(version, ConstantKey.ENTITY));
+      FSManager.instance(version).deleteEntity(basePath);
 
       return xml.createResponse(null, null, null, null, Response.Status.NO_CONTENT);
     } catch (Exception e) {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/377ddb95/fit/src/main/java/org/apache/olingo/fit/utils/FSManager.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/utils/FSManager.java b/fit/src/main/java/org/apache/olingo/fit/utils/FSManager.java
index 2599b8f..4eac3a0 100644
--- a/fit/src/main/java/org/apache/olingo/fit/utils/FSManager.java
+++ b/fit/src/main/java/org/apache/olingo/fit/utils/FSManager.java
@@ -35,6 +35,7 @@ import org.apache.commons.vfs2.FileSelectInfo;
 import org.apache.commons.vfs2.FileSelector;
 import org.apache.commons.vfs2.FileSystemException;
 import org.apache.commons.vfs2.FileSystemManager;
+import org.apache.commons.vfs2.FileType;
 import org.apache.commons.vfs2.VFS;
 import org.apache.olingo.commons.api.data.ResWrap;
 import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
@@ -72,6 +73,16 @@ public class FSManager {
   private FSManager(final ODataServiceVersion version) throws Exception {
     this.version = version;
     fsManager = VFS.getManager();
+
+    final FileObject basePath = fsManager.resolveFile(RES_PREFIX + File.separatorChar + version.name());
+    final String absoluteBaseFolder = basePath.getURL().getPath();
+
+    for (FileObject fo : find(basePath, null)) {
+      if (fo.getType() == FileType.FILE) {
+        final String path = fo.getURL().getPath().replace(absoluteBaseFolder, "//" + version.name());
+        putInMemory(fo.getContent().getInputStream(), path);
+      }
+    }
   }
 
   public String getAbsolutePath(final String relativePath, final Accept accept) {
@@ -79,7 +90,7 @@ public class FSManager {
             + (accept == null ? "" : accept.getExtension());
   }
 
-  public FileObject putInMemory(final InputStream is, final String path) throws IOException
{
+  public final FileObject putInMemory(final InputStream is, final String path) throws IOException
{
     LOG.info("Write in memory {}", path);
     final FileObject memObject = fsManager.resolveFile(MEM_PREFIX + path);
 
@@ -116,9 +127,9 @@ public class FSManager {
       final ObjectMapper mapper = Commons.getJSONMapper(version);
       mapper.writeValue(
               writer, new JSONEntryContainer(
-                      container.getContextURL(),
-                      container.getMetadataETag(),
-                      dataBinder.toJSONEntity(container.getPayload())));
+              container.getContextURL(),
+              container.getMetadataETag(),
+              dataBinder.toJSONEntity(container.getPayload())));
 
       putInMemory(new ByteArrayInputStream(content.toByteArray()), getAbsolutePath(relativePath,
Accept.JSON_FULLMETA));
     } catch (Exception e) {
@@ -135,20 +146,10 @@ public class FSManager {
     LOG.info("Read {}", path);
 
     try {
-      FileObject fileObject = fsManager.resolveFile(MEM_PREFIX + path);
+      final FileObject fileObject = fsManager.resolveFile(MEM_PREFIX + path);
 
       if (!fileObject.exists()) {
         LOG.warn("In-memory path '{}' not found", path);
-
-        try {
-          fileObject = fsManager.resolveFile(RES_PREFIX + path);
-          fileObject = putInMemory(fileObject.getContent().getInputStream(), path);
-        } catch (FileSystemException fse) {
-          LOG.warn("Resource path '{}' not found", path, fse);
-        }
-      }
-
-      if (!fileObject.exists()) {
         throw new NotFoundException();
       }
 
@@ -176,12 +177,33 @@ public class FSManager {
     }
   }
 
-  public FileObject resolve(final String path) throws FileSystemException {
-    FileObject res = fsManager.resolveFile(MEM_PREFIX + path);
+  public void deleteEntity(final String relativePath) {
+    final String path = getAbsolutePath(relativePath, null);
+    LOG.info("Delete {}", path);
 
-    if (!res.exists()) {
-      res = fsManager.resolveFile(RES_PREFIX + path);
+    try {
+      final FileObject fileObject = fsManager.resolveFile(MEM_PREFIX + path);
+
+      if (fileObject.exists()) {
+        fileObject.delete(new FileSelector() {
+          @Override
+          public boolean includeFile(final FileSelectInfo fileInfo) throws Exception {
+            return true;
+          }
+
+          @Override
+          public boolean traverseDescendents(final FileSelectInfo fileInfo) throws Exception
{
+            return true;
+          }
+        });
+      }
+    } catch (IOException ignore) {
+      // ignore exception
     }
+  }
+
+  public FileObject resolve(final String path) throws FileSystemException {
+    final FileObject res = fsManager.resolveFile(MEM_PREFIX + path);
 
     if (!res.exists()) {
       throw new FileSystemException("Unresolved path " + path);
@@ -190,11 +212,11 @@ public class FSManager {
     return res;
   }
 
-  public FileObject[] findByExtension(final FileObject fo, final String ext) throws FileSystemException
{
+  public final FileObject[] find(final FileObject fo, final String ext) throws FileSystemException
{
     return fo.findFiles(new FileSelector() {
       @Override
       public boolean includeFile(final FileSelectInfo fileInfo) throws Exception {
-        return fileInfo.getFile().getName().getExtension().equals(ext);
+        return ext == null ? true : fileInfo.getFile().getName().getExtension().equals(ext);
       }
 
       @Override

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/377ddb95/fit/src/main/java/org/apache/olingo/fit/utils/XMLUtilities.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/utils/XMLUtilities.java b/fit/src/main/java/org/apache/olingo/fit/utils/XMLUtilities.java
index b4f9969..84a6cd2 100644
--- a/fit/src/main/java/org/apache/olingo/fit/utils/XMLUtilities.java
+++ b/fit/src/main/java/org/apache/olingo/fit/utils/XMLUtilities.java
@@ -598,7 +598,7 @@ public class XMLUtilities extends AbstractUtilities {
 
     try {
       final FileObject skipToken = fsManager.resolve(skipTokenDirPath);
-      final FileObject[] files = fsManager.findByExtension(skipToken, Accept.XML.getExtension().substring(1));
+      final FileObject[] files = fsManager.find(skipToken, Accept.XML.getExtension().substring(1));
 
       for (FileObject file : files) {
         count += countFeedElements(fsManager.readFile(

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/377ddb95/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AbstractTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AbstractTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AbstractTestITCase.java
index de9cdc3..0bf0eb5 100644
--- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AbstractTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AbstractTestITCase.java
@@ -63,8 +63,6 @@ public abstract class AbstractTestITCase {
 
   protected static String testLargeModelServiceRootURL;
 
-  protected static String testAuthServiceRootURL;
-
   protected final EntityContext entityContext = EntityContainerFactory.getContext().entityContext();
 
   protected static EntityContainerFactory<EdmEnabledODataClient> containerFactory;
@@ -79,7 +77,6 @@ public abstract class AbstractTestITCase {
     testActionOverloadingServiceRootURL = "http://localhost:9080/stub/StaticService/V30/ActionOverloading.svc";
     testOpenTypeServiceRootURL = "http://localhost:9080/stub/StaticService/V30/OpenType.svc";
     testLargeModelServiceRootURL = "http://localhost:9080/stub/StaticService/V30/Static.svc/large";
-    testAuthServiceRootURL = "http://localhost:9080/stub/DefaultService.svc";
 
     containerFactory = EntityContainerFactory.getV3(testStaticServiceRootURL);
     containerFactory.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM);

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/377ddb95/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AuthEntityRetrieveTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AuthEntityRetrieveTestITCase.java
b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AuthEntityRetrieveTestITCase.java
deleted file mode 100644
index 7a721a4..0000000
--- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AuthEntityRetrieveTestITCase.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.fit.proxy.v3;
-
-import static org.junit.Assert.assertNotNull;
-
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-
-import org.apache.olingo.client.core.http.BasicAuthHttpClientFactory;
-import org.apache.olingo.ext.proxy.EntityContainerFactory;
-import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.
-        DefaultContainer;
-
-public class AuthEntityRetrieveTestITCase extends EntityRetrieveTestITCase {
-
-  @BeforeClass
-  public static void setupContaner() {
-    containerFactory = EntityContainerFactory.getV3(testAuthServiceRootURL);
-    containerFactory.getClient().getConfiguration().
-            setHttpClientFactory(new BasicAuthHttpClientFactory("odatajclient", "odatajclient"));
-    container = containerFactory.getEntityContainer(DefaultContainer.class);
-    assertNotNull(container);
-  }
-
-  @AfterClass
-  public static void disableBasicAuth() {
-    containerFactory = EntityContainerFactory.getV3(testStaticServiceRootURL);
-    container = containerFactory.getEntityContainer(DefaultContainer.class);
-    assertNotNull(container);
-  }
-}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/377ddb95/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AuthEntityCreateTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AuthEntityCreateTestITCase.java
b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AuthEntityCreateTestITCase.java
new file mode 100644
index 0000000..d837075
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AuthEntityCreateTestITCase.java
@@ -0,0 +1,50 @@
+/*
+ * 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.proxy.v4;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+import org.apache.olingo.client.core.http.BasicAuthHttpClientFactory;
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.ext.proxy.EntityContainerFactory;
+import static org.apache.olingo.fit.proxy.v4.AbstractTestITCase.containerFactory;
+import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.InMemoryEntities;
+
+public class AuthEntityCreateTestITCase extends EntityCreateTestITCase {
+
+  @BeforeClass
+  public static void setupContaner() {
+    containerFactory = EntityContainerFactory.getV4(testAuthServiceRootURL);
+    containerFactory.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM);
+    containerFactory.getClient().getConfiguration().
+            setHttpClientFactory(new BasicAuthHttpClientFactory("odatajclient", "odatajclient"));
+    container = containerFactory.getEntityContainer(InMemoryEntities.class);
+    assertNotNull(container);
+  }
+
+  @AfterClass
+  public static void disableBasicAuth() {
+    containerFactory = EntityContainerFactory.getV4(testStaticServiceRootURL);
+    container = containerFactory.getEntityContainer(InMemoryEntities.class);
+    assertNotNull(container);
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/377ddb95/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AuthEntityRetrieveTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AuthEntityRetrieveTestITCase.java
b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AuthEntityRetrieveTestITCase.java
index afe4d00..c5391d0 100644
--- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AuthEntityRetrieveTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AuthEntityRetrieveTestITCase.java
@@ -18,8 +18,6 @@
  */
 package org.apache.olingo.fit.proxy.v4;
 
-import static org.apache.olingo.fit.proxy.v4.AbstractTestITCase.testKeyAsSegmentServiceRootURL;
-
 import org.apache.olingo.client.api.v4.EdmEnabledODataClient;
 
 import org.apache.olingo.client.core.http.BasicAuthHttpClientFactory;
@@ -32,7 +30,7 @@ public class AuthEntityRetrieveTestITCase extends EntityRetrieveTestITCase
{
   @Override
   protected InMemoryEntities getContainer() {
     final EntityContainerFactory<EdmEnabledODataClient> ecf =
-            EntityContainerFactory.getV4(testKeyAsSegmentServiceRootURL);
+            EntityContainerFactory.getV4(testAuthServiceRootURL);
     ecf.getClient().getConfiguration().setKeyAsSegment(true);
     ecf.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM);
     ecf.getClient().getConfiguration().

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/377ddb95/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityCreateTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityCreateTestITCase.java
b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityCreateTestITCase.java
index 52cbe51..88c4743 100644
--- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityCreateTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityCreateTestITCase.java
@@ -29,6 +29,8 @@ import java.util.Calendar;
 import java.util.Collections;
 import java.util.TimeZone;
 import org.apache.commons.lang3.RandomUtils;
+import static org.apache.olingo.fit.proxy.v4.AbstractTestITCase.container;
+
 import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.AccessLevel;
 import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Address;
 import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Color;
@@ -94,7 +96,7 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
     container.getPeople().delete(actual.getPersonID());
     container.flush();
 
-    actual = container.getPeople().get(id, Employee.class);;
+    actual = container.getPeople().get(id, Employee.class);
     assertNull(actual);
 
     entityContext.detachAll();
@@ -130,7 +132,7 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
     assertEquals(homeAddress.getCity(), actual.getHomeAddress().getCity());
     assertEquals(1, actual.getOrders().size());
     assertEquals(8, actual.getOrders().iterator().next().getOrderID(), 0);
-
+    
     container.getCustomers().delete(actual.getPersonID());
     container.flush();
 


Mime
View raw message