mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
ALF-20216 "4.2 Preview: valid API URL returns an error"
ALF-20217 "4.2 Preview: Some errors are formatted with Explorer UI look and feel" Note that the discoverablity urls will not work (this is not a regression from Cloud) - see ALF-20218 ALF-20098 "BM-0012: Run v420b1494_01: Exception from executeScript" Two problems were identified with the public api webscript processing: i) No buffering of requests and responses due to a fix for another bug (this is required due to retrying transactions) ii) Exceptions are handled by the public api framework and JSON responses written out. In some cases, exceptions were slipping through and being handled by the Spring web script framework (which was writing them out as non JSON responses). git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@56385 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -17,7 +17,6 @@ import org.alfresco.rest.framework.resource.content.ContentInfo;
|
||||
import org.alfresco.rest.framework.resource.content.FileBinaryResource;
|
||||
import org.alfresco.rest.framework.resource.content.NodeBinaryResource;
|
||||
import org.alfresco.rest.framework.resource.parameters.Params;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.codehaus.jackson.JsonGenerationException;
|
||||
@@ -52,7 +51,6 @@ public abstract class AbstractResourceWebScript extends ApiWebScript implements
|
||||
private ParamsExtractor paramsExtractor;
|
||||
private ContentStreamer streamer;
|
||||
protected ResourceWebScriptHelper helper;
|
||||
protected TransactionService transactionService;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
@@ -60,13 +58,12 @@ public abstract class AbstractResourceWebScript extends ApiWebScript implements
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
final Map<String, Object> respons = new HashMap<String, Object>();
|
||||
final Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
|
||||
final ResourceWithMetadata resource = locator.locateResource(api,templateVars, httpMethod);
|
||||
final Params params = paramsExtractor.extractParams(resource.getMetaData(),req);
|
||||
final ActionExecutor executor = findExecutor(httpMethod, params, resource, req.getContentType());
|
||||
|
||||
|
||||
//This execution usually takes place in a Retrying Transaction (see subclasses)
|
||||
executor.execute(resource, params, new ExecutionCallback()
|
||||
{
|
||||
@@ -172,11 +169,6 @@ public abstract class AbstractResourceWebScript extends ApiWebScript implements
|
||||
//Ignore all params and return this
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setTransactionService(TransactionService transactionService)
|
||||
{
|
||||
this.transactionService = transactionService;
|
||||
}
|
||||
|
||||
public void setLocator(ResourceLocator locator)
|
||||
{
|
||||
|
@@ -1,8 +1,11 @@
|
||||
package org.alfresco.rest.framework.webscripts;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.web.scripts.BufferedRequest;
|
||||
import org.alfresco.repo.web.scripts.BufferedResponse;
|
||||
import org.alfresco.rest.framework.Api;
|
||||
import org.alfresco.rest.framework.core.exceptions.DefaultExceptionResolver;
|
||||
import org.alfresco.rest.framework.core.exceptions.ErrorResponse;
|
||||
@@ -11,6 +14,9 @@ import org.alfresco.rest.framework.jacksonextensions.JacksonHelper;
|
||||
import org.alfresco.rest.framework.jacksonextensions.JacksonHelper.Writer;
|
||||
import org.alfresco.rest.framework.resource.content.ContentInfo;
|
||||
import org.alfresco.rest.framework.resource.content.ContentInfoImpl;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.alfresco.util.TempFileProvider;
|
||||
import org.apache.chemistry.opencmis.server.shared.ThresholdOutputStreamFactory;
|
||||
import org.codehaus.jackson.JsonGenerationException;
|
||||
import org.codehaus.jackson.JsonGenerator;
|
||||
import org.codehaus.jackson.map.JsonMappingException;
|
||||
@@ -36,6 +42,54 @@ public abstract class ApiWebScript extends AbstractWebScript
|
||||
ExceptionResolver<Exception> defaultResolver = new DefaultExceptionResolver();
|
||||
ExceptionResolver<Exception> resolver;
|
||||
|
||||
protected boolean encryptTempFiles = false;
|
||||
protected String tempDirectoryName = null;
|
||||
protected int memoryThreshold = 4 * 1024 * 1024; // 4mb
|
||||
protected long maxContentSize = (long) 4 * 1024 * 1024 * 1024; // 4gb
|
||||
protected ThresholdOutputStreamFactory streamFactory = null;
|
||||
protected TransactionService transactionService;
|
||||
|
||||
public void setTransactionService(TransactionService transactionService)
|
||||
{
|
||||
this.transactionService = transactionService;
|
||||
}
|
||||
|
||||
public void setDefaultResolver(ExceptionResolver<Exception> defaultResolver)
|
||||
{
|
||||
this.defaultResolver = defaultResolver;
|
||||
}
|
||||
|
||||
public void setTempDirectoryName(String tempDirectoryName)
|
||||
{
|
||||
this.tempDirectoryName = tempDirectoryName;
|
||||
}
|
||||
|
||||
public void setEncryptTempFiles(boolean encryptTempFiles)
|
||||
{
|
||||
this.encryptTempFiles = encryptTempFiles;
|
||||
}
|
||||
|
||||
public void setMemoryThreshold(int memoryThreshold)
|
||||
{
|
||||
this.memoryThreshold = memoryThreshold;
|
||||
}
|
||||
|
||||
public void setMaxContentSize(long maxContentSize)
|
||||
{
|
||||
this.maxContentSize = maxContentSize;
|
||||
}
|
||||
|
||||
public void setStreamFactory(ThresholdOutputStreamFactory streamFactory)
|
||||
{
|
||||
this.streamFactory = streamFactory;
|
||||
}
|
||||
|
||||
public void init()
|
||||
{
|
||||
File tempDirectory = new File(TempFileProvider.getTempDir(), tempDirectoryName);
|
||||
this.streamFactory = ThresholdOutputStreamFactory.newInstance(tempDirectory, memoryThreshold, maxContentSize, encryptTempFiles);
|
||||
}
|
||||
|
||||
public final static String UTF8 = "UTF-8";
|
||||
public final static Cache CACHE_NEVER = new Cache(new RequiredCache()
|
||||
{
|
||||
@@ -64,7 +118,28 @@ public abstract class ApiWebScript extends AbstractWebScript
|
||||
{
|
||||
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
|
||||
Api api = determineApi(templateVars);
|
||||
execute(api, req, res);
|
||||
|
||||
final BufferedRequest bufferedReq = getRequest(req);
|
||||
final BufferedResponse bufferedRes = getResponse(res);
|
||||
|
||||
try
|
||||
{
|
||||
execute(api, bufferedReq, bufferedRes);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Get rid of any temporary files
|
||||
if (bufferedReq != null)
|
||||
{
|
||||
bufferedReq.close();
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure a response is always flushed after successful execution
|
||||
if (bufferedRes != null)
|
||||
{
|
||||
bufferedRes.writeResponse();
|
||||
}
|
||||
}
|
||||
|
||||
private Api determineApi(Map<String, String> templateVars)
|
||||
@@ -85,6 +160,20 @@ public abstract class ApiWebScript extends AbstractWebScript
|
||||
return error;
|
||||
}
|
||||
|
||||
protected BufferedRequest getRequest(final WebScriptRequest req)
|
||||
{
|
||||
// create buffered request and response that allow transaction retrying
|
||||
final BufferedRequest bufferedReq = new BufferedRequest(req, streamFactory);
|
||||
return bufferedReq;
|
||||
}
|
||||
|
||||
protected BufferedResponse getResponse(final WebScriptResponse resp)
|
||||
{
|
||||
// create buffered request and response that allow transaction retrying
|
||||
final BufferedResponse bufferedRes = new BufferedResponse(resp, memoryThreshold);
|
||||
return bufferedRes;
|
||||
}
|
||||
|
||||
public abstract void execute(final Api api, WebScriptRequest req, WebScriptResponse res) throws IOException;
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user