</dependencies>\r
\r
<build>\r
- <finalName>CollectionSpace</finalName>\r
+ <finalName>cspace-services</finalName>\r
<plugins>\r
<plugin>\r
<groupId>org.codehaus.mojo</groupId>\r
<artifactId>jboss-maven-plugin</artifactId>\r
<configuration>\r
+ <serverName>cspace</serverName>\r
<jbossHome>${jboss.dir}</jbossHome>\r
<port>8180</port>\r
</configuration>\r
<goal>undeploy</goal>\r
</goals>\r
<configuration>\r
- <fileName>${basedir}/target/CollectionSpace.war</fileName>\r
+ <fileNames>\r
+ <param>${project.build.directory}/${project.build.finalName}.war</param>\r
+ </fileNames>\r
</configuration>\r
</execution>\r
<execution>\r
<goal>deploy</goal>\r
</goals>\r
<configuration>\r
- <fileName>${basedir}/target/CollectionSpace.war</fileName>\r
+ <fileNames>\r
+ <param>${project.build.directory}/${project.build.finalName}.war</param>\r
+ </fileNames>\r
</configuration>\r
</execution>\r
</executions>\r
+++ /dev/null
-java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
-java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
-java.naming.provider.url=jnp://localhost:1099
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<jboss-web>\r
+ <!-- All secure web resources will use this security domain -->\r
+ <security-domain>java:/jaas/cspace</security-domain>\r
+</jboss-web>
\ No newline at end of file
-->
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
- <display-name>CollectionSpace</display-name>
+ <display-name>CollectionSpace Services</display-name>
<context-param>
<param-name>javax.ws.rs.Application</param-name>
<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
- <param-value>/nuxeo-rest</param-value>
+ <param-value>/</param-value>
</context-param>
<!-- Listeners -->
<servlet-mapping>
<servlet-name>Resteasy</servlet-name>
- <url-pattern>/nuxeo-rest/*</url-pattern>
+ <url-pattern>/*</url-pattern>
</servlet-mapping>
+<!-- BEGIN-AUTH uncomment the following
+ <security-constraint>
+ <web-resource-collection>
+ <web-resource-name>CollectionSpace Services</web-resource-name>
+ <url-pattern>/*</url-pattern>
+ </web-resource-collection>
+ <auth-constraint>
+ <role-name>*</role-name>
+ </auth-constraint>
+
+ <user-data-constraint>
+ <transport-guarantee>NONE</transport-guarantee>
+ </user-data-constraint>
+ </security-constraint>
+
+ <login-config>
+ <auth-method>BASIC</auth-method>
+ <realm-name>CollectionSpace realm</realm-name>
+ </login-config>
+ END AUTH -->
</web-app>
package org.collectionspace.services.client;\r
\r
+import org.apache.commons.httpclient.HttpClient;\r
+import org.apache.commons.httpclient.UsernamePasswordCredentials;\r
+import org.apache.commons.httpclient.auth.AuthScope;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
public abstract class CollectionSpaceClient {\r
- static final String URL_PROPERTY = "org.collectionspace.url";\r
- /*\r
- static final String URL_PROPERTY_SCHEME = "org.collectionspace.url.schme";\r
- static final String URL_PROPERTY_HOST = "org.collectionspace.url.host";\r
- static final String URL_PROPERTY_PORT = "org.collectionspace.url.port";\r
- static final String URL_PROPERTY_CONTEXT = "org.collectionspace.url.context";\r
- */\r
- \r
- private static final String SCHEME = "http";\r
- private static final String HOST = "localhost";\r
- private static final String PORT = "8180";\r
- private static final String URI = "/CollectionSpace/nuxeo-rest";\r
- private static final String URL = SCHEME + "://" +\r
- HOST + ":" +\r
- PORT +\r
- URI;\r
- private String collectionSpaceURL = null;\r
- \r
- \r
- String getURL() {\r
- String result = collectionSpaceURL;\r
- \r
- if (collectionSpaceURL == null) {\r
- result = collectionSpaceURL = System.getProperty(URL_PROPERTY, URL);\r
- }\r
- \r
- return result;\r
- }\r
+\r
+ static final String AUTH_PROPERTY = "org.collectionspace.auth";\r
+ static final String SSL_PROPERTY = "org.collectionspace.ssl";\r
+ static final String URL_PROPERTY = "org.collectionspace.url";\r
+ /*\r
+ static final String URL_PROPERTY_SCHEME = "org.collectionspace.url.schme";\r
+ static final String URL_PROPERTY_HOST = "org.collectionspace.url.host";\r
+ static final String URL_PROPERTY_PORT = "org.collectionspace.url.port";\r
+ static final String URL_PROPERTY_CONTEXT = "org.collectionspace.url.context";\r
+ */\r
+ private static final String HOST = "localhost";\r
+ private static final int PORT = 8180;\r
+ private static final int SSL_PORT = 8543;\r
+ private static final String PATH = "/cspace-services/";\r
+ private static final String DEFAULT_URL = "http://" +\r
+ HOST + ":" + PORT + PATH;\r
+ private static final String DEFAULT_SSL_URL = "https://" +\r
+ HOST + ":" + SSL_PORT + PATH;\r
+ private String baseURL = null;\r
+ private HttpClient httpClient;\r
+ private boolean useAuth;\r
+ private boolean useSSL;\r
+ final Logger logger = LoggerFactory.getLogger(CollectionSpaceClient.class);\r
+\r
+ protected CollectionSpaceClient() {\r
+\r
+ String url = System.getProperty(URL_PROPERTY, DEFAULT_URL);\r
+ if(url != null){\r
+ baseURL = url;\r
+ }\r
+ useAuth = Boolean.getBoolean(AUTH_PROPERTY);\r
+ if(useAuth){\r
+ httpClient = new HttpClient();\r
+ httpClient.getState().setCredentials(\r
+ new AuthScope(HOST, PORT, AuthScope.ANY_REALM),\r
+ new UsernamePasswordCredentials("test", "test"));\r
+ httpClient.getParams().setAuthenticationPreemptive(true);\r
+ if(logger.isDebugEnabled()){\r
+ logger.debug("set up httpClient for authentication");\r
+ }\r
+ }\r
+ useSSL = Boolean.getBoolean(SSL_PROPERTY);\r
+ if(logger.isDebugEnabled()){\r
+ logger.debug("useSSL=" + useSSL);\r
+ }\r
+ baseURL = useSSL ? DEFAULT_SSL_URL : DEFAULT_URL;\r
+ if(logger.isDebugEnabled()){\r
+ logger.debug("using baseURL=" + baseURL);\r
+ }\r
+ }\r
+\r
+ protected String getBaseURL() {\r
+ return baseURL;\r
+ }\r
+\r
+ protected HttpClient getHttpClient() {\r
+ return httpClient;\r
+ }\r
+\r
+ protected boolean useAuth() {\r
+ return useAuth;\r
+ }\r
+\r
+ protected boolean useSSL() {\r
+ return useSSL;\r
+ }\r
}\r
</dependencies>\r
\r
<build>\r
- <finalName>collectionspace-services-collectionobject-client</finalName>\r
+ <finalName>cspace-services-collectionobject-client</finalName>\r
<plugins>\r
+ <plugin>\r
+ <groupId>org.apache.maven.plugins</groupId>\r
+ <artifactId>maven-surefire-plugin</artifactId>\r
+ <configuration>\r
+ <systemProperties>\r
+ <property>\r
+ <name>log4j.configuration</name>\r
+ <value>log4j.xml</value>\r
+ </property>\r
+ </systemProperties>\r
+ </configuration>\r
+ </plugin>\r
<plugin>\r
<artifactId>maven-compiler-plugin</artifactId>\r
<version>2.0.2</version>\r
*/
public class CollectionObjectClient extends CollectionSpaceClient {
-
/**
*
*/
private CollectionObjectClient() {
ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance();
RegisterBuiltin.register(factory);
- collectionObjectProxy = ProxyFactory.create(CollectionObjectProxy.class, getURL());
+ if(useAuth()){
+ collectionObjectProxy = ProxyFactory.create(CollectionObjectProxy.class,
+ getBaseURL(), getHttpClient());
+ }else{
+ collectionObjectProxy = ProxyFactory.create(CollectionObjectProxy.class,
+ getBaseURL());
+ }
}
/**
import org.collectionspace.services.collectionobject.CollectionObject;
import org.collectionspace.services.collectionobject.CollectionObjectList;
import org.collectionspace.services.client.CollectionObjectClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* A CollectionObjectNuxeoServiceTest.
private CollectionObjectClient collectionObjectClient = CollectionObjectClient.getInstance();
private String updateId = null;
private String deleteId = null;
+ final Logger logger = LoggerFactory.getLogger(CollectionObjectServiceTest.class);
@Test
public void createCollectionObject() {
- long identifier = this.createIdentifier();
-
- CollectionObject collectionObject = createCollectionObject(identifier);
+ long identifier = this.createIdentifier();
+
+ CollectionObject collectionObject = createCollectionObject(identifier);
ClientResponse<Response> res = collectionObjectClient.createCollectionObject(collectionObject);
Assert.assertEquals(res.getStatus(), Response.Status.CREATED.getStatusCode());
-
+
//store updateId locally for "update" test
- if (updateId == null) {
- updateId = extractId(res);
- } else {
- deleteId = extractId(res);
- System.out.println("Set deleteId: " + deleteId);
+ if(updateId == null){
+ updateId = extractId(res);
+ }else{
+ deleteId = extractId(res);
+ verbose("Set deleteId: " + deleteId);
}
}
@Test(dependsOnMethods = {"createCollectionObject"})
public void updateCollectionObject() {
- ClientResponse<CollectionObject> res = collectionObjectClient.getCollectionObject(updateId);
+ ClientResponse<CollectionObject> res = collectionObjectClient.getCollectionObject(updateId);
CollectionObject collectionObject = res.getEntity();
verbose("Got CollectionObject to update with ID: " + updateId,
- collectionObject, CollectionObject.class);
-
+ collectionObject, CollectionObject.class);
+
//collectionObject.setCsid("updated-" + updateId);
collectionObject.setObjectNumber("updated-" + collectionObject.getObjectNumber());
collectionObject.setObjectName("updated-" + collectionObject.getObjectName());
-
+
// make call to update service
res = collectionObjectClient.updateCollectionObject(updateId, collectionObject);
-
+
// check the response
- CollectionObject updatedCollectionObject = res.getEntity();
+ CollectionObject updatedCollectionObject = res.getEntity();
Assert.assertEquals(updatedCollectionObject.getObjectName(), collectionObject.getObjectName());
verbose("updateCollectionObject: ", updatedCollectionObject, CollectionObject.class);
-
+
return;
}
@Test(dependsOnMethods = {"createCollectionObject"})
public void createCollection() {
- for (int i = 0; i < 3; i++) {
- this.createCollectionObject();
- }
+ for(int i = 0; i < 3; i++){
+ this.createCollectionObject();
+ }
}
-
+
@Test(dependsOnMethods = {"createCollection"})
public void getCollectionObjectList() {
//the resource method is expected to return at least an empty list
CollectionObjectList coList = collectionObjectClient.getCollectionObjectList().getEntity();
List<CollectionObjectList.CollectionObjectListItem> coItemList = coList.getCollectionObjectListItem();
int i = 0;
- for(CollectionObjectList.CollectionObjectListItem pli : coItemList) {
+ for(CollectionObjectList.CollectionObjectListItem pli : coItemList){
verbose("getCollectionObjectList: list-item[" + i + "] csid=" + pli.getCsid());
verbose("getCollectionObjectList: list-item[" + i + "] objectNumber=" + pli.getObjectNumber());
verbose("getCollectionObjectList: list-item[" + i + "] URI=" + pli.getUri());
@Test(dependsOnMethods = {"createCollection"})
public void deleteCollectionObject() {
- System.out.println("Calling deleteCollectionObject:" + deleteId);
+ verbose("Calling deleteCollectionObject:" + deleteId);
ClientResponse<Response> res = collectionObjectClient.deleteCollectionObject(deleteId);
verbose("deleteCollectionObject: csid=" + deleteId);
verbose("deleteCollectionObject: status = " + res.getStatus());
}
private CollectionObject createCollectionObject(long identifier) {
- CollectionObject collectionObject = createCollectionObject("objectNumber-" + identifier,
- "objectName-" + identifier);
+ CollectionObject collectionObject = createCollectionObject("objectNumber-" + identifier,
+ "objectName-" + identifier);
return collectionObject;
}
private CollectionObject createCollectionObject(String objectNumber, String objectName) {
- CollectionObject collectionObject = new CollectionObject();
-
- collectionObject.setObjectNumber(objectNumber);
- collectionObject.setObjectName(objectName);
+ CollectionObject collectionObject = new CollectionObject();
+
+ collectionObject.setObjectNumber(objectNumber);
+ collectionObject.setObjectName(objectName);
return collectionObject;
}
}
private void verbose(String msg) {
- System.out.println("CollectionObject Test: " + msg);
+// if(logger.isInfoEnabled()){
+// logger.debug(msg);
+// }
+ System.out.println(msg);
}
private void verbose(String msg, Object o, Class clazz) {
verbose(" name=" + mentry.getKey() + " value=" + mentry.getValue());
}
}
-
+
private long createIdentifier() {
- long identifier = System.currentTimeMillis();
- return identifier;
+ long identifier = System.currentTimeMillis();
+ return identifier;
}
}
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
- <appender name="console" class="org.apache.log4j.ConsoleAppender">
- <param name="Target" value="System.out" />
- <layout class="org.apache.log4j.TTCCLayout">
- <param name="DateFormat" value="ISO8601" />
- </layout>
- </appender>
-
-
- <appender name="unit-tests"
+ <appender name="console" class="org.apache.log4j.ConsoleAppender">
+ <param name="Target" value="System.out" />
+ <layout class="org.apache.log4j.TTCCLayout">
+ <param name="DateFormat" value="ISO8601" />
+ </layout>
+ </appender>
+
+ <appender name="unit-tests"
class="org.apache.log4j.RollingFileAppender">
- <param name="File" value="./target/unit-tests.log" />
- <param name="MaxFileSize" value="10240KB" />
- <param name="MaxBackupIndex" value="6" />
- <layout class="org.apache.log4j.TTCCLayout">
- <param name="DateFormat" value="ISO8601" />
- </layout>
- </appender>
-
- <logger name="org.apache.commons.httpclient" additivity="false">
- <level value="warn" />
+ <param name="File" value="./target/unit-tests.log" />
+ <param name="MaxFileSize" value="10240KB" />
+ <param name="MaxBackupIndex" value="6" />
+ <layout class="org.apache.log4j.TTCCLayout">
+ <param name="DateFormat" value="ISO8601" />
+ </layout>
+ </appender>
+
+ <!--logger name="org.apache.commons.httpclient" additivity="false">
+ <level value="info" />
<appender-ref ref="console" />
<appender-ref ref="unit-tests" />
</logger>
<appender-ref ref="unit-tests" />
</logger>
- <root>
- <priority value="debug" />
+ <logger name="org.collectionspace" additivity="false">
+ <level value="info" />
<appender-ref ref="console" />
<appender-ref ref="unit-tests" />
- </root>
+ </logger-->
+ <category name="org.apache.commons.httpclient">
+ <priority value="INFO"/>
+ </category>
+ <category name="httpclient.wire">
+ <priority value="INFO"/>
+ </category>
+ <category name="org.collectionspace.services.client">
+ <priority value="DEBUG"/>
+ </category>
+ <root>
+ <priority value="debug" />
+ <appender-ref ref="console" />
+ <appender-ref ref="unit-tests" />
+ </root>
</log4j:configuration>
<modules>
<module>common</module>
+ <module>authentication</module>
<module>client</module>
<module>collectionobject</module>
<module>JaxRsServiceProvider</module>