From 56acf9b343beb00308b788afa1486761f2a758c8 Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Fri, 3 Apr 2009 16:35:36 +0000 Subject: [PATCH] Adding my sandbox version of the HelloWorld prototype work. --- .../.settings/org.eclipse.jdt.core.prefs | 12 + .../.settings/org.maven.ide.eclipse.prefs | 8 + .../HelloWorld/HelloWorldClient/.classpath | 11 + .../HelloWorld/HelloWorldClient/.project | 23 ++ .../.settings/org.eclipse.jdt.core.prefs | 12 + .../.settings/org.maven.ide.eclipse.prefs | 8 + .../HelloWorldClient/nb-configuration.xml | 20 + .../HelloWorld/HelloWorldClient/nbactions.xml | 17 + .../HelloWorld/HelloWorldClient/pom.xml | 69 ++++ .../hello/client/IdentifierClient.java | 64 +++ .../hello/client/IdentifierProxy.java | 32 ++ .../hello/client/PersonClient.java | 93 +++++ .../hello/client/PersonNuxeoClient.java | 93 +++++ .../hello/client/PersonNuxeoProxy.java | 42 ++ .../hello/client/PersonProxy.java | 42 ++ .../client/test/IdentifierServiceTest.java | 64 +++ .../client/test/PersonNuxeoServiceTest.java | 133 +++++++ .../hello/client/test/PersonServiceTest.java | 159 ++++++++ .../src/test/resources/log4j.xml | 45 +++ .../temp-testng-customsuite.xml | 8 + .../HelloWorld/HelloWorldJaxb/.classpath | 9 + .../HelloWorld/HelloWorldJaxb/.project | 23 ++ .../.settings/org.eclipse.jdt.core.prefs | 5 + .../.settings/org.maven.ide.eclipse.prefs | 8 + .../HelloWorldJaxb/nb-configuration.xml | 20 + .../richard/HelloWorld/HelloWorldJaxb/pom.xml | 62 +++ .../src/main/resources/hello.xsd | 119 ++++++ .../HelloWorldNuxeoService/README.txt | 14 + .../HelloWorldNuxeoService/build.properties | 4 + .../HelloWorldNuxeoService/build.xml | 13 + .../nb-configuration.xml | 21 + .../HelloWorldNuxeoService/nbactions.xml | 74 ++++ .../HelloWorld/HelloWorldNuxeoService/pom.xml | 270 +++++++++++++ .../services/HelloworldNuxeoApplication.java | 25 ++ .../hello/services/PersonNuxeoResource.java | 371 ++++++++++++++++++ .../hello/services/nuxeo/NuxeoCallback.java | 50 +++ .../services/nuxeo/NuxeoCallbackHandler.java | 85 ++++ .../nuxeo/NuxeoLoginConfiguration.java | 53 +++ .../nuxeo/NuxeoLoginContextFactory.java | 48 +++ .../hello/services/nuxeo/NuxeoRESTClient.java | 308 +++++++++++++++ .../PortalSSOAuthenticationProvider.java | 72 ++++ .../src/main/resources/jndi.properties | 3 + .../src/main/resources/nuxeo.properties | 2 + .../src/main/webapp/WEB-INF/web.xml | 34 ++ sandbox/richard/HelloWorld/pom.xml | 231 +++++++++++ 45 files changed, 2879 insertions(+) create mode 100644 sandbox/richard/HelloWorld/.settings/org.eclipse.jdt.core.prefs create mode 100644 sandbox/richard/HelloWorld/.settings/org.maven.ide.eclipse.prefs create mode 100644 sandbox/richard/HelloWorld/HelloWorldClient/.classpath create mode 100644 sandbox/richard/HelloWorld/HelloWorldClient/.project create mode 100644 sandbox/richard/HelloWorld/HelloWorldClient/.settings/org.eclipse.jdt.core.prefs create mode 100644 sandbox/richard/HelloWorld/HelloWorldClient/.settings/org.maven.ide.eclipse.prefs create mode 100644 sandbox/richard/HelloWorld/HelloWorldClient/nb-configuration.xml create mode 100644 sandbox/richard/HelloWorld/HelloWorldClient/nbactions.xml create mode 100644 sandbox/richard/HelloWorld/HelloWorldClient/pom.xml create mode 100644 sandbox/richard/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/IdentifierClient.java create mode 100644 sandbox/richard/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/IdentifierProxy.java create mode 100644 sandbox/richard/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/PersonClient.java create mode 100644 sandbox/richard/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/PersonNuxeoClient.java create mode 100644 sandbox/richard/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/PersonNuxeoProxy.java create mode 100644 sandbox/richard/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/PersonProxy.java create mode 100644 sandbox/richard/HelloWorld/HelloWorldClient/src/test/java/org/collectionspace/hello/client/test/IdentifierServiceTest.java create mode 100644 sandbox/richard/HelloWorld/HelloWorldClient/src/test/java/org/collectionspace/hello/client/test/PersonNuxeoServiceTest.java create mode 100644 sandbox/richard/HelloWorld/HelloWorldClient/src/test/java/org/collectionspace/hello/client/test/PersonServiceTest.java create mode 100644 sandbox/richard/HelloWorld/HelloWorldClient/src/test/resources/log4j.xml create mode 100644 sandbox/richard/HelloWorld/HelloWorldClient/temp-testng-customsuite.xml create mode 100644 sandbox/richard/HelloWorld/HelloWorldJaxb/.classpath create mode 100644 sandbox/richard/HelloWorld/HelloWorldJaxb/.project create mode 100644 sandbox/richard/HelloWorld/HelloWorldJaxb/.settings/org.eclipse.jdt.core.prefs create mode 100644 sandbox/richard/HelloWorld/HelloWorldJaxb/.settings/org.maven.ide.eclipse.prefs create mode 100644 sandbox/richard/HelloWorld/HelloWorldJaxb/nb-configuration.xml create mode 100644 sandbox/richard/HelloWorld/HelloWorldJaxb/pom.xml create mode 100644 sandbox/richard/HelloWorld/HelloWorldJaxb/src/main/resources/hello.xsd create mode 100644 sandbox/richard/HelloWorld/HelloWorldNuxeoService/README.txt create mode 100644 sandbox/richard/HelloWorld/HelloWorldNuxeoService/build.properties create mode 100644 sandbox/richard/HelloWorld/HelloWorldNuxeoService/build.xml create mode 100644 sandbox/richard/HelloWorld/HelloWorldNuxeoService/nb-configuration.xml create mode 100644 sandbox/richard/HelloWorld/HelloWorldNuxeoService/nbactions.xml create mode 100644 sandbox/richard/HelloWorld/HelloWorldNuxeoService/pom.xml create mode 100644 sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/HelloworldNuxeoApplication.java create mode 100644 sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/PersonNuxeoResource.java create mode 100644 sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/nuxeo/NuxeoCallback.java create mode 100644 sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/nuxeo/NuxeoCallbackHandler.java create mode 100644 sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/nuxeo/NuxeoLoginConfiguration.java create mode 100644 sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/nuxeo/NuxeoLoginContextFactory.java create mode 100644 sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/nuxeo/NuxeoRESTClient.java create mode 100644 sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/nuxeo/PortalSSOAuthenticationProvider.java create mode 100644 sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/resources/jndi.properties create mode 100644 sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/resources/nuxeo.properties create mode 100644 sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/webapp/WEB-INF/web.xml create mode 100644 sandbox/richard/HelloWorld/pom.xml diff --git a/sandbox/richard/HelloWorld/.settings/org.eclipse.jdt.core.prefs b/sandbox/richard/HelloWorld/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..63daa7058 --- /dev/null +++ b/sandbox/richard/HelloWorld/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +#Mon Mar 30 16:16:36 PDT 2009 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/sandbox/richard/HelloWorld/.settings/org.maven.ide.eclipse.prefs b/sandbox/richard/HelloWorld/.settings/org.maven.ide.eclipse.prefs new file mode 100644 index 000000000..acbd721a0 --- /dev/null +++ b/sandbox/richard/HelloWorld/.settings/org.maven.ide.eclipse.prefs @@ -0,0 +1,8 @@ +#Thu Mar 26 12:47:04 PDT 2009 +activeProfiles= +eclipse.preferences.version=1 +fullBuildGoals=process-test-resources +includeModules=false +resolveWorkspaceProjects=true +resourceFilterGoals=process-resources resources\:testResources +version=1 diff --git a/sandbox/richard/HelloWorld/HelloWorldClient/.classpath b/sandbox/richard/HelloWorld/HelloWorldClient/.classpath new file mode 100644 index 000000000..5fc0d1639 --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldClient/.classpath @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/sandbox/richard/HelloWorld/HelloWorldClient/.project b/sandbox/richard/HelloWorld/HelloWorldClient/.project new file mode 100644 index 000000000..f44220ec1 --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldClient/.project @@ -0,0 +1,23 @@ + + + javaee-addressbook-client + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.maven.ide.eclipse.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.maven.ide.eclipse.maven2Nature + + diff --git a/sandbox/richard/HelloWorld/HelloWorldClient/.settings/org.eclipse.jdt.core.prefs b/sandbox/richard/HelloWorld/HelloWorldClient/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..8a8650d9d --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldClient/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +#Thu Mar 26 13:03:04 PDT 2009 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/sandbox/richard/HelloWorld/HelloWorldClient/.settings/org.maven.ide.eclipse.prefs b/sandbox/richard/HelloWorld/HelloWorldClient/.settings/org.maven.ide.eclipse.prefs new file mode 100644 index 000000000..c6e4123cd --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldClient/.settings/org.maven.ide.eclipse.prefs @@ -0,0 +1,8 @@ +#Thu Feb 26 16:30:28 PST 2009 +activeProfiles= +eclipse.preferences.version=1 +fullBuildGoals=process-test-resources +includeModules=false +resolveWorkspaceProjects=true +resourceFilterGoals=process-resources resources\:testResources +version=1 diff --git a/sandbox/richard/HelloWorld/HelloWorldClient/nb-configuration.xml b/sandbox/richard/HelloWorld/HelloWorldClient/nb-configuration.xml new file mode 100644 index 000000000..6c3fe600b --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldClient/nb-configuration.xml @@ -0,0 +1,20 @@ + + + + + + default + 8 + 80 + + diff --git a/sandbox/richard/HelloWorld/HelloWorldClient/nbactions.xml b/sandbox/richard/HelloWorld/HelloWorldClient/nbactions.xml new file mode 100644 index 000000000..047c73d4e --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldClient/nbactions.xml @@ -0,0 +1,17 @@ + + + + rebuild + + * + + + clean + install + + + true + + + + diff --git a/sandbox/richard/HelloWorld/HelloWorldClient/pom.xml b/sandbox/richard/HelloWorld/HelloWorldClient/pom.xml new file mode 100644 index 000000000..4eff1b8e5 --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldClient/pom.xml @@ -0,0 +1,69 @@ + + + + helloworld + org.collectionspace.hello.services + 0.1 + + 4.0.0 + org.collectionspace.hello.services + helloworld-client + jar + 0.1 + Helloworld Client + + + org.collectionspace.hello.services + helloworld-jaxb + 0.1 + + + org.testng + testng + 5.6 + + + org.slf4j + slf4j-api + + + org.slf4j + slf4j-log4j12 + + + org.jboss.resteasy + resteasy-jaxrs + 1.0.2.GA + + + + tjws + webserver + + + + + org.jboss.resteasy + resteasy-jaxb-provider + 1.0.2.GA + + + commons-httpclient + commons-httpclient + + + + + + maven-compiler-plugin + 2.0.2 + + 1.5 + 1.5 + + + + + diff --git a/sandbox/richard/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/IdentifierClient.java b/sandbox/richard/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/IdentifierClient.java new file mode 100644 index 000000000..a7b12f967 --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/IdentifierClient.java @@ -0,0 +1,64 @@ +package org.collectionspace.hello.client; + +import javax.ws.rs.core.Response; + +import org.collectionspace.hello.Identifier; +import org.jboss.resteasy.client.ProxyFactory; +import org.jboss.resteasy.plugins.providers.RegisterBuiltin; +import org.jboss.resteasy.client.ClientResponse; +import org.jboss.resteasy.spi.ResteasyProviderFactory; + +/** + * A IdentifierClient. + + * @version $Revision:$ + */ +public class IdentifierClient { + + /** + * + */ + private static final IdentifierClient instance = new IdentifierClient(); + /** + * + */ + private IdentifierProxy identifierProxy; + + /** + * + * Create a new IdentifierClient. + * + */ + private IdentifierClient() { + ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance(); + RegisterBuiltin.register(factory); + identifierProxy = ProxyFactory.create(IdentifierProxy.class, "http://localhost:8080/helloworld/cspace"); + } + + /** + * FIXME Comment this + * + * @return + */ + public static IdentifierClient getInstance() { + return instance; + } + + /** + * @param id + * @return + * @see org.collectionspace.hello.client.IdentifierProxy#getIdentifier(java.lang.Long) + */ + public ClientResponse getIdentifier(Long id) { + return identifierProxy.getIdentifier(id); + } + + /** + * @param identifier + * @return + * @see org.collectionspace.hello.client.IdentifierProxy#createIdentifier(org.collectionspace.hello.client.entity.Identifier) + */ + public ClientResponse createIdentifier(Identifier identifier) { + return identifierProxy.createIdentifier(identifier); + } +} diff --git a/sandbox/richard/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/IdentifierProxy.java b/sandbox/richard/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/IdentifierProxy.java new file mode 100644 index 000000000..125aab47d --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/IdentifierProxy.java @@ -0,0 +1,32 @@ +package org.collectionspace.hello.client; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Response; + +import org.collectionspace.hello.Identifier; +import org.jboss.resteasy.client.ClientResponse; + +/** + * @version $Revision:$ + */ +@Path("/identifiers/") +@Produces({"application/xml"}) +@Consumes({"application/xml"}) +public interface IdentifierProxy { + + /** + * @param id + * @return + */ + @GET + @Path("/{id}") + ClientResponse getIdentifier(@PathParam("id") Long id); + + @POST + ClientResponse createIdentifier(Identifier so); +} \ No newline at end of file diff --git a/sandbox/richard/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/PersonClient.java b/sandbox/richard/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/PersonClient.java new file mode 100644 index 000000000..e5de8f6e6 --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/PersonClient.java @@ -0,0 +1,93 @@ +package org.collectionspace.hello.client; + +import javax.ws.rs.core.Response; + +import org.collectionspace.hello.Person; +import org.collectionspace.hello.Persons; +import org.jboss.resteasy.client.ProxyFactory; +import org.jboss.resteasy.plugins.providers.RegisterBuiltin; +import org.jboss.resteasy.client.ClientResponse; +import org.jboss.resteasy.spi.ResteasyProviderFactory; + +/** + * A PersonClient. + + * @version $Revision:$ + */ +public class PersonClient { + + /** + * + */ + private static final PersonClient instance = new PersonClient(); + /** + * + */ + private PersonProxy personProxy; + + /** + * + * Create a new PersonClient. + * + */ + private PersonClient() { + ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance(); + RegisterBuiltin.register(factory); + personProxy = ProxyFactory.create(PersonProxy.class, "http://localhost:8080/helloworld/cspace"); + } + + /** + * FIXME Comment this + * + * @return + */ + public static PersonClient getInstance() { + return instance; + } + + /** + * @param id + * @return + * @see org.collectionspace.hello.client.PersonProxy#getPerson() + */ + public ClientResponse getPersons() { + return personProxy.getPersons(); + } + + /** + * @param id + * @return + * @see org.collectionspace.hello.client.PersonProxy#getPerson(java.lang.Long) + */ + public ClientResponse getPerson(Long id) { + return personProxy.getPerson(id); + } + + /** + * @param person + * @return + * @see org.collectionspace.hello.client.PersonProxy#createPerson(org.collectionspace.hello.client.entity.Person) + */ + public ClientResponse createPerson(Person person) { + return personProxy.createPerson(person); + } + + /** + * @param id + * @param person + * @return + * @see org.collectionspace.hello.client.PersonProxy#updatePerson(java.lang.Long, org.collectionspace.hello.client.entity.Person) + */ + public ClientResponse updatePerson(Long id, Person person) { + return personProxy.updatePerson(id, person); + } + + /** + * @param id + * @return + * @see org.collectionspace.hello.client.PersonProxy#deletePerson(java.lang.Long) + */ + public ClientResponse deletePerson(Long id) { + return personProxy.deletePerson(id); + } +} diff --git a/sandbox/richard/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/PersonNuxeoClient.java b/sandbox/richard/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/PersonNuxeoClient.java new file mode 100644 index 000000000..cc99f11ee --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/PersonNuxeoClient.java @@ -0,0 +1,93 @@ +package org.collectionspace.hello.client; + +import javax.ws.rs.core.Response; + +import org.collectionspace.hello.PersonNuxeo; +import org.collectionspace.hello.People; +import org.jboss.resteasy.client.ProxyFactory; +import org.jboss.resteasy.plugins.providers.RegisterBuiltin; +import org.jboss.resteasy.client.ClientResponse; +import org.jboss.resteasy.spi.ResteasyProviderFactory; + +/** + * A PersonNuxeoClient. + + * @version $Revision:$ + */ +public class PersonNuxeoClient { + + /** + * + */ + private static final PersonNuxeoClient instance = new PersonNuxeoClient(); + /** + * + */ + private PersonNuxeoProxy personProxy; + + /** + * + * Create a new PersonNuxeoClient. + * + */ + private PersonNuxeoClient() { + ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance(); + RegisterBuiltin.register(factory); + personProxy = ProxyFactory.create(PersonNuxeoProxy.class, "http://localhost:8080/helloworld/cspace-nuxeo"); + } + + /** + * FIXME Comment this + * + * @return + */ + public static PersonNuxeoClient getInstance() { + return instance; + } + + /** + * @param id + * @return + * @see org.collectionspace.hello.client.PersonNuxeoProxy#getPerson() + */ + public ClientResponse getPeople() { + return personProxy.getPeople(); + } + + /** + * @param id + * @return + * @see org.collectionspace.hello.client.PersonNuxeoProxy#getPerson(java.lang.String) + */ + public ClientResponse getPerson(String id) { + return personProxy.getPerson(id); + } + + /** + * @param person + * @return + * @see org.collectionspace.hello.client.PersonNuxeoProxy#createPerson(org.collectionspace.hello.PersonNuxeo) + */ + public ClientResponse createPerson(PersonNuxeo person) { + return personProxy.createPerson(person); + } + + /** + * @param id + * @param person + * @return + * @see org.collectionspace.hello.client.PersonNuxeoProxy#updatePerson(java.lang.Long, org.collectionspace.hello.PersonNuxeo) + */ + public ClientResponse updatePerson(String id, PersonNuxeo person) { + return personProxy.updatePerson(id, person); + } + + /** + * @param id + * @return + * @see org.collectionspace.hello.client.PersonNuxeoProxy#deletePerson(java.lang.Long) + */ + public ClientResponse deletePerson(String id) { + return personProxy.deletePerson(id); + } +} diff --git a/sandbox/richard/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/PersonNuxeoProxy.java b/sandbox/richard/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/PersonNuxeoProxy.java new file mode 100644 index 000000000..53265de84 --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/PersonNuxeoProxy.java @@ -0,0 +1,42 @@ +package org.collectionspace.hello.client; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Response; + +import org.collectionspace.hello.PersonNuxeo; +import org.collectionspace.hello.People; +import org.jboss.resteasy.client.ClientResponse; + +/** + * @version $Revision:$ + */ +@Path("/persons/") +@Produces({"application/xml"}) +@Consumes({"application/xml"}) +public interface PersonNuxeoProxy { + + @GET + ClientResponse getPeople(); + + @GET + @Path("/{id}") + ClientResponse getPerson(@PathParam("id") String id); + + @POST + ClientResponse createPerson(PersonNuxeo so); + + @PUT + @Path("/{id}") + ClientResponse updatePerson(@PathParam("id") String id, PersonNuxeo so); + + @DELETE + @Path("/{id}") + ClientResponse deletePerson(@PathParam("id") String id); +} \ No newline at end of file diff --git a/sandbox/richard/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/PersonProxy.java b/sandbox/richard/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/PersonProxy.java new file mode 100644 index 000000000..2b6f2370b --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/PersonProxy.java @@ -0,0 +1,42 @@ +package org.collectionspace.hello.client; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Response; + +import org.collectionspace.hello.Person; +import org.collectionspace.hello.Persons; +import org.jboss.resteasy.client.ClientResponse; + +/** + * @version $Revision:$ + */ +@Path("/persons/") +@Produces({"application/xml"}) +@Consumes({"application/xml"}) +public interface PersonProxy { + + @GET + ClientResponse getPersons(); + + @GET + @Path("/{id}") + ClientResponse getPerson(@PathParam("id") Long id); + + @POST + ClientResponse createPerson(Person so); + + @PUT + @Path("/{id}") + ClientResponse updatePerson(@PathParam("id") Long id, Person so); + + @DELETE + @Path("/{id}") + ClientResponse deletePerson(@PathParam("id") Long id); +} \ No newline at end of file diff --git a/sandbox/richard/HelloWorld/HelloWorldClient/src/test/java/org/collectionspace/hello/client/test/IdentifierServiceTest.java b/sandbox/richard/HelloWorld/HelloWorldClient/src/test/java/org/collectionspace/hello/client/test/IdentifierServiceTest.java new file mode 100644 index 000000000..05bc199b5 --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldClient/src/test/java/org/collectionspace/hello/client/test/IdentifierServiceTest.java @@ -0,0 +1,64 @@ +package org.collectionspace.hello.client.test; + +import org.collectionspace.hello.client.*; +import java.util.ArrayList; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Response; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; +import org.collectionspace.hello.Identifier; +import org.jboss.resteasy.client.ClientResponse; +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + * A IdentifierServiceTest. + * + * @version $Revision:$ + */ +public class IdentifierServiceTest { + + private IdentifierClient identifierClient = IdentifierClient.getInstance(); + private Long id = 0L; + + @Test + public void createIdentifier() { + Identifier identifier = new Identifier(); + identifier.setNamespace("org.bnhm"); + ClientResponse res = identifierClient.createIdentifier(identifier); + Assert.assertEquals(res.getStatus(), Response.Status.CREATED.getStatusCode()); + id = extractId(res); + } + + @Test(dependsOnMethods = {"createIdentifier"}) + public void getIdentifier() { + Identifier i = identifierClient.getIdentifier(id).getEntity(); + verbose("got Identifier", i); + } + + private Long extractId(ClientResponse res) { + MultivaluedMap mvm = res.getMetadata(); + String uri = (String) ((ArrayList) mvm.get("Location")).get(0); + String[] segments = uri.split("/"); + verbose("id=" + segments[segments.length - 1]); + return Long.valueOf(segments[segments.length - 1]); + } + + private void verbose(String msg) { + System.out.println("IdentifierServiceTest : " + msg); + } + + private void verbose(String msg, Identifier p) { + try { + verbose(msg); + JAXBContext jc = JAXBContext.newInstance(Identifier.class); + Marshaller m = jc.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, + Boolean.TRUE); + m.marshal(p, System.out); + //m.marshal(new JAXBElement(new QName("uri", "local"), Identifier.class, p), System.out); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/sandbox/richard/HelloWorld/HelloWorldClient/src/test/java/org/collectionspace/hello/client/test/PersonNuxeoServiceTest.java b/sandbox/richard/HelloWorld/HelloWorldClient/src/test/java/org/collectionspace/hello/client/test/PersonNuxeoServiceTest.java new file mode 100644 index 000000000..6c53d0510 --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldClient/src/test/java/org/collectionspace/hello/client/test/PersonNuxeoServiceTest.java @@ -0,0 +1,133 @@ +package org.collectionspace.hello.client.test; + +import java.util.ArrayList; +import java.util.List; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Response; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; +import org.collectionspace.hello.PersonNuxeo; +import org.collectionspace.hello.People; +import org.collectionspace.hello.client.PersonNuxeoClient; +import org.jboss.resteasy.client.ClientResponse; +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + * A PersonNuxeoServiceTest. + * + * @version $Revision:$ + */ +public class PersonNuxeoServiceTest { + + private PersonNuxeoClient personClient = PersonNuxeoClient.getInstance(); + private String updateId = ""; + private String deleteId = ""; + + @Test + public void createPerson() { + PersonNuxeo person = createPerson("Chris", "Hoffman"); + ClientResponse res = personClient.createPerson(person); + Assert.assertEquals(res.getStatus(), Response.Status.CREATED.getStatusCode()); + //store updateId locally + updateId = extractId(res); + } + + @Test + public void createTeam() { + PersonNuxeo person = createPerson("Sanjay", "Dalal"); + ClientResponse res = personClient.createPerson(person); + Assert.assertEquals(res.getStatus(), Response.Status.CREATED.getStatusCode()); + deleteId = extractId(res); + + person = createPerson("Aron", "Roberts"); + res = personClient.createPerson(person); + Assert.assertEquals(res.getStatus(), Response.Status.CREATED.getStatusCode()); + + person = createPerson("Richard", "Millet"); + res = personClient.createPerson(person); + Assert.assertEquals(res.getStatus(), Response.Status.CREATED.getStatusCode()); + + } + + @Test(dependsOnMethods = {"createPerson"}) + public void updatePerson() { + PersonNuxeo touPerson = personClient.getPerson(updateId).getEntity(); + touPerson.setId(updateId); + verbose("got person to update", touPerson, PersonNuxeo.class); + touPerson.setFirstName("Patrick"); + touPerson.setLastName("Schmitz"); + PersonNuxeo uPerson = personClient.updatePerson(updateId, touPerson).getEntity(); + verbose("updated person", uPerson, PersonNuxeo.class); + //Assert.assertNotSame(uPerson.getVersion(), initialVersion); + Assert.assertEquals(uPerson.getFirstName(), "Patrick"); + } + + @Test(dependsOnMethods = {"createTeam"}) + public void getPeople() { + //the resource method is expected to return at least an empty list + People people = personClient.getPeople().getEntity(); + List list = people.getPeopleItem(); + int i = 0; + for(People.PeopleItem pli : list){ + verbose("getPeople: list-item[" + i + "] title=" + pli.getTitle()); + verbose("getPeople: list-item[" + i + "] id=" + pli.getId()); + verbose("getPeople: list-item[" + i + "] uri=" + pli.getUri()); + i++; + } + } + + @Test(dependsOnMethods = {"updatePerson"}) + public void deletePerson() { + ClientResponse res = personClient.deletePerson(deleteId); + verbose("deletePerson: id=" + deleteId); + verbose("deletePerson: status = " + res.getStatus()); + Assert.assertEquals(res.getStatus(), Response.Status.NO_CONTENT.getStatusCode()); + } + + private PersonNuxeo createPerson(String firstName, String lastName) { + PersonNuxeo person = new PersonNuxeo(); + person.setFirstName(firstName); + person.setLastName(lastName); + person.setStreet("2195 Hearst Ave."); + person.setCity("Berkeley"); + person.setState("CA"); + person.setZip("94704"); + person.setCountry("US"); + person.setVersion("1.0"); + return person; + } + + private String extractId(ClientResponse res) { + MultivaluedMap mvm = res.getMetadata(); + String uri = (String) ((ArrayList) mvm.get("Location")).get(0); + String[] segments = uri.split("/"); + String id = segments[segments.length - 1]; + verbose("id=" + id); + return id; + } + + private void verbose(String msg) { + System.out.println("PersonServiceTest : " + msg); + } + + private void verbose(String msg, Object o, Class clazz) { + try{ + verbose(msg); + JAXBContext jc = JAXBContext.newInstance(clazz); + Marshaller m = jc.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, + Boolean.TRUE); + m.marshal(o, System.out); + }catch(Exception e){ + e.printStackTrace(); + } + } + + private void verboseMap(MultivaluedMap map) { + for(Object entry : map.entrySet()){ + MultivaluedMap.Entry mentry = (MultivaluedMap.Entry) entry; + verbose(" name=" + mentry.getKey() + " value=" + mentry.getValue()); + } + } +} diff --git a/sandbox/richard/HelloWorld/HelloWorldClient/src/test/java/org/collectionspace/hello/client/test/PersonServiceTest.java b/sandbox/richard/HelloWorld/HelloWorldClient/src/test/java/org/collectionspace/hello/client/test/PersonServiceTest.java new file mode 100644 index 000000000..cf60e22bf --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldClient/src/test/java/org/collectionspace/hello/client/test/PersonServiceTest.java @@ -0,0 +1,159 @@ +package org.collectionspace.hello.client.test; + +import java.util.ArrayList; +import java.util.List; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Response; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; +import org.collectionspace.hello.Person; +import org.collectionspace.hello.Persons; +import org.collectionspace.hello.client.PersonClient; +import org.jboss.resteasy.client.ClientResponse; +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + * A PersonServiceTest. + * + * @version $Revision:$ + */ +public class PersonServiceTest { + + private PersonClient personClient = PersonClient.getInstance(); + private Long updateId = 0L; + + @Test + public void createPerson() { + Person person = createPerson("Chris", "Hoffman"); + ClientResponse res = personClient.createPerson(person); + Assert.assertEquals(res.getStatus(), Response.Status.CREATED.getStatusCode()); + //store updateId locally + updateId = extractId(res); + } + + @Test + public void createPersons() { + Person person = createPerson("Aron", "Roberts"); + ClientResponse res = personClient.createPerson(person); + Assert.assertEquals(res.getStatus(), Response.Status.CREATED.getStatusCode()); + person = createPerson("Dan", "Sheppard"); + res = personClient.createPerson(person); + Assert.assertEquals(res.getStatus(), Response.Status.CREATED.getStatusCode()); + } + + @Test(dependsOnMethods = {"createPerson"}) + public void updatePerson() { + Person touPerson = personClient.getPerson(updateId).getEntity(); + verbose("got person to update", touPerson, Person.class); + touPerson.setFirstName("Richard"); + touPerson.setLastName("Millet"); + int initialVersion = touPerson.getVersion(); + Person uPerson = personClient.updatePerson(updateId, touPerson).getEntity(); + verbose("updated person", uPerson, Person.class); + Assert.assertNotSame(uPerson.getVersion(), initialVersion); + Assert.assertEquals(uPerson.getFirstName(), "Richard"); + } + + @Test(dependsOnMethods = {"createPerson"}) + public void getPersons() { + //the resource method is expected to return at least an empty list + Persons persons = personClient.getPersons().getEntity(); + List list = persons.getPersonListItem(); + int i = 0; + for (Persons.PersonListItem pli : list) { + verbose("getPersons: list-item[" + i + "] firstName=" + pli.getFirstName()); + verbose("getPersons: list-item[" + i + "] lastName=" + pli.getLastName()); + verbose("getPersons: list-item[" + i + "] uri=" + pli.getUri()); + i++; + } + } + + + @Test + public void getNonExistingPerson() { + ClientResponse res = personClient.getPerson(999L); + + Response.Status status = res.getResponseStatus(); + verbose(this.getClass().getName() + ": " + + "getNonExistingPerson: Status: code=" + status.getStatusCode() + + " message=" + status.toString()); + verbose("getNonExistingPerson: Metadata:"); + verboseMap(res.getMetadata()); + verbose("getNonExistingPerson: Headers:"); + verboseMap(res.getHeaders()); + if (status.equals(Response.Status.NOT_FOUND)) { + String msg = res.getEntity(String.class, String.class); + verbose("getNonExistingPerson: error message=" + msg); + } + } + + @Test(dependsOnMethods = {"updatePerson"}) + public void updateWrongPerson() { + Person touPerson = personClient.getPerson(updateId).getEntity(); + verbose("updateWrongPerson: got person to update", touPerson, Person.class); + touPerson.setFirstName("Richard"); + touPerson.setLastName("Millet"); + //use non existing person to update + ClientResponse res = personClient.updatePerson(9999L, touPerson); + if (res.getResponseStatus().equals(Response.Status.NOT_FOUND)) { + verbose("updateWrongPerson: Status=" + res.getResponseStatus().toString()); + String msg = res.getEntity(String.class, String.class); + verbose("updateWrongPerson: application error message=" + msg); + } + } + + + @Test(dependsOnMethods = {"updateWrongPerson"}) + public void deletePerson() { + ClientResponse res = personClient.deletePerson(updateId); + verbose("deletePerson: id=" + updateId); + verbose("deletePerson: status = " + res.getStatus()); + Assert.assertEquals(res.getStatus(), Response.Status.NO_CONTENT.getStatusCode()); + } + + private Person createPerson(String firstName, String lastName) { + Person person = new Person(); + person.setFirstName(firstName); + person.setLastName(lastName); + person.setStreet("2195 Hearst Ave."); + person.setCity("Berkeley"); + person.setState("CA"); + person.setZip("94704"); + person.setCountry("US"); + return person; + } + + private Long extractId(ClientResponse res) { + MultivaluedMap mvm = res.getMetadata(); + String uri = (String) ((ArrayList) mvm.get("Location")).get(0); + String[] segments = uri.split("/"); + verbose("id=" + segments[segments.length - 1]); + return Long.valueOf(segments[segments.length - 1]); + } + + private void verbose(String msg) { + System.out.println("PersonServiceTest : " + msg); + } + + private void verbose(String msg, Object o, Class clazz) { + try { + verbose(msg); + JAXBContext jc = JAXBContext.newInstance(clazz); + Marshaller m = jc.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, + Boolean.TRUE); + m.marshal(o, System.out); + //m.marshal(new JAXBElement(new QName("uri", "local"), Person.class, p), System.out); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void verboseMap(MultivaluedMap map) { + for (Object entry : map.entrySet()) { + MultivaluedMap.Entry mentry = (MultivaluedMap.Entry) entry; + verbose(" name=" + mentry.getKey() + " value=" + mentry.getValue()); + } + } +} diff --git a/sandbox/richard/HelloWorld/HelloWorldClient/src/test/resources/log4j.xml b/sandbox/richard/HelloWorld/HelloWorldClient/src/test/resources/log4j.xml new file mode 100644 index 000000000..52121cb83 --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldClient/src/test/resources/log4j.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/richard/HelloWorld/HelloWorldClient/temp-testng-customsuite.xml b/sandbox/richard/HelloWorld/HelloWorldClient/temp-testng-customsuite.xml new file mode 100644 index 000000000..9f2480621 --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldClient/temp-testng-customsuite.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/sandbox/richard/HelloWorld/HelloWorldJaxb/.classpath b/sandbox/richard/HelloWorld/HelloWorldJaxb/.classpath new file mode 100644 index 000000000..a92b24a87 --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldJaxb/.classpath @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/sandbox/richard/HelloWorld/HelloWorldJaxb/.project b/sandbox/richard/HelloWorld/HelloWorldJaxb/.project new file mode 100644 index 000000000..db1c789f7 --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldJaxb/.project @@ -0,0 +1,23 @@ + + + javaee-addressbook-jaxb + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.maven.ide.eclipse.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.maven.ide.eclipse.maven2Nature + + diff --git a/sandbox/richard/HelloWorld/HelloWorldJaxb/.settings/org.eclipse.jdt.core.prefs b/sandbox/richard/HelloWorld/HelloWorldJaxb/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..8780c51c5 --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldJaxb/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +#Thu Feb 26 16:32:52 PST 2009 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/sandbox/richard/HelloWorld/HelloWorldJaxb/.settings/org.maven.ide.eclipse.prefs b/sandbox/richard/HelloWorld/HelloWorldJaxb/.settings/org.maven.ide.eclipse.prefs new file mode 100644 index 000000000..c6e4123cd --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldJaxb/.settings/org.maven.ide.eclipse.prefs @@ -0,0 +1,8 @@ +#Thu Feb 26 16:30:28 PST 2009 +activeProfiles= +eclipse.preferences.version=1 +fullBuildGoals=process-test-resources +includeModules=false +resolveWorkspaceProjects=true +resourceFilterGoals=process-resources resources\:testResources +version=1 diff --git a/sandbox/richard/HelloWorld/HelloWorldJaxb/nb-configuration.xml b/sandbox/richard/HelloWorld/HelloWorldJaxb/nb-configuration.xml new file mode 100644 index 000000000..6c3fe600b --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldJaxb/nb-configuration.xml @@ -0,0 +1,20 @@ + + + + + + default + 8 + 80 + + diff --git a/sandbox/richard/HelloWorld/HelloWorldJaxb/pom.xml b/sandbox/richard/HelloWorld/HelloWorldJaxb/pom.xml new file mode 100644 index 000000000..20227a0c4 --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldJaxb/pom.xml @@ -0,0 +1,62 @@ + + + + helloworld + org.collectionspace.hello.services + 0.1 + + 4.0.0 + org.collectionspace.hello.services + helloworld-jaxb + 0.1 + Helloworld Client JAXB + + + com.sun.xml.bind + jaxb-impl + 2.0.2 + + + org.jvnet.jaxb2-commons + property-listener-injector + 1.0 + + + org.jvnet.jaxb2_commons + runtime + 0.4.1.4 + + + + install + + + org.jvnet.jaxb2.maven2 + maven-jaxb2-plugin + + + + javax.activation + activation + 1.1 + + + com.sun.xml.bind + jaxb-impl + 2.1.2 + + + + + maven-compiler-plugin + 2.0.2 + + 1.5 + 1.5 + + + + + diff --git a/sandbox/richard/HelloWorld/HelloWorldJaxb/src/main/resources/hello.xsd b/sandbox/richard/HelloWorld/HelloWorldJaxb/src/main/resources/hello.xsd new file mode 100644 index 000000000..64a6b43b4 --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldJaxb/src/main/resources/hello.xsd @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/richard/HelloWorld/HelloWorldNuxeoService/README.txt b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/README.txt new file mode 100644 index 000000000..b1aa460dd --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/README.txt @@ -0,0 +1,14 @@ +Helloworld service interfacing with Nuxeo repository through Nuxeo +REST apis. + +System Requirements: +==================== +- Maven 2.0.9 or higher +- Nuxeo CollectionSpace Extensions + +Building the project: +==================== +In root directoy... +1. customize build.properties for your environment +2. mvn clean package +3. ant diff --git a/sandbox/richard/HelloWorld/HelloWorldNuxeoService/build.properties b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/build.properties new file mode 100644 index 000000000..f051cc0d6 --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/build.properties @@ -0,0 +1,4 @@ +jboss.dir=C:/dev/tools/jboss-4.2.3.GA +nuxeo.dir=${jboss.dir}/server/default/deploy/nuxeo.ear/system +nuxeo.local.repo.dir=file:///C:/dev/jboss-4.2.3.GA/server/default/deploy/nuxeo.ear/system +nuxeo.local.repo.client.dir=file:///C:/dev/nuxeo/nuxeo-core/nuxeo-core-client/target diff --git a/sandbox/richard/HelloWorld/HelloWorldNuxeoService/build.xml b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/build.xml new file mode 100644 index 000000000..cdba8639c --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/build.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/sandbox/richard/HelloWorld/HelloWorldNuxeoService/nb-configuration.xml b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/nb-configuration.xml new file mode 100644 index 000000000..3e5cd988f --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/nb-configuration.xml @@ -0,0 +1,21 @@ + + + + + + default + 8 + 80 + false + + diff --git a/sandbox/richard/HelloWorld/HelloWorldNuxeoService/nbactions.xml b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/nbactions.xml new file mode 100644 index 000000000..9d30c239a --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/nbactions.xml @@ -0,0 +1,74 @@ + + + + test + + * + + + test + + + + build + + * + + + install + + + + clean + + * + + + clean + + + + rebuild + + * + + + clean + install + + + true + + + + run + + war + ear + ejb + + + package + + + + true + + + + debug + + war + ear + ejb + + + package + + + + true + true + + + diff --git a/sandbox/richard/HelloWorld/HelloWorldNuxeoService/pom.xml b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/pom.xml new file mode 100644 index 000000000..f2fcee769 --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/pom.xml @@ -0,0 +1,270 @@ + + + + helloworld + org.collectionspace.hello.services + 0.1 + + 4.0.0 + org.collectionspace.hello.services + helloworld-nuxeo-service + war + 0.1 + Helloworld Nuxeo Service + + + + java.net + http://download.java.net/maven/1 + legacy + + + maven repo + maven repo + http://repo1.maven.org/maven2/ + + + + jboss + jboss repo + http://repository.jboss.org/maven2 + + + mojo + mojo repo + http://svn.codehaus.org/mojo/trunk/mojo/jboss-maven-plugin + + + + maven-restlet + Public online Restlet repository + http://maven.restlet.org + + + + cspace.local.nuxeo + ${nuxeo.local.repo.dir} + + + cspace.local.nuxeo.client + ${nuxeo.local.repo.client.dir} + + + public + http://maven.nuxeo.org/public + + + + false + + + + public-snapshot + http://maven.nuxeo.org/public-snapshot + + false + + + + + + + + + + + public + http://maven.nuxeo.org/public + Nuxeo virtual release repository + + + + false + + + + public-snapshot + http://maven.nuxeo.org/public-snapshot + Nuxeo virtual snapshot repository + + false + + + + + + + + + 4.2.3.GA + 3.0 + UTF-8 + 1.5.1 + 0.9.7 + 5.2-SNAPSHOT + 1.5-SNAPSHOT + + + + + + org.collectionspace.hello.services + helloworld-jaxb + 0.1 + + + org.jboss.resteasy + resteasy-jaxrs + 1.0.2.GA + + + tjws + webserver + + + + + org.jboss.resteasy + resteasy-jaxb-provider + 1.0.2.GA + + + junit + junit + 4.1 + test + + + + + + + javax.security + jaas + 1.0.01 + provided + + + + dom4j + dom4j + 1.6.1 + provided + + + + + + + + org.nuxeo.ecm.core + nuxeo-core-api + ${nuxeo.version.1.5} + + + jboss-remoting + jboss + + + + + + + + org.restlet + org.restlet + 1.0.7 + + + com.noelios.restlet + com.noelios.restlet.ext.httpclient + 1.0.7 + + + com.noelios.restlet + com.noelios.restlet + 1.0.7 + + + + jaxen + jaxen + 1.1.1 + + + + + + + helloworld + + + org.codehaus.mojo + jboss-maven-plugin + + ${jboss.dir} + + + + jboss-undeploy + pre-integration-test + + undeploy + + + ${basedir}/target/helloworld.war + + + + jboss-deploy + pre-integration-test + + deploy + + + ${basedir}/target/helloworld.war + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + + surefire-it + integration-test + + test + + + false + + + + + + org.apache.maven.plugins + maven-war-plugin + 2.0 + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.5 + 1.5 + + + + + diff --git a/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/HelloworldNuxeoApplication.java b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/HelloworldNuxeoApplication.java new file mode 100644 index 000000000..9443764b9 --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/HelloworldNuxeoApplication.java @@ -0,0 +1,25 @@ +package org.collectionspace.hello.services; + +import javax.ws.rs.core.Application; +import java.util.HashSet; +import java.util.Set; + +public class HelloworldNuxeoApplication extends Application { + + private Set singletons = new HashSet(); + private Set> empty = new HashSet>(); + + public HelloworldNuxeoApplication() { + singletons.add(new PersonNuxeoResource()); + } + + @Override + public Set> getClasses() { + return empty; + } + + @Override + public Set getSingletons() { + return singletons; + } +} diff --git a/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/PersonNuxeoResource.java b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/PersonNuxeoResource.java new file mode 100644 index 000000000..c43426f24 --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/PersonNuxeoResource.java @@ -0,0 +1,371 @@ +package org.collectionspace.hello.services; + +import java.io.ByteArrayInputStream; +import org.collectionspace.hello.services.nuxeo.NuxeoRESTClient; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import java.util.Map; +import javax.ws.rs.DELETE; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.PathParam; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriBuilder; +import javax.ws.rs.core.UriInfo; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; +import org.collectionspace.hello.*; + + +import org.collectionspace.hello.People.PeopleItem; +import org.dom4j.Document; +import org.dom4j.Element; +import org.dom4j.Namespace; +import org.dom4j.io.SAXReader; +import org.restlet.resource.Representation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Path("/persons") +@Consumes("application/xml") +@Produces("application/xml") +public class PersonNuxeoResource { + + final Logger logger = LoggerFactory.getLogger(PersonNuxeoResource.class); + + public PersonNuxeoResource() { + } + + @GET + public People getPeople(@Context UriInfo ui) { + People p = new People(); + try{ + List list = p.getPeopleItem(); + NuxeoRESTClient nxClient = getClient(); + + List pathParams = new ArrayList(); + Map queryParams = new HashMap(); + //browse default repository for People + //For sanjay, People repository id is f084243e-4b81-42a1-9a05-518e974facbd + //For Richard, workspace repos ID is 77187c27-0467-4c3d-b395-122b82113f4d + pathParams = Arrays.asList("default", "1b58eef7-4fff-430b-b773-8c98724f19de", "browse"); + Representation res = nxClient.get(pathParams, queryParams); + SAXReader reader = new SAXReader(); + Document document = reader.read(res.getStream()); + Element root = document.getRootElement(); + for(Iterator i = root.elementIterator(); i.hasNext();){ + Element element = (Element) i.next(); + PeopleItem pli = new PeopleItem(); + pli.setTitle(element.attributeValue("title")); + pli.setUri(element.attributeValue("url")); + pli.setId(element.attributeValue("id")); + list.add(pli); + } + + }catch(Exception e){ + e.printStackTrace(); + } + return p; + } + + @POST + public Response createPerson(PersonNuxeo p) { + + NuxeoRESTClient nxClient = getClient(); + + List pathParams = new ArrayList(); + Map queryParams = new HashMap(); + pathParams.add("default"); + pathParams.add("1b58eef7-4fff-430b-b773-8c98724f19de"); + pathParams.add("createDocument"); + queryParams.put("docType", "Hello"); + queryParams.put("dublincore:title", p.getFirstName() + " " + p.getLastName()); + queryParams.put("hello:cversion", Integer.valueOf(1).toString()); + queryParams.put("hello:firstName", p.getFirstName()); + queryParams.put("hello:lastName", p.getLastName()); + queryParams.put("hello:street", p.getStreet()); + queryParams.put("hello:city", p.getCity()); + queryParams.put("hello:state", p.getState()); + queryParams.put("hello:zip", p.getZip()); + queryParams.put("hello:country", p.getCountry()); + ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]); + Representation res = nxClient.post(pathParams, queryParams, bais); + + SAXReader reader = new SAXReader(); + try{ + Document document = reader.read(res.getStream()); + Element root = document.getRootElement(); + for(Iterator i = root.elementIterator(); i.hasNext();){ + Element element = (Element) i.next(); + if("docRef".equals(element.getName())){ + String id = (String) element.getData(); + p.setId(id); + } + } + }catch(Exception e){ + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Create failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + + verbose("created person", p); + UriBuilder path = UriBuilder.fromResource(PersonNuxeoResource.class); + path.path("" + p.getId()); + Response response = Response.created(path.build()).build(); + return response; + } + + @GET + @Path("{id}") + public PersonNuxeo getPerson(@PathParam("id") String id) { + + PersonNuxeo p = null; + try{ + + NuxeoRESTClient nxClient = getClient(); + + List pathParams = new ArrayList(); + Map queryParams = new HashMap(); + + pathParams.add("default"); + pathParams.add(id); + pathParams.add("export"); + queryParams.put("format", "XML"); + + Representation res = nxClient.get(pathParams, queryParams); + SAXReader reader = new SAXReader(); + + Document document = reader.read(res.getStream()); + Element root = document.getRootElement(); + p = new PersonNuxeo(); + //TODO: recognize schema thru namespace uri +// Namespace ns = new Namespace("hello", "http://collectionspace.org/hello"); + Iterator siter = root.elementIterator("schema"); + while(siter.hasNext()){ + + Element s = siter.next(); + + System.err.println("PersonNuxeo.getPerson() called."); + + //TODO: recognize schema thru namespace uri + if("hello".equals(s.attribute("name").getValue())){ + p.setId(id); + Element ele = s.element("cversion"); + if(ele != null){ + p.setVersion((String) ele.getData()); + } + ele = s.element("firstName"); + if(ele != null){ + p.setFirstName((String) ele.getData()); + } + ele = s.element("lastName"); + if(ele != null){ + p.setLastName((String) ele.getData()); + } + ele = s.element("city"); + if(ele != null){ + p.setCity((String) ele.getData()); + } + ele = s.element("state"); + if(ele != null){ + p.setState((String) ele.getData()); + } + ele = s.element("zip"); + if(ele != null){ + p.setZip((String) ele.getData()); + } + ele = s.element("country"); + if(ele != null){ + p.setCountry((String) ele.getData()); + } + } + } + + }catch(Exception e){ + e.printStackTrace(); + Response response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + "Get failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + if(p == null){ + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Get failed, the requested person ID:" + id + ": was not found.").type("text/plain").build(); + throw new WebApplicationException(response); + } + verbose("get person", p); + return p; + } + + @PUT + @Path("{id}") + public PersonNuxeo updatePerson( + @PathParam("id") String id, + PersonNuxeo update) { + + verbose("updating person input", update); + + NuxeoRESTClient nxClient = getClient(); + + List pathParams = new ArrayList(); + Map queryParams = new HashMap(); + pathParams.add("default"); + pathParams.add(update.getId()); + pathParams.add("updateDocumentRestlet"); + queryParams.put("dublincore:title", "change title"); + //todo: intelligent merge needed + if(update.getFirstName() != null){ + queryParams.put("hello:firstName", update.getFirstName()); + } + + if(update.getLastName() != null){ + queryParams.put("hello:lastName", update.getLastName()); + } + + if(update.getFirstName() != null && update.getLastName() != null){ + queryParams.put("dublincore:title", update.getFirstName() + " " + update.getLastName()); + } + + if(update.getStreet() != null){ + queryParams.put("hello:street", update.getStreet()); + } + + if(update.getCity() != null){ + queryParams.put("hello:city", update.getCity()); + } + + if(update.getState() != null){ + queryParams.put("hello:state", update.getState()); + } + + if(update.getZip() != null){ + queryParams.put("hello:zip", update.getZip()); + } + + if(update.getCountry() != null){ + queryParams.put("hello:country", update.getCountry()); + } + + Representation res = nxClient.get(pathParams, queryParams); + SAXReader reader = new SAXReader(); + String status = ""; + try{ + Document document = reader.read(res.getStream()); + Element root = document.getRootElement(); + for(Iterator i = root.elementIterator(); i.hasNext();){ + Element element = (Element) i.next(); + if("docRef".equals(element.getName())){ + status = (String) element.getData(); + verbose("updatePerson: response=" + status); + } + + } + }catch(Exception e){ + //FIXME: NOT_FOUND? + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Update failed ").type("text/plain").build(); + throw new WebApplicationException(response); + } + return update; + } + + @DELETE + @Path("{id}") + public void deletePerson(@PathParam("id") String id) { + verbose("deleting person with id=" + id); + NuxeoRESTClient nxClient = getClient(); + List pathParams = new ArrayList(); + Map queryParams = new HashMap(); + pathParams.add("default"); + pathParams.add(id); + pathParams.add("deleteDocumentRestlet"); + Representation res = nxClient.get(pathParams, queryParams); + SAXReader reader = new SAXReader(); + String status = ""; + try{ + Document document = reader.read(res.getStream()); + Element root = document.getRootElement(); + for(Iterator i = root.elementIterator(); i.hasNext();){ + Element element = (Element) i.next(); + if("docRef".equals(element.getName())){ + status = (String) element.getData(); + verbose("deletePerson: response=" + status); + } + + } + }catch(Exception e){ + //FIXME: NOT_FOUND? + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Delete failed ").type("text/plain").build(); + throw new WebApplicationException(response); + } + + } + + private void verbose(String msg, PersonNuxeo p) { + try{ + verbose(msg); + JAXBContext jc = JAXBContext.newInstance( + PersonNuxeo.class); + + Marshaller m = jc.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, + Boolean.TRUE); + m.marshal(p, System.out); + }catch(Exception e){ + e.printStackTrace(); + } + + } + +// private void getQueryModel() throws IOException { +// NuxeoRESTClient nxClient = getClient(); +// +// List pathParams = new ArrayList(); +// Map queryParams = new HashMap(); +// +// //query model for user documents +// pathParams = Arrays.asList("execQueryModel", "USER_DOCUMENTS"); +// queryParams.put("QP1", "Administrator"); +// queryParams.put("format", "XML"); +// +// +// Representation res = nxClient.get(pathParams, queryParams); +// String resStr = res.getText(); +// verbose("getQueryModel:" + resStr); +// +// } +// +// private void getVocabulary() throws IOException { +// NuxeoRESTClient nxClient = getClient(); +// +// List pathParams = new ArrayList(); +// Map queryParams = new HashMap(); +// //get vocabulary +// pathParams = Arrays.asList("vocabulary", "continent_country"); +// queryParams.put("lang", "en"); +// +// Representation res = nxClient.get(pathParams, queryParams); +// String resStr = res.getText(); +// verbose("getVocabulary:" + resStr); +// +// } + private NuxeoRESTClient getClient() { + NuxeoRESTClient nxClient = new NuxeoRESTClient("http://127.0.0.1:8080/nuxeo"); + nxClient.setAuthType(NuxeoRESTClient.AUTH_TYPE_BASIC); + nxClient.setBasicAuthentication("Administrator", "Administrator"); + return nxClient; + } + + private void verbose(String msg) { + System.out.println("PersonNuxeoResource: " + msg); + } +} diff --git a/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/nuxeo/NuxeoCallback.java b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/nuxeo/NuxeoCallback.java new file mode 100644 index 000000000..8e78e0076 --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/nuxeo/NuxeoCallback.java @@ -0,0 +1,50 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package org.collectionspace.hello.services.nuxeo; + + +import javax.security.auth.callback.Callback; + +/** + * Copied from jbossx + * + * An implementation of Callback that simply obtains an Object to be used + * as the authentication credential. Interpretation of the Object is up to + * the LoginModules that validate the credential. + * + * @author Scott.Stark@jboss.org + */ +public class NuxeoCallback implements Callback { + + private final String prompt; + + private Object credential; + + public NuxeoCallback() { + this(""); + } + + public NuxeoCallback(String prompt) { + this.prompt = prompt; + } + + public String getPrompt() { + return prompt; + } + + public Object getCredential() { + return credential; + } + + public void setCredential(Object credential) { + this.credential = credential; + } + + public void clearCredential() { + credential = null; + } + +} diff --git a/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/nuxeo/NuxeoCallbackHandler.java b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/nuxeo/NuxeoCallbackHandler.java new file mode 100644 index 000000000..e8fff8c25 --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/nuxeo/NuxeoCallbackHandler.java @@ -0,0 +1,85 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.collectionspace.hello.services.nuxeo; + +/** + * + * @author sanjaydalal + */ +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.NameCallback; +import javax.security.auth.callback.PasswordCallback; +import javax.security.auth.callback.UnsupportedCallbackException; + +/** + * Copied from jbossx. + * + * @author Scott.Stark@jboss.org + */ +public class NuxeoCallbackHandler implements CallbackHandler { + + private final String username; + private char[] password; + private final Object credential; + + /** + * Initializes the UsernamePasswordHandler with the username and password to + * use. + * + * @param username the user name + * @param password the password for this user + */ + public NuxeoCallbackHandler(String username, char[] password) { + this.username = username; + this.password = password; + credential = password; + } + + public NuxeoCallbackHandler(String username, Object credential) { + this.username = username; + this.credential = credential; + if (credential instanceof char[]) { + password = (char[]) credential; + } else if (credential instanceof CharSequence) { + password = credential.toString().toCharArray(); + } + } + + /** + * Sets any NameCallback name property to the instance username, sets any + * PasswordCallback password property to the instance, and any password. + * + * @exception UnsupportedCallbackException, + * thrown if any callback of type other than NameCallback or + * PasswordCallback are seen. + */ + public void handle(Callback[] callbacks) + throws UnsupportedCallbackException { + for (Callback c : callbacks) { + if (c instanceof NameCallback) { + NameCallback nc = (NameCallback) c; + nc.setName(username); + } else if (c instanceof PasswordCallback) { + PasswordCallback pc = (PasswordCallback) c; + if (password == null) { + // We were given an opaque Object credential but a char[] is + // requested? + if (credential != null) { + String tmp = credential.toString(); + password = tmp.toCharArray(); + } + } + pc.setPassword(password); + } else if (c instanceof NuxeoCallback) { + NuxeoCallback oc = (NuxeoCallback) c; + oc.setCredential(credential); + } else { + throw new UnsupportedCallbackException(c, + "Unrecognized Callback"); + } + } + } +} diff --git a/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/nuxeo/NuxeoLoginConfiguration.java b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/nuxeo/NuxeoLoginConfiguration.java new file mode 100644 index 000000000..81cedc3c4 --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/nuxeo/NuxeoLoginConfiguration.java @@ -0,0 +1,53 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.collectionspace.hello.services.nuxeo; + +/** + * + * @author sanjaydalal + */ +import java.util.HashMap; +import java.util.Map; + +import javax.security.auth.login.AppConfigurationEntry; +import javax.security.auth.login.Configuration; +import javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag; + +public class NuxeoLoginConfiguration extends Configuration { + + private final Configuration parent; + public static final String LOGIN_DOMAIN = "nuxeo-client-login"; + + public NuxeoLoginConfiguration(Configuration parent) { + this.parent = parent; + } + + @Override + public AppConfigurationEntry[] getAppConfigurationEntry(String name) { + + if (LOGIN_DOMAIN.equals(name)) { + AppConfigurationEntry[] entries = new AppConfigurationEntry[1]; + + Map options = new HashMap(); + + options.put("restore-login-identity", "True"); + options.put("multi-threaded", "True"); + + entries[0] = new AppConfigurationEntry("org.jboss.security.ClientLoginModule", LoginModuleControlFlag.REQUIRED, options); + + + return entries; + } else { + return parent.getAppConfigurationEntry(name); + } + } + + @Override + public void refresh() { + if (parent != null) { + parent.refresh(); + } + } +} diff --git a/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/nuxeo/NuxeoLoginContextFactory.java b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/nuxeo/NuxeoLoginContextFactory.java new file mode 100644 index 000000000..d1d23f7fc --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/nuxeo/NuxeoLoginContextFactory.java @@ -0,0 +1,48 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package org.collectionspace.hello.services.nuxeo; + +/** + * + * @author sanjaydalal + */ + +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.login.Configuration; +import javax.security.auth.login.LoginContext; +import javax.security.auth.login.LoginException; + +public class NuxeoLoginContextFactory { + + + private static boolean initDone=false; + + private static void initLoginConfig() + { + if (initDone) + return; + + Configuration parentConfig = null; + try { + parentConfig = Configuration.getConfiguration(); + } catch (Exception e) { + // do nothing - this can happen if default configuration provider is not correctly configured + // for examnple FileConfig fails if no config file was defined + } + Configuration config = new NuxeoLoginConfiguration(parentConfig); + Configuration.setConfiguration(config); + + initDone=true; + + } + + + public static LoginContext getLoginContext(CallbackHandler handler) throws LoginException + { + initLoginConfig(); + return new LoginContext(NuxeoLoginConfiguration.LOGIN_DOMAIN, handler); + } +} diff --git a/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/nuxeo/NuxeoRESTClient.java b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/nuxeo/NuxeoRESTClient.java new file mode 100644 index 000000000..175dca70a --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/nuxeo/NuxeoRESTClient.java @@ -0,0 +1,308 @@ +/* + * (C) Copyright 2006-2007 Nuxeo SAS (http://nuxeo.com/) and contributors. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser General Public License + * (LGPL) version 2.1 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Contributors: + * Nuxeo - initial API and implementation + * + * $Id: JOOoConvertPluginImpl.java 18651 2007-05-13 20:28:53Z sfermigier $ + */ +package org.collectionspace.hello.services.nuxeo; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.List; +import java.util.Map; + + +import org.restlet.Client; +import org.restlet.data.ChallengeResponse; +import org.restlet.data.ChallengeScheme; +import org.restlet.data.Cookie; +import org.restlet.data.Form; +import org.restlet.data.MediaType; +import org.restlet.data.Method; +import org.restlet.data.Parameter; +import org.restlet.data.Protocol; +import org.restlet.data.Request; +import org.restlet.resource.OutputRepresentation; +import org.restlet.resource.Representation; +import org.restlet.util.Series; + +public class NuxeoRESTClient { + + public static final int AUTH_TYPE_NONE = 0; + public static final int AUTH_TYPE_BASIC = 1; + public static final int AUTH_TYPE_SECRET = 2; + protected String baseURL = "http://127.0.0.1:8080/nuxeo"; + protected String restPrefix = "restAPI"; + protected String davPrefix = "dav"; + protected List cookies; + protected int authType = AUTH_TYPE_NONE; + protected String userName; + protected String password; + protected String secretToken; + protected Client restClient; + + public NuxeoRESTClient(String baseURL) { + this.baseURL = baseURL; + } + + public NuxeoRESTClient(String protocol, String serverIP, String serverPort) { + this(protocol, serverIP, serverPort, "nuxeo"); + } + + public NuxeoRESTClient(String protocol, String serverIP, String serverPort, + String servletPath) { + StringBuffer sb = new StringBuffer(); + sb.append(protocol); + sb.append("://"); + sb.append(serverIP); + if (serverPort != null && !serverIP.equals("80")) { + sb.append(':'); + sb.append(serverPort); + } + sb.append(servletPath); + sb.append('/'); + baseURL = sb.toString(); + } + + public void setBasicAuthentication(String userName, String password) { + authType = AUTH_TYPE_BASIC; + this.userName = userName; + this.password = password; + } + + public void setSharedSecretAuthentication(String userName, + String secretToken) { + authType = AUTH_TYPE_SECRET; + this.userName = userName; + this.secretToken = secretToken; + } + + public void setCookies(List cookies) { + this.cookies = cookies; + } + + public Representation post(List pathParams, + Map queryParams, InputStream istream) { + String path = ""; + StringBuffer pathBuffer = new StringBuffer(); + + if (pathParams != null) { + for (String p : pathParams) { + pathBuffer.append(p); + pathBuffer.append('/'); + } + path = pathBuffer.toString(); + } + + return post(path, queryParams, istream); + } + + public Representation post(String subPath, + Map queryParams, InputStream istream) { + StringBuffer urlBuffer = new StringBuffer(); + + if (subPath.startsWith("/")) { + subPath = subPath.substring(1); + } + if (subPath.endsWith("/")) { + subPath = subPath.substring(0, subPath.length() - 1); + } + + urlBuffer.append(baseURL); + urlBuffer.append('/'); + urlBuffer.append(restPrefix); + urlBuffer.append('/'); + urlBuffer.append(subPath); + + if (queryParams != null) { + urlBuffer.append('?'); + for (String qpName : queryParams.keySet()) { + urlBuffer.append(qpName); + urlBuffer.append('='); + urlBuffer.append(queryParams.get(qpName).replaceAll(" ", "%20")); + urlBuffer.append('&'); + } + } + + String completeURL = urlBuffer.toString(); + + Request request = new Request(Method.POST, completeURL); + + setupAuth(request); + setupCookies(request); + final InputStream in = istream; + request.setEntity(new OutputRepresentation( + MediaType.MULTIPART_FORM_DATA) { + + @Override + public void write(OutputStream outputStream) throws IOException { + byte[] buffer = new byte[1024 * 64]; + int read; + while ((read = in.read(buffer)) != -1) { + outputStream.write(buffer, 0, read); + } + + } + }); + + return getRestClient().handle(request).getEntity(); + } + + public Representation get(List pathParams, + Map queryParams) { + String path = ""; + StringBuffer pathBuffer = new StringBuffer(); + + if (pathParams != null) { + for (String p : pathParams) { + pathBuffer.append(p); + pathBuffer.append('/'); + } + path = pathBuffer.toString(); + } + + return get(path, queryParams); + } + + public Representation get(String subPath, + Map queryParams) { + StringBuffer urlBuffer = new StringBuffer(); + + if (subPath.startsWith("/")) { + subPath = subPath.substring(1); + } + if (subPath.endsWith("/")) { + subPath = subPath.substring(0, subPath.length() - 1); + } + + urlBuffer.append(baseURL); + urlBuffer.append('/'); + urlBuffer.append(restPrefix); + urlBuffer.append('/'); + urlBuffer.append(subPath); + + if (queryParams != null) { + urlBuffer.append('?'); + for (String qpName : queryParams.keySet()) { + urlBuffer.append(qpName); + urlBuffer.append('='); + urlBuffer.append(queryParams.get(qpName).replaceAll(" ", "%20")); + urlBuffer.append('&'); + } + } + + String completeURL = urlBuffer.toString(); + System.out.println("\nNuxeoRESTClient: calling " + completeURL); + Request request = new Request(Method.GET, completeURL); + setupAuth(request); + setupCookies(request); + + return getRestClient().handle(request).getEntity(); + } + + protected void setupAuth(Request request) { + + if (authType == AUTH_TYPE_BASIC) { + ChallengeScheme scheme = ChallengeScheme.HTTP_BASIC; + ChallengeResponse authentication = new ChallengeResponse(scheme, + userName, password); + request.setChallengeResponse(authentication); + + } else if (authType == AUTH_TYPE_SECRET) { + Series additionnalHeaders = new Form(); + + Map securityHeaders = PortalSSOAuthenticationProvider.getHeaders( + secretToken, userName); + + for (String hn : securityHeaders.keySet()) { + additionnalHeaders.add(hn, securityHeaders.get(hn)); + } + + request.getAttributes().put("org.restlet.http.headers", + additionnalHeaders); + } + } + + protected void setupCookies(Request request) { + if (cookies != null) { + request.getCookies().clear(); + for (Cookie cookie : cookies) { + request.getCookies().add(cookie); + } + } + + } + + protected Client getRestClient() { + if (restClient == null) { + if (baseURL.startsWith("https")) { + restClient = new Client(Protocol.HTTPS); + } else { + restClient = new Client(Protocol.HTTP); + } + } + + return restClient; + } + + public int getAuthType() { + return authType; + } + + public void setAuthType(int authType) { + this.authType = authType; + } + + public String getDavPrefix() { + return davPrefix; + } + + public void setDavPrefix(String davPrefix) { + this.davPrefix = davPrefix; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getRestPrefix() { + return restPrefix; + } + + public void setRestPrefix(String restPrefix) { + this.restPrefix = restPrefix; + } + + public String getSecretToken() { + return secretToken; + } + + public void setSecretToken(String secretToken) { + this.secretToken = secretToken; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } +} diff --git a/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/nuxeo/PortalSSOAuthenticationProvider.java b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/nuxeo/PortalSSOAuthenticationProvider.java new file mode 100644 index 000000000..ef1a61a40 --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/nuxeo/PortalSSOAuthenticationProvider.java @@ -0,0 +1,72 @@ +/* + * (C) Copyright 2006-2007 Nuxeo SAS (http://nuxeo.com/) and contributors. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser General Public License + * (LGPL) version 2.1 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Contributors: + * Nuxeo - initial API and implementation + * + * $Id: JOOoConvertPluginImpl.java 18651 2007-05-13 20:28:53Z sfermigier $ + */ + +package org.collectionspace.hello.services.nuxeo; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.Random; + +import com.noelios.restlet.util.Base64; + +public class PortalSSOAuthenticationProvider { + + private static final String TOKEN_SEP = ":"; + + private static final String TS_HEADER = "NX_TS"; + + private static final String RANDOM_HEADER = "NX_RD"; + + private static final String TOKEN_HEADER = "NX_TOKEN"; + + private static final String USER_HEADER = "NX_USER"; + + public static Map getHeaders(String secretKey, + String userName) { + + Map headers = new HashMap(); + + Date timestamp = new Date(); + int randomData = new Random(timestamp.getTime()).nextInt(); + + String clearToken = timestamp.getTime() + TOKEN_SEP + randomData + + TOKEN_SEP + secretKey + TOKEN_SEP + userName; + + byte[] hashedToken; + + try { + hashedToken = MessageDigest.getInstance("MD5").digest( + clearToken.getBytes()); + } catch (NoSuchAlgorithmException e) { + return null; + } + + String base64HashedToken = Base64.encodeBytes(hashedToken); + + headers.put(TS_HEADER, String.valueOf(timestamp.getTime())); + headers.put(RANDOM_HEADER, String.valueOf(randomData)); + headers.put(TOKEN_HEADER, base64HashedToken); + headers.put(USER_HEADER, userName); + + return headers; + } + +} diff --git a/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/resources/jndi.properties b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/resources/jndi.properties new file mode 100644 index 000000000..a3aa40712 --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/resources/jndi.properties @@ -0,0 +1,3 @@ +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 diff --git a/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/resources/nuxeo.properties b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/resources/nuxeo.properties new file mode 100644 index 000000000..3c9d5afb5 --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/resources/nuxeo.properties @@ -0,0 +1,2 @@ +org.nuxeo.runtime.server.enabled=false +org.nuxeo.runtime.streaming.isServer=false diff --git a/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/webapp/WEB-INF/web.xml b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..0c188a4fb --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,34 @@ + + + + HelloworldNuxeo + + + javax.ws.rs.Application + org.collectionspace.hello.services.HelloworldNuxeoApplication + + + + resteasy.servlet.mapping.prefix + /cspace-nuxeo + + + + + org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap + + + + + Resteasy + + org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher + + + + + Resteasy + /cspace-nuxeo/* + + + diff --git a/sandbox/richard/HelloWorld/pom.xml b/sandbox/richard/HelloWorld/pom.xml new file mode 100644 index 000000000..cc90907a2 --- /dev/null +++ b/sandbox/richard/HelloWorld/pom.xml @@ -0,0 +1,231 @@ + + + + 4.0.0 + org.collectionspace.hello.services + 0.1 + helloworld + pom + HelloWorld + + HelloWorldJaxb + HelloWorldClient + HelloWorldNuxeoService + + + + jboss + http://repository.jboss.org/maven2 + + + sun + http://download.java.net/maven/2 + + + java.net + java.net Maven Repository + + https://maven-repository.dev.java.net/nonav/repository + + legacy + + + maven2-repository.dev.java.net + Java.net Maven 2 Repository + http://download.java.net/maven/2 + + + + + + java.net + java.net Maven Repository + + https://maven-repository.dev.java.net/nonav/repository + + legacy + + + maven2-repository.dev.java.net + Java.net Maven 2 Repository + http://download.java.net/maven/2 + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.5 + 1.5 + + + + org.apache.maven.plugins + maven-site-plugin + + + /usr/bin/unzip -o > err.txt + + + + + org.apache.maven.plugins + maven-war-plugin + 2.0.1 + + + + WEB-INF/lib/*.jar + + + + true + + + + + + + org.jvnet.jaxb2.maven2 + maven-jaxb2-plugin + + + + generate + + + + + + -XtoString + -Xinject-listener-code + + + + + + + org.jvnet.jaxb2_commons + + basic + 0.4.1 + + + + org.jvnet.jaxb2-commons + + + property-listener-injector + + 1.0 + + + + + org.collectionspace.hello + + + + + + + + + + net.java.dev.jaxb2-commons + jaxb-fluent-api + 2.0.1 + + + org.testng + testng + 5.6 + test + jdk15 + + + org.jboss.resteasy + jaxrs-api + 1.0.2.GA + + + net.java.dev.jaxb2-commons + jaxb-fluent-api + 2.0.1 + + + org.jvnet.jaxb2-commons + property-listener-injector + 1.0 + + + org.jvnet.jaxb2_commons + runtime + 0.4.1 + + + org.jboss.resteasy + resteasy-jaxrs + 1.0.2.GA + + + commons-httpclient + commons-httpclient + 3.1 + + + com.sun.xml.bind + jaxb-impl + 2.1.7 + + + org.testng + testng + 5.6 + test + jdk15 + + + org.slf4j + slf4j-api + 1.5.2 + + + org.slf4j + slf4j-log4j12 + 1.5.2 + + + mysql + mysql-connector-java + 5.1.5 + test + + + com.jgoodies + binding + 2.0.2 + + + com.jgoodies + forms + 1.2.0 + + + + -- 2.47.3