Merged HEAD (5.2) to 5.2.N (5.2.1)

126380 jkaabimofrad: Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2)
      120084 jkaabimofrad: RA-640, RA-681: made "update node content" API to return the default JSON representation of the file node. Also added a test.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@126726 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Ancuta Morarasu
2016-05-11 10:53:26 +00:00
parent 79848e45da
commit 5fbede5332
12 changed files with 306 additions and 79 deletions

View File

@@ -33,6 +33,7 @@ import org.apache.commons.httpclient.methods.DeleteMethod;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.PutMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
@@ -81,16 +82,21 @@ public class HttpResponse
{
requestType = "GET";
}
else if(method instanceof PutMethod)
{
requestType = "PUT";
StringRequestEntity requestEntity = (StringRequestEntity)((PutMethod)method).getRequestEntity();
if(requestEntity != null)
{
requestBody = requestEntity.getContent();
}
}
else if(method instanceof PostMethod)
else if (method instanceof PutMethod)
{
requestType = "PUT";
RequestEntity requestEntity = ((PutMethod) method).getRequestEntity();
if (requestEntity instanceof StringRequestEntity)
{
StringRequestEntity stringRequestEntity = (StringRequestEntity) requestEntity;
requestBody = stringRequestEntity.getContent();
}
else if (requestEntity != null)
{
requestBody = requestEntity.toString();
}
}
else if(method instanceof PostMethod)
{
requestType = "POST";
StringRequestEntity requestEntity = (StringRequestEntity)((PostMethod)method).getRequestEntity();

View File

@@ -39,6 +39,7 @@ import javax.servlet.http.HttpServletResponse;
import org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl;
import org.alfresco.opencmis.CMISDispatcherRegistry.Binding;
import org.alfresco.rest.api.tests.client.PublicApiHttpClient.BinaryPayload;
import org.alfresco.rest.api.tests.client.data.Activities;
import org.alfresco.rest.api.tests.client.data.Activity;
import org.alfresco.rest.api.tests.client.data.CMISNode;
@@ -548,7 +549,18 @@ public class PublicApiClient
return response;
}
public HttpResponse putBinary(String scope, int version, String entityCollectionName, Object entityId, String relationCollectionName,
Object relationshipEntityId, BinaryPayload payload, Map<String, String> params) throws IOException
{
HttpResponse response = client.putBinary(getRequestContext(), scope, version, entityCollectionName, entityId, relationCollectionName, relationshipEntityId,
payload, params);
logger.debug(response.toString());
return response;
}
public HttpResponse delete(String scope, String entityCollectionName, Object entityId, String relationCollectionName, Object relationshipEntityId) throws IOException
{
HttpResponse response = client.delete(getRequestContext(), scope, entityCollectionName, entityId, relationCollectionName, relationshipEntityId);

View File

@@ -26,7 +26,12 @@
package org.alfresco.rest.api.tests.client;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.MessageFormat;
@@ -55,6 +60,7 @@ import org.apache.commons.httpclient.methods.HeadMethod;
import org.apache.commons.httpclient.methods.OptionsMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.PutMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.commons.httpclient.methods.TraceMethod;
import org.apache.commons.logging.Log;
@@ -570,6 +576,23 @@ public class PublicApiHttpClient
return submitRequest(req, rq);
}
public HttpResponse putBinary(final RequestContext rq, final String scope, final int version, final String entityCollectionName,
final Object entityId, final String relationCollectionName, final Object relationshipEntityId, final BinaryPayload payload,
final Map<String, String> params) throws IOException
{
RestApiEndpoint endpoint = new RestApiEndpoint(rq.getNetworkId(), scope, version, entityCollectionName, entityId, relationCollectionName,
relationshipEntityId, params);
String url = endpoint.getUrl();
PutMethod req = new PutMethod(url);
if (payload != null)
{
BinaryRequestEntity requestEntity = new BinaryRequestEntity(payload.getFile(), payload.getMimeType(), payload.getCharset());
req.setRequestEntity(requestEntity);
}
return submitRequest(req, rq);
}
/*
* Encapsulates information relating to a rest api end point, generating and
* encoding urls based on the rest api implementation class.
@@ -824,4 +847,100 @@ public class PublicApiHttpClient
return url;
}
}
/**
* @author Jamal Kaabi-Mofrad
*/
public static class BinaryRequestEntity implements RequestEntity
{
private final File file;
private final String mimeType;
private final String charset;
public BinaryRequestEntity(File file, String mimeType, String charset)
{
this.file = file;
this.mimeType = (mimeType == null) ? "application/octet-stream" : mimeType;
this.charset = (charset == null) ? "UTF-8" : charset;
}
@Override
public boolean isRepeatable()
{
return true;
}
@Override
public void writeRequest(OutputStream out) throws IOException
{
InputStream inputStream = new BufferedInputStream(new FileInputStream(file));
try
{
int len;
byte[] buffer = new byte[8190];
while ((len = inputStream.read(buffer)) != -1)
{
out.write(buffer, 0, len);
}
}
finally
{
inputStream.close();
}
}
@Override
public long getContentLength()
{
return file.length();
}
@Override
public String getContentType()
{
return mimeType + "; " + charset;
}
}
/**
* @author Jamal Kaabi-Mofrad
*/
public static class BinaryPayload
{
private File file;
private String mimeType;
private String charset;
public BinaryPayload(File file, String mimeType, String charset)
{
this.file = file;
this.mimeType = mimeType;
this.charset = charset;
}
public BinaryPayload(File file, String mimeType)
{
this(file, mimeType, null);
}
public BinaryPayload(File file)
{
this(file, null, null);
}
public File getFile()
{
return file;
}
public String getMimeType()
{
return mimeType;
}
public String getCharset()
{
return charset;
}
}
}