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:
@@ -142,9 +142,14 @@
|
|||||||
/> <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"
|
/> <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"
|
||||||
/> -->
|
/> -->
|
||||||
|
|
||||||
<bean id="apiWebScriptParent" abstract="true" parent="webscript">
|
<bean id="apiWebScriptParent" abstract="true" parent="webscript" init-method="init">
|
||||||
<property name="resolver" ref="simpleMappingExceptionResolver" />
|
<property name="resolver" ref="simpleMappingExceptionResolver" />
|
||||||
<property name="jsonHelper" ref="jsonHelper" />
|
<property name="jsonHelper" ref="jsonHelper" />
|
||||||
|
<property name="encryptTempFiles" value="${webscripts.encryptTempFiles}"/>
|
||||||
|
<property name="tempDirectoryName" value="${webscripts.tempDirectoryName}"/>
|
||||||
|
<property name="memoryThreshold" value="${webscripts.memoryThreshold}"/>
|
||||||
|
<property name="maxContentSize" value="${webscripts.setMaxContentSize}"/>
|
||||||
|
<property name="transactionService" ref="transactionService" />
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<alias name="webscript.org.alfresco.api.ResourceWebScript.get" alias="executorForHttpGet"/>
|
<alias name="webscript.org.alfresco.api.ResourceWebScript.get" alias="executorForHttpGet"/>
|
||||||
@@ -159,7 +164,6 @@
|
|||||||
class="org.alfresco.rest.framework.webscripts.ResourceWebScriptGet" parent="apiWebScriptParent">
|
class="org.alfresco.rest.framework.webscripts.ResourceWebScriptGet" parent="apiWebScriptParent">
|
||||||
<property name="helper" ref="webscriptHelper" />
|
<property name="helper" ref="webscriptHelper" />
|
||||||
<property name="locator" ref="apiLookup" />
|
<property name="locator" ref="apiLookup" />
|
||||||
<property name="transactionService" ref="transactionService" />
|
|
||||||
<property name="streamer" ref="webscript.content.streamer" />
|
<property name="streamer" ref="webscript.content.streamer" />
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
@@ -167,7 +171,6 @@
|
|||||||
class="org.alfresco.rest.framework.webscripts.ResourceWebScriptPost" parent="apiWebScriptParent">
|
class="org.alfresco.rest.framework.webscripts.ResourceWebScriptPost" parent="apiWebScriptParent">
|
||||||
<property name="helper" ref="webscriptHelper" />
|
<property name="helper" ref="webscriptHelper" />
|
||||||
<property name="locator" ref="apiLookup" />
|
<property name="locator" ref="apiLookup" />
|
||||||
<property name="transactionService" ref="transactionService" />
|
|
||||||
<property name="streamer" ref="webscript.content.streamer" />
|
<property name="streamer" ref="webscript.content.streamer" />
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
@@ -175,7 +178,6 @@
|
|||||||
class="org.alfresco.rest.framework.webscripts.ResourceWebScriptPut" parent="apiWebScriptParent">
|
class="org.alfresco.rest.framework.webscripts.ResourceWebScriptPut" parent="apiWebScriptParent">
|
||||||
<property name="helper" ref="webscriptHelper" />
|
<property name="helper" ref="webscriptHelper" />
|
||||||
<property name="locator" ref="apiLookup" />
|
<property name="locator" ref="apiLookup" />
|
||||||
<property name="transactionService" ref="transactionService" />
|
|
||||||
<property name="streamer" ref="webscript.content.streamer" />
|
<property name="streamer" ref="webscript.content.streamer" />
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
@@ -183,7 +185,6 @@
|
|||||||
class="org.alfresco.rest.framework.webscripts.ResourceWebScriptDelete" parent="apiWebScriptParent">
|
class="org.alfresco.rest.framework.webscripts.ResourceWebScriptDelete" parent="apiWebScriptParent">
|
||||||
<property name="helper" ref="webscriptHelper" />
|
<property name="helper" ref="webscriptHelper" />
|
||||||
<property name="locator" ref="apiLookup" />
|
<property name="locator" ref="apiLookup" />
|
||||||
<property name="transactionService" ref="transactionService" />
|
|
||||||
<property name="streamer" ref="webscript.content.streamer" />
|
<property name="streamer" ref="webscript.content.streamer" />
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
@@ -702,16 +703,14 @@
|
|||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="getNetworksWebScript"
|
<bean id="getNetworksWebScript"
|
||||||
class="org.alfresco.rest.api.NetworksWebScriptGet">
|
class="org.alfresco.rest.api.NetworksWebScriptGet" parent="apiWebScriptParent">
|
||||||
<property name="networks" ref="Networks" />
|
<property name="networks" ref="Networks" />
|
||||||
<property name="jsonHelper" ref="jsonHelper" />
|
|
||||||
<property name="helper" ref="webscriptHelper" />
|
<property name="helper" ref="webscriptHelper" />
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="getNetworkWebScript"
|
<bean id="getNetworkWebScript"
|
||||||
class="org.alfresco.rest.api.NetworkWebScriptGet">
|
class="org.alfresco.rest.api.NetworkWebScriptGet" parent="apiWebScriptParent">
|
||||||
<property name="networks" ref="Networks" />
|
<property name="networks" ref="Networks" />
|
||||||
<property name="jsonHelper" ref="jsonHelper" />
|
|
||||||
<property name="helper" ref="webscriptHelper" />
|
<property name="helper" ref="webscriptHelper" />
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
365
source/java/org/alfresco/repo/web/scripts/BufferedRequest.java
Normal file
365
source/java/org/alfresco/repo/web/scripts/BufferedRequest.java
Normal file
@@ -0,0 +1,365 @@
|
|||||||
|
package org.alfresco.repo.web.scripts;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
|
import org.apache.chemistry.opencmis.server.shared.ThresholdOutputStream;
|
||||||
|
import org.apache.chemistry.opencmis.server.shared.ThresholdOutputStreamFactory;
|
||||||
|
import org.springframework.extensions.surf.util.Content;
|
||||||
|
import org.springframework.extensions.webscripts.Description.FormatStyle;
|
||||||
|
import org.springframework.extensions.webscripts.Match;
|
||||||
|
import org.springframework.extensions.webscripts.Runtime;
|
||||||
|
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||||
|
import org.springframework.extensions.webscripts.WrappingWebScriptRequest;
|
||||||
|
import org.springframework.util.FileCopyUtils;
|
||||||
|
|
||||||
|
public class BufferedRequest implements WrappingWebScriptRequest
|
||||||
|
{
|
||||||
|
private ThresholdOutputStreamFactory streamFactory;
|
||||||
|
private WebScriptRequest req;
|
||||||
|
private File requestBody;
|
||||||
|
private InputStream contentStream;
|
||||||
|
private BufferedReader contentReader;
|
||||||
|
|
||||||
|
public BufferedRequest(WebScriptRequest req, ThresholdOutputStreamFactory streamFactory)
|
||||||
|
{
|
||||||
|
this.req = req;
|
||||||
|
this.streamFactory = streamFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
private InputStream bufferInputStream() throws IOException
|
||||||
|
{
|
||||||
|
ThresholdOutputStream bufferStream = streamFactory.newOutputStream();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FileCopyUtils.copy(req.getContent().getInputStream(), bufferStream);
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
bufferStream.destroy(); // remove temp file
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
return bufferStream.getInputStream();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reset()
|
||||||
|
{
|
||||||
|
if (contentStream != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
contentStream.close();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
contentStream = null;
|
||||||
|
}
|
||||||
|
if (contentReader != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
contentReader.close();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
contentReader = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close()
|
||||||
|
{
|
||||||
|
reset();
|
||||||
|
if (requestBody != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
requestBody.delete();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
requestBody = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.extensions.webscripts.WrappingWebScriptRequest#getNext()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public WebScriptRequest getNext()
|
||||||
|
{
|
||||||
|
return req;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.extensions.webscripts.WebScriptRequest#forceSuccessStatus()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean forceSuccessStatus()
|
||||||
|
{
|
||||||
|
return req.forceSuccessStatus();
|
||||||
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.extensions.webscripts.WebScriptRequest#getAgent()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getAgent()
|
||||||
|
{
|
||||||
|
return req.getAgent();
|
||||||
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.extensions.webscripts.WebScriptRequest#getContent()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Content getContent()
|
||||||
|
{
|
||||||
|
final Content wrapped = req.getContent();
|
||||||
|
return new Content(){
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getContent() throws IOException
|
||||||
|
{
|
||||||
|
return wrapped.getContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getEncoding()
|
||||||
|
{
|
||||||
|
return wrapped.getEncoding();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMimetype()
|
||||||
|
{
|
||||||
|
return wrapped.getMimetype();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getSize()
|
||||||
|
{
|
||||||
|
return wrapped.getSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputStream getInputStream()
|
||||||
|
{
|
||||||
|
if (BufferedRequest.this.contentReader != null)
|
||||||
|
{
|
||||||
|
throw new IllegalStateException("Reader in use");
|
||||||
|
}
|
||||||
|
if (BufferedRequest.this.contentStream == null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
BufferedRequest.this.contentStream = bufferInputStream();
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return BufferedRequest.this.contentStream;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BufferedReader getReader() throws IOException
|
||||||
|
{
|
||||||
|
if (BufferedRequest.this.contentStream != null)
|
||||||
|
{
|
||||||
|
throw new IllegalStateException("Input Stream in use");
|
||||||
|
}
|
||||||
|
if (BufferedRequest.this.contentReader == null)
|
||||||
|
{
|
||||||
|
String encoding = wrapped.getEncoding();
|
||||||
|
InputStream in = bufferInputStream();
|
||||||
|
BufferedRequest.this.contentReader = new BufferedReader(new InputStreamReader(in, encoding == null ? "ISO-8859-1" : encoding));
|
||||||
|
}
|
||||||
|
return BufferedRequest.this.contentReader;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.extensions.webscripts.WebScriptRequest#getContentType()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getContentType()
|
||||||
|
{
|
||||||
|
return req.getContentType();
|
||||||
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.extensions.webscripts.WebScriptRequest#getContextPath()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getContextPath()
|
||||||
|
{
|
||||||
|
return req.getContextPath();
|
||||||
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.extensions.webscripts.WebScriptRequest#getExtensionPath()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getExtensionPath()
|
||||||
|
{
|
||||||
|
return req.getExtensionPath();
|
||||||
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.extensions.webscripts.WebScriptRequest#getFormat()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getFormat()
|
||||||
|
{
|
||||||
|
return req.getFormat();
|
||||||
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.extensions.webscripts.WebScriptRequest#getFormatStyle()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public FormatStyle getFormatStyle()
|
||||||
|
{
|
||||||
|
return req.getFormatStyle();
|
||||||
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.extensions.webscripts.WebScriptRequest#getHeader(java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getHeader(String name)
|
||||||
|
{
|
||||||
|
return req.getHeader(name);
|
||||||
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.extensions.webscripts.WebScriptRequest#getHeaderNames()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String[] getHeaderNames()
|
||||||
|
{
|
||||||
|
return req.getHeaderNames();
|
||||||
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.extensions.webscripts.WebScriptRequest#getHeaderValues(java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String[] getHeaderValues(String name)
|
||||||
|
{
|
||||||
|
return req.getHeaderValues(name);
|
||||||
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.extensions.webscripts.WebScriptRequest#getJSONCallback()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getJSONCallback()
|
||||||
|
{
|
||||||
|
return req.getJSONCallback();
|
||||||
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.extensions.webscripts.WebScriptRequest#getParameter(java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getParameter(String name)
|
||||||
|
{
|
||||||
|
return req.getParameter(name);
|
||||||
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.extensions.webscripts.WebScriptRequest#getParameterNames()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String[] getParameterNames()
|
||||||
|
{
|
||||||
|
return req.getParameterNames();
|
||||||
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.extensions.webscripts.WebScriptRequest#getParameterValues(java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String[] getParameterValues(String name)
|
||||||
|
{
|
||||||
|
return req.getParameterValues(name);
|
||||||
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.extensions.webscripts.WebScriptRequest#getPathInfo()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getPathInfo()
|
||||||
|
{
|
||||||
|
return req.getPathInfo();
|
||||||
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.extensions.webscripts.WebScriptRequest#getQueryString()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getQueryString()
|
||||||
|
{
|
||||||
|
return req.getQueryString();
|
||||||
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.extensions.webscripts.WebScriptRequest#getRuntime()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Runtime getRuntime()
|
||||||
|
{
|
||||||
|
return req.getRuntime();
|
||||||
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.extensions.webscripts.WebScriptRequest#getServerPath()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getServerPath()
|
||||||
|
{
|
||||||
|
return req.getServerPath();
|
||||||
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.extensions.webscripts.WebScriptRequest#getServiceContextPath()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getServiceContextPath()
|
||||||
|
{
|
||||||
|
return req.getServiceContextPath();
|
||||||
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.extensions.webscripts.WebScriptRequest#getServiceMatch()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Match getServiceMatch()
|
||||||
|
{
|
||||||
|
return req.getServiceMatch();
|
||||||
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.extensions.webscripts.WebScriptRequest#getServicePath()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getServicePath()
|
||||||
|
{
|
||||||
|
return req.getServicePath();
|
||||||
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.extensions.webscripts.WebScriptRequest#getURL()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getURL()
|
||||||
|
{
|
||||||
|
return req.getURL();
|
||||||
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.extensions.webscripts.WebScriptRequest#isGuest()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean isGuest()
|
||||||
|
{
|
||||||
|
return req.isGuest();
|
||||||
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.extensions.webscripts.WebScriptRequest#parseContent()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Object parseContent()
|
||||||
|
{
|
||||||
|
return req.parseContent();
|
||||||
|
}
|
||||||
|
}
|
231
source/java/org/alfresco/repo/web/scripts/BufferedResponse.java
Normal file
231
source/java/org/alfresco/repo/web/scripts/BufferedResponse.java
Normal file
@@ -0,0 +1,231 @@
|
|||||||
|
package org.alfresco.repo.web.scripts;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.io.Writer;
|
||||||
|
|
||||||
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.springframework.extensions.surf.util.StringBuilderWriter;
|
||||||
|
import org.springframework.extensions.webscripts.Cache;
|
||||||
|
import org.springframework.extensions.webscripts.Runtime;
|
||||||
|
import org.springframework.extensions.webscripts.WebScriptResponse;
|
||||||
|
import org.springframework.extensions.webscripts.WrappingWebScriptResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transactional Buffered Response
|
||||||
|
*/
|
||||||
|
public class BufferedResponse implements WrappingWebScriptResponse
|
||||||
|
{
|
||||||
|
// Logger
|
||||||
|
protected static final Log logger = LogFactory.getLog(BufferedResponse.class);
|
||||||
|
|
||||||
|
private WebScriptResponse res;
|
||||||
|
private int bufferSize;
|
||||||
|
private ByteArrayOutputStream outputStream = null;
|
||||||
|
private StringBuilderWriter outputWriter = null;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct
|
||||||
|
*
|
||||||
|
* @param res
|
||||||
|
* @param bufferSize
|
||||||
|
*/
|
||||||
|
public BufferedResponse(WebScriptResponse res, int bufferSize)
|
||||||
|
{
|
||||||
|
this.res = res;
|
||||||
|
this.bufferSize = bufferSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.alfresco.web.scripts.WrappingWebScriptResponse#getNext()
|
||||||
|
*/
|
||||||
|
public WebScriptResponse getNext()
|
||||||
|
{
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.alfresco.web.scripts.WebScriptResponse#addHeader(java.lang.String, java.lang.String)
|
||||||
|
*/
|
||||||
|
public void addHeader(String name, String value)
|
||||||
|
{
|
||||||
|
res.addHeader(name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.alfresco.web.scripts.WebScriptResponse#encodeScriptUrl(java.lang.String)
|
||||||
|
*/
|
||||||
|
public String encodeScriptUrl(String url)
|
||||||
|
{
|
||||||
|
return res.encodeScriptUrl(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.alfresco.web.scripts.WebScriptResponse#getEncodeScriptUrlFunction(java.lang.String)
|
||||||
|
*/
|
||||||
|
public String getEncodeScriptUrlFunction(String name)
|
||||||
|
{
|
||||||
|
return res.getEncodeScriptUrlFunction(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.extensions.webscripts.WebScriptResponse#encodeResourceUrl(java.lang.String)
|
||||||
|
*/
|
||||||
|
public String encodeResourceUrl(String url)
|
||||||
|
{
|
||||||
|
return res.encodeResourceUrl(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.extensions.webscripts.WebScriptResponse#getEncodeResourceUrlFunction(java.lang.String)
|
||||||
|
*/
|
||||||
|
public String getEncodeResourceUrlFunction(String name)
|
||||||
|
{
|
||||||
|
return res.getEncodeResourceUrlFunction(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.alfresco.web.scripts.WebScriptResponse#getOutputStream()
|
||||||
|
*/
|
||||||
|
public OutputStream getOutputStream() throws IOException
|
||||||
|
{
|
||||||
|
if (outputStream == null)
|
||||||
|
{
|
||||||
|
if (outputWriter != null)
|
||||||
|
{
|
||||||
|
throw new AlfrescoRuntimeException("Already buffering output writer");
|
||||||
|
}
|
||||||
|
this.outputStream = new ByteArrayOutputStream(bufferSize);
|
||||||
|
}
|
||||||
|
return outputStream;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.alfresco.web.scripts.WebScriptResponse#getRuntime()
|
||||||
|
*/
|
||||||
|
public Runtime getRuntime()
|
||||||
|
{
|
||||||
|
return res.getRuntime();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.alfresco.web.scripts.WebScriptResponse#getWriter()
|
||||||
|
*/
|
||||||
|
public Writer getWriter() throws IOException
|
||||||
|
{
|
||||||
|
if (outputWriter == null)
|
||||||
|
{
|
||||||
|
if (outputStream != null)
|
||||||
|
{
|
||||||
|
throw new AlfrescoRuntimeException("Already buffering output stream");
|
||||||
|
}
|
||||||
|
outputWriter = new StringBuilderWriter(bufferSize);
|
||||||
|
}
|
||||||
|
return outputWriter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.alfresco.web.scripts.WebScriptResponse#reset()
|
||||||
|
*/
|
||||||
|
public void reset()
|
||||||
|
{
|
||||||
|
if (outputStream != null)
|
||||||
|
{
|
||||||
|
outputStream.reset();
|
||||||
|
}
|
||||||
|
else if (outputWriter != null)
|
||||||
|
{
|
||||||
|
outputWriter = null;
|
||||||
|
}
|
||||||
|
res.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.alfresco.web.scripts.WebScriptResponse#setCache(org.alfresco.web.scripts.Cache)
|
||||||
|
*/
|
||||||
|
public void setCache(Cache cache)
|
||||||
|
{
|
||||||
|
res.setCache(cache);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.alfresco.web.scripts.WebScriptResponse#setContentType(java.lang.String)
|
||||||
|
*/
|
||||||
|
public void setContentType(String contentType)
|
||||||
|
{
|
||||||
|
res.setContentType(contentType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.alfresco.web.scripts.WebScriptResponse#setContentEncoding(java.lang.String)
|
||||||
|
*/
|
||||||
|
public void setContentEncoding(String contentEncoding)
|
||||||
|
{
|
||||||
|
res.setContentEncoding(contentEncoding);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.alfresco.web.scripts.WebScriptResponse#setHeader(java.lang.String, java.lang.String)
|
||||||
|
*/
|
||||||
|
public void setHeader(String name, String value)
|
||||||
|
{
|
||||||
|
res.setHeader(name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.alfresco.web.scripts.WebScriptResponse#setStatus(int)
|
||||||
|
*/
|
||||||
|
public void setStatus(int status)
|
||||||
|
{
|
||||||
|
res.setStatus(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write buffered response to underlying response
|
||||||
|
*/
|
||||||
|
public void writeResponse()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (logger.isDebugEnabled() && outputStream != null)
|
||||||
|
{
|
||||||
|
logger.debug("Writing Transactional response: size=" + outputStream.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (outputWriter != null)
|
||||||
|
{
|
||||||
|
outputWriter.flush();
|
||||||
|
res.getWriter().write(outputWriter.toString());
|
||||||
|
}
|
||||||
|
else if (outputStream != null)
|
||||||
|
{
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
logger.debug("Writing Transactional response: size=" + outputStream.size());
|
||||||
|
|
||||||
|
outputStream.flush();
|
||||||
|
outputStream.writeTo(res.getOutputStream());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
throw new AlfrescoRuntimeException("Failed to commit buffered response", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -18,14 +18,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.repo.web.scripts;
|
package org.alfresco.repo.web.scripts;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.Writer;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -33,7 +27,6 @@ import javax.servlet.http.HttpServletResponse;
|
|||||||
import javax.transaction.Status;
|
import javax.transaction.Status;
|
||||||
import javax.transaction.UserTransaction;
|
import javax.transaction.UserTransaction;
|
||||||
|
|
||||||
import org.alfresco.error.AlfrescoRuntimeException;
|
|
||||||
import org.alfresco.repo.model.Repository;
|
import org.alfresco.repo.model.Repository;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||||
@@ -48,34 +41,24 @@ import org.alfresco.service.cmr.security.AuthorityService;
|
|||||||
import org.alfresco.service.descriptor.DescriptorService;
|
import org.alfresco.service.descriptor.DescriptorService;
|
||||||
import org.alfresco.service.transaction.TransactionService;
|
import org.alfresco.service.transaction.TransactionService;
|
||||||
import org.alfresco.util.TempFileProvider;
|
import org.alfresco.util.TempFileProvider;
|
||||||
import org.apache.chemistry.opencmis.server.shared.ThresholdOutputStream;
|
|
||||||
import org.apache.chemistry.opencmis.server.shared.ThresholdOutputStreamFactory;
|
import org.apache.chemistry.opencmis.server.shared.ThresholdOutputStreamFactory;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.ApplicationEvent;
|
import org.springframework.context.ApplicationEvent;
|
||||||
import org.springframework.context.event.ContextRefreshedEvent;
|
import org.springframework.context.event.ContextRefreshedEvent;
|
||||||
import org.springframework.extensions.surf.util.Content;
|
|
||||||
import org.springframework.extensions.surf.util.StringBuilderWriter;
|
|
||||||
import org.springframework.extensions.webscripts.AbstractRuntimeContainer;
|
import org.springframework.extensions.webscripts.AbstractRuntimeContainer;
|
||||||
import org.springframework.extensions.webscripts.Authenticator;
|
import org.springframework.extensions.webscripts.Authenticator;
|
||||||
import org.springframework.extensions.webscripts.Cache;
|
|
||||||
import org.springframework.extensions.webscripts.Description;
|
import org.springframework.extensions.webscripts.Description;
|
||||||
import org.springframework.extensions.webscripts.Description.FormatStyle;
|
|
||||||
import org.springframework.extensions.webscripts.Description.RequiredAuthentication;
|
import org.springframework.extensions.webscripts.Description.RequiredAuthentication;
|
||||||
import org.springframework.extensions.webscripts.Description.RequiredTransaction;
|
import org.springframework.extensions.webscripts.Description.RequiredTransaction;
|
||||||
import org.springframework.extensions.webscripts.Description.RequiredTransactionParameters;
|
import org.springframework.extensions.webscripts.Description.RequiredTransactionParameters;
|
||||||
import org.springframework.extensions.webscripts.Description.TransactionCapability;
|
import org.springframework.extensions.webscripts.Description.TransactionCapability;
|
||||||
import org.springframework.extensions.webscripts.Match;
|
|
||||||
import org.springframework.extensions.webscripts.Runtime;
|
|
||||||
import org.springframework.extensions.webscripts.ServerModel;
|
import org.springframework.extensions.webscripts.ServerModel;
|
||||||
import org.springframework.extensions.webscripts.WebScript;
|
import org.springframework.extensions.webscripts.WebScript;
|
||||||
import org.springframework.extensions.webscripts.WebScriptException;
|
import org.springframework.extensions.webscripts.WebScriptException;
|
||||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||||
import org.springframework.extensions.webscripts.WebScriptResponse;
|
import org.springframework.extensions.webscripts.WebScriptResponse;
|
||||||
import org.springframework.extensions.webscripts.WrappingWebScriptRequest;
|
|
||||||
import org.springframework.extensions.webscripts.WrappingWebScriptResponse;
|
|
||||||
import org.springframework.util.FileCopyUtils;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -634,565 +617,4 @@ public class RepositoryContainer extends AbstractRuntimeContainer
|
|||||||
{
|
{
|
||||||
super.reset();
|
super.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Transactional Buffered Response
|
|
||||||
*/
|
|
||||||
private static class BufferedResponse implements WrappingWebScriptResponse
|
|
||||||
{
|
|
||||||
private WebScriptResponse res;
|
|
||||||
private int bufferSize;
|
|
||||||
private ByteArrayOutputStream outputStream = null;
|
|
||||||
private StringBuilderWriter outputWriter = null;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Construct
|
|
||||||
*
|
|
||||||
* @param res
|
|
||||||
* @param bufferSize
|
|
||||||
*/
|
|
||||||
public BufferedResponse(WebScriptResponse res, int bufferSize)
|
|
||||||
{
|
|
||||||
this.res = res;
|
|
||||||
this.bufferSize = bufferSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
* @see org.alfresco.web.scripts.WrappingWebScriptResponse#getNext()
|
|
||||||
*/
|
|
||||||
public WebScriptResponse getNext()
|
|
||||||
{
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
* @see org.alfresco.web.scripts.WebScriptResponse#addHeader(java.lang.String, java.lang.String)
|
|
||||||
*/
|
|
||||||
public void addHeader(String name, String value)
|
|
||||||
{
|
|
||||||
res.addHeader(name, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
* @see org.alfresco.web.scripts.WebScriptResponse#encodeScriptUrl(java.lang.String)
|
|
||||||
*/
|
|
||||||
public String encodeScriptUrl(String url)
|
|
||||||
{
|
|
||||||
return res.encodeScriptUrl(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
* @see org.alfresco.web.scripts.WebScriptResponse#getEncodeScriptUrlFunction(java.lang.String)
|
|
||||||
*/
|
|
||||||
public String getEncodeScriptUrlFunction(String name)
|
|
||||||
{
|
|
||||||
return res.getEncodeScriptUrlFunction(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.extensions.webscripts.WebScriptResponse#encodeResourceUrl(java.lang.String)
|
|
||||||
*/
|
|
||||||
public String encodeResourceUrl(String url)
|
|
||||||
{
|
|
||||||
return res.encodeResourceUrl(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.extensions.webscripts.WebScriptResponse#getEncodeResourceUrlFunction(java.lang.String)
|
|
||||||
*/
|
|
||||||
public String getEncodeResourceUrlFunction(String name)
|
|
||||||
{
|
|
||||||
return res.getEncodeResourceUrlFunction(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
* @see org.alfresco.web.scripts.WebScriptResponse#getOutputStream()
|
|
||||||
*/
|
|
||||||
public OutputStream getOutputStream() throws IOException
|
|
||||||
{
|
|
||||||
if (outputStream == null)
|
|
||||||
{
|
|
||||||
if (outputWriter != null)
|
|
||||||
{
|
|
||||||
throw new AlfrescoRuntimeException("Already buffering output writer");
|
|
||||||
}
|
|
||||||
this.outputStream = new ByteArrayOutputStream(bufferSize);
|
|
||||||
}
|
|
||||||
return outputStream;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
* @see org.alfresco.web.scripts.WebScriptResponse#getRuntime()
|
|
||||||
*/
|
|
||||||
public Runtime getRuntime()
|
|
||||||
{
|
|
||||||
return res.getRuntime();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
* @see org.alfresco.web.scripts.WebScriptResponse#getWriter()
|
|
||||||
*/
|
|
||||||
public Writer getWriter() throws IOException
|
|
||||||
{
|
|
||||||
if (outputWriter == null)
|
|
||||||
{
|
|
||||||
if (outputStream != null)
|
|
||||||
{
|
|
||||||
throw new AlfrescoRuntimeException("Already buffering output stream");
|
|
||||||
}
|
|
||||||
outputWriter = new StringBuilderWriter(bufferSize);
|
|
||||||
}
|
|
||||||
return outputWriter;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
* @see org.alfresco.web.scripts.WebScriptResponse#reset()
|
|
||||||
*/
|
|
||||||
public void reset()
|
|
||||||
{
|
|
||||||
if (outputStream != null)
|
|
||||||
{
|
|
||||||
outputStream.reset();
|
|
||||||
}
|
|
||||||
else if (outputWriter != null)
|
|
||||||
{
|
|
||||||
outputWriter = null;
|
|
||||||
}
|
|
||||||
res.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
* @see org.alfresco.web.scripts.WebScriptResponse#setCache(org.alfresco.web.scripts.Cache)
|
|
||||||
*/
|
|
||||||
public void setCache(Cache cache)
|
|
||||||
{
|
|
||||||
res.setCache(cache);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
* @see org.alfresco.web.scripts.WebScriptResponse#setContentType(java.lang.String)
|
|
||||||
*/
|
|
||||||
public void setContentType(String contentType)
|
|
||||||
{
|
|
||||||
res.setContentType(contentType);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
* @see org.alfresco.web.scripts.WebScriptResponse#setContentEncoding(java.lang.String)
|
|
||||||
*/
|
|
||||||
public void setContentEncoding(String contentEncoding)
|
|
||||||
{
|
|
||||||
res.setContentEncoding(contentEncoding);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
* @see org.alfresco.web.scripts.WebScriptResponse#setHeader(java.lang.String, java.lang.String)
|
|
||||||
*/
|
|
||||||
public void setHeader(String name, String value)
|
|
||||||
{
|
|
||||||
res.setHeader(name, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
* @see org.alfresco.web.scripts.WebScriptResponse#setStatus(int)
|
|
||||||
*/
|
|
||||||
public void setStatus(int status)
|
|
||||||
{
|
|
||||||
res.setStatus(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write buffered response to underlying response
|
|
||||||
*/
|
|
||||||
private void writeResponse()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (logger.isDebugEnabled() && outputStream != null)
|
|
||||||
{
|
|
||||||
logger.debug("Writing Transactional response: size=" + outputStream.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (outputWriter != null)
|
|
||||||
{
|
|
||||||
outputWriter.flush();
|
|
||||||
res.getWriter().write(outputWriter.toString());
|
|
||||||
}
|
|
||||||
else if (outputStream != null)
|
|
||||||
{
|
|
||||||
if (logger.isDebugEnabled())
|
|
||||||
logger.debug("Writing Transactional response: size=" + outputStream.size());
|
|
||||||
|
|
||||||
outputStream.flush();
|
|
||||||
outputStream.writeTo(res.getOutputStream());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
throw new AlfrescoRuntimeException("Failed to commit buffered response", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class BufferedRequest implements WrappingWebScriptRequest
|
|
||||||
{
|
|
||||||
private ThresholdOutputStreamFactory streamFactory;
|
|
||||||
private WebScriptRequest req;
|
|
||||||
private File requestBody;
|
|
||||||
private InputStream contentStream;
|
|
||||||
private BufferedReader contentReader;
|
|
||||||
|
|
||||||
public BufferedRequest(WebScriptRequest req, ThresholdOutputStreamFactory streamFactory)
|
|
||||||
{
|
|
||||||
this.req = req;
|
|
||||||
this.streamFactory = streamFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
private InputStream bufferInputStream() throws IOException
|
|
||||||
{
|
|
||||||
ThresholdOutputStream bufferStream = streamFactory.newOutputStream();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
FileCopyUtils.copy(req.getContent().getInputStream(), bufferStream);
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
bufferStream.destroy(); // remove temp file
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
return bufferStream.getInputStream();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reset()
|
|
||||||
{
|
|
||||||
if (contentStream != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
contentStream.close();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
contentStream = null;
|
|
||||||
}
|
|
||||||
if (contentReader != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
contentReader.close();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
contentReader = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void close()
|
|
||||||
{
|
|
||||||
reset();
|
|
||||||
if (requestBody != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
requestBody.delete();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
requestBody = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.extensions.webscripts.WrappingWebScriptRequest#getNext()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public WebScriptRequest getNext()
|
|
||||||
{
|
|
||||||
return req;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.extensions.webscripts.WebScriptRequest#forceSuccessStatus()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean forceSuccessStatus()
|
|
||||||
{
|
|
||||||
return req.forceSuccessStatus();
|
|
||||||
}
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.extensions.webscripts.WebScriptRequest#getAgent()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getAgent()
|
|
||||||
{
|
|
||||||
return req.getAgent();
|
|
||||||
}
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.extensions.webscripts.WebScriptRequest#getContent()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Content getContent()
|
|
||||||
{
|
|
||||||
final Content wrapped = req.getContent();
|
|
||||||
return new Content(){
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getContent() throws IOException
|
|
||||||
{
|
|
||||||
return wrapped.getContent();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getEncoding()
|
|
||||||
{
|
|
||||||
return wrapped.getEncoding();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getMimetype()
|
|
||||||
{
|
|
||||||
return wrapped.getMimetype();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getSize()
|
|
||||||
{
|
|
||||||
return wrapped.getSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public InputStream getInputStream()
|
|
||||||
{
|
|
||||||
if (BufferedRequest.this.contentReader != null)
|
|
||||||
{
|
|
||||||
throw new IllegalStateException("Reader in use");
|
|
||||||
}
|
|
||||||
if (BufferedRequest.this.contentStream == null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
BufferedRequest.this.contentStream = bufferInputStream();
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return BufferedRequest.this.contentStream;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BufferedReader getReader() throws IOException
|
|
||||||
{
|
|
||||||
if (BufferedRequest.this.contentStream != null)
|
|
||||||
{
|
|
||||||
throw new IllegalStateException("Input Stream in use");
|
|
||||||
}
|
|
||||||
if (BufferedRequest.this.contentReader == null)
|
|
||||||
{
|
|
||||||
String encoding = wrapped.getEncoding();
|
|
||||||
InputStream in = bufferInputStream();
|
|
||||||
BufferedRequest.this.contentReader = new BufferedReader(new InputStreamReader(in, encoding == null ? "ISO-8859-1" : encoding));
|
|
||||||
}
|
|
||||||
return BufferedRequest.this.contentReader;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.extensions.webscripts.WebScriptRequest#getContentType()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getContentType()
|
|
||||||
{
|
|
||||||
return req.getContentType();
|
|
||||||
}
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.extensions.webscripts.WebScriptRequest#getContextPath()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getContextPath()
|
|
||||||
{
|
|
||||||
return req.getContextPath();
|
|
||||||
}
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.extensions.webscripts.WebScriptRequest#getExtensionPath()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getExtensionPath()
|
|
||||||
{
|
|
||||||
return req.getExtensionPath();
|
|
||||||
}
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.extensions.webscripts.WebScriptRequest#getFormat()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getFormat()
|
|
||||||
{
|
|
||||||
return req.getFormat();
|
|
||||||
}
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.extensions.webscripts.WebScriptRequest#getFormatStyle()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public FormatStyle getFormatStyle()
|
|
||||||
{
|
|
||||||
return req.getFormatStyle();
|
|
||||||
}
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.extensions.webscripts.WebScriptRequest#getHeader(java.lang.String)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getHeader(String name)
|
|
||||||
{
|
|
||||||
return req.getHeader(name);
|
|
||||||
}
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.extensions.webscripts.WebScriptRequest#getHeaderNames()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String[] getHeaderNames()
|
|
||||||
{
|
|
||||||
return req.getHeaderNames();
|
|
||||||
}
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.extensions.webscripts.WebScriptRequest#getHeaderValues(java.lang.String)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String[] getHeaderValues(String name)
|
|
||||||
{
|
|
||||||
return req.getHeaderValues(name);
|
|
||||||
}
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.extensions.webscripts.WebScriptRequest#getJSONCallback()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getJSONCallback()
|
|
||||||
{
|
|
||||||
return req.getJSONCallback();
|
|
||||||
}
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.extensions.webscripts.WebScriptRequest#getParameter(java.lang.String)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getParameter(String name)
|
|
||||||
{
|
|
||||||
return req.getParameter(name);
|
|
||||||
}
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.extensions.webscripts.WebScriptRequest#getParameterNames()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String[] getParameterNames()
|
|
||||||
{
|
|
||||||
return req.getParameterNames();
|
|
||||||
}
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.extensions.webscripts.WebScriptRequest#getParameterValues(java.lang.String)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String[] getParameterValues(String name)
|
|
||||||
{
|
|
||||||
return req.getParameterValues(name);
|
|
||||||
}
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.extensions.webscripts.WebScriptRequest#getPathInfo()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getPathInfo()
|
|
||||||
{
|
|
||||||
return req.getPathInfo();
|
|
||||||
}
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.extensions.webscripts.WebScriptRequest#getQueryString()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getQueryString()
|
|
||||||
{
|
|
||||||
return req.getQueryString();
|
|
||||||
}
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.extensions.webscripts.WebScriptRequest#getRuntime()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Runtime getRuntime()
|
|
||||||
{
|
|
||||||
return req.getRuntime();
|
|
||||||
}
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.extensions.webscripts.WebScriptRequest#getServerPath()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getServerPath()
|
|
||||||
{
|
|
||||||
return req.getServerPath();
|
|
||||||
}
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.extensions.webscripts.WebScriptRequest#getServiceContextPath()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getServiceContextPath()
|
|
||||||
{
|
|
||||||
return req.getServiceContextPath();
|
|
||||||
}
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.extensions.webscripts.WebScriptRequest#getServiceMatch()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Match getServiceMatch()
|
|
||||||
{
|
|
||||||
return req.getServiceMatch();
|
|
||||||
}
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.extensions.webscripts.WebScriptRequest#getServicePath()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getServicePath()
|
|
||||||
{
|
|
||||||
return req.getServicePath();
|
|
||||||
}
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.extensions.webscripts.WebScriptRequest#getURL()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getURL()
|
|
||||||
{
|
|
||||||
return req.getURL();
|
|
||||||
}
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.extensions.webscripts.WebScriptRequest#isGuest()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean isGuest()
|
|
||||||
{
|
|
||||||
return req.isGuest();
|
|
||||||
}
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.extensions.webscripts.WebScriptRequest#parseContent()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Object parseContent()
|
|
||||||
{
|
|
||||||
return req.parseContent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -4,34 +4,30 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
import org.alfresco.repo.tenant.TenantUtil;
|
import org.alfresco.repo.tenant.TenantUtil;
|
||||||
|
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||||
import org.alfresco.rest.api.model.PersonNetwork;
|
import org.alfresco.rest.api.model.PersonNetwork;
|
||||||
import org.alfresco.rest.api.networks.NetworksEntityResource;
|
import org.alfresco.rest.api.networks.NetworksEntityResource;
|
||||||
import org.alfresco.rest.framework.Api;
|
import org.alfresco.rest.framework.Api;
|
||||||
|
import org.alfresco.rest.framework.core.exceptions.ApiException;
|
||||||
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
|
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
|
||||||
import org.alfresco.rest.framework.jacksonextensions.JacksonHelper;
|
|
||||||
import org.alfresco.rest.framework.jacksonextensions.JacksonHelper.Writer;
|
import org.alfresco.rest.framework.jacksonextensions.JacksonHelper.Writer;
|
||||||
import org.alfresco.rest.framework.resource.parameters.Params;
|
import org.alfresco.rest.framework.resource.parameters.Params;
|
||||||
|
import org.alfresco.rest.framework.webscripts.ApiWebScript;
|
||||||
import org.alfresco.rest.framework.webscripts.ResourceWebScriptHelper;
|
import org.alfresco.rest.framework.webscripts.ResourceWebScriptHelper;
|
||||||
import org.codehaus.jackson.JsonGenerationException;
|
import org.codehaus.jackson.JsonGenerationException;
|
||||||
import org.codehaus.jackson.JsonGenerator;
|
import org.codehaus.jackson.JsonGenerator;
|
||||||
import org.codehaus.jackson.map.JsonMappingException;
|
import org.codehaus.jackson.map.JsonMappingException;
|
||||||
import org.codehaus.jackson.map.ObjectMapper;
|
import org.codehaus.jackson.map.ObjectMapper;
|
||||||
import org.springframework.extensions.webscripts.AbstractWebScript;
|
|
||||||
import org.springframework.extensions.webscripts.Format;
|
import org.springframework.extensions.webscripts.Format;
|
||||||
|
import org.springframework.extensions.webscripts.WebScriptException;
|
||||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||||
import org.springframework.extensions.webscripts.WebScriptResponse;
|
import org.springframework.extensions.webscripts.WebScriptResponse;
|
||||||
|
|
||||||
public class NetworkWebScriptGet extends AbstractWebScript
|
public class NetworkWebScriptGet extends ApiWebScript
|
||||||
{
|
{
|
||||||
private Networks networks;
|
private Networks networks;
|
||||||
private JacksonHelper jsonHelper;
|
|
||||||
private ResourceWebScriptHelper helper;
|
private ResourceWebScriptHelper helper;
|
||||||
|
|
||||||
public void setJsonHelper(JacksonHelper jsonHelper)
|
|
||||||
{
|
|
||||||
this.jsonHelper = jsonHelper;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHelper(ResourceWebScriptHelper helper)
|
public void setHelper(ResourceWebScriptHelper helper)
|
||||||
{
|
{
|
||||||
this.helper = helper;
|
this.helper = helper;
|
||||||
@@ -42,36 +38,60 @@ public class NetworkWebScriptGet extends AbstractWebScript
|
|||||||
this.networks = networks;
|
this.networks = networks;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(final WebScriptRequest req, WebScriptResponse res) throws IOException
|
public void execute(final Api api, final WebScriptRequest req, final WebScriptResponse res) throws IOException
|
||||||
{
|
{
|
||||||
// apply content type
|
try
|
||||||
res.setContentType(Format.JSON.mimetype() + ";charset=UTF-8");
|
|
||||||
|
|
||||||
jsonHelper.withWriter(res.getOutputStream(), new Writer()
|
|
||||||
{
|
{
|
||||||
@Override
|
transactionService.getRetryingTransactionHelper().doInTransaction(
|
||||||
public void writeContents(JsonGenerator generator, ObjectMapper objectMapper)
|
new RetryingTransactionCallback<Void>()
|
||||||
throws JsonGenerationException, JsonMappingException, IOException
|
|
||||||
{
|
{
|
||||||
String personId = AuthenticationUtil.getFullyAuthenticatedUser();
|
@Override
|
||||||
String networkId = TenantUtil.getCurrentDomain();
|
public Void execute() throws Throwable
|
||||||
|
{
|
||||||
PersonNetwork networkMembership = networks.getNetwork(personId, networkId);
|
// apply content type
|
||||||
if(networkMembership != null)
|
res.setContentType(Format.JSON.mimetype() + ";charset=UTF-8");
|
||||||
{
|
|
||||||
// TODO this is not ideal, but the only way to populate the embedded network entities (this would normally be
|
jsonHelper.withWriter(res.getOutputStream(), new Writer()
|
||||||
// done automatically by the api framework).
|
{
|
||||||
Object wrapped = helper.postProcessResponse(Api.ALFRESCO_PUBLIC, NetworksEntityResource.NAME, Params.valueOf(personId, null), networkMembership);
|
@Override
|
||||||
|
public void writeContents(JsonGenerator generator, ObjectMapper objectMapper)
|
||||||
objectMapper.writeValue(generator, wrapped);
|
throws JsonGenerationException, JsonMappingException, IOException
|
||||||
}
|
{
|
||||||
else
|
String personId = AuthenticationUtil.getFullyAuthenticatedUser();
|
||||||
{
|
String networkId = TenantUtil.getCurrentDomain();
|
||||||
throw new EntityNotFoundException(networkId);
|
|
||||||
}
|
PersonNetwork networkMembership = networks.getNetwork(personId, networkId);
|
||||||
}
|
if(networkMembership != null)
|
||||||
});
|
{
|
||||||
}
|
// 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), networkMembership);
|
||||||
|
|
||||||
|
objectMapper.writeValue(generator, wrapped);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new EntityNotFoundException(networkId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}, true, true);
|
||||||
|
}
|
||||||
|
catch (ApiException apiException)
|
||||||
|
{
|
||||||
|
renderErrorResponse(resolveException(apiException), res);
|
||||||
|
}
|
||||||
|
catch (WebScriptException webException)
|
||||||
|
{
|
||||||
|
renderErrorResponse(resolveException(webException), res);
|
||||||
|
}
|
||||||
|
catch (RuntimeException runtimeException)
|
||||||
|
{
|
||||||
|
renderErrorResponse(resolveException(runtimeException), res);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -23,21 +23,23 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
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.model.PersonNetwork;
|
||||||
import org.alfresco.rest.api.networks.NetworksEntityResource;
|
import org.alfresco.rest.api.networks.NetworksEntityResource;
|
||||||
import org.alfresco.rest.framework.Api;
|
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.jacksonextensions.JacksonHelper.Writer;
|
||||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||||
import org.alfresco.rest.framework.resource.parameters.Paging;
|
import org.alfresco.rest.framework.resource.parameters.Paging;
|
||||||
import org.alfresco.rest.framework.resource.parameters.Params;
|
import org.alfresco.rest.framework.resource.parameters.Params;
|
||||||
|
import org.alfresco.rest.framework.webscripts.ApiWebScript;
|
||||||
import org.alfresco.rest.framework.webscripts.ResourceWebScriptHelper;
|
import org.alfresco.rest.framework.webscripts.ResourceWebScriptHelper;
|
||||||
import org.codehaus.jackson.JsonGenerationException;
|
import org.codehaus.jackson.JsonGenerationException;
|
||||||
import org.codehaus.jackson.JsonGenerator;
|
import org.codehaus.jackson.JsonGenerator;
|
||||||
import org.codehaus.jackson.map.JsonMappingException;
|
import org.codehaus.jackson.map.JsonMappingException;
|
||||||
import org.codehaus.jackson.map.ObjectMapper;
|
import org.codehaus.jackson.map.ObjectMapper;
|
||||||
import org.springframework.extensions.webscripts.AbstractWebScript;
|
|
||||||
import org.springframework.extensions.webscripts.Format;
|
import org.springframework.extensions.webscripts.Format;
|
||||||
|
import org.springframework.extensions.webscripts.WebScriptException;
|
||||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||||
import org.springframework.extensions.webscripts.WebScriptResponse;
|
import org.springframework.extensions.webscripts.WebScriptResponse;
|
||||||
|
|
||||||
@@ -47,17 +49,11 @@ import org.springframework.extensions.webscripts.WebScriptResponse;
|
|||||||
* @author steveglover
|
* @author steveglover
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class NetworksWebScriptGet extends AbstractWebScript
|
public class NetworksWebScriptGet extends ApiWebScript
|
||||||
{
|
{
|
||||||
private Networks networks;
|
private Networks networks;
|
||||||
private JacksonHelper jsonHelper;
|
|
||||||
private ResourceWebScriptHelper helper;
|
private ResourceWebScriptHelper helper;
|
||||||
|
|
||||||
public void setJsonHelper(JacksonHelper jsonHelper)
|
|
||||||
{
|
|
||||||
this.jsonHelper = jsonHelper;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHelper(ResourceWebScriptHelper helper)
|
public void setHelper(ResourceWebScriptHelper helper)
|
||||||
{
|
{
|
||||||
this.helper = helper;
|
this.helper = helper;
|
||||||
@@ -68,35 +64,60 @@ public class NetworksWebScriptGet extends AbstractWebScript
|
|||||||
this.networks = networks;
|
this.networks = networks;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException
|
public void execute(final Api api, final WebScriptRequest req, final WebScriptResponse res) throws IOException
|
||||||
{
|
{
|
||||||
final Paging paging = ResourceWebScriptHelper.findPaging(req);
|
try
|
||||||
|
|
||||||
// apply content type
|
|
||||||
res.setContentType(Format.JSON.mimetype() + ";charset=UTF-8");
|
|
||||||
|
|
||||||
jsonHelper.withWriter(res.getOutputStream(), new Writer()
|
|
||||||
{
|
{
|
||||||
@Override
|
transactionService.getRetryingTransactionHelper().doInTransaction(
|
||||||
public void writeContents(JsonGenerator generator, ObjectMapper objectMapper)
|
new RetryingTransactionCallback<Void>()
|
||||||
throws JsonGenerationException, JsonMappingException, IOException
|
|
||||||
{
|
{
|
||||||
List<Object> entities = new ArrayList<Object>();
|
@Override
|
||||||
|
public Void execute() throws Throwable
|
||||||
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
|
final Paging paging = ResourceWebScriptHelper.findPaging(req);
|
||||||
// done automatically by the api framework).
|
|
||||||
Object wrapped = helper.postProcessResponse(Api.ALFRESCO_PUBLIC, NetworksEntityResource.NAME, Params.valueOf(personId, null), networkMember);
|
// apply content type
|
||||||
entities.add(wrapped);
|
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;
|
||||||
}
|
}
|
||||||
|
}, true, true);
|
||||||
objectMapper.writeValue(generator, CollectionWithPagingInfo.asPaged(paging, entities));
|
}
|
||||||
}
|
catch (ApiException apiException)
|
||||||
});
|
{
|
||||||
}
|
renderErrorResponse(resolveException(apiException), res);
|
||||||
|
}
|
||||||
|
catch (WebScriptException webException)
|
||||||
|
{
|
||||||
|
renderErrorResponse(resolveException(webException), res);
|
||||||
|
}
|
||||||
|
catch (RuntimeException runtimeException)
|
||||||
|
{
|
||||||
|
renderErrorResponse(resolveException(runtimeException), res);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@@ -18,7 +18,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.rest.api;
|
package org.alfresco.rest.api;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -62,13 +61,19 @@ public class PublicApiDeclarativeRegistry extends DeclarativeRegistry
|
|||||||
{
|
{
|
||||||
if(method.equalsIgnoreCase("get") && uri.equals(PublicApiTenantWebScriptServletRequest.NETWORKS_PATH))
|
if(method.equalsIgnoreCase("get") && uri.equals(PublicApiTenantWebScriptServletRequest.NETWORKS_PATH))
|
||||||
{
|
{
|
||||||
Map<String, String> templateVars = Collections.emptyMap();
|
Map<String, String> templateVars = new HashMap<String, String>();
|
||||||
|
templateVars.put("apiScope", "public");
|
||||||
|
templateVars.put("apiVersion", "1");
|
||||||
|
templateVars.put("apiName", "networks");
|
||||||
Match match = new Match("", templateVars, "", getNetworksWebScript);
|
Match match = new Match("", templateVars, "", getNetworksWebScript);
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
else if(method.equalsIgnoreCase("get") && uri.equals(PublicApiTenantWebScriptServletRequest.NETWORK_PATH))
|
else if(method.equalsIgnoreCase("get") && uri.equals(PublicApiTenantWebScriptServletRequest.NETWORK_PATH))
|
||||||
{
|
{
|
||||||
Map<String, String> templateVars = new HashMap<String, String>();
|
Map<String, String> templateVars = new HashMap<String, String>();
|
||||||
|
templateVars.put("apiScope", "public");
|
||||||
|
templateVars.put("apiVersion", "1");
|
||||||
|
templateVars.put("apiName", "network");
|
||||||
Match match = new Match("", templateVars, "", getNetworkWebScript);
|
Match match = new Match("", templateVars, "", getNetworkWebScript);
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
|
@@ -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.FileBinaryResource;
|
||||||
import org.alfresco.rest.framework.resource.content.NodeBinaryResource;
|
import org.alfresco.rest.framework.resource.content.NodeBinaryResource;
|
||||||
import org.alfresco.rest.framework.resource.parameters.Params;
|
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.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.codehaus.jackson.JsonGenerationException;
|
import org.codehaus.jackson.JsonGenerationException;
|
||||||
@@ -52,7 +51,6 @@ public abstract class AbstractResourceWebScript extends ApiWebScript implements
|
|||||||
private ParamsExtractor paramsExtractor;
|
private ParamsExtractor paramsExtractor;
|
||||||
private ContentStreamer streamer;
|
private ContentStreamer streamer;
|
||||||
protected ResourceWebScriptHelper helper;
|
protected ResourceWebScriptHelper helper;
|
||||||
protected TransactionService transactionService;
|
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
@Override
|
@Override
|
||||||
@@ -60,13 +58,12 @@ public abstract class AbstractResourceWebScript extends ApiWebScript implements
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
final Map<String, Object> respons = new HashMap<String, Object>();
|
final Map<String, Object> respons = new HashMap<String, Object>();
|
||||||
final Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
|
final Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
|
||||||
final ResourceWithMetadata resource = locator.locateResource(api,templateVars, httpMethod);
|
final ResourceWithMetadata resource = locator.locateResource(api,templateVars, httpMethod);
|
||||||
final Params params = paramsExtractor.extractParams(resource.getMetaData(),req);
|
final Params params = paramsExtractor.extractParams(resource.getMetaData(),req);
|
||||||
final ActionExecutor executor = findExecutor(httpMethod, params, resource, req.getContentType());
|
final ActionExecutor executor = findExecutor(httpMethod, params, resource, req.getContentType());
|
||||||
|
|
||||||
//This execution usually takes place in a Retrying Transaction (see subclasses)
|
//This execution usually takes place in a Retrying Transaction (see subclasses)
|
||||||
executor.execute(resource, params, new ExecutionCallback()
|
executor.execute(resource, params, new ExecutionCallback()
|
||||||
{
|
{
|
||||||
@@ -172,11 +169,6 @@ public abstract class AbstractResourceWebScript extends ApiWebScript implements
|
|||||||
//Ignore all params and return this
|
//Ignore all params and return this
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTransactionService(TransactionService transactionService)
|
|
||||||
{
|
|
||||||
this.transactionService = transactionService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLocator(ResourceLocator locator)
|
public void setLocator(ResourceLocator locator)
|
||||||
{
|
{
|
||||||
|
@@ -1,8 +1,11 @@
|
|||||||
package org.alfresco.rest.framework.webscripts;
|
package org.alfresco.rest.framework.webscripts;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
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.Api;
|
||||||
import org.alfresco.rest.framework.core.exceptions.DefaultExceptionResolver;
|
import org.alfresco.rest.framework.core.exceptions.DefaultExceptionResolver;
|
||||||
import org.alfresco.rest.framework.core.exceptions.ErrorResponse;
|
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.jacksonextensions.JacksonHelper.Writer;
|
||||||
import org.alfresco.rest.framework.resource.content.ContentInfo;
|
import org.alfresco.rest.framework.resource.content.ContentInfo;
|
||||||
import org.alfresco.rest.framework.resource.content.ContentInfoImpl;
|
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.JsonGenerationException;
|
||||||
import org.codehaus.jackson.JsonGenerator;
|
import org.codehaus.jackson.JsonGenerator;
|
||||||
import org.codehaus.jackson.map.JsonMappingException;
|
import org.codehaus.jackson.map.JsonMappingException;
|
||||||
@@ -36,6 +42,54 @@ public abstract class ApiWebScript extends AbstractWebScript
|
|||||||
ExceptionResolver<Exception> defaultResolver = new DefaultExceptionResolver();
|
ExceptionResolver<Exception> defaultResolver = new DefaultExceptionResolver();
|
||||||
ExceptionResolver<Exception> resolver;
|
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 String UTF8 = "UTF-8";
|
||||||
public final static Cache CACHE_NEVER = new Cache(new RequiredCache()
|
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();
|
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
|
||||||
Api api = determineApi(templateVars);
|
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)
|
private Api determineApi(Map<String, String> templateVars)
|
||||||
@@ -85,6 +160,20 @@ public abstract class ApiWebScript extends AbstractWebScript
|
|||||||
return error;
|
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;
|
public abstract void execute(final Api api, WebScriptRequest req, WebScriptResponse res) throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -405,5 +405,21 @@ public class TestNetworks extends EnterpriseTestApi
|
|||||||
Person ret = peopleProxy.getPerson(person31.getId());
|
Person ret = peopleProxy.getPerson(person31.getId());
|
||||||
person31.expected(ret);
|
person31.expected(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ALF-20216, ALF-20217, ALF-20098
|
||||||
|
// http://localhost:8080/alfresco/api/-default-
|
||||||
|
@Test
|
||||||
|
public void testALF20098() throws Exception
|
||||||
|
{
|
||||||
|
final TestNetwork testAccount = getTestFixture().getRandomNetwork();
|
||||||
|
Iterator<TestPerson> personIt = testAccount.getPeople().iterator();
|
||||||
|
final TestPerson person = personIt.next();
|
||||||
|
|
||||||
|
RequestContext rc = new RequestContext("-default-", person.getId());
|
||||||
|
publicApiClient.setRequestContext(rc);
|
||||||
|
|
||||||
|
HttpResponse response = publicApiClient.get("/-default-", null);
|
||||||
|
assertEquals(200, response.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user