REPO-908: V1 REST API - minor test fwk improvement

- change default port from 8081 to 8765 (to avoid clash with Share, if already running in local dev env)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@133650 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2016-12-14 10:09:53 +00:00
parent 135d6696a0
commit cfdbdd6c29
5 changed files with 350 additions and 328 deletions

View File

@@ -1,28 +1,28 @@
/* /*
* #%L * #%L
* Alfresco Remote API * Alfresco Remote API
* %% * %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited * Copyright (C) 2005 - 2016 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of * If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is * the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms: * provided under the following open source license terms:
* *
* Alfresco is free software: you can redistribute it and/or modify * Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by * it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Alfresco is distributed in the hope that it will be useful, * Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.rest.api.tests; package org.alfresco.rest.api.tests;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@@ -73,9 +73,9 @@ public abstract class AbstractTestApi
@Before @Before
public void setupTests() throws Exception public void setupTests() throws Exception
{ {
TestFixture testFixture = getTestFixture(false); TestFixture testFixture = getTestFixture(false);
this.applicationContext = testFixture.getApplicationContext(); this.applicationContext = testFixture.getApplicationContext();
this.repoService = testFixture.getRepoService(); this.repoService = testFixture.getRepoService();
this.transactionHelper = (RetryingTransactionHelper)applicationContext.getBean("retryingTransactionHelper"); this.transactionHelper = (RetryingTransactionHelper)applicationContext.getBean("retryingTransactionHelper");
HttpClientProvider httpClientProvider = (HttpClientProvider)applicationContext.getBean("httpClientProvider"); HttpClientProvider httpClientProvider = (HttpClientProvider)applicationContext.getBean("httpClientProvider");
@@ -95,7 +95,7 @@ public abstract class AbstractTestApi
}; };
AuthenticationDetailsProvider authenticationDetailsProvider = new UserAuthenticationDetailsProviderImpl(userDataService, "admin", "admin"); AuthenticationDetailsProvider authenticationDetailsProvider = new UserAuthenticationDetailsProviderImpl(userDataService, "admin", "admin");
AuthenticatedHttp authenticatedHttp = new AuthenticatedHttp(httpClientProvider, authenticationDetailsProvider); AuthenticatedHttp authenticatedHttp = new AuthenticatedHttp(httpClientProvider, authenticationDetailsProvider);
this.httpClient = new PublicApiHttpClient("localhost", TestFixture.PORT, TestFixture.CONTEXT_PATH, this.httpClient = new PublicApiHttpClient(TestFixture.HOST, TestFixture.PORT, TestFixture.CONTEXT_PATH,
TestFixture.PUBLIC_API_SERVLET_NAME, authenticatedHttp); TestFixture.PUBLIC_API_SERVLET_NAME, authenticatedHttp);
this.publicApiClient = new PublicApiClient(httpClient, userDataService); this.publicApiClient = new PublicApiClient(httpClient, userDataService);
} }
@@ -223,9 +223,9 @@ public abstract class AbstractTestApi
} }
protected abstract TestFixture getTestFixture() throws Exception; protected abstract TestFixture getTestFixture() throws Exception;
/** /**
* @param createTestData The created instance can optionally create test data if required * @param createTestData The created instance can optionally create test data if required
*/ */
protected abstract TestFixture getTestFixture(boolean createTestData) throws Exception; protected abstract TestFixture getTestFixture(boolean createTestData) throws Exception;
} }

View File

@@ -1,28 +1,28 @@
/* /*
* #%L * #%L
* Alfresco Remote API * Alfresco Remote API
* %% * %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited * Copyright (C) 2005 - 2016 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of * If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is * the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms: * provided under the following open source license terms:
* *
* Alfresco is free software: you can redistribute it and/or modify * Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by * it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Alfresco is distributed in the hope that it will be useful, * Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.rest.api.tests; package org.alfresco.rest.api.tests;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
@@ -54,12 +54,12 @@ public abstract class AbstractTestFixture implements TestFixture
protected TreeMap<String, TestNetwork> networks = new TreeMap<String, TestNetwork>(); protected TreeMap<String, TestNetwork> networks = new TreeMap<String, TestNetwork>();
protected TreeMap<String, SiteInformation> sites = new TreeMap<String, SiteInformation>(); protected TreeMap<String, SiteInformation> sites = new TreeMap<String, SiteInformation>();
protected String[] configLocations; private String[] configLocations;
protected final String[] classLocations; private final String[] classLocations;
protected int port = 8081; private int port = PORT;
protected String contextPath = "/alfresco"; private String contextPath = CONTEXT_PATH;
protected String servletName = "api"; private String servletName = PUBLIC_API_SERVLET_NAME;
protected String hostname = "localhost";
protected JettyComponent jetty; protected JettyComponent jetty;
protected boolean cleanup; protected boolean cleanup;
protected Random random = new Random(); protected Random random = new Random();
@@ -94,29 +94,49 @@ public abstract class AbstractTestFixture implements TestFixture
{ {
return port; return port;
} }
public String getContextPath()
{
return contextPath;
}
public String getServletName()
{
return servletName;
}
public String[] getConfigLocations()
{
return configLocations;
}
public String[] getClassLocations()
{
return classLocations;
}
protected abstract JettyComponent makeJettyComponent(); protected abstract JettyComponent makeJettyComponent();
protected abstract void populateTestData(); protected abstract void populateTestData();
protected abstract RepoService makeRepoService() throws Exception; protected abstract RepoService makeRepoService() throws Exception;
public void setup() throws Exception public void setup() throws Exception
{ {
setup(true); setup(true);
} }
public void setup(boolean createTestData) throws Exception public void setup(boolean createTestData) throws Exception
{ {
this.jetty = makeJettyComponent(); this.jetty = makeJettyComponent();
this.jetty.start(); this.jetty.start();
this.applicationContext = jetty.getApplicationContext(); this.applicationContext = jetty.getApplicationContext();
this.repoService = makeRepoService(); this.repoService = makeRepoService();
this.transactionHelper = (RetryingTransactionHelper)repoService.getApplicationContext().getBean("retryingTransactionHelper"); this.transactionHelper = (RetryingTransactionHelper)repoService.getApplicationContext().getBean("retryingTransactionHelper");
if (createTestData) if (createTestData)
{ {
populateTestData(); populateTestData();
createTestData(); createTestData();
} }
} }
public RepoService getRepoService() public RepoService getRepoService()
@@ -146,11 +166,11 @@ public abstract class AbstractTestFixture implements TestFixture
public TestNetwork getRandomNetwork() public TestNetwork getRandomNetwork()
{ {
if (networks.isEmpty()) if (networks.isEmpty())
{ {
populateTestData(); populateTestData();
createTestData(); createTestData();
} }
int r = random.nextInt(networks.size()); int r = random.nextInt(networks.size());
List<TestNetwork> a = new ArrayList<TestNetwork>(); List<TestNetwork> a = new ArrayList<TestNetwork>();
a.addAll(networks.values()); a.addAll(networks.values());

View File

@@ -1,28 +1,28 @@
/* /*
* #%L * #%L
* Alfresco Remote API * Alfresco Remote API
* %% * %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited * Copyright (C) 2005 - 2016 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of * If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is * the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms: * provided under the following open source license terms:
* *
* Alfresco is free software: you can redistribute it and/or modify * Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by * it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Alfresco is distributed in the hope that it will be useful, * Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.rest.api.tests; package org.alfresco.rest.api.tests;
import org.alfresco.repo.web.util.JettyComponent; import org.alfresco.repo.web.util.JettyComponent;
@@ -45,21 +45,21 @@ public class EnterprisePublicApiTestFixture extends EnterpriseTestFixture
/* /*
* Note: synchronized for multi-threaded test access * Note: synchronized for multi-threaded test access
*/ */
public synchronized static EnterprisePublicApiTestFixture getInstance(boolean createTestData) throws Exception public synchronized static EnterprisePublicApiTestFixture getInstance(boolean createTestData) throws Exception
{ {
if(instance == null) if(instance == null)
{ {
instance = new EnterprisePublicApiTestFixture(); instance = new EnterprisePublicApiTestFixture();
instance.setup(createTestData); instance.setup(createTestData);
} }
return instance; return instance;
} }
public static EnterprisePublicApiTestFixture getInstance() throws Exception public static EnterprisePublicApiTestFixture getInstance() throws Exception
{ {
return getInstance(true); return getInstance(true);
} }
private EnterprisePublicApiTestFixture() private EnterprisePublicApiTestFixture()
{ {
super(CONFIG_LOCATIONS, CLASS_LOCATIONS, PORT, CONTEXT_PATH, PUBLIC_API_SERVLET_NAME, DEFAULT_NUM_MEMBERS_PER_SITE, false); super(CONFIG_LOCATIONS, CLASS_LOCATIONS, PORT, CONTEXT_PATH, PUBLIC_API_SERVLET_NAME, DEFAULT_NUM_MEMBERS_PER_SITE, false);
@@ -68,7 +68,7 @@ public class EnterprisePublicApiTestFixture extends EnterpriseTestFixture
@Override @Override
protected JettyComponent makeJettyComponent() protected JettyComponent makeJettyComponent()
{ {
JettyComponent jettyComponent = new EnterpriseJettyComponent(port, contextPath, configLocations, classLocations); JettyComponent jettyComponent = new EnterpriseJettyComponent(getPort(), getContextPath(), getConfigLocations(), getClassLocations());
return jettyComponent; return jettyComponent;
} }

View File

@@ -23,25 +23,26 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.rest.api.tests; package org.alfresco.rest.api.tests;
import java.util.Iterator; import java.util.Iterator;
import org.alfresco.repo.web.util.JettyComponent; import org.alfresco.repo.web.util.JettyComponent;
import org.alfresco.rest.api.tests.RepoService.TestNetwork; import org.alfresco.rest.api.tests.RepoService.TestNetwork;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
public interface TestFixture public interface TestFixture
{ {
public final static int PORT = 8081; public final static String HOST = "localhost";
public final static String CONTEXT_PATH = "/alfresco"; public final static int PORT = 8765;
public final static String PUBLIC_API_SERVLET_NAME = "api"; public final static String CONTEXT_PATH = "/alfresco";
public final static String PUBLIC_API_SERVLET_NAME = "api";
ApplicationContext getApplicationContext();
RepoService getRepoService(); ApplicationContext getApplicationContext();
Iterator<TestNetwork> getNetworksIt(); RepoService getRepoService();
TestNetwork getRandomNetwork(); Iterator<TestNetwork> getNetworksIt();
Iterator<TestNetwork> networksIterator(); TestNetwork getRandomNetwork();
JettyComponent getJettyComponent(); Iterator<TestNetwork> networksIterator();
TestNetwork getNetwork(String name); JettyComponent getJettyComponent();
} TestNetwork getNetwork(String name);
}

View File

@@ -23,96 +23,97 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.rest.api.tests.client; package org.alfresco.rest.api.tests.client;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
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.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.opencmis.CMISDispatcherRegistry.Binding; import org.alfresco.opencmis.CMISDispatcherRegistry.Binding;
import org.alfresco.repo.tenant.TenantService; import org.alfresco.repo.tenant.TenantService;
import org.alfresco.repo.tenant.TenantUtil; import org.alfresco.repo.tenant.TenantUtil;
import org.alfresco.repo.web.scripts.BaseWebScriptTest.PatchMethod; import org.alfresco.repo.web.scripts.BaseWebScriptTest.PatchMethod;
import org.alfresco.rest.api.tests.client.AuthenticatedHttp.HttpRequestCallback; import org.alfresco.rest.api.tests.TestFixture;
import org.alfresco.rest.framework.Api; import org.alfresco.rest.api.tests.client.AuthenticatedHttp.HttpRequestCallback;
import org.alfresco.rest.framework.Api.SCOPE; import org.alfresco.rest.framework.Api;
import org.alfresco.rest.framework.core.ResourceInspector; import org.alfresco.rest.framework.Api.SCOPE;
import org.alfresco.rest.framework.resource.EntityResource; import org.alfresco.rest.framework.core.ResourceInspector;
import org.alfresco.rest.framework.resource.RelationshipResource; import org.alfresco.rest.framework.resource.EntityResource;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.rest.framework.resource.RelationshipResource;
import org.alfresco.util.Pair; import org.alfresco.service.cmr.repository.NodeRef;
import org.apache.commons.httpclient.Header; import org.alfresco.util.Pair;
import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpMethod; import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpMethodBase; import org.apache.commons.httpclient.HttpMethodBase;
import org.apache.commons.httpclient.methods.ByteArrayRequestEntity; import org.apache.commons.httpclient.methods.ByteArrayRequestEntity;
import org.apache.commons.httpclient.methods.DeleteMethod; import org.apache.commons.httpclient.methods.DeleteMethod;
import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.HeadMethod; import org.apache.commons.httpclient.methods.HeadMethod;
import org.apache.commons.httpclient.methods.OptionsMethod; import org.apache.commons.httpclient.methods.OptionsMethod;
import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.PutMethod; import org.apache.commons.httpclient.methods.PutMethod;
import org.apache.commons.httpclient.methods.RequestEntity; import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.methods.StringRequestEntity; import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.commons.httpclient.methods.TraceMethod; import org.apache.commons.httpclient.methods.TraceMethod;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
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.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver; import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.core.type.AnnotationMetadata; import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.classreading.CachingMetadataReaderFactory; import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
import org.springframework.core.type.classreading.MetadataReader; import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory; import org.springframework.core.type.classreading.MetadataReaderFactory;
/** /**
* A http client for talking to the rest apis. The caller can pass in a rest api * A http client for talking to the rest apis. The caller can pass in a rest api
* implementation class to the http method (get, post, put, delete supported) * implementation class to the http method (get, post, put, delete supported)
* and the url will be generated. * and the url will be generated.
* *
* @author steveglover * @author steveglover
*/ */
public class PublicApiHttpClient public class PublicApiHttpClient
{ {
private static final Log logger = LogFactory.getLog(PublicApiHttpClient.class); private static final Log logger = LogFactory.getLog(PublicApiHttpClient.class);
private static final String OLD_BASE_URL = "{0}://{1}:{2}{3}{4}{5}/api/"; private static final String OLD_BASE_URL = "{0}://{1}:{2}{3}{4}{5}/api/";
private static final String INDEX_URL = "{0}://{1}:{2}{3}{4}"; private static final String INDEX_URL = "{0}://{1}:{2}{3}{4}";
private static final String BASE_URL = "{0}://{1}:{2}{3}{4}{5}/{6}/{7}/versions/{8}"; private static final String BASE_URL = "{0}://{1}:{2}{3}{4}{5}/{6}/{7}/versions/{8}";
private static final String PUBLICAPI_CMIS_SERVICE_URL = "{0}://{1}:{2}{3}{4}cmis/versions/{5}/{6}"; private static final String PUBLICAPI_CMIS_SERVICE_URL = "{0}://{1}:{2}{3}{4}cmis/versions/{5}/{6}";
private static final String PUBLICAPI_CMIS_URL = "{0}://{1}:{2}{3}{4}{5}/{6}/cmis/versions/{7}/{8}"; private static final String PUBLICAPI_CMIS_URL = "{0}://{1}:{2}{3}{4}{5}/{6}/cmis/versions/{7}/{8}";
private static final String PUBLICAPI_CMIS_URL_SUFFIX = "{0}/{1}/cmis/versions/{2}/{3}"; private static final String PUBLICAPI_CMIS_URL_SUFFIX = "{0}/{1}/cmis/versions/{2}/{3}";
private static final String ATOM_PUB_URL = "{0}://{1}:{2}{3}cmisatom"; private static final String ATOM_PUB_URL = "{0}://{1}:{2}{3}cmisatom";
private String scheme = "http"; private String scheme = "http";
private String host = "localhost"; private String host = TestFixture.HOST;
private int port = 8081; private int port = TestFixture.PORT;
private String contextPath; private String contextPath;
private String servletName; private String servletName;
private AuthenticatedHttp authenticatedHttp; private AuthenticatedHttp authenticatedHttp;
private ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver(); private ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
private MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(this.resourcePatternResolver); private MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(this.resourcePatternResolver);
// can be overriden by other clients like the workflow client // can be overriden by other clients like the workflow client
protected String apiName = "alfresco"; protected String apiName = "alfresco";
public PublicApiHttpClient(String host, int port, String contextPath, String servletName, AuthenticatedHttp authenticatedHttp) public PublicApiHttpClient(String host, int port, String contextPath, String servletName, AuthenticatedHttp authenticatedHttp)
{ {
this("http", host, port, contextPath, servletName, authenticatedHttp); this("http", host, port, contextPath, servletName, authenticatedHttp);
} }
public PublicApiHttpClient(String scheme, String host, int port, String contextPath, String servletName, AuthenticatedHttp authenticatedHttp) public PublicApiHttpClient(String scheme, String host, int port, String contextPath, String servletName, AuthenticatedHttp authenticatedHttp)
{ {
super(); super();
@@ -135,7 +136,7 @@ public class PublicApiHttpClient
} }
this.authenticatedHttp = authenticatedHttp; this.authenticatedHttp = authenticatedHttp;
} }
public String getCmisUrl(String repositoryId, String operation) public String getCmisUrl(String repositoryId, String operation)
{ {
StringBuilder url = new StringBuilder(); StringBuilder url = new StringBuilder();
@@ -149,16 +150,16 @@ public class PublicApiHttpClient
url.append("/"); url.append("/");
url.append(repositoryId); url.append(repositoryId);
} }
if (operation != null) if (operation != null)
{ {
url.append("/"); url.append("/");
url.append(operation); url.append(operation);
} }
return url.toString(); return url.toString();
} }
public String getPublicApiCmisUrl(String networkId, Binding binding, String version, String operation) public String getPublicApiCmisUrl(String networkId, Binding binding, String version, String operation)
{ {
StringBuilder url = new StringBuilder(); StringBuilder url = new StringBuilder();
@@ -172,41 +173,41 @@ public class PublicApiHttpClient
url.append(MessageFormat.format(PUBLICAPI_CMIS_URL, new Object[] { scheme, host, String.valueOf(port), contextPath, servletName, url.append(MessageFormat.format(PUBLICAPI_CMIS_URL, new Object[] { scheme, host, String.valueOf(port), contextPath, servletName,
networkId, "public", version, binding.toString().toLowerCase() })); networkId, "public", version, binding.toString().toLowerCase() }));
} }
if (operation != null) if (operation != null)
{ {
url.append("/"); url.append("/");
url.append(operation); url.append(operation);
} }
return url.toString(); return url.toString();
} }
public String getPublicApiCmisUrlSuffix(String networkId, Binding binding, String version, String operation) public String getPublicApiCmisUrlSuffix(String networkId, Binding binding, String version, String operation)
{ {
StringBuilder url = new StringBuilder(); StringBuilder url = new StringBuilder();
url.append(MessageFormat.format(PUBLICAPI_CMIS_URL_SUFFIX, new Object[] { networkId, "public", version, binding.toString().toLowerCase() })); url.append(MessageFormat.format(PUBLICAPI_CMIS_URL_SUFFIX, new Object[] { networkId, "public", version, binding.toString().toLowerCase() }));
if (operation != null) if (operation != null)
{ {
url.append("/"); url.append("/");
url.append(operation); url.append(operation);
} }
return url.toString(); return url.toString();
} }
public void setHost(String host) public void setHost(String host)
{ {
this.host = host; this.host = host;
} }
public void setPort(int port) public void setPort(int port)
{ {
this.port = port; this.port = port;
} }
public void setContextPath(String contextPath) public void setContextPath(String contextPath)
{ {
this.contextPath = contextPath; this.contextPath = contextPath;
@@ -224,19 +225,19 @@ public class PublicApiHttpClient
} }
} }
protected AnnotationMetadata getAnnotationMetadata(String classname) throws IOException protected AnnotationMetadata getAnnotationMetadata(String classname) throws IOException
{ {
MetadataReader metadataReader = this.metadataReaderFactory.getMetadataReader(classname); MetadataReader metadataReader = this.metadataReaderFactory.getMetadataReader(classname);
AnnotationMetadata annotationMetaData = metadataReader.getAnnotationMetadata(); AnnotationMetadata annotationMetaData = metadataReader.getAnnotationMetadata();
return annotationMetaData; return annotationMetaData;
} }
public HttpResponse submitRequest(HttpMethod req, final RequestContext rq) throws HttpException, IOException public HttpResponse submitRequest(HttpMethod req, final RequestContext rq) throws HttpException, IOException
{ {
try try
{ {
final long start = System.currentTimeMillis(); final long start = System.currentTimeMillis();
final HttpRequestCallback<HttpResponse> callback = new HttpRequestCallback<HttpResponse>() final HttpRequestCallback<HttpResponse> callback = new HttpRequestCallback<HttpResponse>()
{ {
@Override @Override
@@ -250,14 +251,14 @@ public class PublicApiHttpClient
{ {
headersMap = new HashMap<String, String>(headers.length); headersMap = new HashMap<String, String>(headers.length);
for (Header header : headers) for (Header header : headers)
{ {
headersMap.put(header.getName(), header.getValue()); headersMap.put(header.getName(), header.getValue());
} }
} }
return new HttpResponse(method, rq.getRunAsUser(), method.getResponseBody(), headersMap, (end - start)); return new HttpResponse(method, rq.getRunAsUser(), method.getResponseBody(), headersMap, (end - start));
} }
@Override @Override
public boolean onError(HttpMethod method, Throwable t) public boolean onError(HttpMethod method, Throwable t)
{ {
@@ -283,40 +284,40 @@ public class PublicApiHttpClient
req.releaseConnection(); req.releaseConnection();
} }
} }
} }
public HttpResponse get(final RequestContext rq, final String urlSuffix, Map<String, String> params) throws IOException public HttpResponse get(final RequestContext rq, final String urlSuffix, Map<String, String> params) throws IOException
{ {
RestApiEndpoint endpoint = new RestApiEndpoint(rq.getNetworkId(), urlSuffix, params); RestApiEndpoint endpoint = new RestApiEndpoint(rq.getNetworkId(), urlSuffix, params);
String url = endpoint.getUrl(); String url = endpoint.getUrl();
GetMethod req = new GetMethod(url); GetMethod req = new GetMethod(url);
return submitRequest(req, rq); return submitRequest(req, rq);
} }
public HttpResponse get(final Class<?> c, final RequestContext rq, final Object entityId, final Object relationshipEntityId, public HttpResponse get(final Class<?> c, final RequestContext rq, final Object entityId, final Object relationshipEntityId,
Map<String, String> params) throws IOException Map<String, String> params) throws IOException
{ {
RestApiEndpoint endpoint = new RestApiEndpoint(c, rq.getNetworkId(), entityId, relationshipEntityId, params); RestApiEndpoint endpoint = new RestApiEndpoint(c, rq.getNetworkId(), entityId, relationshipEntityId, params);
String url = endpoint.getUrl(); String url = endpoint.getUrl();
GetMethod req = new GetMethod(url); GetMethod req = new GetMethod(url);
return submitRequest(req, rq); return submitRequest(req, rq);
} }
public HttpResponse get(final RequestContext rq, String scope, final String entityCollectionName, final Object entityId, public HttpResponse get(final RequestContext rq, String scope, final String entityCollectionName, final Object entityId,
final String relationCollectionName, final Object relationshipEntityId, Map<String, String> params) throws IOException final String relationCollectionName, final Object relationshipEntityId, Map<String, String> params) throws IOException
{ {
return get(rq, scope, 1, entityCollectionName, entityId, relationCollectionName, relationshipEntityId, params); return get(rq, scope, 1, entityCollectionName, entityId, relationCollectionName, relationshipEntityId, params);
} }
public HttpResponse get(final RequestContext rq, final String scope, final int version, final String entityCollectionName, final Object entityId, public HttpResponse get(final RequestContext rq, final String scope, final int version, final String entityCollectionName, final Object entityId,
final String relationCollectionName, final Object relationshipEntityId, Map<String, String> params) throws IOException final String relationCollectionName, final Object relationshipEntityId, Map<String, String> params) throws IOException
{ {
RestApiEndpoint endpoint = new RestApiEndpoint(rq.getNetworkId(), scope, version, entityCollectionName, entityId, relationCollectionName, RestApiEndpoint endpoint = new RestApiEndpoint(rq.getNetworkId(), scope, version, entityCollectionName, entityId, relationCollectionName,
relationshipEntityId, params); relationshipEntityId, params);
String url = endpoint.getUrl(); String url = endpoint.getUrl();
GetMethod req = new GetMethod(url); GetMethod req = new GetMethod(url);
return submitRequest(req, rq); return submitRequest(req, rq);
} }
@@ -338,7 +339,7 @@ public class PublicApiHttpClient
return submitRequest(req, rq); return submitRequest(req, rq);
} }
public HttpResponse get(final String urlSuffix, final RequestContext rq, Map<String, String> params) throws IOException public HttpResponse get(final String urlSuffix, final RequestContext rq, Map<String, String> params) throws IOException
{ {
RestApiEndpoint endpoint = new RestApiEndpoint(urlSuffix, params); RestApiEndpoint endpoint = new RestApiEndpoint(urlSuffix, params);
String url = endpoint.getUrl(); String url = endpoint.getUrl();
@@ -347,15 +348,15 @@ public class PublicApiHttpClient
return submitRequest(req, rq); return submitRequest(req, rq);
} }
public HttpResponse getWithPassword(final String urlSuffix, final RequestContext rq, Map<String, String> params) throws IOException public HttpResponse getWithPassword(final String urlSuffix, final RequestContext rq, Map<String, String> params) throws IOException
{ {
RestApiEndpoint endpoint = new RestApiEndpoint(urlSuffix, params); RestApiEndpoint endpoint = new RestApiEndpoint(urlSuffix, params);
String url = endpoint.getUrl(); String url = endpoint.getUrl();
GetMethod req = new GetMethod(url); GetMethod req = new GetMethod(url);
return submitRequest(req, rq); return submitRequest(req, rq);
} }
public HttpResponse post(final Class<?> c, final RequestContext rq, final Object entityId, final Object relationshipEntityId, final String body) public HttpResponse post(final Class<?> c, final RequestContext rq, final Object entityId, final Object relationshipEntityId, final String body)
throws IOException throws IOException
{ {
@@ -371,11 +372,11 @@ public class PublicApiHttpClient
return submitRequest(req, rq); return submitRequest(req, rq);
} }
public HttpResponse post(final RequestContext rq, final String urlSuffix, String body) throws IOException public HttpResponse post(final RequestContext rq, final String urlSuffix, String body) throws IOException
{ {
RestApiEndpoint endpoint = new RestApiEndpoint(rq.getNetworkId(), urlSuffix, null); RestApiEndpoint endpoint = new RestApiEndpoint(rq.getNetworkId(), urlSuffix, null);
String url = endpoint.getUrl(); String url = endpoint.getUrl();
PostMethod req = new PostMethod(url.toString()); PostMethod req = new PostMethod(url.toString());
if (body != null) if (body != null)
{ {
@@ -384,12 +385,12 @@ public class PublicApiHttpClient
} }
return submitRequest(req, rq); return submitRequest(req, rq);
} }
public HttpResponse post(final RequestContext rq, Binding cmisBinding, String version, String cmisOperation, final String body) throws IOException public HttpResponse post(final RequestContext rq, Binding cmisBinding, String version, String cmisOperation, final String body) throws IOException
{ {
RestApiEndpoint endpoint = new RestApiEndpoint(rq.getNetworkId(), cmisBinding, version, cmisOperation, null); RestApiEndpoint endpoint = new RestApiEndpoint(rq.getNetworkId(), cmisBinding, version, cmisOperation, null);
String url = endpoint.getUrl(); String url = endpoint.getUrl();
PostMethod req = new PostMethod(url.toString()); PostMethod req = new PostMethod(url.toString());
if (body != null) if (body != null)
{ {
@@ -406,7 +407,7 @@ public class PublicApiHttpClient
} }
return submitRequest(req, rq); return submitRequest(req, rq);
} }
public HttpResponse put(final RequestContext rq, Binding cmisBinding, String version, String cmisOperation, final String body) throws IOException public HttpResponse put(final RequestContext rq, Binding cmisBinding, String version, String cmisOperation, final String body) throws IOException
{ {
RestApiEndpoint endpoint = new RestApiEndpoint(rq.getNetworkId(), cmisBinding, version, cmisOperation, null); RestApiEndpoint endpoint = new RestApiEndpoint(rq.getNetworkId(), cmisBinding, version, cmisOperation, null);
@@ -484,15 +485,15 @@ public class PublicApiHttpClient
return submitRequest(req, rq); return submitRequest(req, rq);
} }
public HttpResponse post(final RequestContext rq, final String scope, final String entityCollectionName, final Object entityId, public HttpResponse post(final RequestContext rq, final String scope, final String entityCollectionName, final Object entityId,
final String relationCollectionName, final Object relationshipEntityId, final String body) throws IOException final String relationCollectionName, final Object relationshipEntityId, final String body) throws IOException
{ {
return post(rq, scope, entityCollectionName, entityId, relationCollectionName, relationshipEntityId, body, "application/json"); return post(rq, scope, entityCollectionName, entityId, relationCollectionName, relationshipEntityId, body, "application/json");
} }
public HttpResponse post(final RequestContext rq, final String scope, final String entityCollectionName, final Object entityId, public HttpResponse post(final RequestContext rq, final String scope, final String entityCollectionName, final Object entityId,
final String relationCollectionName, final Object relationshipEntityId, final String body, String contentType) throws IOException final String relationCollectionName, final Object relationshipEntityId, final String body, String contentType) throws IOException
{ {
return post(rq, scope, 1, entityCollectionName, entityId, relationCollectionName, relationshipEntityId, body, contentType); return post(rq, scope, 1, entityCollectionName, entityId, relationCollectionName, relationshipEntityId, body, contentType);
} }
@@ -500,22 +501,22 @@ public class PublicApiHttpClient
final String relationCollectionName, final Object relationshipEntityId, final String body, String contentType) throws IOException final String relationCollectionName, final Object relationshipEntityId, final String body, String contentType) throws IOException
{ {
RestApiEndpoint endpoint = new RestApiEndpoint(rq.getNetworkId(), scope, version, entityCollectionName, entityId, relationCollectionName, RestApiEndpoint endpoint = new RestApiEndpoint(rq.getNetworkId(), scope, version, entityCollectionName, entityId, relationCollectionName,
relationshipEntityId, null); relationshipEntityId, null);
String url = endpoint.getUrl(); String url = endpoint.getUrl();
PostMethod req = new PostMethod(url.toString()); PostMethod req = new PostMethod(url.toString());
if (body != null) if (body != null)
{ {
if (contentType == null || contentType.isEmpty()) if (contentType == null || contentType.isEmpty())
{ {
contentType = "application/json"; contentType = "application/json";
} }
StringRequestEntity requestEntity = new StringRequestEntity(body, contentType, "UTF-8"); StringRequestEntity requestEntity = new StringRequestEntity(body, contentType, "UTF-8");
req.setRequestEntity(requestEntity); req.setRequestEntity(requestEntity);
} }
return submitRequest(req, rq); return submitRequest(req, rq);
} }
public HttpResponse post(final RequestContext rq, final String scope, final String entityCollectionName, final Object entityId, public HttpResponse post(final RequestContext rq, final String scope, final String entityCollectionName, final Object entityId,
final String relationCollectionName, final Object relationshipEntityId, final byte[] body, String contentType) throws IOException final String relationCollectionName, final Object relationshipEntityId, final byte[] body, String contentType) throws IOException
{ {
@@ -546,34 +547,34 @@ public class PublicApiHttpClient
{ {
RestApiEndpoint endpoint = new RestApiEndpoint(c, rq.getNetworkId(), entityId, relationshipEntityId, null); RestApiEndpoint endpoint = new RestApiEndpoint(c, rq.getNetworkId(), entityId, relationshipEntityId, null);
String url = endpoint.getUrl(); String url = endpoint.getUrl();
DeleteMethod req = new DeleteMethod(url); DeleteMethod req = new DeleteMethod(url);
return submitRequest(req, rq); return submitRequest(req, rq);
} }
public HttpResponse delete(final RequestContext rq, final String scope, final String entityCollectionName, final Object entityId, public HttpResponse delete(final RequestContext rq, final String scope, final String entityCollectionName, final Object entityId,
final String relationCollectionName, final Object relationshipEntityId) throws IOException final String relationCollectionName, final Object relationshipEntityId) throws IOException
{ {
return delete(rq, scope, 1, entityCollectionName, entityId, relationCollectionName, relationshipEntityId, null); return delete(rq, scope, 1, entityCollectionName, entityId, relationCollectionName, relationshipEntityId, null);
} }
public HttpResponse delete(final RequestContext rq, final String scope, final int version, final String entityCollectionName, final Object entityId, public HttpResponse delete(final RequestContext rq, final String scope, final int version, final String entityCollectionName, final Object entityId,
final String relationCollectionName, final Object relationshipEntityId, final Map<String, String> params) throws IOException final String relationCollectionName, final Object relationshipEntityId, final Map<String, String> params) throws IOException
{ {
RestApiEndpoint endpoint = new RestApiEndpoint(rq.getNetworkId(), scope, version, entityCollectionName, entityId, relationCollectionName, RestApiEndpoint endpoint = new RestApiEndpoint(rq.getNetworkId(), scope, version, entityCollectionName, entityId, relationCollectionName,
relationshipEntityId, params); relationshipEntityId, params);
String url = endpoint.getUrl(); String url = endpoint.getUrl();
DeleteMethod req = new DeleteMethod(url); DeleteMethod req = new DeleteMethod(url);
return submitRequest(req, rq); return submitRequest(req, rq);
} }
public HttpResponse put(final Class<?> c, final RequestContext rq, final Object entityId, final Object relationshipEntityId, final String body) public HttpResponse put(final Class<?> c, final RequestContext rq, final Object entityId, final Object relationshipEntityId, final String body)
throws IOException throws IOException
{ {
RestApiEndpoint endpoint = new RestApiEndpoint(c, rq.getNetworkId(), entityId, relationshipEntityId, null); RestApiEndpoint endpoint = new RestApiEndpoint(c, rq.getNetworkId(), entityId, relationshipEntityId, null);
String url = endpoint.getUrl(); String url = endpoint.getUrl();
PutMethod req = new PutMethod(url); PutMethod req = new PutMethod(url);
if (body != null) if (body != null)
{ {
@@ -582,7 +583,7 @@ public class PublicApiHttpClient
} }
return submitRequest(req, rq); return submitRequest(req, rq);
} }
public HttpResponse put(final RequestContext rq, final String scope, final String entityCollectionName, final Object entityId, public HttpResponse put(final RequestContext rq, final String scope, final String entityCollectionName, final Object entityId,
final String relationCollectionName, final Object relationshipEntityId, final String body, final Map<String, String> params) throws IOException final String relationCollectionName, final Object relationshipEntityId, final String body, final Map<String, String> params) throws IOException
{ {
@@ -631,10 +632,10 @@ public class PublicApiHttpClient
* Encapsulates information relating to a rest api end point, generating and * Encapsulates information relating to a rest api end point, generating and
* encoding urls based on the rest api implementation class. * encoding urls based on the rest api implementation class.
*/ */
private class RestApiEndpoint private class RestApiEndpoint
{ {
private String url; private String url;
RestApiEndpoint(String url, Map<String, String> params) throws IOException RestApiEndpoint(String url, Map<String, String> params) throws IOException
{ {
StringBuilder sb = new StringBuilder( StringBuilder sb = new StringBuilder(
@@ -643,29 +644,29 @@ public class PublicApiHttpClient
{ {
sb.append(url); sb.append(url);
} }
addParams(sb, params); addParams(sb, params);
this.url = sb.toString(); this.url = sb.toString();
} }
RestApiEndpoint(String tenantDomain, String url, Map<String, String> params) throws IOException RestApiEndpoint(String tenantDomain, String url, Map<String, String> params) throws IOException
{ {
StringBuilder sb = new StringBuilder(MessageFormat.format(OLD_BASE_URL, new Object[] { scheme, host, String.valueOf(port), contextPath, StringBuilder sb = new StringBuilder(MessageFormat.format(OLD_BASE_URL, new Object[] { scheme, host, String.valueOf(port), contextPath,
servletName, tenantDomain == null ? TenantUtil.DEFAULT_TENANT : tenantDomain })); servletName, tenantDomain == null ? TenantUtil.DEFAULT_TENANT : tenantDomain }));
sb.append("/"); sb.append("/");
sb.append(url); sb.append(url);
addParams(sb, params); addParams(sb, params);
this.url = sb.toString(); this.url = sb.toString();
} }
RestApiEndpoint(Class<?> resourceClass, String tenantDomain, Object collectionEntityId, Object relationEntityId, Map<String, String> params) RestApiEndpoint(Class<?> resourceClass, String tenantDomain, Object collectionEntityId, Object relationEntityId, Map<String, String> params)
throws IOException throws IOException
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
Api api = ResourceInspector.inspectApi(resourceClass); Api api = ResourceInspector.inspectApi(resourceClass);
SCOPE scope = api.getScope(); SCOPE scope = api.getScope();
int version = api.getVersion(); int version = api.getVersion();
@@ -676,17 +677,17 @@ public class PublicApiHttpClient
} }
Pair<String, String> relationshipCollectionInfo = getRelationCollectionInfo(resourceClass); Pair<String, String> relationshipCollectionInfo = getRelationCollectionInfo(resourceClass);
sb.append(MessageFormat.format(BASE_URL, new Object[] { scheme, host, String.valueOf(port), contextPath, servletName, sb.append(MessageFormat.format(BASE_URL, new Object[] { scheme, host, String.valueOf(port), contextPath, servletName,
tenantDomain == null ? TenantUtil.DEFAULT_TENANT : tenantDomain, scope.toString(), name, version })); tenantDomain == null ? TenantUtil.DEFAULT_TENANT : tenantDomain, scope.toString(), name, version }));
if (relationshipCollectionInfo != null) if (relationshipCollectionInfo != null)
{ {
String entityCollectionName = relationshipCollectionInfo.getFirst(); String entityCollectionName = relationshipCollectionInfo.getFirst();
String relationshipCollectionName = relationshipCollectionInfo.getSecond(); String relationshipCollectionName = relationshipCollectionInfo.getSecond();
String relationEntityIdString = encodeToString(relationEntityId); String relationEntityIdString = encodeToString(relationEntityId);
String collectionEntityIdString = encodeToString(collectionEntityId); String collectionEntityIdString = encodeToString(collectionEntityId);
sb.append('/'); sb.append('/');
sb.append(entityCollectionName); sb.append(entityCollectionName);
sb.append('/'); sb.append('/');
@@ -695,7 +696,7 @@ public class PublicApiHttpClient
sb.append(collectionEntityIdString); sb.append(collectionEntityIdString);
sb.append('/'); sb.append('/');
} }
sb.append(relationshipCollectionName); sb.append(relationshipCollectionName);
sb.append('/'); sb.append('/');
if (relationEntityIdString != null) if (relationEntityIdString != null)
@@ -710,7 +711,7 @@ public class PublicApiHttpClient
if (entityCollectionName != null) if (entityCollectionName != null)
{ {
String collectionEntityIdString = encodeToString(collectionEntityId); String collectionEntityIdString = encodeToString(collectionEntityId);
sb.append('/'); sb.append('/');
sb.append(entityCollectionName); sb.append(entityCollectionName);
sb.append('/'); sb.append('/');
@@ -725,16 +726,16 @@ public class PublicApiHttpClient
throw new RuntimeException(); throw new RuntimeException();
} }
} }
addParams(sb, params); addParams(sb, params);
this.url = sb.toString(); this.url = sb.toString();
} }
RestApiEndpoint(String networkId, Binding cmisBinding, String version, String cmisOperation, Map<String, String> params) throws IOException RestApiEndpoint(String networkId, Binding cmisBinding, String version, String cmisOperation, Map<String, String> params) throws IOException
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
if (networkId != null) if (networkId != null)
{ {
sb.append(getPublicApiCmisUrl(networkId, cmisBinding, version, cmisOperation)); sb.append(getPublicApiCmisUrl(networkId, cmisBinding, version, cmisOperation));
@@ -743,12 +744,12 @@ public class PublicApiHttpClient
{ {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
addParams(sb, params); addParams(sb, params);
this.url = sb.toString(); this.url = sb.toString();
} }
RestApiEndpoint(String tenantDomain, String scope, int version, String collectionName, Object collectionEntityId, String relationName, RestApiEndpoint(String tenantDomain, String scope, int version, String collectionName, Object collectionEntityId, String relationName,
Object relationEntityId, Map<String, String> params) throws IOException Object relationEntityId, Map<String, String> params) throws IOException
{ {
@@ -759,7 +760,7 @@ public class PublicApiHttpClient
String relationName, Object relationEntityId, Map<String, String> params) throws IOException String relationName, Object relationEntityId, Map<String, String> params) throws IOException
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
if (tenantDomain == null || tenantDomain.equals(TenantService.DEFAULT_DOMAIN)) if (tenantDomain == null || tenantDomain.equals(TenantService.DEFAULT_DOMAIN))
{ {
tenantDomain = TenantUtil.DEFAULT_TENANT; tenantDomain = TenantUtil.DEFAULT_TENANT;
@@ -772,7 +773,7 @@ public class PublicApiHttpClient
sb.append(MessageFormat.format(BASE_URL, sb.append(MessageFormat.format(BASE_URL,
new Object[] { scheme, host, String.valueOf(port), contextPath, servletName, tenantDomain, scope, apiName, version })); new Object[] { scheme, host, String.valueOf(port), contextPath, servletName, tenantDomain, scope, apiName, version }));
if (collectionName != null) if (collectionName != null)
{ {
sb.append('/'); sb.append('/');
@@ -783,7 +784,7 @@ public class PublicApiHttpClient
sb.append(collectionEntityId); sb.append(collectionEntityId);
} }
} }
if (relationName != null) if (relationName != null)
{ {
sb.append('/'); sb.append('/');
@@ -794,24 +795,24 @@ public class PublicApiHttpClient
sb.append(relationEntityId); sb.append(relationEntityId);
} }
} }
addParams(sb, params); addParams(sb, params);
this.url = sb.toString(); this.url = sb.toString();
} }
RestApiEndpoint(String tenantDomain, String scope, String collectionName, Object collectionEntityId, String relationName, RestApiEndpoint(String tenantDomain, String scope, String collectionName, Object collectionEntityId, String relationName,
Object relationEntityId, Map<String, String> params) throws IOException Object relationEntityId, Map<String, String> params) throws IOException
{ {
this(tenantDomain, scope, 1, collectionName, collectionEntityId, relationName, relationEntityId, params); this(tenantDomain, scope, 1, collectionName, collectionEntityId, relationName, relationEntityId, params);
} }
private void addParams(StringBuilder sb, Map<String, String> params) throws UnsupportedEncodingException private void addParams(StringBuilder sb, Map<String, String> params) throws UnsupportedEncodingException
{ {
if (params != null && params.size() > 0) if (params != null && params.size() > 0)
{ {
sb.append("?"); sb.append("?");
for (String paramName : params.keySet()) for (String paramName : params.keySet())
{ {
sb.append(URLEncoder.encode(paramName, "UTF-8")); sb.append(URLEncoder.encode(paramName, "UTF-8"));
@@ -824,8 +825,8 @@ public class PublicApiHttpClient
} }
} }
private String encodeToString(Object o) throws UnsupportedEncodingException private String encodeToString(Object o) throws UnsupportedEncodingException
{ {
String ret = null; String ret = null;
if (o instanceof NodeRef) if (o instanceof NodeRef)
@@ -839,10 +840,10 @@ public class PublicApiHttpClient
} }
return ret; return ret;
} }
private Pair<String, String> getRelationCollectionInfo(Class<?> resourceClass) throws IOException private Pair<String, String> getRelationCollectionInfo(Class<?> resourceClass) throws IOException
{ {
AnnotationMetadata annotationMetaData = getAnnotationMetadata(resourceClass.getCanonicalName()); AnnotationMetadata annotationMetaData = getAnnotationMetadata(resourceClass.getCanonicalName());
if (annotationMetaData.isConcrete() && annotationMetaData.isIndependent()) if (annotationMetaData.isConcrete() && annotationMetaData.isIndependent())
{ {
@@ -851,7 +852,7 @@ public class PublicApiHttpClient
Map<String, Object> attrs = annotationMetaData.getAnnotationAttributes(RelationshipResource.class.getName()); Map<String, Object> attrs = annotationMetaData.getAnnotationAttributes(RelationshipResource.class.getName());
String relationshipCollectionName = (String) attrs.get("name"); String relationshipCollectionName = (String) attrs.get("name");
Class<?> entityResource = (Class<?>) attrs.get("entityResource"); Class<?> entityResource = (Class<?>) attrs.get("entityResource");
String entityCollectionName = getEntityCollectionInfo(entityResource.getCanonicalName()); String entityCollectionName = getEntityCollectionInfo(entityResource.getCanonicalName());
Pair<String, String> ret = new Pair<String, String>(entityCollectionName, relationshipCollectionName); Pair<String, String> ret = new Pair<String, String>(entityCollectionName, relationshipCollectionName);
@@ -866,15 +867,15 @@ public class PublicApiHttpClient
{ {
throw new AlfrescoRuntimeException(""); throw new AlfrescoRuntimeException("");
} }
} }
private String getEntityCollectionInfo(Class<?> resourceClass) throws IOException private String getEntityCollectionInfo(Class<?> resourceClass) throws IOException
{ {
return getEntityCollectionInfo(resourceClass.getCanonicalName()); return getEntityCollectionInfo(resourceClass.getCanonicalName());
} }
private String getEntityCollectionInfo(String className) throws IOException private String getEntityCollectionInfo(String className) throws IOException
{ {
AnnotationMetadata annotationMetaData = getAnnotationMetadata(className); AnnotationMetadata annotationMetaData = getAnnotationMetadata(className);
if (annotationMetaData.isConcrete() && annotationMetaData.isIndependent()) if (annotationMetaData.isConcrete() && annotationMetaData.isIndependent())
{ {
@@ -892,13 +893,13 @@ public class PublicApiHttpClient
{ {
throw new AlfrescoRuntimeException(""); throw new AlfrescoRuntimeException("");
} }
} }
public String getUrl() throws UnsupportedEncodingException public String getUrl() throws UnsupportedEncodingException
{ {
return url; return url;
} }
} }
/** /**
* @author Jamal Kaabi-Mofrad * @author Jamal Kaabi-Mofrad
@@ -1305,4 +1306,4 @@ public class PublicApiHttpClient
return req; return req;
} }
} }
} }