[OLINGO-260] provided authenticated entity creation on proxy
This commit is contained in:
parent
84203da0a4
commit
377ddb9598
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.fit.proxy.v3;
|
||||
package org.apache.olingo.fit.proxy.v4;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
|
@ -24,25 +24,27 @@ 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 org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.
|
||||
DefaultContainer;
|
||||
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 AuthEntityRetrieveTestITCase extends EntityRetrieveTestITCase {
|
||||
public class AuthEntityCreateTestITCase extends EntityCreateTestITCase {
|
||||
|
||||
@BeforeClass
|
||||
public static void setupContaner() {
|
||||
containerFactory = EntityContainerFactory.getV3(testAuthServiceRootURL);
|
||||
containerFactory = EntityContainerFactory.getV4(testAuthServiceRootURL);
|
||||
containerFactory.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM);
|
||||
containerFactory.getClient().getConfiguration().
|
||||
setHttpClientFactory(new BasicAuthHttpClientFactory("odatajclient", "odatajclient"));
|
||||
container = containerFactory.getEntityContainer(DefaultContainer.class);
|
||||
container = containerFactory.getEntityContainer(InMemoryEntities.class);
|
||||
assertNotNull(container);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void disableBasicAuth() {
|
||||
containerFactory = EntityContainerFactory.getV3(testStaticServiceRootURL);
|
||||
container = containerFactory.getEntityContainer(DefaultContainer.class);
|
||||
containerFactory = EntityContainerFactory.getV4(testStaticServiceRootURL);
|
||||
container = containerFactory.getEntityContainer(InMemoryEntities.class);
|
||||
assertNotNull(container);
|
||||
}
|
||||
}
|
|
@ -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().
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Reference in New Issue