mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged HEAD-BUG-FIX (5.1/Cloud) to HEAD (5.1/Cloud)
104025: Merged 5.0.N (5.0.2) to HEAD-BUG-FIX (5.1/Cloud) 103975: MNT-13938: Public API does not set any HTTP caching headers git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@104120 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -80,6 +80,10 @@ public abstract class AbstractResourceWebScript extends ApiWebScript implements
|
|||||||
Object toSerialize = respons.get("toSerialize");
|
Object toSerialize = respons.get("toSerialize");
|
||||||
ContentInfo contentInfo = (ContentInfo) respons.get("contentInfo");
|
ContentInfo contentInfo = (ContentInfo) respons.get("contentInfo");
|
||||||
|
|
||||||
|
// set caching (MNT-13938)
|
||||||
|
res.setCache(ApiWebScript.CACHE_NEVER);
|
||||||
|
|
||||||
|
// set content info
|
||||||
setContentInfoOnResponse(res, contentInfo);
|
setContentInfoOnResponse(res, contentInfo);
|
||||||
|
|
||||||
if (toSerialize != null)
|
if (toSerialize != null)
|
||||||
|
@@ -28,7 +28,8 @@ import org.junit.runners.Suite;
|
|||||||
TestSiteMembershipRequests.class,
|
TestSiteMembershipRequests.class,
|
||||||
TestFavourites.class,
|
TestFavourites.class,
|
||||||
TestRemovePermissions.class,
|
TestRemovePermissions.class,
|
||||||
TestPublicApi128.class
|
TestPublicApi128.class,
|
||||||
|
TestPublicApiCaching.class
|
||||||
})
|
})
|
||||||
public class ApiTest
|
public class ApiTest
|
||||||
{
|
{
|
||||||
|
@@ -0,0 +1,60 @@
|
|||||||
|
package org.alfresco.rest.api.tests;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.alfresco.rest.api.tests.RepoService.TestNetwork;
|
||||||
|
import org.alfresco.rest.api.tests.client.HttpResponse;
|
||||||
|
import org.alfresco.rest.api.tests.client.RequestContext;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HTTP cache header public api tests.
|
||||||
|
*
|
||||||
|
* @author Gavin Cornwell
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class TestPublicApiCaching extends EnterpriseTestApi
|
||||||
|
{
|
||||||
|
@Test
|
||||||
|
public void testMNT13938() throws Exception
|
||||||
|
{
|
||||||
|
Iterator<TestNetwork> accountsIt = getTestFixture().getNetworksIt();
|
||||||
|
final TestNetwork account1 = accountsIt.next();
|
||||||
|
Iterator<String> personIt1 = account1.getPersonIds().iterator();
|
||||||
|
final String person1 = personIt1.next();
|
||||||
|
|
||||||
|
// make a request to any API (we'll get our own profile)
|
||||||
|
{
|
||||||
|
publicApiClient.setRequestContext(new RequestContext(account1.getId(), person1));
|
||||||
|
HttpResponse response = publicApiClient.get("public", "people", person1, null, null, null);
|
||||||
|
|
||||||
|
int responseCode = response.getStatusCode();
|
||||||
|
// make sure request was successful
|
||||||
|
assertTrue("Response code should be 200", responseCode == HttpServletResponse.SC_OK);
|
||||||
|
|
||||||
|
Map<String, String> headers = response.getHeaders();
|
||||||
|
// assert headers are present
|
||||||
|
assertNotNull("HTTP headers should be present on response", headers);
|
||||||
|
|
||||||
|
// assert the cache headers are present
|
||||||
|
String cacheControlHeader = headers.get("Cache-Control");
|
||||||
|
assertNotNull("Cache-Control header should be present", cacheControlHeader);
|
||||||
|
assertTrue("Cache-Control header should be set to no-cache but it was: " + cacheControlHeader,
|
||||||
|
cacheControlHeader.equals("no-cache"));
|
||||||
|
|
||||||
|
String pragmaHeader = headers.get("Pragma");
|
||||||
|
assertNotNull("Pragma header should be present", pragmaHeader);
|
||||||
|
assertTrue("Pragma header should be set to no-cache but it was: " + pragmaHeader,
|
||||||
|
pragmaHeader.equals("no-cache"));
|
||||||
|
|
||||||
|
String expiresHeader = headers.get("Expires");
|
||||||
|
assertNotNull("Expires header should be present", expiresHeader);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,5 +1,7 @@
|
|||||||
package org.alfresco.rest.api.tests.client;
|
package org.alfresco.rest.api.tests.client;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpMethod;
|
import org.apache.commons.httpclient.HttpMethod;
|
||||||
import org.apache.commons.httpclient.URIException;
|
import org.apache.commons.httpclient.URIException;
|
||||||
import org.apache.commons.httpclient.methods.DeleteMethod;
|
import org.apache.commons.httpclient.methods.DeleteMethod;
|
||||||
@@ -16,14 +18,16 @@ public class HttpResponse
|
|||||||
private HttpMethod method;
|
private HttpMethod method;
|
||||||
private String user;
|
private String user;
|
||||||
private String response;
|
private String response;
|
||||||
|
private Map<String,String> headers;
|
||||||
private long time;
|
private long time;
|
||||||
|
|
||||||
public HttpResponse(HttpMethod method, String user, String response, long time)
|
public HttpResponse(HttpMethod method, String user, String response, Map<String,String> headers, long time)
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
this.method = method;
|
this.method = method;
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.time = time;
|
this.time = time;
|
||||||
|
this.headers = headers;
|
||||||
this.response = response;
|
this.response = response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,6 +41,11 @@ public class HttpResponse
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String,String> getHeaders()
|
||||||
|
{
|
||||||
|
return headers;
|
||||||
|
}
|
||||||
|
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
@@ -22,6 +22,7 @@ import java.io.IOException;
|
|||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.alfresco.error.AlfrescoRuntimeException;
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
@@ -37,6 +38,7 @@ import org.alfresco.rest.framework.resource.EntityResource;
|
|||||||
import org.alfresco.rest.framework.resource.RelationshipResource;
|
import org.alfresco.rest.framework.resource.RelationshipResource;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.util.Pair;
|
import org.alfresco.util.Pair;
|
||||||
|
import org.apache.commons.httpclient.Header;
|
||||||
import org.apache.commons.httpclient.HttpException;
|
import org.apache.commons.httpclient.HttpException;
|
||||||
import org.apache.commons.httpclient.HttpMethod;
|
import org.apache.commons.httpclient.HttpMethod;
|
||||||
import org.apache.commons.httpclient.methods.DeleteMethod;
|
import org.apache.commons.httpclient.methods.DeleteMethod;
|
||||||
@@ -227,7 +229,19 @@ public class PublicApiHttpClient
|
|||||||
public HttpResponse onCallSuccess(HttpMethod method) throws Exception
|
public HttpResponse onCallSuccess(HttpMethod method) throws Exception
|
||||||
{
|
{
|
||||||
long end = System.currentTimeMillis();
|
long end = System.currentTimeMillis();
|
||||||
return new HttpResponse(method, rq.getRunAsUser(), method.getResponseBodyAsString(), (end - start));
|
|
||||||
|
Map<String, String> headersMap = null;
|
||||||
|
Header[] headers = method.getResponseHeaders();
|
||||||
|
if (headers != null)
|
||||||
|
{
|
||||||
|
headersMap = new HashMap<String, String>(headers.length);
|
||||||
|
for (Header header : headers)
|
||||||
|
{
|
||||||
|
headersMap.put(header.getName(), header.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new HttpResponse(method, rq.getRunAsUser(), method.getResponseBodyAsString(), headersMap, (end - start));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user