Merged HEAD-BUG-FIX (4.3/Cloud) to HEAD (4.3/Cloud)

69695: Merged V4.2-BUG-FIX (4.2.3) to HEAD-BUG-FIX (4.3/Cloud)
      68570: Merged DEV to V4.2-BUG-FIX (4.2.3)
         68084 : MNT-11237 : CMIS uploading file larger the 4mb fails
            - Ensure that temp directory exists before buffering request input stream.
            - Test webscript was added (simply buffers request input stream)
            - TempFileProvider now has method to get or create temp folder inside system temp directory
            - Unit test was added


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@70435 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2014-05-16 17:35:21 +00:00
parent ffd09244c9
commit 962295dc5a
7 changed files with 103 additions and 2 deletions

View File

@@ -93,7 +93,7 @@ public class RepositoryContainer extends AbstractRuntimeContainer
*/ */
public void setup() public void setup()
{ {
File tempDirectory = new File(TempFileProvider.getTempDir(), tempDirectoryName); File tempDirectory = TempFileProvider.getTempDir(tempDirectoryName);
this.streamFactory = ThresholdOutputStreamFactory.newInstance(tempDirectory, memoryThreshold, maxContentSize, encryptTempFiles); this.streamFactory = ThresholdOutputStreamFactory.newInstance(tempDirectory, memoryThreshold, maxContentSize, encryptTempFiles);
} }

View File

@@ -86,7 +86,7 @@ public abstract class ApiWebScript extends AbstractWebScript
public void init() public void init()
{ {
File tempDirectory = new File(TempFileProvider.getTempDir(), tempDirectoryName); File tempDirectory = TempFileProvider.getTempDir(tempDirectoryName);
this.streamFactory = ThresholdOutputStreamFactory.newInstance(tempDirectory, memoryThreshold, maxContentSize, encryptTempFiles); this.streamFactory = ThresholdOutputStreamFactory.newInstance(tempDirectory, memoryThreshold, maxContentSize, encryptTempFiles);
} }

View File

@@ -18,13 +18,16 @@
*/ */
package org.alfresco.repo.web.scripts; package org.alfresco.repo.web.scripts;
import java.util.Arrays;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.security.authentication.AuthenticationComponent; import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.service.cmr.security.MutableAuthenticationService; import org.alfresco.service.cmr.security.MutableAuthenticationService;
import org.alfresco.service.cmr.security.PersonService; import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.util.CronTriggerBean;
import org.alfresco.util.PropertyMap; import org.alfresco.util.PropertyMap;
import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest; import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.Response; import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
import static org.springframework.extensions.webscripts.Status.*; import static org.springframework.extensions.webscripts.Status.*;
@@ -41,6 +44,7 @@ public class RepositoryContainerTest extends BaseWebScriptTest
private static final String USER_ONE = "RunAsOne"; private static final String USER_ONE = "RunAsOne";
private static final String USER_TWO = "RunAsTwo"; private static final String USER_TWO = "RunAsTwo";
private static final String SUCCESS = "success";
@Override @Override
protected void setUp() throws Exception protected void setUp() throws Exception
@@ -109,4 +113,34 @@ public class RepositoryContainerTest extends BaseWebScriptTest
RepositoryContainer repoContainer = (RepositoryContainer) getServer().getApplicationContext().getBean("webscripts.container"); RepositoryContainer repoContainer = (RepositoryContainer) getServer().getApplicationContext().getBean("webscripts.container");
repoContainer.reset(); repoContainer.reset();
} }
/*
* Test for MNT-11237 : CMIS uploading file larger the 4mb fails
*
* Tests that requests with content larger than 4mb (default memoryThreshold value) can be successfully handled by repository container
*/
public void testLargeContentRequest() throws Exception
{
authenticationComponent.setCurrentUser(USER_ONE);
// create the 5 mb size buffer of zero bytes
byte[] content = new byte[5 * 1024 * 1024];
Arrays.fill(content, (byte)0);
// chek that we can upload file larger than 4 mb
Response response = sendRequest(new PutRequest("/test/largecontenttest", content, "text/plain"), STATUS_OK);
assertEquals(SUCCESS, response.getContentAsString());
// trigger the webscript temp folder cleaner job
CronTriggerBean webscriptsTempFileCleanerJobTrigger = (CronTriggerBean) getServer().getApplicationContext().getBean("webscripts.tempFileCleanerTrigger");
webscriptsTempFileCleanerJobTrigger.getScheduler().triggerJobWithVolatileTrigger(
webscriptsTempFileCleanerJobTrigger.getJobDetail().getName(),
webscriptsTempFileCleanerJobTrigger.getJobDetail().getGroup(),
webscriptsTempFileCleanerJobTrigger.getJobDetail().getJobDataMap());
// check that we still can upload file larger than 4 mb, i.e. ensure that cleaner has not deleted temp folder
response = sendRequest(new PutRequest("/test/largecontenttest", content, "text/plain"), STATUS_OK);
assertEquals(SUCCESS, response.getContentAsString());
}
} }

View File

@@ -0,0 +1,55 @@
/*
* Copyright (C) 2005-2014 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.web.scripts.test;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Test webscript class that simply read request content. Used in unit test for MNT-11237 issue.
*
* @author pavel.yurkevich
*/
public class LargeContentTestPut extends DeclarativeWebScript
{
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
Map<String, Object> model = new HashMap<String, Object>();
try
{
req.getContent().getInputStream().close();
model.put("result", "success");
}
catch (IOException e)
{
throw new WebScriptException(Status.STATUS_INTERNAL_SERVER_ERROR, "Fail to read request content.");
}
return model;
}
}

View File

@@ -0,0 +1,8 @@
<webscript>
<shortname>Large Request Test</shortname>
<description>Large Request Test </description>
<url>/test/largecontenttest</url>
<format default="html">argument</format>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>

View File

@@ -23,4 +23,7 @@
</property> </property>
</bean> </bean>
<bean id="webscript.org.alfresco.runas.largecontent.put" class="org.alfresco.repo.web.scripts.test.LargeContentTestPut" parent="webscript">
</bean>
</beans> </beans>