incubator-wink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ngalla...@apache.org
Subject svn commit: r787552 [5/5] - in /incubator/wink/contrib/ibm-jaxrs/samples: ./ addressBook/ addressBook/build/ addressBook/build/classes/ addressBook/build/classes/server/ addressBook/build/classes/server/com/ addressBook/build/classes/server/com/ibm/ ad...
Date Tue, 23 Jun 2009 05:33:38 GMT
Added: incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/source/PhoneBookResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/source/PhoneBookResource.java?rev=787552&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/source/PhoneBookResource.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/source/PhoneBookResource.java Tue Jun 23 05:33:31 2009
@@ -0,0 +1,257 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ibm.jaxrs.sample.phonebook.source;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+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.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.TransformerFactoryConfigurationError;
+import javax.xml.transform.dom.DOMResult;
+import javax.xml.transform.dom.DOMSource;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+/**
+ * The {@link Source} version of the PhoneBook. Resource methods use Source to
+ * receive requests and send responses.
+ */
+@Path("phonebook/source")
+public class PhoneBookResource {
+
+    @Context
+    private UriInfo uriInfo;
+
+    /**
+     * Retrieves a directory list of names in the phone book. Returns the
+     * content via an {@link Source}.
+     * 
+     * @return an {@link Source} that contains a listing of all the entries
+     * @throws ParserConfigurationException
+     * @throws IOException
+     * @throws SAXException
+     */
+    @GET
+    @Produces("text/xml")
+    public Source getDirectory() throws SAXException, IOException, ParserConfigurationException {
+        final StringWriter sw = new StringWriter();
+        sw.append("<phonebook>");
+        sw.append("<entries>");
+        List<Integer> sortedKeys = new ArrayList<Integer>(PhoneBook.getPhoneBook().getEntries().keySet());
+        Collections.sort(sortedKeys);
+        for (Integer id : sortedKeys) {
+            sw.append("<entry>" + "<href>" + id + "</href>" + "</entry>");
+        }
+        sw.append("</entries>");
+        sw.append("</phonebook>");
+
+        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(sw.getBuffer()
+            .toString().getBytes());
+        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(
+            byteArrayInputStream);
+        return new DOMSource(doc);
+    }
+
+    /**
+     * Creates a new entry in the PhoneBook with a new ID. Receives the POST
+     * entity via an {@link Reader}.
+     * 
+     * @param requestSource the incoming entity via a Source
+     * @return the newly created entity via a Reader
+     * @throws SAXException
+     * @throws IOException
+     * @throws ParserConfigurationException
+     * @throws URISyntaxException
+     * @throws TransformerFactoryConfigurationError
+     * @throws TransformerException
+     * @throws TransformerConfigurationException
+     */
+    @POST
+    public Response createEntry(Source requestSource) throws SAXException, IOException,
+        ParserConfigurationException, URISyntaxException, TransformerConfigurationException,
+        TransformerException, TransformerFactoryConfigurationError {
+        DOMResult result = new DOMResult();
+        TransformerFactory.newInstance().newTransformer().transform(requestSource, result);
+        Node n = result.getNode();
+        Document doc = (Document)n;
+
+        NodeList nameNodes = doc.getDocumentElement().getElementsByTagName("name");
+        if (nameNodes.getLength() != 1) {
+            throw new WebApplicationException(Response.Status.BAD_REQUEST);
+        }
+
+        NodeList numberNodes = doc.getDocumentElement().getElementsByTagName("number");
+        if (numberNodes.getLength() != 1) {
+            throw new WebApplicationException(Response.Status.BAD_REQUEST);
+        }
+
+        /*
+         * add the phone entry
+         */
+        int id = PhoneBook.getPhoneBook().getNextID();
+
+        PhoneEntry entry = new PhoneEntry();
+        entry.setName(nameNodes.item(0).getTextContent());
+        entry.setNumber(numberNodes.item(0).getTextContent());
+
+        PhoneBook.getPhoneBook().getEntries().put(Integer.valueOf(id), entry);
+
+        /*
+         * return XML entity via a Reader
+         */
+        StringWriter sw = new StringWriter();
+        sw.append("<entry>" + "<id>" + id + "</id>" + "<name>" + entry.getName() + "</name>"
+            + "<number>" + entry.getNumber() + "</number>" + "</entry>");
+
+        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(sw.getBuffer()
+            .toString().getBytes());
+        Document responseDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(
+            byteArrayInputStream);
+        return Response.created(new URI(uriInfo.getAbsolutePath() + "/" + id)).entity(
+            new DOMSource(responseDoc)).type(MediaType.TEXT_XML_TYPE).build();
+    }
+
+    /**
+     * Retrieves an individual phone book entry. Returns the content via a
+     * Source.
+     * 
+     * @return an {@link Source} that contains a listing of all the entries
+     * @throws ParserConfigurationException
+     * @throws IOException
+     * @throws SAXException
+     */
+    @GET
+    @Path("{id}")
+    @Produces("text/xml")
+    public Source getEntry(@PathParam("id") Integer id) throws SAXException, IOException,
+        ParserConfigurationException {
+        /*
+         * get the phone entry
+         */
+        PhoneEntry entry = PhoneBook.getPhoneBook().getEntries().get(id);
+
+        StringWriter sw = new StringWriter();
+        sw.append("<entry>" + "<href>" + uriInfo.getAbsolutePath() + "</href>" + "<name>"
+            + entry.getName() + "</name>" + "<number>" + entry.getNumber() + "</number>"
+            + "</entry>");
+
+        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(sw.getBuffer()
+            .toString().getBytes());
+        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(
+            byteArrayInputStream);
+        return new DOMSource(doc);
+    }
+
+    /**
+     * Updates an entry in the PhoneBook. Retrieves the entity via a Source
+     * object and returns the updated entity via a Source.
+     * 
+     * @param requestReader the incoming entity via a Source
+     * @return the updated data via a Source
+     * @throws SAXException
+     * @throws IOException
+     * @throws ParserConfigurationException
+     * @throws URISyntaxException
+     * @throws TransformerFactoryConfigurationError
+     * @throws TransformerException
+     * @throws TransformerConfigurationException
+     */
+    @PUT
+    @Path("{id}")
+    @Produces("text/xml")
+    public Source updateEntry(Source requestSource, @PathParam("id") Integer id)
+        throws SAXException, IOException, ParserConfigurationException, URISyntaxException,
+        TransformerConfigurationException, TransformerException,
+        TransformerFactoryConfigurationError {
+        DOMResult result = new DOMResult();
+        TransformerFactory.newInstance().newTransformer().transform(requestSource, result);
+        Node n = result.getNode();
+        Document doc = (Document)n;
+
+        NodeList nameNodes = doc.getDocumentElement().getElementsByTagName("name");
+        if (nameNodes.getLength() != 1) {
+            throw new WebApplicationException(Response.Status.BAD_REQUEST);
+        }
+
+        NodeList numberNodes = doc.getDocumentElement().getElementsByTagName("number");
+        if (numberNodes.getLength() != 1) {
+            throw new WebApplicationException(Response.Status.BAD_REQUEST);
+        }
+
+        /*
+         * get the phone entry and update
+         */
+        PhoneEntry entry = PhoneBook.getPhoneBook().getEntries().get(id);
+        entry.setName(nameNodes.item(0).getTextContent());
+        entry.setNumber(numberNodes.item(0).getTextContent());
+
+        StringWriter sw = new StringWriter();
+        sw.append("<entry>" + "<href>" + uriInfo.getAbsolutePath() + "</href>" + "<name>"
+            + entry.getName() + "</name>" + "<number>" + entry.getNumber() + "</number>"
+            + "</entry>");
+        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(sw.getBuffer()
+            .toString().getBytes());
+        Document responseDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(
+            byteArrayInputStream);
+        return new DOMSource(responseDoc);
+    }
+
+    /**
+     * Deletes an entry in the PhoneBook.
+     * 
+     * @param id
+     * @return
+     */
+    @DELETE
+    @Path("{id}")
+    public Response deleteEntry(@PathParam("id") Integer id) {
+        if (PhoneBook.getPhoneBook().getEntries().remove(id) == null) {
+            return Response.status(Response.Status.NOT_FOUND).build();
+        }
+        return Response.ok().build();
+    }
+}

Added: incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/source/PhoneEntry.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/source/PhoneEntry.java?rev=787552&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/source/PhoneEntry.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/source/PhoneEntry.java Tue Jun 23 05:33:31 2009
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ibm.jaxrs.sample.phonebook.source;
+
+class PhoneEntry {
+    
+    private String name;
+    
+    private String number;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getNumber() {
+        return number;
+    }
+
+    public void setNumber(String number) {
+        this.number = number;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/streamingoutput/PhoneBook.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/streamingoutput/PhoneBook.java?rev=787552&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/streamingoutput/PhoneBook.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/streamingoutput/PhoneBook.java Tue Jun 23 05:33:31 2009
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ibm.jaxrs.sample.phonebook.streamingoutput;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+class PhoneBook {
+
+    private Map<Integer, PhoneEntry> entries = Collections
+        .synchronizedMap(new HashMap<Integer, PhoneEntry>());
+
+    private int idCounter = -1;
+
+    private static PhoneBook singleton;
+
+    static PhoneBook getPhoneBook() {
+        if (singleton == null) {
+            singleton = new PhoneBook();
+        }
+        return singleton;
+    }
+
+    public Map<Integer, PhoneEntry> getEntries() {
+        return entries;
+    }
+
+    public synchronized int getNextID() {
+        ++idCounter;
+        return idCounter;
+    }
+}

Added: incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/streamingoutput/PhoneBookResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/streamingoutput/PhoneBookResource.java?rev=787552&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/streamingoutput/PhoneBookResource.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/streamingoutput/PhoneBookResource.java Tue Jun 23 05:33:31 2009
@@ -0,0 +1,230 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ibm.jaxrs.sample.phonebook.streamingoutput;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.StringWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+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.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.StreamingOutput;
+import javax.ws.rs.core.UriInfo;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+/**
+ * The {@link StreamingOutput} version of the PhoneBook. Resource methods use
+ * StreamingOutput to receive requests and send responses.
+ */
+@Path("phonebook/streamingoutput")
+public class PhoneBookResource {
+
+    @Context
+    private UriInfo uriInfo;
+
+    /**
+     * Retrieves a directory list of names in the phone book. Returns the
+     * content via an {@link StreamingOutput}.
+     * 
+     * @return an {@link StreamingOutput} that contains a listing of all the
+     *         entries
+     */
+    @GET
+    @Produces("text/xml")
+    public StreamingOutput getDirectory() {
+        final StringWriter sw = new StringWriter();
+        sw.append("<phonebook>");
+        sw.append("<entries>");
+        List<Integer> sortedKeys = new ArrayList<Integer>(PhoneBook.getPhoneBook().getEntries().keySet());
+        Collections.sort(sortedKeys);
+        for (Integer id : sortedKeys) {
+            sw.append("<entry>" + "<href>" + id + "</href>" + "</entry>");
+        }
+        sw.append("</entries>");
+        sw.append("</phonebook>");
+
+        return new StreamingOutput() {
+            public void write(OutputStream arg0) throws IOException, WebApplicationException {
+                arg0.write(sw.toString().getBytes());
+            }
+        };
+    }
+
+    /**
+     * Creates a new entry in the PhoneBook with a new ID. Receives the POST
+     * entity via an InputStream.
+     * 
+     * @param is the incoming entity via an InputStream
+     * @return the newly created entity via an InputStream
+     * @throws SAXException
+     * @throws IOException
+     * @throws ParserConfigurationException
+     * @throws URISyntaxException
+     */
+    @POST
+    public Response createEntry(InputStream is) throws SAXException, IOException,
+        ParserConfigurationException, URISyntaxException {
+        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(is);
+
+        NodeList nameNodes = doc.getDocumentElement().getElementsByTagName("name");
+        if (nameNodes.getLength() != 1) {
+            throw new WebApplicationException(Response.Status.BAD_REQUEST);
+        }
+
+        NodeList numberNodes = doc.getDocumentElement().getElementsByTagName("number");
+        if (numberNodes.getLength() != 1) {
+            throw new WebApplicationException(Response.Status.BAD_REQUEST);
+        }
+
+        /*
+         * add the phone entry
+         */
+        int id = PhoneBook.getPhoneBook().getNextID();
+
+        PhoneEntry entry = new PhoneEntry();
+        entry.setName(nameNodes.item(0).getTextContent());
+        entry.setNumber(numberNodes.item(0).getTextContent());
+
+        PhoneBook.getPhoneBook().getEntries().put(Integer.valueOf(id), entry);
+
+        /*
+         * return XML entity via an InputStream
+         */
+        final StringWriter sw = new StringWriter();
+        sw.append("<entry>" + "<id>" + id + "</id>" + "<name>" + entry.getName() + "</name>"
+            + "<number>" + entry.getNumber() + "</number>" + "</entry>");
+
+        return Response.created(new URI(uriInfo.getAbsolutePath() + "/" + id)).entity(
+            new StreamingOutput() {
+                public void write(OutputStream arg0) throws IOException, WebApplicationException {
+                    arg0.write(sw.toString().getBytes());
+                }
+            }).type(MediaType.TEXT_XML_TYPE).build();
+    }
+
+    /**
+     * Retrieves an individual phone book entry. Returns the content via an
+     * InputStream.
+     * 
+     * @return an {@link InputStream} that contains a listing of all the entries
+     */
+    @GET
+    @Path("{id}")
+    @Produces("text/xml")
+    public StreamingOutput getEntry(@PathParam("id") Integer id) {
+        /*
+         * get the phone entry
+         */
+        PhoneEntry entry = PhoneBook.getPhoneBook().getEntries().get(id);
+
+        final StringWriter sw = new StringWriter();
+        sw.append("<entry>" + "<href>" + uriInfo.getAbsolutePath() + "</href>" + "<name>"
+            + entry.getName() + "</name>" + "<number>" + entry.getNumber() + "</number>"
+            + "</entry>");
+
+        return new StreamingOutput() {
+            public void write(OutputStream arg0) throws IOException, WebApplicationException {
+                arg0.write(sw.toString().getBytes());
+            }
+        };
+    }
+
+    /**
+     * Updates an entry in the PhoneBook. Retrieves the entity via an
+     * InputStream and returns the updated entity via an InputStream.
+     * 
+     * @param is the incoming entity via an InputStream
+     * @return the updated data via an InputStream
+     * @throws SAXException
+     * @throws IOException
+     * @throws ParserConfigurationException
+     * @throws URISyntaxException
+     */
+    @PUT
+    @Path("{id}")
+    @Produces("text/xml")
+    public StreamingOutput updateEntry(InputStream is, @PathParam("id") Integer id)
+        throws SAXException, IOException, ParserConfigurationException, URISyntaxException {
+        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(is);
+
+        NodeList nameNodes = doc.getDocumentElement().getElementsByTagName("name");
+        if (nameNodes.getLength() != 1) {
+            throw new WebApplicationException(Response.Status.BAD_REQUEST);
+        }
+
+        NodeList numberNodes = doc.getDocumentElement().getElementsByTagName("number");
+        if (numberNodes.getLength() != 1) {
+            throw new WebApplicationException(Response.Status.BAD_REQUEST);
+        }
+
+        /*
+         * get the phone entry and update
+         */
+        PhoneEntry entry = PhoneBook.getPhoneBook().getEntries().get(id);
+        entry.setName(nameNodes.item(0).getTextContent());
+        entry.setNumber(numberNodes.item(0).getTextContent());
+
+        final StringWriter sw = new StringWriter();
+        sw.append("<entry>" + "<href>" + uriInfo.getAbsolutePath() + "</href>" + "<name>"
+            + entry.getName() + "</name>" + "<number>" + entry.getNumber() + "</number>"
+            + "</entry>");
+
+        return new StreamingOutput() {
+            public void write(OutputStream arg0) throws IOException, WebApplicationException {
+                arg0.write(sw.toString().getBytes());
+            }
+        };
+    }
+
+    /**
+     * Deletes an entry in the PhoneBook.
+     * 
+     * @param id
+     * @return
+     */
+    @DELETE
+    @Path("{id}")
+    public Response deleteEntry(@PathParam("id") Integer id) {
+        if (PhoneBook.getPhoneBook().getEntries().remove(id) == null) {
+            return Response.status(Response.Status.NOT_FOUND).build();
+        }
+        return Response.ok().build();
+    }
+}

Added: incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/streamingoutput/PhoneEntry.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/streamingoutput/PhoneEntry.java?rev=787552&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/streamingoutput/PhoneEntry.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/streamingoutput/PhoneEntry.java Tue Jun 23 05:33:31 2009
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ibm.jaxrs.sample.phonebook.streamingoutput;
+
+class PhoneEntry {
+    
+    private String name;
+    
+    private String number;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getNumber() {
+        return number;
+    }
+
+    public void setNumber(String number) {
+        this.number = number;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/string/PhoneBook.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/string/PhoneBook.java?rev=787552&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/string/PhoneBook.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/string/PhoneBook.java Tue Jun 23 05:33:31 2009
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ibm.jaxrs.sample.phonebook.string;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+class PhoneBook {
+
+    private Map<Integer, PhoneEntry> entries = Collections
+        .synchronizedMap(new HashMap<Integer, PhoneEntry>());
+
+    private int idCounter = -1;
+
+    private static PhoneBook singleton;
+
+    static PhoneBook getPhoneBook() {
+        if (singleton == null) {
+            singleton = new PhoneBook();
+        }
+        return singleton;
+    }
+
+    public Map<Integer, PhoneEntry> getEntries() {
+        return entries;
+    }
+
+    public synchronized int getNextID() {
+        ++idCounter;
+        return idCounter;
+    }
+}

Added: incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/string/PhoneBookResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/string/PhoneBookResource.java?rev=787552&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/string/PhoneBookResource.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/string/PhoneBookResource.java Tue Jun 23 05:33:31 2009
@@ -0,0 +1,218 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ibm.jaxrs.sample.phonebook.string;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+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.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+/**
+ * The {@link String} version of the PhoneBook. Resource methods use Strings to
+ * receive requests and send responses.
+ */
+@Path("phonebook/string")
+public class PhoneBookResource {
+
+    @Context
+    private UriInfo uriInfo;
+
+    /**
+     * Retrieves a directory list of names in the phone book. Returns the
+     * content via a String.
+     * 
+     * @return an {@link String} that contains a listing of all the entries
+     */
+    @GET
+    @Produces("text/xml")
+    public String getDirectory() {
+        StringWriter sw = new StringWriter();
+        sw.append("<phonebook>");
+        sw.append("<entries>");
+        List<Integer> sortedKeys = new ArrayList<Integer>(PhoneBook.getPhoneBook().getEntries().keySet());
+        Collections.sort(sortedKeys);
+        for (Integer id : sortedKeys) {
+            sw.append("<entry>" + "<href>" + id + "</href>" + "</entry>");
+        }
+        sw.append("</entries>");
+        sw.append("</phonebook>");
+
+        return sw.toString();
+    }
+
+    /**
+     * Creates a new entry in the PhoneBook with a new ID. Receives the POST
+     * entity via a String.
+     * 
+     * @param is the incoming entity via a String
+     * @return the newly created entity via a String
+     * @throws SAXException
+     * @throws IOException
+     * @throws ParserConfigurationException
+     * @throws URISyntaxException
+     */
+    @POST
+    @Produces("text/xml")
+    public Response createEntry(String requestXMLContent) throws SAXException, IOException,
+        ParserConfigurationException, URISyntaxException {
+        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(requestXMLContent
+            .getBytes());
+        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(
+            byteArrayInputStream);
+
+        NodeList nameNodes = doc.getDocumentElement().getElementsByTagName("name");
+        if (nameNodes.getLength() != 1) {
+            throw new WebApplicationException(Response.Status.BAD_REQUEST);
+        }
+
+        NodeList numberNodes = doc.getDocumentElement().getElementsByTagName("number");
+        if (numberNodes.getLength() != 1) {
+            throw new WebApplicationException(Response.Status.BAD_REQUEST);
+        }
+
+        /*
+         * add the phone entry
+         */
+        int id = PhoneBook.getPhoneBook().getNextID();
+
+        PhoneEntry entry = new PhoneEntry();
+        entry.setName(nameNodes.item(0).getTextContent());
+        entry.setNumber(numberNodes.item(0).getTextContent());
+
+        PhoneBook.getPhoneBook().getEntries().put(Integer.valueOf(id), entry);
+
+        /*
+         * return XML entity via an InputStream
+         */
+        StringWriter sw = new StringWriter();
+        sw.append("<entry>" + "<id>" + id + "</id>" + "<name>" + entry.getName() + "</name>"
+            + "<number>" + entry.getNumber() + "</number>" + "</entry>");
+
+        return Response.created(new URI(uriInfo.getAbsolutePath() + "/" + id))
+            .entity(sw.toString()).type(MediaType.TEXT_XML_TYPE).build();
+    }
+
+    /**
+     * Retrieves an individual phone book entry. Returns the content via an
+     * InputStream.
+     * 
+     * @return an {@link InputStream} that contains a listing of all the entries
+     */
+    @GET
+    @Path("{id}")
+    @Produces("text/xml")
+    public String getEntry(@PathParam("id") Integer id) {
+        /*
+         * get the phone entry
+         */
+        PhoneEntry entry = PhoneBook.getPhoneBook().getEntries().get(id);
+
+        StringWriter sw = new StringWriter();
+        sw.append("<entry>" + "<href>" + uriInfo.getAbsolutePath() + "</href>" + "<name>"
+            + entry.getName() + "</name>" + "<number>" + entry.getNumber() + "</number>"
+            + "</entry>");
+
+        return sw.toString();
+    }
+
+    /**
+     * Updates an entry in the PhoneBook. Retrieves the entity via a String and
+     * returns the updated entity via a String.
+     * 
+     * @param requestXMLContent the incoming entity via a String
+     * @return the updated data via a String
+     * @throws SAXException
+     * @throws IOException
+     * @throws ParserConfigurationException
+     * @throws URISyntaxException
+     */
+    @PUT
+    @Path("{id}")
+    @Produces("text/xml")
+    public String updateEntry(String requestXMLContent, @PathParam("id") Integer id)
+        throws SAXException, IOException, ParserConfigurationException, URISyntaxException {
+        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(requestXMLContent
+            .getBytes());
+        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(
+            byteArrayInputStream);
+
+        NodeList nameNodes = doc.getDocumentElement().getElementsByTagName("name");
+        if (nameNodes.getLength() != 1) {
+            throw new WebApplicationException(Response.Status.BAD_REQUEST);
+        }
+
+        NodeList numberNodes = doc.getDocumentElement().getElementsByTagName("number");
+        if (numberNodes.getLength() != 1) {
+            throw new WebApplicationException(Response.Status.BAD_REQUEST);
+        }
+
+        /*
+         * get the phone entry and update
+         */
+        PhoneEntry entry = PhoneBook.getPhoneBook().getEntries().get(id);
+        entry.setName(nameNodes.item(0).getTextContent());
+        entry.setNumber(numberNodes.item(0).getTextContent());
+
+        StringWriter sw = new StringWriter();
+        sw.append("<entry>" + "<href>" + uriInfo.getAbsolutePath() + "</href>" + "<name>"
+            + entry.getName() + "</name>" + "<number>" + entry.getNumber() + "</number>"
+            + "</entry>");
+        return sw.toString();
+    }
+
+    /**
+     * Deletes an entry in the PhoneBook.
+     * 
+     * @param id
+     * @return
+     */
+    @DELETE
+    @Path("{id}")
+    public Response deleteEntry(@PathParam("id") Integer id) {
+        if (PhoneBook.getPhoneBook().getEntries().remove(id) == null) {
+            return Response.status(Response.Status.NOT_FOUND).build();
+        }
+        return Response.ok().build();
+    }
+}

Added: incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/string/PhoneEntry.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/string/PhoneEntry.java?rev=787552&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/string/PhoneEntry.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/string/PhoneEntry.java Tue Jun 23 05:33:31 2009
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ibm.jaxrs.sample.phonebook.string;
+
+class PhoneEntry {
+    
+    private String name;
+    
+    private String number;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getNumber() {
+        return number;
+    }
+
+    public void setNumber(String number) {
+        this.number = number;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/samples/xml/server/static/content.zip
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/samples/xml/server/static/content.zip?rev=787552&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/wink/contrib/ibm-jaxrs/samples/xml/server/static/content.zip
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/wink/contrib/ibm-jaxrs/samples/xml/server/static/index.html
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/samples/xml/server/static/index.html?rev=787552&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/samples/xml/server/static/index.html (added)
+++ incubator/wink/contrib/ibm-jaxrs/samples/xml/server/static/index.html Tue Jun 23 05:33:31 2009
@@ -0,0 +1,395 @@
+<html>
+<head>
+<title>Phonebook - XML Requests and Responses via different types</title>
+
+<link rel="stylesheet" href="dijit/themes/soria/soria.css" type="text/css" media="screen" id="themeCss" charset="utf-8"> 
+<script type="text/javascript" src="dojo/dojo.js" djConfig="parseOnLoad: true"></script>
+<script type="text/javascript" src="dijit/dijit-all.js"></script>
+<script type="text/javascript">
+dojo.require("dijit.layout.TabContainer");
+dojo.require("dijit.layout.ContentPane");
+dojo.require("dijit.form.Button");
+dojo.require("dijit.form.TextBox");
+dojo.require("dijit.form.ComboBox");
+dojo.require("dijit.form.FilteringSelect");
+</script>
+<script>
+    function updateResponse(data, ioArgs) {
+        var responseStatus = dojo.byId("responseStatusCode");
+        responseStatus.innerHTML = "<pre>" + ioArgs.xhr.status + "</pre>";
+
+        var responseEntity = dojo.byId("responseEntity");
+        var responseEntityValue = ioArgs.xhr.responseText;
+        responseEntityValue = responseEntityValue.replace(/</g, "&lt;").replace(/>/g, "&gt;");
+        responseEntity.innerHTML = "<pre>" + responseEntityValue + "</pre>";
+
+        var responseHeadersValue = ioArgs.xhr.getAllResponseHeaders();
+
+        var responseHeaders = dojo.byId("responseHeaders");
+        responseHeaders.innerHTML = "<pre>" + responseHeadersValue + "</pre>";
+    }
+
+    function updateRequest(url, method, entity, headers) {
+        var requestURL = dojo.byId("requestURL");
+        var requestEntity = dojo.byId("requestEntity");
+        var requestMethod = dojo.byId("requestMethod");
+        var requestHeaders = dojo.byId("requestHeaders");
+
+        requestURL.innerHTML = "<pre>" + url + "</pre>";
+        requestMethod.innerHTML = "<pre>" + method + "</pre>";
+        requestEntity.innerHTML = "<pre>" + entity + "</pre>";
+        requestHeaders.innerHTML = "<pre>" + headers + "</pre>";
+    }
+
+    function fillInMoreInfo(selectedEntityType, entryTextID) {
+        dojo.xhrGet({
+            url : "phonebook/" + selectedEntityType.value + "/" + entryTextID,
+            timeout: 5000,
+            preventCache: true,
+            handleAs: "xml",
+            handle: function(data, ioArgs) {
+                console.log(entryTextID);
+                var trElement = dojo.byId("entryRow" + entryTextID);
+                var tdName = document.createElement("td");
+                var nameValue = data.getElementsByTagName("name").item(0).firstChild;
+                if (nameValue == null) {
+                    nameValue = "";
+                } else {
+                    nameValue = nameValue.nodeValue;
+                }
+                tdName.appendChild(document.createTextNode(nameValue));
+                var tdNumber = document.createElement("td");
+                var numberValue = data.getElementsByTagName("number").item(0).firstChild;
+                if (numberValue == null) {
+                    numberValue = "";
+                } else {
+                    numberValue = numberValue.nodeValue;
+                }
+                
+                tdNumber.appendChild(document.createTextNode(numberValue));
+                trElement.appendChild(tdName);
+                trElement.appendChild(tdNumber);
+                return data;
+            }
+        });
+    }
+
+    function connectLink(link, selectedEntityType, entryTextID) {
+        dojo.connect(link, "onclick", function(event) {
+            deletePhonebookEntry(selectedEntityType.value, entryTextID);
+        });
+    }
+
+    function deletePhonebookEntry(entityType, entityID) {
+        var requestURLValue = 'phonebook/' + entityType + "/" + entityID;
+        updateRequest(requestURLValue, "DELETE", "", "");
+        dojo.xhrDelete({
+            url: requestURLValue,
+            handle: function(data, ioArgs) {
+                updateResponse(data, ioArgs);
+                reloadPhonebook();
+            }
+        });
+    }
+
+    function reloadPhonebook() {
+        console.log("Loading PhoneBook");
+        var selectedEntityType = dojo.byId("entitytype");
+        dojo.xhrGet( {
+            url : "phonebook/" + selectedEntityType.value,
+            preventCache: true,
+            handleAs: "xml",
+            handle: function(data, ioArgs) {
+                var phonebookDiv = dojo.byId("phonebook");
+                while(phonebookDiv.childNodes.length > 0) {
+                        phonebookDiv.removeChild(phonebookDiv.firstChild);
+                }
+
+                var putEntryID = dojo.byId("putEntryID");
+                while(putEntryID.childNodes.length > 0) {
+                        putEntryID.removeChild(putEntryID.firstChild);
+                }
+
+                var deleteEntryID = dojo.byId("deleteEntryID");
+                while(deleteEntryID.childNodes.length > 0) {
+                    deleteEntryID.removeChild(deleteEntryID.firstChild);
+                }
+
+                var getEntryID = dojo.byId("getEntryID");
+                while(getEntryID.childNodes.length > 0) {
+                    getEntryID.removeChild(getEntryID.firstChild);
+                }
+
+                if (ioArgs.xhr.status != 200 && ioArgs.xhr.status != 201) {
+                    phonebookDiv.appendChild(document.createTextNode("Error retrieving phonebook data."));
+                    return data;
+                }
+
+                var headerRow = document.createElement("tr");
+                var id = document.createElement("th");
+                id.appendChild(document.createTextNode("ID"));
+                var name = document.createElement("th");
+                name.appendChild(document.createTextNode("Name"));
+                var num = document.createElement("th");
+                num.appendChild(document.createTextNode("Number"));
+
+                headerRow.appendChild(id);
+                headerRow.appendChild(name);
+                headerRow.appendChild(num);
+
+                var thead = document.createElement("thead");
+                thead.appendChild(headerRow);
+
+                var table = document.createElement("table");
+                table.appendChild(thead);
+
+                var tbody = document.createElement("tbody");
+                table.appendChild(tbody);
+
+                var entries = data.getElementsByTagName("entry");
+
+                for(var c = 0; c < entries.length; ++c) {
+                    var entryHrefElement = entries.item(c).firstChild;
+                    var entryHrefText = entryHrefElement.firstChild;
+                    var entryTextID = entryHrefText.nodeValue;
+                    var tr = document.createElement("tr");
+                    tr.setAttribute("id", "entryRow" + entryTextID);
+                    var td = document.createElement("td");
+                    td.appendChild(document.createTextNode(entryTextID));
+                    tr.appendChild(td);
+
+                    tbody.appendChild(tr);
+                    fillInMoreInfo(selectedEntityType, entryTextID);
+
+                    var updateOption = document.createElement("option");
+                    updateOption.setAttribute("value", entryTextID);
+                    updateOption.appendChild(document.createTextNode(entryTextID));
+                    putEntryID.appendChild(updateOption);
+
+                    var deleteOption = document.createElement("option");
+                    deleteOption.setAttribute("value", entryTextID);
+                    deleteOption.appendChild(document.createTextNode(entryTextID));
+                    deleteEntryID.appendChild(deleteOption);
+
+                    var getOption = document.createElement("option");
+                    getOption.setAttribute("value", entryTextID);
+                    getOption.appendChild(document.createTextNode(entryTextID));
+                    getEntryID.appendChild(getOption);
+                }
+                phonebookDiv.appendChild(table);
+                return data;
+            }
+        });
+    };
+
+    dojo.addOnLoad(reloadPhonebook);
+
+    dojo.addOnLoad(function() {
+        var selectedEntityBox = dojo.byId("entitytype");
+        dojo.connect(selectedEntityBox, "onchange", function(newValue) {
+            console.log("Detecting change...");
+            reloadPhonebook();
+        });
+    });
+
+    dojo.addOnLoad(function() {
+        var button = dojo.byId("deleteEntry");
+        dojo.connect(button, "onclick", function(event) {
+            var selectedEntityType = dojo.byId("entitytype");
+            var entryID = dojo.byId("deleteEntryID");
+            deletePhonebookEntry(selectedEntityType.value, entryID.value);
+        });
+    });
+
+    dojo.addOnLoad(function() {
+        var button = dojo.byId("getEntry");
+        dojo.connect(button, "onclick", function(event) {
+            var selectedEntityType = dojo.byId("entitytype");
+            var entryID = dojo.byId("getEntryID");
+            var requestURLValue = 'phonebook/' + selectedEntityType.value + "/" + entryID.value;
+            updateRequest(requestURLValue, "GET", "", "");
+            dojo.xhrGet( {
+                url: requestURLValue,
+                handleAs: "xml",
+                handle: function(data, ioArgs) {
+                    updateResponse(data, ioArgs);
+                    reloadPhonebook();
+                }
+            });
+
+        });
+    });
+
+
+    dojo.addOnLoad(function() {
+        var button = dojo.byId("updateEntry");
+        dojo.connect(button, "onclick", function(event) {
+            var selectedEntityType = dojo.byId("entitytype");
+            var entryID = dojo.byId("putEntryID");
+            var entryName = dojo.byId("putEntryName");
+            var entryNumber = dojo.byId("putEntryNumber");
+            var entity = "<entry><name>" + entryName.value + "</name><number>" + entryNumber.value + "</number></entry>";
+            var cleanedUpString = entity.replace(/</g, "&lt;").replace(/>/g, "&gt;");
+
+            var requestURLValue = 'phonebook/' + selectedEntityType.value + "/" + entryID.value;
+
+            var requestHeaders = {
+                "Content-Type" : "text/xml"
+            };
+
+            var requestHeadersValue = "";
+            for (var h in requestHeaders) {
+                requestHeadersValue += h + ": " + requestHeaders[h] + "\r\n"
+            }
+
+            updateRequest(requestURLValue, "PUT", cleanedUpString, requestHeadersValue);
+
+            dojo.xhrPut( {
+                url: requestURLValue,
+                handleAs: "xml",
+                headers: requestHeaders, 
+                putData: entity,
+                handle: function(data, ioArgs) {
+                    updateResponse(data, ioArgs);
+                    reloadPhonebook();
+                }
+            });
+
+        });
+    });
+
+    dojo.addOnLoad(function() {
+        var button = dojo.byId("createEntry");
+
+        dojo.connect(button, "onclick", function(event) {
+            var selectedEntityType = dojo.byId("entitytype");
+            var entryName = dojo.byId("entryName");
+            var entryNumber = dojo.byId("entryNumber");
+            var entity = "<entry><name>" + entryName.value + "</name><number>" + entryNumber.value + "</number></entry>";
+            var cleanedUpString = entity.replace(/</g, "&lt;").replace(/>/g, "&gt;");
+
+            var requestURLValue = 'phonebook/' + selectedEntityType.value;
+
+            var requestHeaders = {
+                "Content-Type" : "text/xml"
+            };
+
+            var requestHeadersValue = "";
+            for (var h in requestHeaders) {
+                requestHeadersValue += h + ": " + requestHeaders[h] + "\r\n"
+            }
+
+            updateRequest(requestURLValue, "POST", cleanedUpString, requestHeadersValue);
+
+            dojo.xhrPost( {
+                url: requestURLValue,
+                handleAs: "xml",
+                headers: requestHeaders, 
+                postData: entity,
+                handle: function(data, ioArgs) {
+                    updateResponse(data, ioArgs);
+                    reloadPhonebook();
+                }
+            });
+        });
+    });
+
+    </script>
+</head>
+<body class="soria">
+<p>Phonebook XML</p>
+
+<p>Welcome to the Phonebook XML sample.  This sample demonstrate the consumption and production of XML via various entity parameter types (InputStream, Reader, Source, etc.).  The JAX-RS sample application has multiple root resources that are functionally equivilant but have different method parameters and return types.</p>
+
+<p>On this page, you can submit XML to the resources and see the requests and responses.</p>
+
+<div>
+1)  Choose the JAX-RS Entity type to use to process Requests/Responses:
+<form>
+<select id="entitytype" name="entitytype">
+<option value="inputstream" selected>InputStream</option>
+<option value="reader">Reader</option>
+<option value="source">Source</option>
+<option value="streamingoutput">StreamingOutput</option>
+<option value="string">String</option>
+</select>
+</form>
+
+Each entity type has its own phone book data store.
+</div>
+
+<div>
+
+2)  Choose an action by selecting one of the tabs:
+<div dojoType="dijit.layout.TabContainer" style="width: 100%; height: 200px;">
+
+<div dojoType="dijit.layout.ContentPane" title="Create a new entry" selected="true">
+<form id="submissionform">
+<table>
+<tr><td valign="right">Name</td><td><input type="text" name="name" value="" id="entryName" dojoType="dijit.form.TextBox"/></td></tr>
+<tr><td valign="right">Number</td><td><input type="text" name="number" value="" id="entryNumber" dojoType="dijit.form.TextBox"/></td></tr>
+<tr><td colspan="2"><button name="submit" id="createEntry" dojoType="dijit.form.Button">Create a new Phonebook Entry</button></td></tr>
+</table>
+</form>
+</div>
+
+<div dojoType="dijit.layout.ContentPane" title="Read an entry">
+<form>
+<table>
+<tr><td valign="right">Entry ID to get more info:</td><td><select name="getEntryID" id="getEntryID"></select></td></tr>
+<tr><td colspan="2"><button name="submit" id="getEntry" dojoType="dijit.form.Button">Request a Phonebook Entry</button></td></tr>
+</table>
+</form>
+</div>
+
+
+<div dojoType="dijit.layout.ContentPane" title="Update an entry">
+<form>
+<table>
+<tr><td valign="right">Entry ID to Update:</td><td><select name="putEntryID" id="putEntryID"></select></td></tr>
+<tr><td valign="right">Name</td><td><input type="text" name="name" value="" id="putEntryName" dojoType="dijit.form.TextBox"></input></td></tr>
+<tr><td valign="right">Number</td><td><input type="text" name="number" value="" id="putEntryNumber" dojoType="dijit.form.TextBox"/></td></tr>
+<tr><td colspan="2"><button name="submit" id="updateEntry" dojoType="dijit.form.Button">Update a Phonebook Entry</button></td></tr>
+</table>
+</form>
+</div>
+
+<div dojoType="dijit.layout.ContentPane" title="Delete an entry">
+<form>
+<table>
+<tr><td valign="right">Entry ID to Delete:</td><td><select name="deleteEntryID" id="deleteEntryID"></select></td></tr>
+<tr><td colspan="2"><button name="submit" id="deleteEntry" dojoType="dijit.form.Button">Delete a Phonebook Entry</button></td></tr>
+</table>
+</form>
+</div>
+
+</div>
+
+</div>
+
+<div>
+3)  See the actual request/response:
+<table>
+<tr><th colspan="2">Request</th></tr>
+<tr><td valign="top" align="right">URL:</td><td id="requestURL" valign="top"></td></tr>
+<tr><td valign="top" align="right">HTTP Method:</td><td id="requestMethod" valign="top"></td></tr>
+<tr><td valign="top" align="right">Headers:</td><td id="requestHeaders" valign="top"></td></tr>
+<tr><td valign="top" align="right">Entity:</td><td id="requestEntity" valign="top"></td></tr>
+</tr>
+
+
+<tr><th colspan="2">Response</th></tr>
+<tr><td valign="top" align="right">Status Code:</td><td id="responseStatusCode" valign="top"></td></tr>
+<tr><td valign="top" align="right">Headers:</td><td id="responseHeaders" valign="top"></td></tr>
+<tr><td valign="top" align="right">Entity:</td><td id="responseEntity" valign="top"></td></tr>
+</table>
+</div>
+
+<div>
+4) Here is the current phonebook you have selected:
+<div id="phonebook">
+</div>
+</div>
+
+</body>
+</html>



Mime
View raw message