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 [4/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/providers/build.xml
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/samples/providers/build.xml?rev=787552&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/samples/providers/build.xml (added)
+++ incubator/wink/contrib/ibm-jaxrs/samples/providers/build.xml Tue Jun 23 05:33:31 2009
@@ -0,0 +1,184 @@
+<project name="providers" default="all">
+
+<!--
+  ~ 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.
+  -->
+
+	<dirname file="${ant.file.providers}" property="sample.base.dir" />
+	<property name="sample.build.dir" location="${sample.base.dir}/build" />
+	<property name="sample.compile.dir" location="${sample.build.dir}/classes" />
+	<property name="sample.work.dir" location="${sample.build.dir}/work" />
+	<property name="sample.dist.dir" location="${sample.base.dir}/dist" />
+
+	<property name="sample.runtime.dir" location="${sample.base.dir}/runtime" />
+	<available file="${sample.runtime.dir}" type="dir" property="sample.runtime.dir.exists" />
+
+	<property name="sample.server.src.dir" location="${sample.base.dir}/server/src" />
+	<property name="sample.server.build.dir" location="${sample.compile.dir}/server/" />
+
+	<property name="sample.client.src.dir" location="${sample.base.dir}/client/src" />
+	<property name="sample.client.build.dir" location="${sample.compile.dir}/client/" />
+
+	<!-- Get the current directory name.  This is needed to label
+	     the sample WAR, JAR, etc.  -->
+	<basename property="archiveName" file="${sample.base.dir}" />
+
+	<!-- Classpath to compile with -->
+	<path id="sample.compile.classpath">
+		<path refid="${samples.compile.classpathref}" />
+		<pathelement path="${classpath}" />
+	</path>
+
+	<target name="init">
+	</target>
+
+	<target name="clean" description="Cleans all built artifacts." depends="init">
+		<delete dir="${sample.build.dir}" includeemptydirs="true" failonerror="false" />
+		<mkdir dir="${sample.build.dir}" />
+		<mkdir dir="${sample.compile.dir}" />
+		<mkdir dir="${sample.work.dir}" />
+
+		<delete dir="${sample.dist.dir}" includeemptydirs="true" failonerror="false" />
+		<mkdir dir="${sample.dist.dir}" />
+	</target>
+
+	<!-- Just does the compile of sample src.  -->
+	<target name="compileServer" depends="init">
+		<echo>-------------------------------------------</echo>
+		<echo>Compiling Server Side Sample - ${archiveName}</echo>
+		<echo>-------------------------------------------</echo>
+
+		<mkdir dir="${sample.server.build.dir}" />
+		<javac srcdir="${sample.server.src.dir}" destdir="${sample.server.build.dir}" debug="on">
+			<classpath refid="${samples.compile.classpathref}" />
+		</javac>
+	</target>
+	
+	<target name="compileClient" depends="init">
+		<echo>-------------------------------------------</echo>
+		<echo>Compiling Server Side Sample - ${archiveName}</echo>
+		<echo>-------------------------------------------</echo>
+
+		<mkdir dir="${sample.client.build.dir}" />
+		<echo message="${sample.client.src.dir}"/>
+		<javac srcdir="${sample.client.src.dir}" destdir="${sample.client.build.dir}" debug="on">
+			<classpath refid="${samples.compile.classpathref}" />
+		</javac>
+	</target>
+
+	<target name="compile" description="Compiles all source code.">
+		<antcall target="compileServer">
+		</antcall>
+		<antcall target="compileClient"/>
+	</target>
+
+	<!-- Get the current directory name.  This is needed to label
+	     the sample WAR, JAR, etc.  -->
+	<basename property="archiveName" file="${basedir}" />
+
+	<target name="distServer">
+		<war destfile="${sample.dist.dir}/${archiveName}_server.war" webxml="${sample.base.dir}/server/WEB-INF/web.xml">
+			<fileset dir="." includes="server/src/**" />
+			<classes dir="${sample.server.build.dir}" />
+			<lib refid="${samples.filesetref}" />
+			<lib refid="samples.classpath.dist.ibmjaxrs.fileset" />
+		</war>
+	</target>
+	
+	<target name="distClient">
+		<jar destfile="${sample.dist.dir}/${archiveName}_client.jar"
+			 basedir="${sample.client.build.dir}"
+			 update="true"/>
+	</target>
+
+	<target name="dist" description="Packages the sample for distribution.">
+		<antcall target="distServer"/>
+		<antcall target="distClient"/>
+	</target>
+
+	<target name="all" depends="clean, compile, dist">
+	</target>
+
+	<!-- Magic -->
+	<condition property="samples.compile.classpathref" value="samples.compile.classpath.packaged" else="samples.compile.classpath.dist.runtime">
+		<isset property="sample.runtime.dir.exists" />
+	</condition>
+
+	<condition property="samples.filesetref" value="samples.classpath.packaged.fileset" else="samples.classpath.dist.fileset">
+		<isset property="sample.runtime.dir.exists" />
+	</condition>
+
+	<path id="samples.compile.classpath.packaged">
+		<!-- If this is a sample by itself, expect the JARs to be in a subdirectory. -->
+		<fileset refid="${samples.filesetref}" />
+	</path>
+
+	<path id="samples.compile.classpath.dist.runtime">
+		<fileset refid="${samples.filesetref}" />
+	</path>
+
+	<fileset dir="${sample.runtime.dir}/lib" id="samples.classpath.packaged.fileset">
+		<include name="asm-all-3.1.jar" />
+		<include name="serp-1.13.1.jar" />
+
+		<include name="commons-logging-1.1.1.jar" />
+
+		<include name="commons-httpclient-3.1.jar" />
+
+		<include name="abdera-0.4.0-incubating.jar" />
+		<include name="abdera-core-0.4.0-incubating.jar" />
+		<include name="axiom-api-1.2.5.jar" />
+		<include name="axiom-impl-1.2.5.jar" />
+		<include name="commons-codec-1.3.jar" />
+		<include name="jaxen-1.1.1.jar" />
+		<include name="xmlbeans-2.3.0.jar" />
+
+		<include name="jsr311-api-0.11.jar" />
+	</fileset>
+
+	<fileset dir="${sample.base.dir}/../../lib" id="samples.classpath.dist.fileset">
+		<include name="asm-all-3.1.jar" />
+		<include name="serp-1.13.1.jar" />
+
+		<include name="commons-logging-1.1.1.jar" />
+
+		<include name="commons-httpclient-3.1.jar" />
+
+		<include name="abdera-0.4.0-incubating.jar" />
+		<include name="abdera-core-0.4.0-incubating.jar" />
+		<include name="axiom-api-1.2.5.jar" />
+		<include name="axiom-impl-1.2.5.jar" />
+		<include name="commons-codec-1.3.jar" />
+		<include name="jaxen-1.1.1.jar" />
+		<include name="xmlbeans-2.3.0.jar" />
+
+		<include name="jsr311-api-0.11.jar" />
+	</fileset>
+	
+	<fileset dir="${sample.base.dir}/../../build" id="samples.classpath.dist.ibmjaxrs.fileset">
+		<include name="ibmjaxrs*.jar" />
+	</fileset>
+
+	<target name="packageSampleOnly">
+		<mkdir dir="${sample.runtime.dir}/lib" />
+		<copy todir="${sample.runtime.dir}/lib">
+			<fileset refid="samples.classpath.dist.fileset">
+			</fileset>
+		</copy>
+	</target>
+</project>

Added: incubator/wink/contrib/ibm-jaxrs/samples/providers/client/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/samples/providers/client/WEB-INF/web.xml?rev=787552&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/samples/providers/client/WEB-INF/web.xml (added)
+++ incubator/wink/contrib/ibm-jaxrs/samples/providers/client/WEB-INF/web.xml Tue Jun 23 05:33:31 2009
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  ~ 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.
+  -->
+
+<!--
+  This program may be used, executed, copied, modified and distributed
+  without royalty for the purpose of developing, using, marketing, or distributing.
+-->
+<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" 
+xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+
+</web-app>
\ No newline at end of file

Added: incubator/wink/contrib/ibm-jaxrs/samples/providers/client/src/com/ibm/jaxrs/sample/providers/client/ProvidersSample.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/samples/providers/client/src/com/ibm/jaxrs/sample/providers/client/ProvidersSample.java?rev=787552&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/samples/providers/client/src/com/ibm/jaxrs/sample/providers/client/ProvidersSample.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/samples/providers/client/src/com/ibm/jaxrs/sample/providers/client/ProvidersSample.java Tue Jun 23 05:33:31 2009
@@ -0,0 +1,450 @@
+/*
+ * 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.providers.client;
+
+import java.nio.charset.Charset;
+
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.ByteArrayRequestEntity;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.StringRequestEntity;
+
+public class ProvidersSample {
+
+    public static final Charset UTF8_CHARSET = Charset.forName("utf-8");
+
+    protected HttpClient httpclient = new HttpClient();
+    protected String baseURI = null;
+
+    public ProvidersSample(String baseURI) {
+        this.baseURI = baseURI;
+    }
+
+    public static void main(String[] args) {
+        if (args.length == 0 || args[0].length() == 0) {
+            printUsage();
+            return;
+        } else {
+            System.out
+                    .println("\nExecuting the providers samples with baseURI "
+                            + args[0]);
+        }
+
+        ProvidersSample samples = new ProvidersSample(args[0]);
+        if (args.length == 1 || args.length == 2 && "all".equals(args[1])) {
+            samples.unsupportedContentType();
+            samples.unsupportedAcceptType();
+            samples.defaultText();
+            samples.defaultInt();
+            samples.integerTextProvider();
+            samples.integerIntProvider();
+            samples.preferTextMediaType();
+            samples.fallbackToSupportedMediaType();
+            return;
+        }
+
+        for (int i = 1; i < args.length; ++i) {
+            if ("unsupportedContentType".equals(args[i]))
+                samples.unsupportedContentType();
+            else if ("unsupportedAcceptType".equals(args[i]))
+                samples.unsupportedAcceptType();
+            else if ("defaultText".equals(args[i]))
+                samples.defaultText();
+            else if ("defaultInt".equals(args[i]))
+                samples.defaultInt();
+            else if ("integerTextProvider".equals(args[i]))
+                samples.integerTextProvider();
+            else if ("integerIntProvider".equals(args[i]))
+                samples.integerIntProvider();
+            else if ("preferTextMediaType".equals(args[i]))
+                samples.preferTextMediaType();
+            else if ("fallbackToSupportedMediaType".equals(args[i]))
+                samples.fallbackToSupportedMediaType();
+            else
+                System.out.println("!!! Sample with name " + args[i]
+                        + " does not exist. Skipping... !!!");
+        }
+    }
+
+    public static void printUsage() {
+        System.out.println("Usage:");
+        System.out
+                .println("java com.ibm.jaxrs.sample.providers.client.ProvidersSample <baseURI> <sample1> <sample2> ...");
+        System.out
+                .println("baseURI is the URI that the sample application is available up to and including");
+        System.out.println("the context root.");
+        System.out.println("Ex: http://localhost:8080/providers");
+        System.out
+                .println("This is followed by one or more sample names to execute. These are the names of");
+        System.out
+                .println("the methods within the client class or \"all\" to run all the samples.");
+    }
+
+    public String getBaseURI() {
+        return this.baseURI;
+    }
+
+    public void unsupportedContentType() {
+        System.out
+                .println("\n\n***** Running the unsupportedContentType sample. *****");
+        System.out.println("Synopsis:");
+        System.out
+                .println("\tunsupportedContentType makes a POST request using a\n"
+                        + "\tContent-Type of contentType/unsupported. Since this content type\n"
+                        + "\tis not supported by the runtime, and no user provider has\n"
+                        + "\tbeen implemented for the content type, a 415 return code will\n"
+                        + "\tbe returned.\n");
+
+        System.out.println("Executing...");
+        String url = getBaseURI() + "/integer/wrapper";
+        System.out.println("\tInvoking a POST to " + url);
+        PostMethod post = new PostMethod(url);
+        post.setRequestEntity(new ByteArrayRequestEntity(intToBytes(324324322),
+                "contentType/unsupported"));
+        try {
+            int returnCode = httpclient.executeMethod(post);
+            System.out.println("\tReturn code: " + returnCode);
+            if (returnCode != 415)
+                System.out
+                        .println("\n\t!!! Error running the unsupportedContentType sample !!!\n\tReturn code of 415 was not received.");
+        } catch (Exception e) {
+            System.out
+                    .println("\n\t!!! Error running the unsupportedContentType sample !!!");
+            e.printStackTrace();
+        } finally {
+            post.releaseConnection();
+        }
+    }
+
+    public void unsupportedAcceptType() {
+        System.out
+                .println("\n\n***** Running the unsupportedAcceptType sample. *****");
+        System.out.println("Synopsis:");
+        System.out
+                .println("\tunsupportedAcceptType makes a POST request using an\n"
+                        + "\tAccept header of contentType/unsupported. Since this media type\n"
+                        + "\tis not supported by the runtime, and no user provider has\n"
+                        + "\tbeen implemented for the media type, a 406 return code will\n"
+                        + "\tbe returned.\n");
+
+        System.out.println("Executing...");
+        String url = getBaseURI() + "/integer";
+        System.out.println("\tInvoking a GET to " + url);
+        GetMethod get = new GetMethod(url);
+        get.setRequestHeader("Accept", "contentType/unsupported");
+        try {
+            int returnCode = httpclient.executeMethod(get);
+            System.out.println("\tReturn code: " + returnCode);
+            if (returnCode != 406)
+                System.out
+                        .println("\n\t!!! Error running the unsupportedAcceptType sample !!!\n\tReturn code of 406 was not received.");
+        } catch (Exception e) {
+            System.out
+                    .println("\n\t!!! Error running the unsupportedAcceptType sample !!!");
+            e.printStackTrace();
+        } finally {
+            get.releaseConnection();
+        }
+    }
+
+    public void defaultText() {
+        System.out.println("\n\n***** Running the defaultText sample. *****");
+        System.out.println("Synopsis:");
+        System.out
+                .println("\tdefaultText makes a POST request to the resource's reset method\n"
+                        + "\tto reset the Integer to -1. It then makes a GET request using an Accept\n"
+                        + "\theader value of integer/text. This will result in the runtime choosing the\n"
+                        + "\tIntegerTextProvider as the MessageBodyWriter to use. The String \"-1\" will\n"
+                        + "\tbe returned.\n");
+
+        System.out.println("Executing...");
+        GetMethod get = new GetMethod(getBaseURI() + "/integer");
+        try {
+            resetInteger();
+            System.out.println("\tInvoking GET request to " + getBaseURI()
+                    + "/integer");
+            get.setRequestHeader("Accept", "integer/text");
+            int returnCode = httpclient.executeMethod(get);
+            System.out.println("\tReturn Code: " + returnCode);
+            String integer = get.getResponseBodyAsString();
+            System.out.println("\tDefault integer value is: " + integer);
+            if (!"-1".equals(integer))
+                System.out
+                        .println("\n\t!!! Error running the defaultText sample !!!\n\tExpected efault value \"-1\" was not returned.");
+        } catch (Exception e) {
+            System.out
+                    .println("\n\t!!! Error running the defaultText sample !!!");
+            e.printStackTrace();
+        } finally {
+            get.releaseConnection();
+        }
+    }
+
+    public void defaultInt() {
+        System.out.println("\n\n***** Running the defaultInt sample. *****");
+        System.out.println("Synopsis:");
+        System.out
+                .println("\tdefaultInt makes a POST request to the resource's reset method\n"
+                        + "\tto reset the Integer to -1. It then makes a GET request using an Accept\n"
+                        + "\theader value of integer/int. This will result in the runtime choosing the\n"
+                        + "\tIntegerIntProvider as the MessageBodyWriter to use. The binary int value -1 will\n"
+                        + "\tbe returned.\n");
+
+        System.out.println("Executing...");
+        GetMethod get = new GetMethod(getBaseURI() + "/integer");
+        try {
+            resetInteger();
+            get.setRequestHeader("Accept", "integer/int");
+            System.out.println("\tInvoking GET request to " + getBaseURI()
+                    + "/integer");
+            int returnCode = httpclient.executeMethod(get);
+            System.out.println("\tReturn Code: " + returnCode);
+            int integer = bytesToInt(get.getResponseBody());
+            System.out.println("\tDefault integer value is: " + integer);
+            if (-1 != integer)
+                System.out
+                        .println("\n\t!!! Error running the defaultInt sample !!!\n\tExpected default value -1 was not returned.");
+        } catch (Exception e) {
+            System.out
+                    .println("\n\t!!! Error running the defaultInt sample !!!");
+            e.printStackTrace();
+        } finally {
+            get.releaseConnection();
+        }
+    }
+
+    public void integerTextProvider() {
+        System.out
+                .println("\n\n***** Running the integerTextProvider sample. *****");
+        System.out.println("Synopsis:");
+        System.out
+                .println("\tintegerTextProvider makes a POST request with a Content-Type of integer/text\n"
+                        + "\tsetting the server side Integer value to 100. The value 100 is passed as a\n"
+                        + "\tString, \"100\". This results in the runtime choosing the IntegerTextProvider\n"
+                        + "\tas the MessageBodyReader to use. A GET is then issued to get the value that was\n"
+                        + "\tpreviously set using an Accept header value of integer/text. The value \"100\"\n"
+                        + "\tis returned using the IntegerTextProvider as the MessageBodyWriter.\n");
+
+        System.out.println("Executing...");
+        PostMethod post = new PostMethod(getBaseURI() + "/integer");
+        int returnCode = -1;
+        try {
+            resetInteger();
+            System.out.println("\tInvoking POST request to " + getBaseURI()
+                    + "/integer");
+            post.setRequestEntity(new StringRequestEntity("100",
+                    "integer/text", UTF8_CHARSET.name()));
+            returnCode = httpclient.executeMethod(post);
+            System.out.println("\tReturn Code: " + returnCode);
+        } catch (Exception e) {
+            System.out
+                    .println("\n\t!!! Error running the integerTextProvider sample !!!");
+            e.printStackTrace();
+            return;
+        } finally {
+            post.releaseConnection();
+        }
+
+        GetMethod get = new GetMethod(getBaseURI() + "/integer");
+        try {
+            get.setRequestHeader("Accept", "integer/text");
+            System.out.println("\tInvoking a GET request to " + getBaseURI()
+                    + "/integer");
+            returnCode = httpclient.executeMethod(get);
+            System.out.println("\tReturn Code: " + returnCode);
+            String response = get.getResponseBodyAsString();
+            System.out.println("\tRecieved the value " + response);
+            if (!"100".equals(response))
+                System.out
+                        .println("\n\t!!! Error running the integerTextProvider sample !!!\n\tExpected posted value \"100\" was not returned.");
+        } catch (Exception e) {
+            System.out
+                    .println("\n\t!!! Error running the integerTextProvider sample !!!");
+            e.printStackTrace();
+        } finally {
+            get.releaseConnection();
+        }
+    }
+
+    public void integerIntProvider() {
+        System.out
+                .println("\n\n***** Running the integerIntProvider sample. *****");
+        System.out.println("Synopsis:");
+        System.out
+                .println("\tintegerIntProvider makes a POST request with a Content-Type of integer/int\n"
+                        + "\tsetting the server side Integer value to 100. The value 100 is passed as a\n"
+                        + "\tbinary integer. This results in the runtime choosing the IntegerIntProvider\n"
+                        + "\tas the MessageBodyReader to use. A GET is then issued to get the value that was\n"
+                        + "\tpreviously set using an Accept header value of integer/int. 100 in binary\n"
+                        + "\tis returned using the IntegerIntProvider as the MessageBodyWriter.\n");
+
+        System.out.println("Executing...");
+        PostMethod post = new PostMethod(getBaseURI() + "/integer");
+        int returnCode = -1;
+        try {
+            resetInteger();
+            post.setRequestEntity(new ByteArrayRequestEntity(intToBytes(100),
+                    "integer/int"));
+            System.out.println("\tInvoking POST request to " + getBaseURI()
+                    + "/integer");
+            returnCode = httpclient.executeMethod(post);
+            System.out.println("\tReturn Code: " + returnCode);
+        } catch (Exception e) {
+            System.out
+                    .println("\n\t!!! Error running the integerIntProvider sample !!!");
+            e.printStackTrace();
+            return;
+        } finally {
+            post.releaseConnection();
+        }
+        GetMethod get = new GetMethod(getBaseURI() + "/integer");
+        try {
+            get.setRequestHeader("Accept", "integer/int");
+            System.out.println("\tInvoking a GET request to " + getBaseURI()
+                    + "/integer");
+            returnCode = httpclient.executeMethod(get);
+            System.out.println("\tReturn Code: " + returnCode);
+            int integer = bytesToInt(get.getResponseBody());
+            System.out.println("\tRecieved the value " + integer);
+            if (100 != integer)
+                System.out
+                        .println("\n\t!!! Error running the integerIntProvider sample !!!\n\tExpected posted value 100 was not returned.");
+        } catch (Exception e) {
+            System.out
+                    .println("\n\t!!! Error running the integerIntProvider sample !!!");
+            e.printStackTrace();
+        } finally {
+            get.releaseConnection();
+        }
+    }
+
+    public void preferTextMediaType() {
+        System.out
+                .println("\n\n***** Running the preferTextMediaType sample. *****");
+        System.out.println("Synopsis:");
+        System.out
+                .println("\tpreferTextMediaType makes a GET request with an Accept header of\n"
+                        + "\t\"integer/text; q=0.8, integer/int; q=0.2.\" Both of these media types are supported\n"
+                        + "\tby the sample MessageBodyReader/Writer implementaions IntegerTextProvider and\n"
+                        + "\tIntegerIntProvider, respectively. Since the quality factor gives preference to\n"
+                        + "\tthe integer/text media type, the runtime will choose the IntegerTextProvider as\n"
+                        + "\tthe MessageBodyWriter to use.\n");
+
+        System.out.println("Executing...");
+        GetMethod get = new GetMethod(getBaseURI() + "/integer");
+        try {
+            resetInteger();
+            get.setRequestHeader("Accept",
+                    "integer/text; q=0.8, integer/int; q=0.2");
+            System.out.println("\tInvoking a GET request to " + getBaseURI()
+                    + "/integer");
+            System.out.println("\tReturn Code: "
+                    + httpclient.executeMethod(get));
+            Header h = get.getResponseHeaders("Content-Type")[0];
+            System.out.println("\tResponse Content-Type is " + h.getValue());
+            if (!"integer/text".equals(h.getValue()))
+                System.out
+                        .println("\n\t!!! Error running the preferTextMediaType sample !!!\n\tExpected Content-Type on the resonse, integer/text, was not returned.");
+        } catch (Exception e) {
+            System.out
+                    .println("\n\t!!! Error running the preferTextMediaType sample !!!");
+            e.printStackTrace();
+        } finally {
+            get.releaseConnection();
+        }
+    }
+
+    public void fallbackToSupportedMediaType() {
+        System.out
+                .println("\n\n***** Running the fallbackToSupportedMediaType sample. *****");
+        System.out.println("Synopsis:");
+        System.out
+                .println("\tfallbackToSupportedMediaType makes a GET request with an Accept header of\n"
+                        + "\t\"contentType/unsupported; q=0.8, integer/int; q=0.2.\" Only the integer/int media\n"
+                        + "\ttype is supported by the sample MessageBodyReader/Writer implementation IntegerIntProvider.\n"
+                        + "\tSince the quality factor gives preference to an unsupported media type, the runtime\n"
+                        + "\twill choose the supported media type that has the lower quality factor, integer/int.\n"
+                        + "\tThe IntegerIntProvider will be used.\n");
+
+        System.out.println("Executing...");
+        GetMethod get = new GetMethod(getBaseURI() + "/integer");
+        try {
+            resetInteger();
+            get.setRequestHeader("Accept",
+                    "contentType/unsupported; q=0.8, integer/int; q=0.2");
+            System.out.println("\tInvoking a GET request to " + getBaseURI()
+                    + "/integer");
+            System.out.println("\tReturn Code: "
+                    + httpclient.executeMethod(get));
+            Header h = get.getResponseHeaders("Content-Type")[0];
+            System.out.println("\tResponse Content-Type is " + h.getValue());
+            if (!"integer/int".equals(h.getValue()))
+                System.out
+                        .println("\n\t!!! Error running the fallbackToSupportedMediaType sample !!!\n\tExpected Content-Type on the resonse, integer/int, was not returned.");
+        } catch (Exception e) {
+            System.out
+                    .println("\n\t!!! Error running the fallbackToSupportedMediaType sample !!!");
+            e.printStackTrace();
+        } finally {
+            get.releaseConnection();
+        }
+    }
+
+    protected void resetInteger() throws Exception {
+        System.out.println("\tMaking a POST request to " + getBaseURI()
+                + "/integer/reset");
+        PostMethod post = new PostMethod(getBaseURI() + "/integer/reset");
+        try {
+            System.out.println("\tReturn Code: "
+                    + httpclient.executeMethod(post));
+        } finally {
+            post.releaseConnection();
+        }
+    }
+
+    protected int bytesToInt(byte[] b) {
+        int[] i = new int[4];
+        i[0] = b[0];
+        i[1] = b[1];
+        i[2] = b[2];
+        i[3] = b[3];
+        if (i[0] < 0)
+            i[0] = i[0] + 256;
+        if (i[1] < 0)
+            i[1] = i[1] + 256;
+        if (i[2] < 0)
+            i[2] = i[2] + 256;
+        if (i[3] < 0)
+            i[3] = i[3] + 256;
+        int n = (i[0] + (i[1] << 8) + (i[2] << 16) + (i[3] << 24));
+        return n;
+    }
+
+    protected byte[] intToBytes(int n) {
+        byte[] b = new byte[4];
+        b[0] = (byte) (n & 255);
+        b[1] = (byte) ((n >> 8) & 255);
+        b[2] = (byte) ((n >> 16) & 255);
+        b[3] = (byte) ((n >> 24) & 255);
+        return b;
+    }
+}

Added: incubator/wink/contrib/ibm-jaxrs/samples/providers/server/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/samples/providers/server/WEB-INF/web.xml?rev=787552&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/samples/providers/server/WEB-INF/web.xml (added)
+++ incubator/wink/contrib/ibm-jaxrs/samples/providers/server/WEB-INF/web.xml Tue Jun 23 05:33:31 2009
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  ~ 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.
+  -->
+
+	<!--
+		This program may be used, executed, copied, modified and distributed
+		without royalty for the purpose of developing, using, marketing, or
+		distributing.
+	-->
+<web-app id="WebApp_ID" version="2.5"
+	xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+	<servlet>
+		<servlet-name>Providers</servlet-name>
+		<servlet-class> com.ibm.ws.jaxrs.web.RESTServlet </servlet-class>
+		<init-param>
+			<param-name>javax.ws.rs.Application</param-name>
+			<param-value>com.ibm.jaxrs.sample.providers.ProvidersApplication</param-value>
+		</init-param>
+		<load-on-startup>1</load-on-startup>
+	</servlet>
+	<servlet-mapping>
+		<servlet-name>Providers</servlet-name>
+		<url-pattern>/*</url-pattern>
+	</servlet-mapping>
+</web-app>
\ No newline at end of file

Added: incubator/wink/contrib/ibm-jaxrs/samples/providers/server/src/com/ibm/jaxrs/sample/providers/IntegerIntProvider.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/samples/providers/server/src/com/ibm/jaxrs/sample/providers/IntegerIntProvider.java?rev=787552&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/samples/providers/server/src/com/ibm/jaxrs/sample/providers/IntegerIntProvider.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/samples/providers/server/src/com/ibm/jaxrs/sample/providers/IntegerIntProvider.java Tue Jun 23 05:33:31 2009
@@ -0,0 +1,96 @@
+/*
+ * 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.providers;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+
+@Provider
+@Consumes(value = "integer/int")
+@Produces(value = "integer/int")
+public class IntegerIntProvider implements MessageBodyReader<Integer>, MessageBodyWriter<Integer> {
+
+    public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
+        return type == Integer.class;
+    }
+
+    public Integer readFrom(Class<Integer> clazz, Type genericType, Annotation[] annotations, MediaType m, MultivaluedMap<String, String> headers, InputStream is)
+            throws IOException {
+        System.out.println("Reading Integer as int.");
+        byte[] b = new byte[4];
+        is.read(b);
+        int[] i = new int[4];
+        i[0] = b[0];
+        i[1] = b[1];
+        i[2] = b[2];
+        i[3] = b[3];
+        if (i[0] < 0)
+            i[0] = i[0] + 256;
+        if (i[1] < 0)
+            i[1] = i[1] + 256;
+        if (i[2] < 0)
+            i[2] = i[2] + 256;
+        if (i[3] < 0)
+            i[3] = i[3] + 256;
+        int n = (i[0] + (i[1] << 8) + (i[2] << 16) + (i[3] << 24));
+        return new Integer(n);
+    }
+
+    public long getSize(Integer arg0, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4) {
+        return 4;
+    }
+
+    public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
+        return type == Integer.class;
+    }
+
+    public void writeTo(Integer obj, Class<?> clazz, Type genericType, Annotation[] annotations, MediaType m, MultivaluedMap<String, Object> headers, OutputStream os)
+            throws IOException {
+        System.out.println("Writing Integer as int.");
+        System.out.println(m.toString());
+
+        List<Object> list = new ArrayList<Object>();
+        list.add(m.toString());
+        headers.put("Content-Type", list);
+
+        int n = obj;
+        byte[] b = new byte[4];
+        b[0] = (byte) (n & 255);
+        b[1] = (byte) ((n >> 8) & 255);
+        b[2] = (byte) ((n >> 16) & 255);
+        b[3] = (byte) ((n >> 24) & 255);
+        os.write(b);
+        os.close();
+
+    }
+}

Added: incubator/wink/contrib/ibm-jaxrs/samples/providers/server/src/com/ibm/jaxrs/sample/providers/IntegerResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/samples/providers/server/src/com/ibm/jaxrs/sample/providers/IntegerResource.java?rev=787552&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/samples/providers/server/src/com/ibm/jaxrs/sample/providers/IntegerResource.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/samples/providers/server/src/com/ibm/jaxrs/sample/providers/IntegerResource.java Tue Jun 23 05:33:31 2009
@@ -0,0 +1,69 @@
+/*
+ * 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.providers;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Response;
+
+@Path(value = "/integer")
+public class IntegerResource {
+
+    static Integer integer = new Integer(-1);
+
+    @POST
+    @Consumes(value = { "integer/int", "integer/text" })
+    public void setInteger(Integer integer) {
+        IntegerResource.integer = integer;
+    }
+
+    @POST
+    @Path(value = "/wrapper")
+    public void acceptWrapper(IntegerWrapper wrapper) {
+        return;
+    }
+
+    @GET
+    @Produces(value = { "integer/int", "integer/text" })
+    public Response getInteger() {
+        return Response.ok(IntegerResource.integer).build();
+    }
+
+    @POST
+    @Path(value = "/reset")
+    public void reset() {
+        IntegerResource.integer = new Integer(-1);
+    }
+
+    public class IntegerWrapper {
+        private Integer integer;
+
+        public IntegerWrapper(Integer integer) {
+            this.integer = integer;
+        }
+
+        public Integer getInteger() {
+            return this.integer;
+        }
+    }
+}

Added: incubator/wink/contrib/ibm-jaxrs/samples/providers/server/src/com/ibm/jaxrs/sample/providers/IntegerTextProvider.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/samples/providers/server/src/com/ibm/jaxrs/sample/providers/IntegerTextProvider.java?rev=787552&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/samples/providers/server/src/com/ibm/jaxrs/sample/providers/IntegerTextProvider.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/samples/providers/server/src/com/ibm/jaxrs/sample/providers/IntegerTextProvider.java Tue Jun 23 05:33:31 2009
@@ -0,0 +1,95 @@
+/*
+ * 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.providers;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+
+@Provider
+@Consumes(value = "integer/text")
+@Produces(value = "integer/text")
+public class IntegerTextProvider implements MessageBodyReader<Integer>, MessageBodyWriter<Integer> {
+
+    public static final Charset UTF8_CHARSET = Charset.forName("utf-8");
+
+    public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
+        return type == Integer.class;
+    }
+
+    public Integer readFrom(Class<Integer> clazz, Type genericType, Annotation[] annotations, MediaType m, MultivaluedMap<String, String> headers, InputStream is)
+            throws IOException {
+        System.out.println("Reading Integer as text.");
+        return Integer.parseInt(toString(is));
+    }
+
+    public long getSize(Integer arg0, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4) {
+        return arg0.toString().length();
+    }
+
+    public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
+        return type == Integer.class;
+    }
+
+    public void writeTo(Integer obj, Class<?> clazz, Type genericType, Annotation[] annotations, MediaType m, MultivaluedMap<String, Object> headers, OutputStream os)
+            throws IOException {
+        System.out.println("Writing Integer as text.");
+
+        List<Object> list = new ArrayList<Object>();
+        list.add(m.toString());
+        headers.put("Content-Type", list);
+
+        String s = obj.toString();
+        byte[] b = new byte[s.length()];
+        char[] c = s.toCharArray();
+        for (int i = 0; i < b.length; ++i)
+            b[i] = (byte) c[i];
+        os.write(b);
+        os.close();
+    }
+
+    protected String toString(InputStream is) throws IOException {
+        int avail = is.available();
+
+        StringBuilder buf = new StringBuilder();
+        final byte[] buffer = new byte[avail];
+        int n = 0;
+        n = is.read(buffer);
+        while (-1 != n) {
+            buf.append(new String(buffer, 0, n, UTF8_CHARSET.name()));
+            n = is.read(buffer);
+        }
+        is.close();
+        return buf.toString();
+    }
+}

Added: incubator/wink/contrib/ibm-jaxrs/samples/providers/server/src/com/ibm/jaxrs/sample/providers/ProvidersApplication.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/samples/providers/server/src/com/ibm/jaxrs/sample/providers/ProvidersApplication.java?rev=787552&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/samples/providers/server/src/com/ibm/jaxrs/sample/providers/ProvidersApplication.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/samples/providers/server/src/com/ibm/jaxrs/sample/providers/ProvidersApplication.java Tue Jun 23 05:33:31 2009
@@ -0,0 +1,41 @@
+/*
+ * 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.providers;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class ProvidersApplication extends javax.ws.rs.core.Application {
+
+    @Override
+    public Set<Class<?>> getClasses() {
+        Set<Class<?>> clazzes = new HashSet<Class<?>>();
+        clazzes.add(IntegerResource.class);
+        return clazzes;
+    }
+
+    @Override
+    public Set<Object> getSingletons() {
+        Set<Object> singletons = new HashSet<Object>();
+        singletons.add(new IntegerIntProvider());
+        singletons.add(new IntegerTextProvider());
+        return singletons;
+    }
+}

Added: incubator/wink/contrib/ibm-jaxrs/samples/xml/build.xml
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/samples/xml/build.xml?rev=787552&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/samples/xml/build.xml (added)
+++ incubator/wink/contrib/ibm-jaxrs/samples/xml/build.xml Tue Jun 23 05:33:31 2009
@@ -0,0 +1,169 @@
+<project name="addressBook" default="all">
+
+<!--
+  ~ 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.
+  -->
+
+	<dirname file="${ant.file.addressBook}" property="sample.base.dir" />
+	<property name="sample.build.dir" location="${sample.base.dir}/build" />
+	<property name="sample.compile.dir" location="${sample.build.dir}/classes" />
+	<property name="sample.work.dir" location="${sample.build.dir}/work" />
+	<property name="sample.dist.dir" location="${sample.base.dir}/dist" />
+
+	<property name="sample.runtime.dir" location="${sample.base.dir}/runtime" />
+	<available file="${sample.runtime.dir}" type="dir" property="sample.runtime.dir.exists" />
+
+	<property name="sample.server.src.dir" location="${sample.base.dir}/server/src" />
+	<property name="sample.server.build.dir" location="${sample.compile.dir}/server/" />
+	<property name="sample.server.static.dir" location="${sample.base.dir}/server/static" />
+
+	<!-- Get the current directory name.  This is needed to label
+	     the sample WAR, JAR, etc.  -->
+	<basename property="archiveName" file="${sample.base.dir}" />
+
+	<!-- Classpath to compile with -->
+	<path id="sample.compile.classpath">
+		<path refid="${samples.compile.classpathref}" />
+		<pathelement path="${classpath}" />
+	</path>
+
+	<target name="init">
+	</target>
+
+	<target name="clean" description="Cleans all built artifacts." depends="init">
+		<delete dir="${sample.build.dir}" includeemptydirs="true" failonerror="false" />
+		<mkdir dir="${sample.build.dir}" />
+		<mkdir dir="${sample.compile.dir}" />
+		<mkdir dir="${sample.work.dir}" />
+
+		<delete dir="${sample.dist.dir}" includeemptydirs="true" failonerror="false" />
+		<mkdir dir="${sample.dist.dir}" />
+	</target>
+
+	<!-- Just does the compile of sample src.  -->
+	<target name="compileServer" depends="init, clean">
+		<echo>-------------------------------------------</echo>
+		<echo>Compiling Server Side Sample - ${archiveName}</echo>
+		<echo>-------------------------------------------</echo>
+
+		<mkdir dir="${sample.server.build.dir}" />
+		<javac srcdir="${sample.server.src.dir}" destdir="${sample.server.build.dir}" debug="on">
+			<classpath refid="${samples.compile.classpathref}" />
+		</javac>
+	</target>
+
+	<target name="compile" description="Compiles all source code.">
+		<antcall target="compileServer">
+		</antcall>
+	</target>
+
+	<target name="distServer">
+		<war destfile="${sample.dist.dir}/${archiveName}_server.war" webxml="${sample.base.dir}/server/WEB-INF/web.xml">
+			<fileset dir="." includes="server/src/**" />
+			<classes dir="${sample.server.build.dir}" />
+			<lib refid="${samples.filesetref}" />
+			<lib refid="${samples.runtime.filesetref}" />
+			<zipfileset src="${sample.server.static.dir}/content.zip" />
+			<zipfileset dir="${sample.server.static.dir}">
+				<exclude name="*.zip" />
+			</zipfileset>
+		</war>
+	</target>
+
+	<target name="dist" description="Packages the sample for distribution.">
+		<antcall target="distServer">
+		</antcall>
+	</target>
+
+	<target name="all" depends="clean, compile, dist">
+	</target>
+
+	<!-- Magic -->
+	<condition property="samples.compile.classpathref" value="samples.compile.classpath.packaged" else="samples.compile.classpath.dist.runtime">
+		<isset property="sample.runtime.dir.exists" />
+	</condition>
+
+	<condition property="samples.filesetref" value="samples.classpath.packaged.fileset" else="samples.classpath.dist.fileset">
+		<isset property="sample.runtime.dir.exists" />
+	</condition>
+
+	<condition property="samples.runtime.filesetref" value="samples.runtime.packaged.fileset" else="samples.runtime.dist.fileset">
+		<isset property="sample.runtime.dir.exists" />
+	</condition>
+
+	<path id="samples.compile.classpath.packaged">
+		<!-- If this is a sample by itself, expect the JARs to be in a subdirectory. -->
+		<fileset refid="${samples.filesetref}" />
+		<fileset refid="${samples.runtime.filesetref}" />
+	</path>
+
+	<path id="samples.compile.classpath.dist.runtime">
+		<fileset refid="${samples.filesetref}" />
+		<fileset refid="${samples.runtime.filesetref}" />
+	</path>
+
+	<fileset dir="${sample.base.dir}/lib" id="samples.runtime.packaged.fileset">
+		<include name="ibmjaxrs*.jar" />
+	</fileset>
+
+	<fileset dir="${sample.base.dir}/../../build" id="samples.runtime.dist.fileset">
+		<include name="ibmjaxrs*.jar" />
+	</fileset>
+
+	<fileset dir="${sample.runtime.dir}/lib" id="samples.classpath.packaged.fileset">
+		<include name="asm-all-3.1.jar" />
+		<include name="serp-1.13.1.jar" />
+
+		<include name="commons-logging-1.1.1.jar" />
+
+		<include name="abdera-0.4.0-incubating.jar" />
+		<include name="abdera-core-0.4.0-incubating.jar" />
+		<include name="axiom-api-1.2.5.jar" />
+		<include name="axiom-impl-1.2.5.jar" />
+		<include name="commons-codec-1.3.jar" />
+		<include name="jaxen-1.1.1.jar" />
+		<include name="xmlbeans-2.3.0.jar" />
+
+		<include name="jsr311-api-0.11.jar" />
+	</fileset>
+
+	<fileset dir="${sample.base.dir}/../../lib" id="samples.classpath.dist.fileset">
+		<include name="asm-all-3.1.jar" />
+		<include name="serp-1.13.1.jar" />
+
+		<include name="commons-logging-1.1.1.jar" />
+
+		<include name="abdera-0.4.0-incubating.jar" />
+		<include name="abdera-core-0.4.0-incubating.jar" />
+		<include name="axiom-api-1.2.5.jar" />
+		<include name="axiom-impl-1.2.5.jar" />
+		<include name="commons-codec-1.3.jar" />
+		<include name="jaxen-1.1.1.jar" />
+		<include name="xmlbeans-2.3.0.jar" />
+
+		<include name="jsr311-api-0.11.jar" />
+	</fileset>
+
+	<target name="packageSampleOnly">
+		<mkdir dir="${sample.runtime.dir}/lib" />
+		<copy todir="${sample.runtime.dir}/lib">
+			<fileset refid="samples.classpath.dist.fileset">
+			</fileset>
+		</copy>
+	</target>
+</project>

Added: incubator/wink/contrib/ibm-jaxrs/samples/xml/server/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/samples/xml/server/WEB-INF/web.xml?rev=787552&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/samples/xml/server/WEB-INF/web.xml (added)
+++ incubator/wink/contrib/ibm-jaxrs/samples/xml/server/WEB-INF/web.xml Tue Jun 23 05:33:31 2009
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  ~ 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.
+  -->
+
+<web-app id="WebApp_ID" version="2.4"
+	xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+	<servlet>
+		<servlet-name>Phonebook</servlet-name>
+		<servlet-class> com.ibm.ws.jaxrs.web.RESTServlet </servlet-class>
+		<init-param>
+			<param-name>javax.ws.rs.Application</param-name>
+			<param-value>com.ibm.jaxrs.sample.phonebook.PhoneBookApplication</param-value>
+		</init-param>
+		<load-on-startup>1</load-on-startup>
+	</servlet>
+	<servlet-mapping>
+		<servlet-name>Phonebook</servlet-name>
+		<url-pattern>/phonebook/*</url-pattern>
+	</servlet-mapping>
+	<welcome-file-list>
+		<welcome-file>index.html</welcome-file>
+	</welcome-file-list>
+</web-app>
\ No newline at end of file

Added: incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/PhoneBookApplication.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/PhoneBookApplication.java?rev=787552&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/PhoneBookApplication.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/PhoneBookApplication.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;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.core.Application;
+
+
+/**
+ * The JAX-RS {@link Application} subclass which returns all the classes for the application.
+ */
+public class PhoneBookApplication extends Application {
+
+    @Override
+    public Set<Class<?>> getClasses() {
+        Set<Class<?>> classes = new HashSet<Class<?>>();
+        classes.add(com.ibm.jaxrs.sample.phonebook.inputstream.PhoneBookResource.class);
+        classes.add(com.ibm.jaxrs.sample.phonebook.reader.PhoneBookResource.class);
+        classes.add(com.ibm.jaxrs.sample.phonebook.streamingoutput.PhoneBookResource.class);
+        classes.add(com.ibm.jaxrs.sample.phonebook.string.PhoneBookResource.class);
+        classes.add(com.ibm.jaxrs.sample.phonebook.source.PhoneBookResource.class);
+        return classes;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/inputstream/PhoneBook.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/inputstream/PhoneBook.java?rev=787552&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/inputstream/PhoneBook.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/inputstream/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.inputstream;
+
+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/inputstream/PhoneBookResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/inputstream/PhoneBookResource.java?rev=787552&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/inputstream/PhoneBookResource.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/inputstream/PhoneBookResource.java Tue Jun 23 05:33:31 2009
@@ -0,0 +1,228 @@
+/*
+ * 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.inputstream;
+
+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 InputStream} version of the PhoneBook. Resource methods use
+ * InputStreams to receive requests and send responses.
+ */
+@Path("phonebook/inputstream")
+public class PhoneBookResource {
+
+    @Context
+    private UriInfo uriInfo;
+
+    /**
+     * Retrieves a directory list of names in the phone book. Returns the
+     * content via an InputStream.
+     * 
+     * @return an {@link InputStream} that contains a listing of all the entries
+     */
+    @GET
+    @Produces("text/xml")
+    public InputStream 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>");
+
+        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(sw.getBuffer()
+            .toString().getBytes());
+        return byteArrayInputStream;
+    }
+
+    /**
+     * 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
+         */
+        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());
+
+        return Response.created(new URI(uriInfo.getAbsolutePath() + "/" + id)).entity(
+            byteArrayInputStream).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 InputStream 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>");
+
+        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(sw.getBuffer()
+            .toString().getBytes());
+        return byteArrayInputStream;
+    }
+
+    /**
+     * 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 InputStream 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());
+
+        // DOMSource domSource = new DOMSource(doc);
+        // StreamResult streamResult = new StreamResult(out);
+        // TransformerFactory transformerFactory =
+        // TransformerFactory.newInstance();
+        // Transformer transformer = transformerFactory.newTransformer();
+        // transformer.transform(domSource, streamResult);
+
+        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());
+        return byteArrayInputStream;
+    }
+
+    /**
+     * 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/inputstream/PhoneEntry.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/inputstream/PhoneEntry.java?rev=787552&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/inputstream/PhoneEntry.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/inputstream/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.inputstream;
+
+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/reader/PhoneBook.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/reader/PhoneBook.java?rev=787552&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/reader/PhoneBook.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/reader/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.reader;
+
+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/reader/PhoneBookResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/reader/PhoneBookResource.java?rev=787552&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/reader/PhoneBookResource.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/reader/PhoneBookResource.java Tue Jun 23 05:33:31 2009
@@ -0,0 +1,212 @@
+/*
+ * 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.reader;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+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.InputSource;
+import org.xml.sax.SAXException;
+
+/**
+ * The {@link Reader} version of the PhoneBook. Resource methods use Readers to
+ * receive requests and send responses.
+ */
+@Path("phonebook/reader")
+public class PhoneBookResource {
+
+    @Context
+    private UriInfo uriInfo;
+
+    /**
+     * Retrieves a directory list of names in the phone book. Returns the
+     * content via an {@link Reader}.
+     * 
+     * @return an {@link Reader} that contains a listing of all the entries
+     */
+    @GET
+    @Produces("text/xml")
+    public Reader 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 StringReader(sw.toString());
+    }
+
+    /**
+     * Creates a new entry in the PhoneBook with a new ID. Receives the POST
+     * entity via an {@link Reader}.
+     * 
+     * @param requestReader the incoming entity via a Reader
+     * @return the newly created entity via a Reader
+     * @throws SAXException
+     * @throws IOException
+     * @throws ParserConfigurationException
+     * @throws URISyntaxException
+     */
+    @POST
+    public Response createEntry(Reader requestReader) throws SAXException, IOException,
+        ParserConfigurationException, URISyntaxException {
+        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(
+            new InputSource(requestReader));
+
+        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>");
+        return Response.created(new URI(uriInfo.getAbsolutePath() + "/" + id)).entity(
+            new StringReader(sw.toString())).type(MediaType.TEXT_XML_TYPE).build();
+    }
+
+    /**
+     * Retrieves an individual phone book entry. Returns the content via a
+     * Reader.
+     * 
+     * @return an {@link Reader} that contains a listing of all the entries
+     */
+    @GET
+    @Path("{id}")
+    @Produces("text/xml")
+    public Reader 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 new StringReader(sw.toString());
+    }
+
+    /**
+     * Updates an entry in the PhoneBook. Retrieves the entity via a Reader and
+     * returns the updated entity via a Reader.
+     * 
+     * @param requestReader the incoming entity via a Reader
+     * @return the updated data via a Reader
+     * @throws SAXException
+     * @throws IOException
+     * @throws ParserConfigurationException
+     * @throws URISyntaxException
+     */
+    @PUT
+    @Path("{id}")
+    @Produces("text/xml")
+    public Reader updateEntry(Reader requestReader, @PathParam("id") Integer id)
+        throws SAXException, IOException, ParserConfigurationException, URISyntaxException {
+        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(
+            new InputSource(requestReader));
+
+        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 new StringReader(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/reader/PhoneEntry.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/reader/PhoneEntry.java?rev=787552&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/reader/PhoneEntry.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/reader/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.reader;
+
+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/source/PhoneBook.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/source/PhoneBook.java?rev=787552&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/source/PhoneBook.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/samples/xml/server/src/com/ibm/jaxrs/sample/phonebook/source/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.source;
+
+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;
+    }
+}



Mime
View raw message