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:
@@ -23,21 +23,23 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.alfresco.rest.api.model.PersonNetwork;
|
||||
import org.alfresco.rest.api.networks.NetworksEntityResource;
|
||||
import org.alfresco.rest.framework.Api;
|
||||
import org.alfresco.rest.framework.jacksonextensions.JacksonHelper;
|
||||
import org.alfresco.rest.framework.core.exceptions.ApiException;
|
||||
import org.alfresco.rest.framework.jacksonextensions.JacksonHelper.Writer;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Paging;
|
||||
import org.alfresco.rest.framework.resource.parameters.Params;
|
||||
import org.alfresco.rest.framework.webscripts.ApiWebScript;
|
||||
import org.alfresco.rest.framework.webscripts.ResourceWebScriptHelper;
|
||||
import org.codehaus.jackson.JsonGenerationException;
|
||||
import org.codehaus.jackson.JsonGenerator;
|
||||
import org.codehaus.jackson.map.JsonMappingException;
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
import org.springframework.extensions.webscripts.AbstractWebScript;
|
||||
import org.springframework.extensions.webscripts.Format;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
import org.springframework.extensions.webscripts.WebScriptResponse;
|
||||
|
||||
@@ -47,17 +49,11 @@ import org.springframework.extensions.webscripts.WebScriptResponse;
|
||||
* @author steveglover
|
||||
*
|
||||
*/
|
||||
public class NetworksWebScriptGet extends AbstractWebScript
|
||||
public class NetworksWebScriptGet extends ApiWebScript
|
||||
{
|
||||
private Networks networks;
|
||||
private JacksonHelper jsonHelper;
|
||||
private ResourceWebScriptHelper helper;
|
||||
|
||||
public void setJsonHelper(JacksonHelper jsonHelper)
|
||||
{
|
||||
this.jsonHelper = jsonHelper;
|
||||
}
|
||||
|
||||
public void setHelper(ResourceWebScriptHelper helper)
|
||||
{
|
||||
this.helper = helper;
|
||||
@@ -68,35 +64,60 @@ public class NetworksWebScriptGet extends AbstractWebScript
|
||||
this.networks = networks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException
|
||||
{
|
||||
final Paging paging = ResourceWebScriptHelper.findPaging(req);
|
||||
|
||||
// apply content type
|
||||
res.setContentType(Format.JSON.mimetype() + ";charset=UTF-8");
|
||||
|
||||
jsonHelper.withWriter(res.getOutputStream(), new Writer()
|
||||
@Override
|
||||
public void execute(final Api api, final WebScriptRequest req, final WebScriptResponse res) throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
@Override
|
||||
public void writeContents(JsonGenerator generator, ObjectMapper objectMapper)
|
||||
throws JsonGenerationException, JsonMappingException, IOException
|
||||
transactionService.getRetryingTransactionHelper().doInTransaction(
|
||||
new RetryingTransactionCallback<Void>()
|
||||
{
|
||||
List<Object> entities = new ArrayList<Object>();
|
||||
|
||||
String personId = AuthenticationUtil.getFullyAuthenticatedUser();
|
||||
|
||||
CollectionWithPagingInfo<PersonNetwork> networkMemberships = networks.getNetworks(personId, paging);
|
||||
for (PersonNetwork networkMember : networkMemberships.getCollection())
|
||||
@Override
|
||||
public Void execute() throws Throwable
|
||||
{
|
||||
// TODO this is not ideal, but the only way to populate the embedded network entities (this would normally be
|
||||
// done automatically by the api framework).
|
||||
Object wrapped = helper.postProcessResponse(Api.ALFRESCO_PUBLIC, NetworksEntityResource.NAME, Params.valueOf(personId, null), networkMember);
|
||||
entities.add(wrapped);
|
||||
final Paging paging = ResourceWebScriptHelper.findPaging(req);
|
||||
|
||||
// apply content type
|
||||
res.setContentType(Format.JSON.mimetype() + ";charset=UTF-8");
|
||||
|
||||
jsonHelper.withWriter(res.getOutputStream(), new Writer()
|
||||
{
|
||||
@Override
|
||||
public void writeContents(JsonGenerator generator, ObjectMapper objectMapper)
|
||||
throws JsonGenerationException, JsonMappingException, IOException
|
||||
{
|
||||
List<Object> entities = new ArrayList<Object>();
|
||||
|
||||
String personId = AuthenticationUtil.getFullyAuthenticatedUser();
|
||||
|
||||
CollectionWithPagingInfo<PersonNetwork> networkMemberships = networks.getNetworks(personId, paging);
|
||||
for (PersonNetwork networkMember : networkMemberships.getCollection())
|
||||
{
|
||||
// TODO this is not ideal, but the only way to populate the embedded network entities (this would normally be
|
||||
// done automatically by the api framework).
|
||||
Object wrapped = helper.postProcessResponse(Api.ALFRESCO_PUBLIC, NetworksEntityResource.NAME, Params.valueOf(personId, null), networkMember);
|
||||
entities.add(wrapped);
|
||||
}
|
||||
|
||||
objectMapper.writeValue(generator, CollectionWithPagingInfo.asPaged(paging, entities));
|
||||
}
|
||||
});
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
objectMapper.writeValue(generator, CollectionWithPagingInfo.asPaged(paging, entities));
|
||||
}
|
||||
});
|
||||
}
|
||||
}, true, true);
|
||||
}
|
||||
catch (ApiException apiException)
|
||||
{
|
||||
renderErrorResponse(resolveException(apiException), res);
|
||||
}
|
||||
catch (WebScriptException webException)
|
||||
{
|
||||
renderErrorResponse(resolveException(webException), res);
|
||||
}
|
||||
catch (RuntimeException runtimeException)
|
||||
{
|
||||
renderErrorResponse(resolveException(runtimeException), res);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user