mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
MNT-16236 added changeable setMaxContentSize CMIS configuration for uploading a file + unit test.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@135376 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -954,6 +954,8 @@
|
||||
<!-- OpenCMIS -->
|
||||
|
||||
<bean id="publicApiCMISServiceFactory" class="org.alfresco.opencmis.PublicApiAlfrescoCmisServiceFactory" init-method="init">
|
||||
<property name="memoryThreshold" value="${opencmis.memoryThreshold}" />
|
||||
<property name="maxContentSize" value="${opencmis.maxContentSize}" />
|
||||
<property name="cmisConnector" ref="CMISConnector" />
|
||||
<property name="cmisTransactions" ref="CMISService_Transactions" />
|
||||
<property name="cmisExceptions" ref="CMISService_Exceptions" />
|
||||
|
@@ -33,8 +33,12 @@ import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.io.Serializable;
|
||||
import java.io.StringWriter;
|
||||
import java.math.BigInteger;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.util.AbstractList;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -54,6 +58,7 @@ import org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl;
|
||||
import org.alfresco.cmis.client.type.AlfrescoType;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.opencmis.CMISDispatcherRegistry.Binding;
|
||||
import org.alfresco.opencmis.PublicApiAlfrescoCmisServiceFactory;
|
||||
import org.alfresco.opencmis.dictionary.CMISStrictDictionaryService;
|
||||
import org.alfresco.opencmis.dictionary.QNameFilter;
|
||||
import org.alfresco.opencmis.dictionary.QNameFilterImpl;
|
||||
@@ -126,11 +131,11 @@ import org.apache.chemistry.opencmis.commons.SessionParameter;
|
||||
import org.apache.chemistry.opencmis.commons.data.ContentStream;
|
||||
import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
|
||||
import org.apache.chemistry.opencmis.commons.enums.VersioningState;
|
||||
import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException;
|
||||
import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
|
||||
import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException;
|
||||
import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException;
|
||||
import org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException;
|
||||
import org.apache.chemistry.opencmis.commons.impl.Constants;
|
||||
import org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl;
|
||||
import org.apache.commons.httpclient.HttpStatus;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
@@ -161,6 +166,7 @@ public class TestCMIS extends EnterpriseTestApi
|
||||
|
||||
private static final String TEST_PASSWORD = "password";
|
||||
|
||||
private ApplicationContext ctx;
|
||||
|
||||
private DictionaryDAO dictionaryDAO;
|
||||
private LockService lockService;
|
||||
@@ -174,7 +180,7 @@ public class TestCMIS extends EnterpriseTestApi
|
||||
@Before
|
||||
public void before() throws Exception
|
||||
{
|
||||
ApplicationContext ctx = getTestFixture().getApplicationContext();
|
||||
ctx = getTestFixture().getApplicationContext();
|
||||
this.dictionaryDAO = (DictionaryDAO)ctx.getBean("dictionaryDAO");
|
||||
this.lockService = (LockService) ctx.getBean("lockService");
|
||||
this.tenantService = (TenantService)ctx.getBean("tenantService");
|
||||
@@ -242,6 +248,106 @@ public class TestCMIS extends EnterpriseTestApi
|
||||
assertEquals(200, response.getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* REPO-2041 / MNT-16236 Upload via cmis binding atom and browser files with different maxContentSize
|
||||
*/
|
||||
@Test
|
||||
public void testSetMaxContentSize() throws Exception
|
||||
{
|
||||
final TestNetwork network1 = getTestFixture().getRandomNetwork();
|
||||
Iterator<String> personIt = network1.getPersonIds().iterator();
|
||||
final String personId = personIt.next();
|
||||
assertNotNull(personId);
|
||||
|
||||
// Create a site
|
||||
final TestSite site = TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>()
|
||||
{
|
||||
@Override
|
||||
public TestSite doWork() throws Exception
|
||||
{
|
||||
String siteName = "site" + System.currentTimeMillis();
|
||||
SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PRIVATE);
|
||||
TestSite site = network1.createSite(siteInfo);
|
||||
return site;
|
||||
}
|
||||
}, personId, network1.getId());
|
||||
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), personId));
|
||||
CmisSession cmisSessionAtom = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_11, AlfrescoObjectFactoryImpl.class.getName());
|
||||
CmisSession cmisSessionBrowser = publicApiClient.createPublicApiCMISSession(Binding.browser, CMIS_VERSION_11, AlfrescoObjectFactoryImpl.class.getName());
|
||||
Folder documentLibrary = (Folder)cmisSessionAtom.getObjectByPath("/Sites/" + site.getSiteId() + "/documentLibrary");
|
||||
|
||||
// create file for upload
|
||||
String fileName = "test+" + GUID.generate();
|
||||
long fileLength = 6291456L; // 6MB
|
||||
RandomAccessFile f = new RandomAccessFile(fileName, "rw");
|
||||
f.setLength(fileLength);
|
||||
|
||||
Map<String, Serializable> properties = new HashMap<String, Serializable>();
|
||||
properties.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
|
||||
properties.put(PropertyIds.NAME, fileName);
|
||||
|
||||
// change maxContentSize so that the file will be to big
|
||||
long maxContentSize = 5242880L; // 5MB
|
||||
PublicApiAlfrescoCmisServiceFactory publicApiAlfrescoCmisServiceFactory = (PublicApiAlfrescoCmisServiceFactory) ctx.getBean("publicApiCMISServiceFactory");
|
||||
publicApiAlfrescoCmisServiceFactory.setMaxContentSize(maxContentSize);
|
||||
|
||||
// for atom
|
||||
FileChannel fc = f.getChannel();
|
||||
InputStream is = Channels.newInputStream(fc);
|
||||
ContentStreamImpl contentStream = new ContentStreamImpl(fileName, BigInteger.valueOf(fileLength), MimetypeMap.MIMETYPE_TEXT_PLAIN,
|
||||
is);
|
||||
try
|
||||
{
|
||||
cmisSessionAtom.createDocument(documentLibrary.getId(), fileName, properties, contentStream, VersioningState.MAJOR);
|
||||
fail("The file should be to big to upload via atom binding");
|
||||
}
|
||||
catch(CmisConstraintException e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// for browser
|
||||
fc.position(0);
|
||||
try
|
||||
{
|
||||
cmisSessionBrowser.createDocument(documentLibrary.getId(), fileName, properties, contentStream, VersioningState.MAJOR);
|
||||
fail("The file should be to big to upload via browser binding");
|
||||
}
|
||||
catch(CmisConstraintException e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// increase maxContensize so that the file is not to big
|
||||
maxContentSize = 10485760L; // 10MB
|
||||
publicApiAlfrescoCmisServiceFactory.setMaxContentSize(maxContentSize);
|
||||
|
||||
// for atom
|
||||
fc.position(0);
|
||||
Document result = cmisSessionAtom.createDocument(documentLibrary.getId(), fileName, properties, contentStream, VersioningState.MAJOR);
|
||||
assertNotNull(result);
|
||||
|
||||
// for browser
|
||||
fc.position(0);
|
||||
result = cmisSessionBrowser.createDocument(documentLibrary.getId(), fileName + "2", properties, contentStream, VersioningState.MAJOR);
|
||||
assertNotNull(result);
|
||||
|
||||
// ignore the size check
|
||||
maxContentSize = -1L;
|
||||
publicApiAlfrescoCmisServiceFactory.setMaxContentSize(maxContentSize);
|
||||
|
||||
// for atom
|
||||
fc.position(0);
|
||||
result = cmisSessionAtom.createDocument(documentLibrary.getId(), fileName + "3", properties, contentStream, VersioningState.MAJOR);
|
||||
assertNotNull(result);
|
||||
|
||||
// for browser
|
||||
fc.position(0);
|
||||
result = cmisSessionBrowser.createDocument(documentLibrary.getId(), fileName + "4", properties, contentStream, VersioningState.MAJOR);
|
||||
assertNotNull(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests OpenCMIS api.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user