From f064bd05aec97738660d7cfc36d6cea49d40c6d0 Mon Sep 17 00:00:00 2001 From: Aron Roberts Date: Fri, 20 Mar 2009 20:42:51 +0000 Subject: [PATCH] Copying Sanjay's HelloWorld project (with in-memory Collections storage, not using Nuxeo/MySQL) to Aron's sandbox, in preparation for adding a CollectionObject service. This copy builds and runs successfully under JBoss on Mac OS X. --- .../HelloWorldClient/.classpath | 10 + .../HelloWorldClient/.project | 23 ++ .../.settings/org.eclipse.jdt.core.prefs | 5 + .../.settings/org.maven.ide.eclipse.prefs | 8 + .../HelloWorldClient/nb-configuration.xml | 20 ++ .../HelloWorldClient/nbactions.xml | 16 ++ .../HelloWorldClient/pom.xml | 67 +++++ .../hello/client/IdentifierClient.java | 64 +++++ .../hello/client/IdentifierProxy.java | 32 +++ .../hello/client/PersonClient.java | 93 +++++++ .../hello/client/PersonProxy.java | 42 +++ .../client/test/IdentifierServiceTest.java | 64 +++++ .../hello/client/test/PersonServiceTest.java | 159 ++++++++++++ .../src/test/resources/log4j.xml | 45 ++++ .../temp-testng-customsuite.xml | 8 + .../HelloWorldJaxb/.classpath | 9 + .../HelloWorldJaxb/.project | 23 ++ .../.settings/org.eclipse.jdt.core.prefs | 5 + .../.settings/org.maven.ide.eclipse.prefs | 8 + .../HelloWorldJaxb/nb-configuration.xml | 20 ++ .../HelloWorldJaxb/pom.xml | 59 +++++ .../src/main/resources/hello.xsd | 77 ++++++ .../HelloWorldService/README.txt | 15 ++ .../HelloWorldService/build.properties | 1 + .../HelloWorldService/nb-configuration.xml | 21 ++ .../HelloWorldService/nbactions.xml | 74 ++++++ .../HelloWorldService/pom.xml | 177 +++++++++++++ .../hello/services/HelloworldApplication.java | 26 ++ .../hello/services/IdentifierResource.java | 77 ++++++ .../hello/services/PersonResource.java | 241 ++++++++++++++++++ .../src/main/webapp/WEB-INF/web.xml | 34 +++ .../test/IdentifierServiceRawXmlTest.java | 62 +++++ .../hello/test/PersonServiceRawXmlTest.java | 89 +++++++ .../aron/HelloWorld-CollectionObject/pom.xml | 231 +++++++++++++++++ 34 files changed, 1905 insertions(+) create mode 100644 sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/.classpath create mode 100644 sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/.project create mode 100644 sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/.settings/org.eclipse.jdt.core.prefs create mode 100644 sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/.settings/org.maven.ide.eclipse.prefs create mode 100644 sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/nb-configuration.xml create mode 100644 sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/nbactions.xml create mode 100644 sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/pom.xml create mode 100644 sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/src/main/java/org/collectionspace/hello/client/IdentifierClient.java create mode 100644 sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/src/main/java/org/collectionspace/hello/client/IdentifierProxy.java create mode 100644 sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/src/main/java/org/collectionspace/hello/client/PersonClient.java create mode 100644 sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/src/main/java/org/collectionspace/hello/client/PersonProxy.java create mode 100644 sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/src/test/java/org/collectionspace/hello/client/test/IdentifierServiceTest.java create mode 100644 sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/src/test/java/org/collectionspace/hello/client/test/PersonServiceTest.java create mode 100644 sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/src/test/resources/log4j.xml create mode 100644 sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/temp-testng-customsuite.xml create mode 100644 sandbox/aron/HelloWorld-CollectionObject/HelloWorldJaxb/.classpath create mode 100644 sandbox/aron/HelloWorld-CollectionObject/HelloWorldJaxb/.project create mode 100644 sandbox/aron/HelloWorld-CollectionObject/HelloWorldJaxb/.settings/org.eclipse.jdt.core.prefs create mode 100644 sandbox/aron/HelloWorld-CollectionObject/HelloWorldJaxb/.settings/org.maven.ide.eclipse.prefs create mode 100644 sandbox/aron/HelloWorld-CollectionObject/HelloWorldJaxb/nb-configuration.xml create mode 100644 sandbox/aron/HelloWorld-CollectionObject/HelloWorldJaxb/pom.xml create mode 100644 sandbox/aron/HelloWorld-CollectionObject/HelloWorldJaxb/src/main/resources/hello.xsd create mode 100644 sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/README.txt create mode 100644 sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/build.properties create mode 100644 sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/nb-configuration.xml create mode 100644 sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/nbactions.xml create mode 100644 sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/pom.xml create mode 100644 sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/src/main/java/org/collectionspace/hello/services/HelloworldApplication.java create mode 100644 sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/src/main/java/org/collectionspace/hello/services/IdentifierResource.java create mode 100644 sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/src/main/java/org/collectionspace/hello/services/PersonResource.java create mode 100644 sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/src/main/webapp/WEB-INF/web.xml create mode 100644 sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/src/test/java/org/collectionspace/hello/test/IdentifierServiceRawXmlTest.java create mode 100644 sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/src/test/java/org/collectionspace/hello/test/PersonServiceRawXmlTest.java create mode 100644 sandbox/aron/HelloWorld-CollectionObject/pom.xml diff --git a/sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/.classpath b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/.classpath new file mode 100644 index 000000000..f42fb64cf --- /dev/null +++ b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/.project b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/.project new file mode 100644 index 000000000..f44220ec1 --- /dev/null +++ b/sandbox/aron/HelloWorld-CollectionObject/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/aron/HelloWorld-CollectionObject/HelloWorldClient/.settings/org.eclipse.jdt.core.prefs b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..02ba2fa25 --- /dev/null +++ b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +#Thu Feb 26 16:32:51 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/aron/HelloWorld-CollectionObject/HelloWorldClient/.settings/org.maven.ide.eclipse.prefs b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/.settings/org.maven.ide.eclipse.prefs new file mode 100644 index 000000000..669df21c2 --- /dev/null +++ b/sandbox/aron/HelloWorld-CollectionObject/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/aron/HelloWorld-CollectionObject/HelloWorldClient/nb-configuration.xml b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/nb-configuration.xml new file mode 100644 index 000000000..6c3fe600b --- /dev/null +++ b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/nb-configuration.xml @@ -0,0 +1,20 @@ + + + + + + default + 8 + 80 + + diff --git a/sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/nbactions.xml b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/nbactions.xml new file mode 100644 index 000000000..fffbf0fe6 --- /dev/null +++ b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/nbactions.xml @@ -0,0 +1,16 @@ + + + + rebuild + + * + + + clean + install + + + true + + + diff --git a/sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/pom.xml b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/pom.xml new file mode 100644 index 000000000..92a507301 --- /dev/null +++ b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/pom.xml @@ -0,0 +1,67 @@ + + + + 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/aron/HelloWorld-CollectionObject/HelloWorldClient/src/main/java/org/collectionspace/hello/client/IdentifierClient.java b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/src/main/java/org/collectionspace/hello/client/IdentifierClient.java new file mode 100644 index 000000000..a7b12f967 --- /dev/null +++ b/sandbox/aron/HelloWorld-CollectionObject/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/aron/HelloWorld-CollectionObject/HelloWorldClient/src/main/java/org/collectionspace/hello/client/IdentifierProxy.java b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/src/main/java/org/collectionspace/hello/client/IdentifierProxy.java new file mode 100644 index 000000000..125aab47d --- /dev/null +++ b/sandbox/aron/HelloWorld-CollectionObject/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/aron/HelloWorld-CollectionObject/HelloWorldClient/src/main/java/org/collectionspace/hello/client/PersonClient.java b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/src/main/java/org/collectionspace/hello/client/PersonClient.java new file mode 100644 index 000000000..e5de8f6e6 --- /dev/null +++ b/sandbox/aron/HelloWorld-CollectionObject/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/aron/HelloWorld-CollectionObject/HelloWorldClient/src/main/java/org/collectionspace/hello/client/PersonProxy.java b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/src/main/java/org/collectionspace/hello/client/PersonProxy.java new file mode 100644 index 000000000..2b6f2370b --- /dev/null +++ b/sandbox/aron/HelloWorld-CollectionObject/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/aron/HelloWorld-CollectionObject/HelloWorldClient/src/test/java/org/collectionspace/hello/client/test/IdentifierServiceTest.java b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/src/test/java/org/collectionspace/hello/client/test/IdentifierServiceTest.java new file mode 100644 index 000000000..05bc199b5 --- /dev/null +++ b/sandbox/aron/HelloWorld-CollectionObject/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/aron/HelloWorld-CollectionObject/HelloWorldClient/src/test/java/org/collectionspace/hello/client/test/PersonServiceTest.java b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/src/test/java/org/collectionspace/hello/client/test/PersonServiceTest.java new file mode 100644 index 000000000..cf60e22bf --- /dev/null +++ b/sandbox/aron/HelloWorld-CollectionObject/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/aron/HelloWorld-CollectionObject/HelloWorldClient/src/test/resources/log4j.xml b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/src/test/resources/log4j.xml new file mode 100644 index 000000000..52121cb83 --- /dev/null +++ b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/src/test/resources/log4j.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/temp-testng-customsuite.xml b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/temp-testng-customsuite.xml new file mode 100644 index 000000000..9f2480621 --- /dev/null +++ b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/temp-testng-customsuite.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/sandbox/aron/HelloWorld-CollectionObject/HelloWorldJaxb/.classpath b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldJaxb/.classpath new file mode 100644 index 000000000..cb112c7d0 --- /dev/null +++ b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldJaxb/.classpath @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/sandbox/aron/HelloWorld-CollectionObject/HelloWorldJaxb/.project b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldJaxb/.project new file mode 100644 index 000000000..db1c789f7 --- /dev/null +++ b/sandbox/aron/HelloWorld-CollectionObject/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/aron/HelloWorld-CollectionObject/HelloWorldJaxb/.settings/org.eclipse.jdt.core.prefs b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldJaxb/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..6e9989ded --- /dev/null +++ b/sandbox/aron/HelloWorld-CollectionObject/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/aron/HelloWorld-CollectionObject/HelloWorldJaxb/.settings/org.maven.ide.eclipse.prefs b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldJaxb/.settings/org.maven.ide.eclipse.prefs new file mode 100644 index 000000000..669df21c2 --- /dev/null +++ b/sandbox/aron/HelloWorld-CollectionObject/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/aron/HelloWorld-CollectionObject/HelloWorldJaxb/nb-configuration.xml b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldJaxb/nb-configuration.xml new file mode 100644 index 000000000..6c3fe600b --- /dev/null +++ b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldJaxb/nb-configuration.xml @@ -0,0 +1,20 @@ + + + + + + default + 8 + 80 + + diff --git a/sandbox/aron/HelloWorld-CollectionObject/HelloWorldJaxb/pom.xml b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldJaxb/pom.xml new file mode 100644 index 000000000..8f0e2a102 --- /dev/null +++ b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldJaxb/pom.xml @@ -0,0 +1,59 @@ + + + + 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 + + + + + + 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/aron/HelloWorld-CollectionObject/HelloWorldJaxb/src/main/resources/hello.xsd b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldJaxb/src/main/resources/hello.xsd new file mode 100644 index 000000000..8943ef963 --- /dev/null +++ b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldJaxb/src/main/resources/hello.xsd @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/README.txt b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/README.txt new file mode 100644 index 000000000..bd38e834c --- /dev/null +++ b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/README.txt @@ -0,0 +1,15 @@ + +This project is a simple example showing usage of @Path, @GET, PUT, POST, and @PathParam. It uses pure streaming +output as well. + +System Requirements: +==================== +- Maven 2.0.9 or higher + +Building the project: +==================== +1. In root directoy + +mvn clean install + +This will build a WAR and run it with embedded Jetty \ No newline at end of file diff --git a/sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/build.properties b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/build.properties new file mode 100644 index 000000000..e390d9d25 --- /dev/null +++ b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/build.properties @@ -0,0 +1 @@ +jboss.dir=/usr/local/jboss \ No newline at end of file diff --git a/sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/nb-configuration.xml b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/nb-configuration.xml new file mode 100644 index 000000000..3e5cd988f --- /dev/null +++ b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/nb-configuration.xml @@ -0,0 +1,21 @@ + + + + + + default + 8 + 80 + false + + diff --git a/sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/nbactions.xml b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/nbactions.xml new file mode 100644 index 000000000..ce9718100 --- /dev/null +++ b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/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/aron/HelloWorld-CollectionObject/HelloWorldService/pom.xml b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/pom.xml new file mode 100644 index 000000000..dd8c68f88 --- /dev/null +++ b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/pom.xml @@ -0,0 +1,177 @@ + + + + helloworld + org.collectionspace.hello.services + 0.1 + + 4.0.0 + org.collectionspace.hello.services + helloworld-service + war + 0.1 + Helloworld 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 + + + + + + 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 + + + + + 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/aron/HelloWorld-CollectionObject/HelloWorldService/src/main/java/org/collectionspace/hello/services/HelloworldApplication.java b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/src/main/java/org/collectionspace/hello/services/HelloworldApplication.java new file mode 100644 index 000000000..b7b7acdc0 --- /dev/null +++ b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/src/main/java/org/collectionspace/hello/services/HelloworldApplication.java @@ -0,0 +1,26 @@ +package org.collectionspace.hello.services; + +import javax.ws.rs.core.Application; +import java.util.HashSet; +import java.util.Set; + +public class HelloworldApplication extends Application { + + private Set singletons = new HashSet(); + private Set> empty = new HashSet>(); + + public HelloworldApplication() { + singletons.add(new PersonResource()); + singletons.add(new IdentifierResource()); + } + + @Override + public Set> getClasses() { + return empty; + } + + @Override + public Set getSingletons() { + return singletons; + } +} diff --git a/sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/src/main/java/org/collectionspace/hello/services/IdentifierResource.java b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/src/main/java/org/collectionspace/hello/services/IdentifierResource.java new file mode 100644 index 000000000..4c4104890 --- /dev/null +++ b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/src/main/java/org/collectionspace/hello/services/IdentifierResource.java @@ -0,0 +1,77 @@ +package org.collectionspace.hello.services; + +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.WebApplicationException; +import javax.ws.rs.core.Response; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicLong; +import javax.ws.rs.core.UriBuilder; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; +import org.collectionspace.hello.Identifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Path("/identifiers") +@Consumes("application/xml") +@Produces("application/xml") +public class IdentifierResource { + + final Logger logger = LoggerFactory.getLogger(IdentifierResource.class); + private Map idDB = new ConcurrentHashMap(); + private AtomicLong idCounter = new AtomicLong(); + + public IdentifierResource() { + } + + @POST + public Response createIdentifier(Identifier id) { + if (id.getNamespace() == null) { + id.setNamespace("edu.berkeley"); + } + id.setId(idCounter.incrementAndGet()); + id.setVersion(1); + UUID uuid = UUID.nameUUIDFromBytes(id.getNamespace().getBytes()); + id.setValue(uuid.toString()); + idDB.put(id.getId(), id); + verbose("created Id", id); + UriBuilder path = UriBuilder.fromResource(IdentifierResource.class); + path.path("" + id.getId()); + Response response = Response.created(path.build()).build(); + return response; + } + + @GET + @Path("{id}") + public Identifier getIdentifier(@PathParam("id") Long id) { + Identifier i = idDB.get(id); + if (i == null) { + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "The requested ID was not found.").type("text/plain").build(); + throw new WebApplicationException(response); + } + verbose("get Id", i); + return i; + } + + private void verbose(String msg, Identifier id) { + try { + System.out.println("IdentifierResource : " + msg); + JAXBContext jc = JAXBContext.newInstance(Identifier.class); + Marshaller m = jc.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, + Boolean.TRUE); + m.marshal(id, System.out); + + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/src/main/java/org/collectionspace/hello/services/PersonResource.java b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/src/main/java/org/collectionspace/hello/services/PersonResource.java new file mode 100644 index 000000000..b8c06b852 --- /dev/null +++ b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/src/main/java/org/collectionspace/hello/services/PersonResource.java @@ -0,0 +1,241 @@ +package org.collectionspace.hello.services; + +import java.net.URI; +import java.util.List; +import javax.ws.rs.Consumes; +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.WebApplicationException; +import javax.ws.rs.core.Response; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicLong; +import javax.ws.rs.DELETE; +import javax.ws.rs.core.Context; +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.Person; +import org.collectionspace.hello.Persons.PersonListItem; +import org.collectionspace.hello.Persons; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Path("/persons") +@Consumes("application/xml") +@Produces("application/xml") +public class PersonResource { + + final Logger logger = LoggerFactory.getLogger(PersonResource.class); + private Map personDB = new ConcurrentHashMap(); + private AtomicLong idCounter = new AtomicLong(); + + public PersonResource() { + } + + @POST + public Response createPerson(Person p) { + p.setId(idCounter.incrementAndGet()); + p.setVersion(1); + personDB.put(p.getId(), p); + verbose("created person", p); + UriBuilder path = UriBuilder.fromResource(PersonResource.class); + path.path("" + p.getId()); + Response response = Response.created(path.build()).build(); + return response; + } + + @GET + @Path("{id}") + public Person getPerson(@PathParam("id") Long id) { + Person p = personDB.get(id); + 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 Person updatePerson(@PathParam("id") Long id, Person update) { + Person current = personDB.get(id); + if (current == null) { + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Update failed, the person ID:" + id + ": was not found.").type("text/plain").build(); + throw new WebApplicationException(response); + } + verbose("update person input", update); + //todo: intelligent merge needed + current.setFirstName(update.getFirstName()); + current.setLastName(update.getLastName()); + current.setStreet(update.getStreet()); + current.setState(update.getState()); + current.setZip(update.getZip()); + current.setCountry(update.getCountry()); + current.setVersion(current.getVersion() + 1); + verbose("update person output", current); + return current; + } + + @GET + public Persons getPersons(@Context UriInfo ui) { + Persons persons = new Persons(); + List list = persons.getPersonListItem(); + // builder starts with current URI and has appended path of getPerson method + UriBuilder ub = ui.getAbsolutePathBuilder().path(this.getClass(), "getPerson"); + for (Person p : personDB.values()) { + PersonListItem pli = new PersonListItem(); + pli.setFirstName(p.getFirstName()); + pli.setLastName(p.getLastName()); + pli.setId(p.getId()); + // builder has {id} variable that must be filled in for each customer + URI uri = ub.build(p.getId()); + pli.setUri(uri.toString()); + list.add(pli); + } + return persons; + } + + @DELETE + @Path("{id}") + public void deletePerson(@PathParam("id") Long id) { + Person removed = personDB.remove(id); + if (removed == null) { + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Delete failed, the person ID:" + id + ": was not found.").type("text/plain").build(); + throw new WebApplicationException(response); + } + verbose("deleted person", removed); + } + + private void verbose(String msg, Person p) { + try { + System.out.println("PersonResource : " + msg); + JAXBContext jc = JAXBContext.newInstance(Person.class); + Marshaller m = jc.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, + Boolean.TRUE); + m.marshal(p, System.out); + } catch (Exception e) { + e.printStackTrace(); + } + } + +// @POST +// @Consumes("application/xml") +// public Response createPerson(InputStream is) { +// Person p = readPerson(is); +// p.setId(idCounter.incrementAndGet()); +// p.setVersion(1); +// personDB.put(p.getId(), p); +// try { +// System.out.println("Created Person " + p.getId()); +// outputPerson(System.out, p); +// } catch (IOException ioe) { +// throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR); +// } +// return Response.created(URI.create("/persons/" + p.getId())).build(); +// +// } +// +// @GET +// @Path("{id}") +// @Produces("application/xml") +// public StreamingOutput getPerson(@PathParam("id") int id) { +// final Person p = personDB.get(id); +// if (p == null) { +// throw new WebApplicationException(Response.Status.NOT_FOUND); +// } +// return new StreamingOutput() { +// +// public void write(OutputStream outputStream) throws IOException, WebApplicationException { +// outputPerson(outputStream, p); +// } +// }; +// } +// +// @PUT +// @Path("{id}") +// @Consumes("application/xml") +// @Produces("application/xml") +// public StreamingOutput updatePerson(@PathParam("id") int id, InputStream is) { +// Person update = readPerson(is); +// Person current = personDB.get(id); +// if (current == null) { +// throw new WebApplicationException(Response.Status.NOT_FOUND); +// } +// +// current.setFirstName(update.getFirstName()); +// current.setLastName(update.getLastName()); +// current.setStreet(update.getStreet()); +// current.setState(update.getState()); +// current.setZip(update.getZip()); +// current.setCountry(update.getCountry()); +// current.setVersion(current.getVersion() + 1); +// final Person scurrent = current; +// return new StreamingOutput() { +// +// public void write(OutputStream outputStream) throws IOException, WebApplicationException { +// outputPerson(outputStream, scurrent); +// } +// }; +// } +// +// protected void outputPerson(OutputStream os, Person p) throws IOException { +// PrintStream writer = new PrintStream(os); +// writer.println(""); +// writer.println(" " + p.getFirstName() + ""); +// writer.println(" " + p.getLastName() + ""); +// writer.println(" " + p.getStreet() + ""); +// writer.println(" " + p.getCity() + ""); +// writer.println(" " + p.getState() + ""); +// writer.println(" " + p.getZip() + ""); +// writer.println(" " + p.getCountry() + ""); +// writer.println(""); +// } +// +// protected Person readPerson(InputStream is) { +// try { +// DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); +// Document doc = builder.parse(is); +// Element root = doc.getDocumentElement(); +// Person p = new Person(); +// if (root.getAttribute("id") != null && !root.getAttribute("id").trim().equals("")) { +// p.setId(Integer.valueOf(root.getAttribute("id"))); +// } +// if (root.getAttribute("version") != null && !root.getAttribute("version").trim().equals("")) { +// p.setVersion(Integer.valueOf(root.getAttribute("version"))); +// } +// NodeList nodes = root.getChildNodes(); +// for (int i = 0; i < nodes.getLength(); i++) { +// Element element = (Element) nodes.item(i); +// if (element.getTagName().equals("first-name")) { +// p.setFirstName(element.getTextContent()); +// } else if (element.getTagName().equals("last-name")) { +// p.setLastName(element.getTextContent()); +// } else if (element.getTagName().equals("street")) { +// p.setStreet(element.getTextContent()); +// } else if (element.getTagName().equals("city")) { +// p.setCity(element.getTextContent()); +// } else if (element.getTagName().equals("state")) { +// p.setState(element.getTextContent()); +// } else if (element.getTagName().equals("zip")) { +// p.setZip(element.getTextContent()); +// } else if (element.getTagName().equals("country")) { +// p.setCountry(element.getTextContent()); +// } +// } +// return p; +// } catch (Exception e) { +// throw new WebApplicationException(e, Response.Status.BAD_REQUEST); +// } +// } +} diff --git a/sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/src/main/webapp/WEB-INF/web.xml b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..9fa743481 --- /dev/null +++ b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,34 @@ + + + + Helloworld + + + javax.ws.rs.Application + org.collectionspace.hello.services.HelloworldApplication + + + + resteasy.servlet.mapping.prefix + /cspace + + + + + org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap + + + + + Resteasy + + org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher + + + + + Resteasy + /cspace/* + + + diff --git a/sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/src/test/java/org/collectionspace/hello/test/IdentifierServiceRawXmlTest.java b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/src/test/java/org/collectionspace/hello/test/IdentifierServiceRawXmlTest.java new file mode 100644 index 000000000..e9893fecc --- /dev/null +++ b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/src/test/java/org/collectionspace/hello/test/IdentifierServiceRawXmlTest.java @@ -0,0 +1,62 @@ +package org.collectionspace.hello.test; + +import org.junit.Assert; +import org.junit.Test; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.URL; + +/** + * @version $Revision: 1 $ + */ +public class IdentifierServiceRawXmlTest { + + @Test + public void testIdentifierResource() throws Exception { + verbose("create a new Identifier"); + // Create a new object + String newIdentifier = "" + + "edu.stanford" + + ""; + + URL postUrl = new URL("http://localhost:8080/helloworld/cspace/identifiers"); + HttpURLConnection connection = (HttpURLConnection) postUrl.openConnection(); + connection.setDoOutput(true); + connection.setInstanceFollowRedirects(false); + connection.setRequestMethod("POST"); + connection.setRequestProperty("Content-Type", "application/xml"); + OutputStream os = connection.getOutputStream(); + os.write(newIdentifier.getBytes()); + os.flush(); + Assert.assertEquals(HttpURLConnection.HTTP_CREATED, connection.getResponseCode()); + String createdUrl = connection.getHeaderField("Location"); + verbose("Location: " + createdUrl); + connection.disconnect(); + + + // Get the new object + verbose("get created Identifier"); + URL getUrl = new URL(createdUrl); + connection = (HttpURLConnection) getUrl.openConnection(); + connection.setRequestMethod("GET"); + verbose("Content-Type: " + connection.getContentType()); + + BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); + + String line = reader.readLine(); + while (line != null) { + verbose(line); + line = reader.readLine(); + } + Assert.assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode()); + connection.disconnect(); + + } + + private void verbose(String msg) { + System.out.println("IdentifierServiceRawXmlTest : " + msg); + } +} diff --git a/sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/src/test/java/org/collectionspace/hello/test/PersonServiceRawXmlTest.java b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/src/test/java/org/collectionspace/hello/test/PersonServiceRawXmlTest.java new file mode 100644 index 000000000..b455b2f01 --- /dev/null +++ b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldService/src/test/java/org/collectionspace/hello/test/PersonServiceRawXmlTest.java @@ -0,0 +1,89 @@ +package org.collectionspace.hello.test; + +import org.junit.Assert; +import org.junit.Test; +import org.apache.commons.httpclient.HttpMethodBase; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.methods.EntityEnclosingMethod; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.URL; + +/** + * @version $Revision: 1 $ + */ +public class PersonServiceRawXmlTest { + + @Test + public void testPersonResource() throws Exception { + verbose("create a new Person"); + // Create a new object + String newPerson = "" + "John" + "Doe" + "2195 Hearst Ave" + "Berkeley" + "CA" + "94504" + "USA" + ""; + + URL postUrl = new URL("http://localhost:8080/helloworld/cspace/persons"); + HttpURLConnection connection = (HttpURLConnection) postUrl.openConnection(); + connection.setDoOutput(true); + connection.setInstanceFollowRedirects(false); + connection.setRequestMethod("POST"); + connection.setRequestProperty("Content-Type", "application/xml"); + OutputStream os = connection.getOutputStream(); + os.write(newPerson.getBytes()); + os.flush(); + Assert.assertEquals(HttpURLConnection.HTTP_CREATED, connection.getResponseCode()); + String createdUrl = connection.getHeaderField("Location"); + verbose("Location: " + createdUrl); + connection.disconnect(); + + + // Get the new object + verbose("get created Person"); + URL getUrl = new URL(createdUrl); + connection = (HttpURLConnection) getUrl.openConnection(); + connection.setRequestMethod("GET"); + verbose("Content-Type: " + connection.getContentType()); + + BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); + + String line = reader.readLine(); + while (line != null) { + verbose(line); + line = reader.readLine(); + } + Assert.assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode()); + connection.disconnect(); + + String updatePerson = "" + "Jane" + "Doe" + "1 University Ave" + "Berkeley" + "CA" + "94504" + "USA" + ""; + connection = (HttpURLConnection) getUrl.openConnection(); + connection.setDoOutput(true); + connection.setRequestMethod("PUT"); + connection.setRequestProperty("Content-Type", "application/xml"); + os = connection.getOutputStream(); + os.write(updatePerson.getBytes()); + os.flush(); + Assert.assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode()); + connection.disconnect(); + + // Show the update + verbose("updated Person"); + connection = (HttpURLConnection) getUrl.openConnection(); + connection.setRequestMethod("GET"); + + verbose("Content-Type: " + connection.getContentType()); + reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); + + line = reader.readLine(); + while (line != null) { + verbose(line); + line = reader.readLine(); + } + Assert.assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode()); + connection.disconnect(); + } + + private void verbose(String msg) { + System.out.println("PersonServiceRawXmlTest : " + msg); + } +} diff --git a/sandbox/aron/HelloWorld-CollectionObject/pom.xml b/sandbox/aron/HelloWorld-CollectionObject/pom.xml new file mode 100644 index 000000000..a058af929 --- /dev/null +++ b/sandbox/aron/HelloWorld-CollectionObject/pom.xml @@ -0,0 +1,231 @@ + + + + 4.0.0 + org.collectionspace.hello.services + 0.1 + helloworld + pom + HelloWorld + + HelloWorldJaxb + HelloWorldService + HelloWorldClient + + + + 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