From: Sanjay Dalal Date: Thu, 5 Mar 2009 23:31:21 +0000 (+0000) Subject: CSPACE-14, created new resource - Identifier. service providers use jaxb as well... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=81d5bd7a97075084bb866c3a8e8534f33ee56d55;p=tmp%2Fjakarta-migration.git CSPACE-14, created new resource - Identifier. service providers use jaxb as well. fixed maven dependencies. xml schema has namespace. same xsd contains schema for both Person and Identifier resources. un/marshalling works with namespace - XmlRootElement is generated. --- diff --git a/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldClient/pom.xml b/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldClient/pom.xml index 080bb2401..24500e86c 100644 --- a/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldClient/pom.xml +++ b/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldClient/pom.xml @@ -6,14 +6,14 @@ 0.1 4.0.0 - org.collectionspace.services.hello + org.collectionspace.hello.services helloworld-client jar 0.1 Helloworld Client - org.collectionspace.services.hello + org.collectionspace.hello.services helloworld-jaxb 0.1 diff --git a/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/IdentifierClient.java b/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/IdentifierClient.java new file mode 100644 index 000000000..a7b12f967 --- /dev/null +++ b/sandbox/sanjay/prototypes/restws/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/sanjay/prototypes/restws/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/IdentifierProxy.java b/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/IdentifierProxy.java new file mode 100644 index 000000000..125aab47d --- /dev/null +++ b/sandbox/sanjay/prototypes/restws/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/sanjay/prototypes/restws/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/PersonClient.java b/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/PersonClient.java index 3f05d6a74..8f8653c06 100644 --- a/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/PersonClient.java +++ b/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/PersonClient.java @@ -3,6 +3,7 @@ package org.collectionspace.hello.client; import javax.ws.rs.core.Response; +import org.collectionspace.hello.Person; import org.jboss.resteasy.client.ProxyFactory; import org.jboss.resteasy.plugins.providers.RegisterBuiltin; import org.jboss.resteasy.client.ClientResponse; diff --git a/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/PersonProxy.java b/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/PersonProxy.java index 668c1f7fc..69c762a60 100644 --- a/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/PersonProxy.java +++ b/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/PersonProxy.java @@ -1,7 +1,6 @@ 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; @@ -10,6 +9,7 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.Response; +import org.collectionspace.hello.Person; import org.jboss.resteasy.client.ClientResponse; /** diff --git a/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldClient/src/test/java/org/collectionspace/hello/client/test/IdentifierServiceTest.java b/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldClient/src/test/java/org/collectionspace/hello/client/test/IdentifierServiceTest.java new file mode 100644 index 000000000..f050329dd --- /dev/null +++ b/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldClient/src/test/java/org/collectionspace/hello/client/test/IdentifierServiceTest.java @@ -0,0 +1,60 @@ +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("received with get", i); + } + + private Long extractId(ClientResponse res) { + MultivaluedMap mvm = res.getMetadata(); + String uri = (String) ((ArrayList) mvm.get("Location")).get(0); + String[] segments = uri.split("/"); + System.out.println("id=" + segments[segments.length - 1]); + return Long.valueOf(segments[segments.length - 1]); + } + + private void verbose(String msg, Identifier p) { + try { + System.out.println(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/sanjay/prototypes/restws/HelloWorld/HelloWorldClient/src/test/java/org/collectionspace/hello/client/PersonServiceTest.java b/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldClient/src/test/java/org/collectionspace/hello/client/test/PersonServiceTest.java similarity index 89% rename from sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldClient/src/test/java/org/collectionspace/hello/client/PersonServiceTest.java rename to sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldClient/src/test/java/org/collectionspace/hello/client/test/PersonServiceTest.java index 525a086b0..752a0beef 100644 --- a/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldClient/src/test/java/org/collectionspace/hello/client/PersonServiceTest.java +++ b/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldClient/src/test/java/org/collectionspace/hello/client/test/PersonServiceTest.java @@ -1,13 +1,12 @@ -package org.collectionspace.hello.client; +package org.collectionspace.hello.client.test; 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.JAXBElement; import javax.xml.bind.Marshaller; -import javax.xml.namespace.QName; -import org.collectionspace.hello.client.*; +import org.collectionspace.hello.Person; +import org.collectionspace.hello.client.PersonClient; import org.jboss.resteasy.client.ClientResponse; import org.testng.Assert; import org.testng.annotations.Test; @@ -65,7 +64,8 @@ public class PersonServiceTest { Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); - m.marshal(new JAXBElement(new QName("uri", "local"), Person.class, p), System.out); + m.marshal(p, System.out); + //m.marshal(new JAXBElement(new QName("uri", "local"), Person.class, p), System.out); } catch (Exception e) { e.printStackTrace(); } diff --git a/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldJaxb/pom.xml b/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldJaxb/pom.xml index f73ba8dd2..8f0e2a102 100644 --- a/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldJaxb/pom.xml +++ b/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldJaxb/pom.xml @@ -1,15 +1,15 @@ - - helloworld - org.collectionspace.hello.services - 0.1 - + + helloworld + org.collectionspace.hello.services + 0.1 + 4.0.0 - org.collectionspace.services.hello + org.collectionspace.hello.services helloworld-jaxb - Helloworld Client JAXB 0.1 + Helloworld Client JAXB com.sun.xml.bind diff --git a/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldJaxb/src/main/resources/hello.xsd b/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldJaxb/src/main/resources/hello.xsd new file mode 100644 index 000000000..1b0a3b8d0 --- /dev/null +++ b/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldJaxb/src/main/resources/hello.xsd @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldJaxb/src/main/resources/person.xsd b/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldJaxb/src/main/resources/person.xsd deleted file mode 100644 index 319a72283..000000000 --- a/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldJaxb/src/main/resources/person.xsd +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldService/nbactions.xml b/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldService/nbactions.xml index c0f982061..9d30c239a 100644 --- a/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldService/nbactions.xml +++ b/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldService/nbactions.xml @@ -36,6 +36,9 @@ clean install + + true + run diff --git a/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldService/pom.xml b/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldService/pom.xml index ca7743721..b9e0b3da4 100644 --- a/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldService/pom.xml +++ b/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldService/pom.xml @@ -6,7 +6,7 @@ 0.1 4.0.0 - org.collectionspace.prototype + org.collectionspace.hello.services helloworld-service war 0.1 @@ -37,6 +37,11 @@ + + org.collectionspace.hello.services + helloworld-jaxb + 0.1 + org.jboss.resteasy resteasy-jaxrs @@ -140,7 +145,6 @@ org.apache.maven.plugins maven-surefire-plugin - true diff --git a/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldService/src/main/java/org/collectionspace/hello/entity/Person.java b/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldService/src/main/java/org/collectionspace/hello/entity/Person.java deleted file mode 100644 index bf4fc5096..000000000 --- a/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldService/src/main/java/org/collectionspace/hello/entity/Person.java +++ /dev/null @@ -1,126 +0,0 @@ -package org.collectionspace.hello.entity; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; -import javax.xml.bind.Unmarshaller; -import javax.xml.bind.Unmarshaller.Listener; -import javax.xml.bind.annotation.XmlElement; - -@XmlRootElement -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "person", propOrder = { - "firstName", - "lastName", - "street", - "city", - "state", - "zip", - "country" -}) -public class Person extends Listener { - - @XmlAttribute - private int id; - @XmlAttribute - private int version = 1; - private String firstName; - private String lastName; - private String street; - private String city; - private String state; - private String zip; - private String country; - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - /** - * @return the version - */ - public int getVersion() { - return version; - } - - /** - * @param version the version to set - */ - public void setVersion(int version) { - this.version = version; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public String getStreet() { - return street; - } - - public void setStreet(String street) { - this.street = street; - } - - public String getCity() { - return city; - } - - public void setCity(String city) { - this.city = city; - } - - public String getState() { - return state; - } - - public void setState(String state) { - this.state = state; - } - - public String getZip() { - return zip; - } - - public void setZip(String zip) { - this.zip = zip; - } - - public String getCountry() { - return country; - } - - public void setCountry(String country) { - this.country = country; - } - - /** - * JAXB Callback method used to reassociate the item with the owning contact. - * JAXB doesn't seem to read this method from a super class and it must - * therefore be placed on any subclass. - * - * @param unmarshaller the JAXB {@link Unmarshaller}. - * @param parent the owning {@link Contact} instance. - */ - public void afterUnmarshal(Unmarshaller unmarshaller, Object parent) { - super.afterUnmarshal(unmarshaller, parent); - } -} diff --git a/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldService/src/main/java/org/collectionspace/hello/services/HelloworldApplication.java b/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldService/src/main/java/org/collectionspace/hello/services/HelloworldApplication.java index 0021b9ae5..b7b7acdc0 100644 --- a/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldService/src/main/java/org/collectionspace/hello/services/HelloworldApplication.java +++ b/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldService/src/main/java/org/collectionspace/hello/services/HelloworldApplication.java @@ -5,20 +5,22 @@ 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()); - } + private Set singletons = new HashSet(); + private Set> empty = new HashSet>(); - @Override - public Set> getClasses() { - return empty; - } + public HelloworldApplication() { + singletons.add(new PersonResource()); + singletons.add(new IdentifierResource()); + } - @Override - public Set getSingletons() { - return singletons; - } + @Override + public Set> getClasses() { + return empty; + } + + @Override + public Set getSingletons() { + return singletons; + } } diff --git a/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldService/src/main/java/org/collectionspace/hello/services/IdentifierResource.java b/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldService/src/main/java/org/collectionspace/hello/services/IdentifierResource.java new file mode 100644 index 000000000..de9a90598 --- /dev/null +++ b/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldService/src/main/java/org/collectionspace/hello/services/IdentifierResource.java @@ -0,0 +1,74 @@ +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; + +@Path("/identifiers") +@Consumes("application/xml") +@Produces("application/xml") +public class IdentifierResource { + + 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("create 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 getId(@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(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/sanjay/prototypes/restws/HelloWorld/HelloWorldService/src/main/java/org/collectionspace/hello/services/PersonResource.java b/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldService/src/main/java/org/collectionspace/hello/services/PersonResource.java index 7afccdf92..783c39544 100644 --- a/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldService/src/main/java/org/collectionspace/hello/services/PersonResource.java +++ b/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldService/src/main/java/org/collectionspace/hello/services/PersonResource.java @@ -1,7 +1,5 @@ package org.collectionspace.hello.services; -import org.collectionspace.hello.entity.Person; - import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.POST; @@ -13,18 +11,21 @@ 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.AtomicInteger; +import java.util.concurrent.atomic.AtomicLong; import javax.ws.rs.core.UriBuilder; import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; import javax.xml.bind.Marshaller; +import javax.xml.namespace.QName; +import org.collectionspace.hello.Person; @Path("/persons") @Consumes("application/xml") @Produces("application/xml") public class PersonResource { - private Map personDB = new ConcurrentHashMap(); - private AtomicInteger idCounter = new AtomicInteger(); + private Map personDB = new ConcurrentHashMap(); + private AtomicLong idCounter = new AtomicLong(); public PersonResource() { } @@ -43,7 +44,7 @@ public class PersonResource { @GET @Path("{id}") - public Person getPerson(@PathParam("id") int 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( @@ -56,12 +57,12 @@ public class PersonResource { @PUT @Path("{id}") - public Person updatePerson(@PathParam("id") int id, Person update) { + public Person updatePerson(@PathParam("id") Long id, Person update) { Person current = personDB.get(id); if (current == null) { throw new WebApplicationException(Response.Status.NOT_FOUND); } - verbose("received person", update); + verbose("update input", update); //todo: intelligent merge needed current.setFirstName(update.getFirstName()); current.setLastName(update.getLastName()); @@ -70,7 +71,7 @@ public class PersonResource { current.setZip(update.getZip()); current.setCountry(update.getCountry()); current.setVersion(current.getVersion() + 1); - verbose("updated person", current); + verbose("update output", current); return current; } diff --git a/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldService/src/test/java/org/collectionspace/hello/test/IdentifierResourceTest.java b/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldService/src/test/java/org/collectionspace/hello/test/IdentifierResourceTest.java new file mode 100644 index 000000000..ded21d452 --- /dev/null +++ b/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldService/src/test/java/org/collectionspace/hello/test/IdentifierResourceTest.java @@ -0,0 +1,59 @@ +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 IdentifierResourceTest { + + @Test + public void testIdentifierResource() throws Exception { + System.out.println("*** 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"); + System.out.println("Location: " + createdUrl); + connection.disconnect(); + + + // Get the new object + System.out.println("*** GET Created Identifier **"); + URL getUrl = new URL(createdUrl); + connection = (HttpURLConnection) getUrl.openConnection(); + connection.setRequestMethod("GET"); + System.out.println("Content-Type: " + connection.getContentType()); + + BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); + + String line = reader.readLine(); + while (line != null) { + System.out.println(line); + line = reader.readLine(); + } + Assert.assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode()); + connection.disconnect(); + + connection.disconnect(); + } +} diff --git a/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldService/src/test/java/org/collectionspace/hello/test/PersonResourceTest.java b/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldService/src/test/java/org/collectionspace/hello/test/PersonResourceTest.java index 7757b15dd..51b4dffc4 100644 --- a/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldService/src/test/java/org/collectionspace/hello/test/PersonResourceTest.java +++ b/sandbox/sanjay/prototypes/restws/HelloWorld/HelloWorldService/src/test/java/org/collectionspace/hello/test/PersonResourceTest.java @@ -14,7 +14,6 @@ import java.net.URL; /** - * @author Bill Burke * @version $Revision: 1 $ */ public class PersonResourceTest @@ -24,7 +23,7 @@ public class PersonResourceTest { System.out.println("*** Create a new Person ***"); // Create a new object - String newPerson = "" + String newPerson = "" + "John" + "Doe" + "2195 Hearst Ave" @@ -32,7 +31,7 @@ public class PersonResourceTest + "CA" + "94504" + "USA" - + ""; + + ""; URL postUrl = new URL("http://localhost:8080/helloworld/cspace/persons"); HttpURLConnection connection = (HttpURLConnection) postUrl.openConnection(); @@ -68,7 +67,7 @@ public class PersonResourceTest Assert.assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode()); connection.disconnect(); - String updatePerson = "" + String updatePerson = "" + "Jane" + "Doe" + "1 University Ave" @@ -76,7 +75,7 @@ public class PersonResourceTest + "CA" + "94504" + "USA" - + ""; + + ""; connection = (HttpURLConnection) getUrl.openConnection(); connection.setDoOutput(true); connection.setRequestMethod("PUT"); diff --git a/sandbox/sanjay/prototypes/restws/HelloWorld/pom.xml b/sandbox/sanjay/prototypes/restws/HelloWorld/pom.xml index b26a1d350..a058af929 100644 --- a/sandbox/sanjay/prototypes/restws/HelloWorld/pom.xml +++ b/sandbox/sanjay/prototypes/restws/HelloWorld/pom.xml @@ -3,129 +3,129 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - 4.0.0 - org.collectionspace.hello.services - 0.1 - helloworld - pom - HelloWorld - - HelloWorldService - HelloWorldJaxb - HelloWorldClient - - - - jboss - http://repository.jboss.org/maven2 - - - sun - http://download.java.net/maven/2 - - - java.net - java.net Maven Repository - + 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 - - - + + legacy + + + maven2-repository.dev.java.net + Java.net Maven 2 Repository + http://download.java.net/maven/2 + + + - - java.net - java.net Maven Repository - + + 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 - - + + 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 - - + + + + + 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 - + + + + + org.apache.maven.plugins + maven-war-plugin + 2.0.1 + - + WEB-INF/lib/*.jar - - - - true + + + + true - - - - - - org.jvnet.jaxb2.maven2 - maven-jaxb2-plugin - - - - generate - - - - - - -XtoString - -Xinject-listener-code + + + + + + org.jvnet.jaxb2.maven2 + maven-jaxb2-plugin + + + + generate + + + + + + -XtoString + -Xinject-listener-code - - - - + + + + org.jvnet.jaxb2_commons - - basic - 0.4.1 - - - + + basic + 0.4.1 + + + org.jvnet.jaxb2-commons - - + + property-listener-injector - - 1.0 - + + 1.0 + - - - org.collectionspace.hello.client - - - - - - - - - - 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 - - - + + + 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 + + +