import org.collectionspace.services.config.tenant.TenantBindingType;
import org.collectionspace.services.nuxeo.client.java.CoreSessionInterface;
import org.collectionspace.services.nuxeo.util.NuxeoUtils;
-import org.dom4j.DocumentException;
+import org.collectionspace.services.common.document.DocumentException;
+
+//import org.dom4j.DocumentException;
+import org.eclipse.jetty.http.HttpStatus;
import org.nuxeo.ecm.core.api.DocumentModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Response res = client.read(specifier.getURNValue());
try {
int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if (logger.isDebugEnabled()) {
- logger.debug(client.getClass().getCanonicalName() + ": status = " + statusCode);
+ if (statusCode == HttpStatus.OK_200) {
+ result = new PoxPayloadIn((String)res.readEntity(responseType)); // Get the entire response!
+ } else {
+ String errMsg = String.format("Could not retrieve authority information for '%s' on remote server '%s'. Server returned status code %d",
+ specifier.getURNValue(), remoteClientConfig.getUrl(), statusCode);
+ if (logger.isDebugEnabled()) {
+ logger.debug(errMsg);
+ }
+ throw new DocumentException(statusCode, errMsg);
}
-
- result = new PoxPayloadIn((String)res.readEntity(responseType)); // Get the entire response!
} finally {
res.close();
}
try {
int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if (logger.isDebugEnabled()) {
- logger.debug(client.getClass().getCanonicalName() + ": status = " + statusCode);
- }
-
- result = new PoxPayloadIn((String)res.readEntity(responseType)); // Get the entire response!
+ if (statusCode == HttpStatus.OK_200) {
+ result = new PoxPayloadIn((String)res.readEntity(responseType)); // Get the entire response.
+ } else {
+ String errMsg = String.format("Could not retrieve authority item information for '%s:%s' on remote server '%s'. Server returned status code %d",
+ specifier.getParentSpecifier().getURNValue(), specifier.getItemSpecifier().getURNValue(), remoteClientConfig.getUrl(), statusCode);
+ if (logger.isDebugEnabled()) {
+ logger.debug(errMsg);
+ }
+ throw new DocumentException(statusCode, errMsg);
+ }
} finally {
res.close();
}
* refnames with the correct domain name
*/
static public PoxPayloadIn filterRefnameDomains(ServiceContext ctx,
- PoxPayloadIn payload) throws DocumentException {
+ PoxPayloadIn payload) throws org.dom4j.DocumentException {
PoxPayloadIn result = null;
import org.collectionspace.services.nuxeo.client.java.CoreSessionInterface;
import org.collectionspace.services.nuxeo.client.java.RepositoryClientImpl;
import org.collectionspace.services.nuxeo.util.NuxeoUtils;
-
import org.dom4j.Element;
+import org.eclipse.jetty.http.HttpStatus;
import org.nuxeo.ecm.core.api.ClientException;
import org.nuxeo.ecm.core.api.DocumentModel;
import org.slf4j.Logger;
//
//
Long sasRev = getRevision(sasPayloadIn);
- if (sasRev > localRev) {
+ if (sasRev > localRev || true) { // FIXME: Along with the revision number, we need to use other meta information to determine if a sync should happen -for now, alway sync
//
// First, sync all the authority items
//
return result; // -1 = no sync needed/possible, 0 = sync'd, 1 = created new item
- }
+ }
+
+ private void assertStatusCode(Response res, Specifier specifier, AuthorityClient client) throws Exception {
+ int statusCode = res.getStatus();
+
+ if (statusCode != HttpStatus.OK_200) {
+ String errMsg = String.format("Could not retrieve authority information for '%s' on remote server '%s'. Server returned status code %d",
+ specifier.getURNValue(), client.getBaseURL(), statusCode);
+ res.close();
+ throw new DocumentException(statusCode, errMsg);
+ }
+ }
/**
* Request an authority item list payload from the SAS server.
*/
private PoxPayloadIn requestPayloadInItemList(ServiceContext ctx, Specifier specifier) throws Exception {
PoxPayloadIn result = null;
-
AuthorityClient client = (AuthorityClient) ctx.getClient();
+ //
+ // First find out how many items exist
Response res = client.readItemList(specifier.getURNValue(),
null, // partial term string
- null // keyword string
+ null, // keyword string
+ 0, // page size
+ 0 // page number
);
+ assertStatusCode(res, specifier, client);
+ AbstractCommonList commonList = res.readEntity(AbstractCommonList.class);
+ res.close();
+ long numOfItems = commonList.getTotalItems();
+
+ //
+ // Next, request a payload list with all the items
+ res = client.readItemList(specifier.getURNValue(),
+ null, // partial term string
+ null, // keyword string
+ numOfItems, // page size
+ 0 // page number
+ );
+ assertStatusCode(res, specifier, client);
+
try {
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if (logger.isDebugEnabled()) {
- logger.debug(client.getClass().getCanonicalName() + ": status = " + statusCode);
- }
-
- result = new PoxPayloadIn((String)res.readEntity(getEntityResponseType())); // Get the entire response!
+ result = new PoxPayloadIn((String)res.readEntity(getEntityResponseType())); // Get the entire response.
} finally {
res.close();
}
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
// FIXME: Deprecated classes that need to be updated
import org.jboss.resteasy.client.ProxyFactory;
import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.conn.ssl.SSLContexts;
+
+import java.security.SecureRandom;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.X509TrustManager;
+
+/**
+ * Private class for SSL support
+ */
+class HttpsTrustManager implements X509TrustManager {
+
+ @Override
+ public void checkClientTrusted(X509Certificate[] arg0, String arg1)
+ throws CertificateException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void checkServerTrusted(X509Certificate[] arg0, String arg1)
+ throws CertificateException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public X509Certificate[] getAcceptedIssuers() {
+ return new X509Certificate[]{};
+ }
+
+}
/**
* Private class for JAX-RS authentication
* allow to reset proxy as per security needs
*/
@Override
- public void setProxy() {
+ public void setProxy() throws Exception {
ResteasyClient client = null;
String urlString = url.toString();
Class<P> proxyClass = this.getProxyClass();
+ if (useSSL()) {
+ SSLContext sslcontext = SSLContexts.custom().useSSL().build();
+ sslcontext.init(null, new X509TrustManager[]{new HttpsTrustManager()}, new SecureRandom());
+ client = (ResteasyClient)ClientBuilder.newBuilder().sslContext(sslcontext).build();
+ } else {
+ client = (ResteasyClient)ClientBuilder.newClient();
+ }
+
if (useAuth()) {
String user = properties.getProperty(USER_PROPERTY);
String password = properties.getProperty(PASSWORD_PROPERTY);
- client = (ResteasyClient)ClientBuilder.newClient().register(new Authenticator(user, password));
- } else {
- client = (ResteasyClient)ClientBuilder.newClient();
+ client = client.register(new Authenticator(user, password));
}
proxy = client.target(urlString).proxy(proxyClass);
@Override
public void setAuth(boolean useAuth,
String user, boolean useUser,
- String password, boolean usePassword) {
+ String password, boolean usePassword) throws Exception {
if (useAuth == true) {
setProperty(CollectionSpaceClient.AUTH_PROPERTY, "true");
if (useUser) {
* @return the client response
*/
public Response readItemList(String inAuthority, String partialTerm, String keywords);
-
+
+ public Response readItemList(String inAuthority, String partialTerm, String keywords, long pageSize, long pageNum);
+
public Response readItemList(String inAuthority, String partialTerm, String keywords, Boolean includeDeleted);
+ public Response readItemList(String inAuthority, String partialTerm, String keywords, Boolean includeDeleted,
+ long pageSize, long pageNum);
+
/**
* Read item list for named vocabulary, filtering by partial term match, or keywords. Only one of
* partialTerm or keywords should be specified. If both are specified, keywords
return getProxy().readItemList(inAuthority, partialTerm, keywords, INCLUDE_DELETE_TRUE);
}
+ @Override
+ public Response readItemList(String inAuthority, String partialTerm, String keywords, long pageSize, long pageNum) {
+ return getProxy().readItemList(inAuthority, partialTerm, keywords, INCLUDE_DELETE_TRUE, pageSize, pageNum);
+ }
+
@Override
public Response readItemList(String inAuthority, String partialTerm, String keywords, Boolean includeDeleted) {
return getProxy().readItemList(inAuthority, partialTerm, keywords, includeDeleted.toString());
}
+
+ @Override
+ public Response readItemList(String inAuthority, String partialTerm, String keywords, Boolean includeDeleted,
+ long pageSize, long pageNum) {
+ return getProxy().readItemList(inAuthority, partialTerm, keywords, includeDeleted.toString(), pageSize, pageNum);
+ }
+
/**
* Read item list for named vocabulary, filtering by partial term match, or keywords. Only one of
@QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords,
@QueryParam(WorkflowClient.WORKFLOWSTATE_QUERY) String workflowState);
+ @GET
+ @Produces({"application/xml"})
+ @Path("/{csid}/items/")
+ Response readItemList(
+ @PathParam("csid") String vcsid,
+ @QueryParam (IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm,
+ @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords,
+ @QueryParam(WorkflowClient.WORKFLOWSTATE_QUERY) String workflowState,
+ @QueryParam(IClientQueryParams.PAGE_SIZE_PARAM) long pageSize,
+ @QueryParam(IClientQueryParams.START_PAGE_PARAM) long pageNum);
+
// List Items for a named authority matching a partial term or keywords.
@GET
@Produces({"application/xml"})
* setProxy for the client
* might be useful to reset proxy (based on auth requirements) that is usually created at the time of
* constructing a client
+ * @throws Exception
*/
- void setProxy();
+ void setProxy() throws Exception;
/**
* setAuth sets up authentication properties based on given parameters
* @param useUser indicates using user name
* @param password
* @param usePassword indicates using password
+ * @throws Exception
*/
void setAuth(boolean useAuth,
String user, boolean useUser,
- String password, boolean usePassword);
+ String password, boolean usePassword) throws Exception;
/**
* Use auth.
public static final String VALIDATION_FAILURE = "Validation failure ";
public static final String MISSING_CSID = "missing csid";
public static final String MISSING_INVALID_CSID = "missing/invalid csid=";
- public static final String SYNC_FAILED = "Synchonization failed.";
+ public static final String SYNC_FAILED = "Synchonization failed: ";
public static String resourceNotFoundMsg(String csid) {
return String.format("The resource identified by CSID '%s' was not found.", csid);