mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged HEAD (5.2) to 5.2.N (5.2.1)
126487 jkaabimofrad: Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2) 122629 gjames: RA-211: Adding a response callback for setting the response outside a transaction git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@126831 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -55,8 +55,6 @@ import org.codehaus.jackson.map.JsonMappingException;
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
import org.springframework.extensions.surf.util.URLEncoder;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.Description;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
import org.springframework.extensions.webscripts.WebScriptResponse;
|
||||
@@ -152,15 +150,16 @@ public abstract class AbstractResourceWebScript extends ApiWebScript implements
|
||||
public Object execute(final ResourceWithMetadata resource, final Params params, final WebScriptResponse res, boolean isReadOnly)
|
||||
{
|
||||
final String entityCollectionName = ResourceInspector.findEntityCollectionNameName(resource.getMetaData());
|
||||
return transactionService.getRetryingTransactionHelper().doInTransaction(
|
||||
final ResourceOperation operation = resource.getMetaData().getOperation(getHttpMethod());
|
||||
final ResponseCallBack callBack = new ResponseCallBack(operation.getSuccessStatus(),DEFAULT_JSON_CONTENT,ApiWebScript.CACHE_NEVER);
|
||||
Object toReturn = transactionService.getRetryingTransactionHelper().doInTransaction(
|
||||
new RetryingTransactionHelper.RetryingTransactionCallback<Object>()
|
||||
{
|
||||
@Override
|
||||
public Object execute() throws Throwable
|
||||
{
|
||||
final ResourceOperation operation = resource.getMetaData().getOperation(getHttpMethod());
|
||||
|
||||
Object result = executeAction(resource, params);
|
||||
setResponse(res,operation.getSuccessStatus(),ApiWebScript.CACHE_NEVER, DEFAULT_JSON_CONTENT);
|
||||
if (result instanceof BinaryResource)
|
||||
{
|
||||
return result; //don't postprocess it.
|
||||
@@ -168,6 +167,8 @@ public abstract class AbstractResourceWebScript extends ApiWebScript implements
|
||||
return helper.processAdditionsToTheResponse(res, resource.getMetaData().getApi(), entityCollectionName, params, result);
|
||||
}
|
||||
}, isReadOnly, true);
|
||||
setResponse(res,callBack);
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public abstract Object executeAction(ResourceWithMetadata resource, Params params) throws Throwable;
|
||||
@@ -201,14 +202,20 @@ public abstract class AbstractResourceWebScript extends ApiWebScript implements
|
||||
* @param status
|
||||
* @param cache
|
||||
* @param contentInfo
|
||||
* @param headers
|
||||
*/
|
||||
protected void setResponse(final WebScriptResponse res, int status, Cache cache, ContentInfo contentInfo)
|
||||
protected void setResponse(final WebScriptResponse res, int status, Cache cache, ContentInfo contentInfo, Map<String, String> headers)
|
||||
{
|
||||
res.setStatus(status);
|
||||
res.setCache(cache);
|
||||
setContentInfoOnResponse(res,contentInfo);
|
||||
}
|
||||
|
||||
|
||||
protected void setResponse(final WebScriptResponse res, ResponseCallBack withResponse)
|
||||
{
|
||||
setResponse(res, withResponse.getStatus(), withResponse.getCache(), withResponse.getContentInfo(), withResponse.getHeaders());
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the result of an execution.
|
||||
*
|
||||
|
@@ -166,19 +166,21 @@ public class ResourceWebScriptDelete extends AbstractResourceWebScript implement
|
||||
@Override
|
||||
public Void execute(final ResourceWithMetadata resource, final Params params, final WebScriptResponse res, boolean isReadOnly)
|
||||
{
|
||||
final ResourceOperation operation = resource.getMetaData().getOperation(HttpMethod.DELETE);
|
||||
final ResponseCallBack callBack = new ResponseCallBack(operation.getSuccessStatus(),DEFAULT_JSON_CONTENT,ApiWebScript.CACHE_NEVER);
|
||||
transactionService.getRetryingTransactionHelper().doInTransaction(
|
||||
new RetryingTransactionCallback<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void execute() throws Throwable
|
||||
{
|
||||
final ResourceOperation operation = resource.getMetaData().getOperation(HttpMethod.DELETE);
|
||||
executeAction(resource, params); //ignore return result
|
||||
setResponse(res,operation.getSuccessStatus(),ApiWebScript.CACHE_NEVER, DEFAULT_JSON_CONTENT);
|
||||
return null;
|
||||
}
|
||||
}, false, true);
|
||||
setResponse(res,callBack);
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,94 @@
|
||||
package org.alfresco.rest.framework.webscripts;
|
||||
|
||||
import org.alfresco.rest.framework.resource.content.ContentInfo;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Values to be set on the response at the appropriate time.
|
||||
*
|
||||
* It should be ok to set these variables multiple times but only the latest values are used.
|
||||
*
|
||||
* @author Gethin James
|
||||
*/
|
||||
public class ResponseCallBack
|
||||
{
|
||||
private ContentInfo contentInfo;
|
||||
private int status;
|
||||
private Map<String, String> headers;
|
||||
private Cache cache;
|
||||
|
||||
public ResponseCallBack(int status, ContentInfo contentInfo, Cache cache)
|
||||
{
|
||||
this.contentInfo = contentInfo;
|
||||
this.status = status;
|
||||
this.headers = new HashMap<>();
|
||||
this.cache = cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the information about the content: mimetype, encoding, locale, length
|
||||
*
|
||||
* @param contentInfo
|
||||
*/
|
||||
public void setContentInfo(ContentInfo contentInfo)
|
||||
{
|
||||
this.contentInfo = contentInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Response Status
|
||||
*
|
||||
* @param status int
|
||||
*/
|
||||
public void setStatus(int status)
|
||||
{
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a response header with the given name and value. If the header has
|
||||
* already been set, the new value overwrites the previous one.
|
||||
*
|
||||
* @param name header name
|
||||
* @param value header value
|
||||
*/
|
||||
public void setHeader(String name, String value)
|
||||
{
|
||||
headers.put(name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Cache control
|
||||
*
|
||||
* @param cache cache control
|
||||
*/
|
||||
public void setCache(Cache cache)
|
||||
{
|
||||
this.cache = cache;
|
||||
}
|
||||
|
||||
public ContentInfo getContentInfo()
|
||||
{
|
||||
return contentInfo;
|
||||
}
|
||||
|
||||
public int getStatus()
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
public Cache getCache()
|
||||
{
|
||||
return cache;
|
||||
}
|
||||
|
||||
public Map<String, String> getHeaders()
|
||||
{
|
||||
return headers;
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user