incubator-wink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ngalla...@apache.org
Subject svn commit: r787553 [30/34] - in /incubator/wink/contrib/ibm-jaxrs/tests: ./ fvt/ fvt/demo/ fvt/demo/jaxrs/ fvt/demo/jaxrs/cache/ fvt/demo/jaxrs/cache/server/ fvt/demo/jaxrs/cache/test/ fvt/demo/jaxrs/datasource/ fvt/demo/jaxrs/datasource/server/ fvt/d...
Date Tue, 23 Jun 2009 05:38:19 GMT
Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/dd/PhoneBookTests.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/dd/PhoneBookTests.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/dd/PhoneBookTests.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/dd/PhoneBookTests.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,330 @@
+/*
+ * 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.ws.jaxrs.sample.dd;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.util.Iterator;
+
+import javax.servlet.ServletException;
+import javax.ws.rs.HttpMethod;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.namespace.QName;
+import javax.xml.transform.stream.StreamSource;
+
+import com.ibm.rest.test.utils.TestUtils;
+import com.ibm.ws.jaxrs.web.RESTServlet;
+import com.ibm.ws.jaxrs.web.ServletTestFramework;
+import com.ibm.ws.jaxrs.web.mock.ServletRequest;
+import com.ibm.ws.jaxrs.web.mock.ServletResponse;
+
+public class PhoneBookTests extends ServletTestFramework {
+
+    private static String configFileLoc;
+    static {
+        try {
+            configFileLoc = TestUtils.getTestResourceDirPath()
+                    + "/phonebook/ibm-jaxrs.xml";
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail(e.toString());
+        }
+    }
+
+    public void testSimplePostAndGet() throws Exception {
+        PhoneBook.clear();
+        RESTServlet servlet = createServlet(null, configFileLoc);
+
+        // first let's create an entry in our phone book
+        PhoneBookEntryBean bean = new PhoneBookEntryBean();
+        bean.setFirstName("Alexander");
+        bean.setLastName("Hamilton");
+        bean.setPhoneNumber("5125550001");
+        JAXBElement<PhoneBookEntryBean> element = new JAXBElement<PhoneBookEntryBean>(
+                new QName("http://com.ibm.ws.jaxrs.sample.dd", "entry"),
+                PhoneBookEntryBean.class, bean);
+        JAXBContext context = JAXBContext.newInstance(PhoneBookBean.class,
+                PhoneBookEntryBean.class);
+        Marshaller m = context.createMarshaller();
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        m.marshal(element, baos);
+        byte[] bytes = baos.toByteArray();
+        InputStream is = new ByteArrayInputStream(bytes);
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                "/phonebook", null, HttpMethod.POST, is);
+        request.setAttribute(ServletRequest.CONTENT_TYPE, "application/xml");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+        try {
+            servlet.doPost(request, response);
+        } catch (ServletException e) {
+            e.printStackTrace();
+            fail(e.toString());
+        }
+
+        // now let's retrieve the entry we just created
+        request = ServletTestFramework.createServletRequest(
+                "/phonebook/phoneNumber/5125550001", HttpMethod.GET);
+        StringWriter sw = new StringWriter();
+        response = ServletTestFramework.createServletResponse(sw);
+
+        try {
+            servlet.doGet(request, response);
+            Unmarshaller u = context.createUnmarshaller();
+            JAXBElement<PhoneBookEntryBean> entryElement = u
+                    .unmarshal(new StreamSource(new ByteArrayInputStream(sw
+                            .toString().getBytes())), PhoneBookEntryBean.class);
+            assertNotNull(entryElement);
+            PhoneBookEntryBean entry = entryElement.getValue();
+            assertEquals("Alexander", entry.getFirstName());
+            assertEquals("Hamilton", entry.getLastName());
+            assertEquals("5125550001", entry.getPhoneNumber());
+        } catch (ServletException e) {
+            e.printStackTrace();
+            fail(e.toString());
+        }
+
+    }
+
+    public void testPostAndGetAll() throws Exception {
+        PhoneBook.clear();
+        RESTServlet servlet = createServlet(null, configFileLoc);
+
+        // create two entries in our phone book
+        PhoneBookEntryBean bean = new PhoneBookEntryBean();
+        bean.setFirstName("Alexander");
+        bean.setLastName("Hamilton");
+        bean.setPhoneNumber("5125550001");
+        JAXBElement<PhoneBookEntryBean> element = new JAXBElement<PhoneBookEntryBean>(
+                new QName("http://com.ibm.ws.jaxrs.sample.dd", "entry"),
+                PhoneBookEntryBean.class, bean);
+        JAXBContext context = JAXBContext.newInstance(PhoneBookBean.class,
+                PhoneBookEntryBean.class);
+        Marshaller m = context.createMarshaller();
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        m.marshal(element, baos);
+        byte[] bytes = baos.toByteArray();
+        InputStream is = new ByteArrayInputStream(bytes);
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                "/phonebook", null, HttpMethod.POST, is);
+        request.setAttribute(ServletRequest.CONTENT_TYPE, "application/xml");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+        try {
+            servlet.doPost(request, response);
+        } catch (ServletException e) {
+            e.printStackTrace();
+            fail(e.toString());
+        }
+
+        bean = new PhoneBookEntryBean();
+        bean.setFirstName("Benjamin");
+        bean.setLastName("Rush");
+        bean.setPhoneNumber("5125550002");
+        element = new JAXBElement<PhoneBookEntryBean>(new QName(
+                "http://com.ibm.ws.jaxrs.sample.dd", "entry"),
+                PhoneBookEntryBean.class, bean);
+        context = JAXBContext.newInstance(PhoneBookBean.class,
+                PhoneBookEntryBean.class);
+        m = context.createMarshaller();
+        baos = new ByteArrayOutputStream();
+        m.marshal(element, baos);
+        is = new ByteArrayInputStream(baos.toByteArray());
+        request = ServletTestFramework.createServletRequest("/phonebook", null,
+                HttpMethod.POST, is);
+        request.setAttribute(ServletRequest.CONTENT_TYPE, "application/xml");
+        response = ServletTestFramework.createServletResponse();
+        try {
+            servlet.doPost(request, response);
+        } catch (ServletException e) {
+            e.printStackTrace();
+            fail(e.toString());
+        }
+
+        // now let's get all the entries and ensure we have both
+        request = ServletTestFramework.createServletRequest("/phonebook",
+                HttpMethod.GET);
+        StringWriter sw = new StringWriter();
+        response = ServletTestFramework.createServletResponse(sw);
+
+        try {
+            servlet.doGet(request, response);
+            Unmarshaller u = context.createUnmarshaller();
+            PhoneBookBean phoneBook = (PhoneBookBean) u
+                    .unmarshal(new ByteArrayInputStream(sw.toString()
+                            .getBytes()));
+            assertNotNull(phoneBook);
+            assertEquals(2, phoneBook.getEntries().size());
+            Iterator<PhoneBookEntryBean> iter = phoneBook.getEntries()
+                    .iterator();
+            while (iter.hasNext()) {
+                PhoneBookEntryBean entryBean = iter.next();
+                if (entryBean.getPhoneNumber().equals("5125550001")) {
+                    assertEquals("Alexander", entryBean.getFirstName());
+                    assertEquals("Hamilton", entryBean.getLastName());
+                } else if (entryBean.getPhoneNumber().equals("5125550002")) {
+                    assertEquals("Benjamin", entryBean.getFirstName());
+                    assertEquals("Rush", entryBean.getLastName());
+                } else {
+                    fail("Unknown telephone number returned: "
+                            + entryBean.getPhoneNumber());
+                }
+            }
+        } catch (ServletException e) {
+            e.printStackTrace();
+            fail(e.toString());
+        }
+    }
+
+    public void testPostAndUpdate() throws Exception {
+        PhoneBook.clear();
+        RESTServlet servlet = createServlet(null, configFileLoc);
+
+        // create an entry in our phone book
+        PhoneBookEntryBean bean = new PhoneBookEntryBean();
+        bean.setFirstName("Alexander");
+        bean.setLastName("Hamilton");
+        bean.setPhoneNumber("5125550001");
+        JAXBElement<PhoneBookEntryBean> element = new JAXBElement<PhoneBookEntryBean>(
+                new QName("http://com.ibm.ws.jaxrs.sample.dd", "entry"),
+                PhoneBookEntryBean.class, bean);
+        JAXBContext context = JAXBContext.newInstance(PhoneBookBean.class,
+                PhoneBookEntryBean.class);
+        Marshaller m = context.createMarshaller();
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        m.marshal(element, baos);
+        byte[] bytes = baos.toByteArray();
+        InputStream is = new ByteArrayInputStream(bytes);
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                "/phonebook", null, HttpMethod.POST, is);
+        request.setAttribute(ServletRequest.CONTENT_TYPE, "application/xml");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+        try {
+            servlet.doPost(request, response);
+        } catch (ServletException e) {
+            e.printStackTrace();
+            fail(e.toString());
+        }
+
+        bean = new PhoneBookEntryBean();
+        bean.setFirstName("Alexander");
+        bean.setLastName("Bell");
+        bean.setPhoneNumber("5125550001");
+        element = new JAXBElement<PhoneBookEntryBean>(new QName(
+                "http://com.ibm.ws.jaxrs.sample.dd", "entry"),
+                PhoneBookEntryBean.class, bean);
+        context = JAXBContext.newInstance(PhoneBookBean.class,
+                PhoneBookEntryBean.class);
+        m = context.createMarshaller();
+        baos = new ByteArrayOutputStream();
+        m.marshal(element, baos);
+        is = new ByteArrayInputStream(baos.toByteArray());
+        request = ServletTestFramework.createServletRequest("/phonebook", null,
+                HttpMethod.PUT, is);
+        request.setAttribute(ServletRequest.CONTENT_TYPE, "application/xml");
+        response = ServletTestFramework.createServletResponse();
+        try {
+            servlet.doPut(request, response);
+        } catch (ServletException e) {
+            e.printStackTrace();
+            fail(e.toString());
+        }
+
+        // now let's retrieve the entry we just updated
+        request = ServletTestFramework.createServletRequest(
+                "/phonebook/phoneNumber/5125550001", HttpMethod.GET);
+        StringWriter sw = new StringWriter();
+        response = ServletTestFramework.createServletResponse(sw);
+
+        try {
+            servlet.doGet(request, response);
+            Unmarshaller u = context.createUnmarshaller();
+            JAXBElement<PhoneBookEntryBean> entryElement = u
+                    .unmarshal(new StreamSource(new ByteArrayInputStream(sw
+                            .toString().getBytes())), PhoneBookEntryBean.class);
+            assertNotNull(entryElement);
+            PhoneBookEntryBean entry = entryElement.getValue();
+            assertEquals("Alexander", entry.getFirstName());
+            assertEquals("Bell", entry.getLastName());
+            assertEquals("5125550001", entry.getPhoneNumber());
+        } catch (ServletException e) {
+            e.printStackTrace();
+            fail(e.toString());
+        }
+    }
+
+    public void testPostAndDelete() throws Exception {
+        PhoneBook.clear();
+        RESTServlet servlet = createServlet(null, configFileLoc);
+
+        // create an entry in our phone book
+        PhoneBookEntryBean bean = new PhoneBookEntryBean();
+        bean.setFirstName("Alexander");
+        bean.setLastName("Hamilton");
+        bean.setPhoneNumber("5125550001");
+        JAXBElement<PhoneBookEntryBean> element = new JAXBElement<PhoneBookEntryBean>(
+                new QName("http://com.ibm.ws.jaxrs.sample.dd", "entry"),
+                PhoneBookEntryBean.class, bean);
+        JAXBContext context = JAXBContext.newInstance(PhoneBookBean.class,
+                PhoneBookEntryBean.class);
+        Marshaller m = context.createMarshaller();
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        m.marshal(element, baos);
+        byte[] bytes = baos.toByteArray();
+        InputStream is = new ByteArrayInputStream(bytes);
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                "/phonebook", null, HttpMethod.POST, is);
+        request.setAttribute(ServletRequest.CONTENT_TYPE, "application/xml");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+        try {
+            servlet.doPost(request, response);
+        } catch (ServletException e) {
+            e.printStackTrace();
+            fail(e.toString());
+        }
+
+        // now let's delete the entry we just created
+        request = ServletTestFramework.createServletRequest(
+                "/phonebook/phoneNumber/5125550001", HttpMethod.DELETE);
+        StringWriter sw = new StringWriter();
+        response = ServletTestFramework.createServletResponse(sw);
+
+        try {
+            servlet.doDelete(request, response);
+        } catch (ServletException e) {
+            e.printStackTrace();
+            fail(e.toString());
+        }
+
+        // now make sure we do not have any entries
+        try {
+            servlet.doGet(request, response);
+            assertEquals("", sw.toString());
+        } catch (ServletException e) {
+            e.printStackTrace();
+            fail(e.toString());
+        }
+
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/encodedecode/EncodeDecodeResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/encodedecode/EncodeDecodeResource.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/encodedecode/EncodeDecodeResource.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/encodedecode/EncodeDecodeResource.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,98 @@
+/*
+ * 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.ws.jaxrs.sample.encodedecode;
+
+import javax.ws.rs.Encoded;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.GET;
+import javax.ws.rs.MatrixParam;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Response;
+
+@Path(value = "/encode/decode")
+public class EncodeDecodeResource {
+
+    @GET
+    @Path(value = "/qpencoded")
+    public Response getQueryParamEncoded(@Encoded @QueryParam(value = "name") String name) {
+        Response response = Response.ok().build();
+        response.getMetadata().putSingle("encodeDecodeHeader", name);
+        return response;
+    }
+
+    @GET
+    @Path(value = "/qpdecoded")
+    public Response getQueryParamDecoded(@QueryParam(value = "name") String name) {
+        Response response = Response.ok().build();
+        response.getMetadata().putSingle("encodeDecodeHeader", name);
+        return response;
+    }
+
+    @GET
+    @Path(value = "/fpencoded")
+    public Response getFormParamEncoded(@Encoded @FormParam(value = "name") String name) {
+        Response response = Response.ok().build();
+        response.getMetadata().putSingle("encodeDecodeHeader", name);
+        return response;
+    }
+
+    @GET
+    @Path(value = "/fpdecoded")
+    public Response getFormParamDecoded(@FormParam(value = "name") String name) {
+        Response response = Response.ok().build();
+        response.getMetadata().putSingle("encodeDecodeHeader", name);
+        return response;
+    }
+
+    @GET
+    @Path(value = "/mpencoded")
+    public Response getMatrixParamEncoded(@Encoded @MatrixParam(value = "name") String name) {
+        Response response = Response.ok().build();
+        response.getMetadata().putSingle("encodeDecodeHeader", name);
+        return response;
+    }
+
+    @GET
+    @Path(value = "/mpdecoded")
+    public Response getMatrixParamDecoded(@MatrixParam(value = "name") String name) {
+        Response response = Response.ok().build();
+        response.getMetadata().putSingle("encodeDecodeHeader", name);
+        return response;
+    }
+
+    @GET
+    @Path(value = "/ppencoded/{name}")
+    public Response getPathParamEncoded(@Encoded @PathParam(value = "name") String name) {
+        Response response = Response.ok().build();
+        response.getMetadata().putSingle("encodeDecodeHeader", name);
+        return response;
+    }
+
+    @GET
+    @Path(value = "/ppdecoded/{name}")
+    public Response getPathParamDecoded(@PathParam(value = "name") String name) {
+        Response response = Response.ok().build();
+        response.getMetadata().putSingle("encodeDecodeHeader", name);
+        return response;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/encodedecode/EncodingApplication.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/encodedecode/EncodingApplication.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/encodedecode/EncodingApplication.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/encodedecode/EncodingApplication.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,35 @@
+/*
+ * 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.ws.jaxrs.sample.encodedecode;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.core.Application;
+
+public class EncodingApplication extends Application {
+
+    public Set<Class<?>> getClasses() {
+        Set<Class<?>> set = new HashSet<Class<?>>();
+        set.add(EncodeDecodeResource.class);
+        return set;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/encodedecode/EncodingTests.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/encodedecode/EncodingTests.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/encodedecode/EncodingTests.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/encodedecode/EncodingTests.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,279 @@
+/*
+ * 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.ws.jaxrs.sample.encodedecode;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import com.ibm.ws.jaxrs.web.RESTServlet;
+import com.ibm.ws.jaxrs.web.ServletTestFramework;
+import com.ibm.ws.jaxrs.web.mock.ServletRequest;
+import com.ibm.ws.jaxrs.web.mock.ServletResponse;
+
+/**
+ * These tests will verify certain aspects of our decoding/encoding
+ * support in the runtime.
+ *
+ */
+public class EncodingTests extends ServletTestFramework {
+
+    private static final String URI_ROOT_RESOURCE = "/encode/decode";
+
+    /**
+     * Test the ability to receive an encoded query param value via injection
+     *
+     * INPUT: none
+     * OUTPUT: injected value in response header
+     */
+    public void testGetQueryParamEncoded() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.encodedecode.EncodingApplication");
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE + "/qpencoded", "GET");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            request.setAttribute(ServletRequest.QUERY_STRING,
+                    "name=James%20Bond");
+            servlet.doGet(request, response);
+            assertTrue(
+                    "Response did not contain expected 'encodeDecodeHeader' header",
+                    response.containsHeader("encodeDecodeHeader"));
+            String value = response.getHeader("encodeDecodeHeader");
+            assertNotNull(value);
+            assertEquals("James%20Bond", value);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * Test the ability to receive a decoded query param value via injection
+     *
+     * INPUT: none
+     * OUTPUT: injected value in response header
+     */
+    public void testGetQueryParamDecoded() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.encodedecode.EncodingApplication");
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE + "/qpdecoded", "GET");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            request.setAttribute(ServletRequest.QUERY_STRING,
+                    "name=James%20Bond");
+            servlet.doGet(request, response);
+            assertTrue(
+                    "Response did not contain expected 'encodeDecodeHeader' header",
+                    response.containsHeader("encodeDecodeHeader"));
+            String value = response.getHeader("encodeDecodeHeader");
+            assertNotNull(value);
+            assertEquals("James Bond", value);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * Test the ability to receive an encoded form param value via injection
+     *
+     * INPUT: none
+     * OUTPUT: injected value in response header
+     */
+    public void testGetFormParamEncoded() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.encodedecode.EncodingApplication");
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE + "/fpencoded", "GET");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            List<String> formValues = new LinkedList<String>();
+            formValues.add("James%20Bond");
+            Map<String, List<String>> formMap = new HashMap<String, List<String>>();
+            formMap.put("name", formValues);
+            request.setAttribute(ServletRequest.FORM_PARAMS, formMap);
+            servlet.doGet(request, response);
+            assertTrue(
+                    "Response did not contain expected 'encodeDecodeHeader' header",
+                    response.containsHeader("encodeDecodeHeader"));
+            String value = response.getHeader("encodeDecodeHeader");
+            assertNotNull(value);
+            assertEquals("James%20Bond", value);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * Test the ability to receive a decoded form param value via injection
+     *
+     * INPUT: none
+     * OUTPUT: injected value in response header
+     */
+    public void testGetFormParamDecoded() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.encodedecode.EncodingApplication");
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE + "/fpdecoded", "GET");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            List<String> formValues = new LinkedList<String>();
+            formValues.add("James%20Bond");
+            Map<String, List<String>> formMap = new HashMap<String, List<String>>();
+            formMap.put("name", formValues);
+            request.setAttribute(ServletRequest.FORM_PARAMS, formMap);
+            servlet.doGet(request, response);
+            assertTrue(
+                    "Response did not contain expected 'encodeDecodeHeader' header",
+                    response.containsHeader("encodeDecodeHeader"));
+            String value = response.getHeader("encodeDecodeHeader");
+            assertNotNull(value);
+            assertEquals("James Bond", value);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * Test the ability to receive an encoded matrix param value via injection
+     *
+     * INPUT: none
+     * OUTPUT: injected value in response header
+     */
+    public void testGetMatrixParamEncoded() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.encodedecode.EncodingApplication");
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE + "/mpencoded;name=James%20Bond", "GET");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doGet(request, response);
+            assertTrue(
+                    "Response did not contain expected 'encodeDecodeHeader' header",
+                    response.containsHeader("encodeDecodeHeader"));
+            String value = response.getHeader("encodeDecodeHeader");
+            assertNotNull(value);
+            assertEquals("James%20Bond", value);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * Test the ability to receive a decoded matrix param value via injection
+     *
+     * INPUT: none
+     * OUTPUT: injected value in response header
+     */
+    public void testGetMatrixParamDecoded() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.encodedecode.EncodingApplication");
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE + "/mpdecoded;name=James%20Bond", "GET");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doGet(request, response);
+            assertTrue(
+                    "Response did not contain expected 'encodeDecodeHeader' header",
+                    response.containsHeader("encodeDecodeHeader"));
+            String value = response.getHeader("encodeDecodeHeader");
+            assertNotNull(value);
+            assertEquals("James Bond", value);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * Test the ability to receive an encoded path param value via injection
+     *
+     * INPUT: none
+     * OUTPUT: injected value in response header
+     */
+    public void testGetPathParamEncoded() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.encodedecode.EncodingApplication");
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE + "/ppencoded/James%20Bond", "GET");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doGet(request, response);
+            assertTrue(
+                    "Response did not contain expected 'encodeDecodeHeader' header",
+                    response.containsHeader("encodeDecodeHeader"));
+            String value = response.getHeader("encodeDecodeHeader");
+            assertNotNull(value);
+            assertEquals("James%20Bond", value);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * Test the ability to receive a decoded path param value via injection
+     *
+     * INPUT: none
+     * OUTPUT: injected value in response header
+     */
+    public void testGetPathParamDecoded() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.encodedecode.EncodingApplication");
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE + "/ppdecoded/James%20Bond", "GET");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doGet(request, response);
+            assertTrue(
+                    "Response did not contain expected 'encodeDecodeHeader' header",
+                    response.containsHeader("encodeDecodeHeader"));
+            String value = response.getHeader("encodeDecodeHeader");
+            assertNotNull(value);
+            assertEquals("James Bond", value);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/CustomMapper.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/CustomMapper.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/CustomMapper.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/CustomMapper.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,33 @@
+/*
+ * 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.ws.jaxrs.sample.exception.eps;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Provider;
+
+@Provider
+public class CustomMapper implements ExceptionMapper<Malfunction> {
+
+    public Response toResponse(Malfunction arg0) {
+        return Response.status(430).entity("BLAH!").build();
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/CustomReader.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/CustomReader.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/CustomReader.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/CustomReader.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,47 @@
+/*
+ * 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.ws.jaxrs.sample.exception.eps;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.Provider;
+
+@Provider
+@Produces(value = "application/exception")
+public class CustomReader implements MessageBodyReader<MalfunctionBean> {
+
+    public boolean isReadable(Class<?> arg0, Type arg1, Annotation[] arg2, MediaType arg3) {
+        return true;
+    }
+
+    public MalfunctionBean readFrom(Class<MalfunctionBean> arg0, Type arg1, Annotation[] arg2, MediaType arg3, MultivaluedMap<String, String> arg4, InputStream arg5)
+            throws IOException, WebApplicationException {
+        throw new Malfunction(null);
+    }
+
+}
\ No newline at end of file

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/CustomWriter.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/CustomWriter.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/CustomWriter.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/CustomWriter.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,61 @@
+/*
+ * 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.ws.jaxrs.sample.exception.eps;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.ws.rs.POST;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+
+@Provider
+@Produces(value = "application/exception")
+public class CustomWriter implements MessageBodyWriter<Object> {
+
+    public long getSize(Object arg0, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4) {
+        return 0;
+    }
+
+    public boolean isWriteable(Class<?> arg0, Type arg1, Annotation[] arg2, MediaType arg3) {
+        return true;
+    }
+
+    public void writeTo(Object arg0, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4, MultivaluedMap<String, Object> arg5, OutputStream arg6)
+            throws IOException, WebApplicationException {
+        boolean post = false;
+        for (Annotation annotation : arg3) {
+            if (annotation.annotationType().equals(POST.class)) {
+                post = true;
+                break;
+            }
+        }
+        if (!post) {
+            throw new Malfunction(null);
+        }
+    }
+
+}
\ No newline at end of file

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/ExceptionTests.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/ExceptionTests.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/ExceptionTests.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/ExceptionTests.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,106 @@
+/*
+ * 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.ws.jaxrs.sample.exception.eps;
+
+import java.io.ByteArrayInputStream;
+
+import javax.ws.rs.HttpMethod;
+
+import com.ibm.ws.jaxrs.web.RESTServlet;
+import com.ibm.ws.jaxrs.web.ServletTestFramework;
+import com.ibm.ws.jaxrs.web.mock.ServletRequest;
+import com.ibm.ws.jaxrs.web.mock.ServletResponse;
+
+public class ExceptionTests extends ServletTestFramework {
+
+    // Ensure infinite loop does not occur when serialization of response
+    // results in error
+    public void testInfiniteLoop() throws Exception {
+        RESTServlet servlet = createServlet(MalfunctionApplicationWriterInfiniteLoop.class
+                .getName());
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                "/malfunction/runtime", HttpMethod.GET);
+        ServletResponse response = ServletTestFramework.createServletResponse();
+        try {
+            servlet.doGet(request, response);
+            assertEquals(500, response.getStatus());
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    // Ensure MessageBodyReaders can throw exceptions and return status
+    public void testReaderException() throws Exception {
+        RESTServlet servlet = createServlet(MalfunctionApplicationReaderException.class
+                .getName());
+        MalfunctionBean bean = new MalfunctionBean();
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                "/malfunction", null, HttpMethod.POST,
+                new ByteArrayInputStream(bean.toString().getBytes()));
+        ServletResponse response = ServletTestFramework.createServletResponse();
+        try {
+            servlet.doPost(request, response);
+            assertEquals(430, response.getStatus());
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    // Test the case where no MessageBodyReader can be found for a request
+    public void testNoReader() throws Exception {
+        RESTServlet servlet = createServlet(MalfunctionApplicationNoReader.class
+                .getName());
+        MalfunctionBean bean = new MalfunctionBean();
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                "/malfunction", null, HttpMethod.POST,
+                new ByteArrayInputStream(bean.toString().getBytes()));
+        ServletResponse response = ServletTestFramework.createServletResponse();
+        try {
+            servlet.doPost(request, response);
+            assertEquals(415, response.getStatus());
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    // Test the case when no MessageBodyWriter is available to write the response
+    public void testWriterException() throws Exception {
+        RESTServlet servlet = createServlet(MalfunctionApplicationWriterException.class
+                .getName());
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                "/malfunction/bean", HttpMethod.GET);
+        ServletResponse response = ServletTestFramework.createServletResponse();
+        try {
+            servlet.doGet(request, response);
+            assertEquals(500, response.getStatus());
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/Malfunction.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/Malfunction.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/Malfunction.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/Malfunction.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,31 @@
+/*
+ * 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.ws.jaxrs.sample.exception.eps;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+
+public class Malfunction extends WebApplicationException {
+
+    public Malfunction(Response response) {
+        super(response);
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/MalfunctionApplicationNoReader.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/MalfunctionApplicationNoReader.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/MalfunctionApplicationNoReader.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/MalfunctionApplicationNoReader.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,38 @@
+/*
+ * 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.ws.jaxrs.sample.exception.eps;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.core.Application;
+
+public class MalfunctionApplicationNoReader extends Application {
+
+    @Override
+    public Set<Class<?>> getClasses() {
+        Set<Class<?>> classes = new HashSet<Class<?>>();
+        classes.add(MalfunctionResource.class);
+        classes.add(CustomWriter.class);
+        classes.add(CustomMapper.class);
+        return classes;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/MalfunctionApplicationReaderException.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/MalfunctionApplicationReaderException.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/MalfunctionApplicationReaderException.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/MalfunctionApplicationReaderException.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,39 @@
+/*
+ * 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.ws.jaxrs.sample.exception.eps;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.core.Application;
+
+public class MalfunctionApplicationReaderException extends Application {
+
+    @Override
+    public Set<Class<?>> getClasses() {
+        Set<Class<?>> classes = new HashSet<Class<?>>();
+        classes.add(MalfunctionResource.class);
+        classes.add(CustomWriter.class);
+        classes.add(CustomMapper.class);
+        classes.add(CustomReader.class);
+        return classes;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/MalfunctionApplicationWriterException.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/MalfunctionApplicationWriterException.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/MalfunctionApplicationWriterException.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/MalfunctionApplicationWriterException.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,37 @@
+/*
+ * 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.ws.jaxrs.sample.exception.eps;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.core.Application;
+
+public class MalfunctionApplicationWriterException  extends Application {
+
+    @Override
+    public Set<Class<?>> getClasses() {
+        Set<Class<?>> classes = new HashSet<Class<?>>();
+        classes.add(MalfunctionResource.class);
+        classes.add(CustomMapper.class);
+        classes.add(CustomReader.class);
+        return classes;
+    }
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/MalfunctionApplicationWriterInfiniteLoop.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/MalfunctionApplicationWriterInfiniteLoop.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/MalfunctionApplicationWriterInfiniteLoop.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/MalfunctionApplicationWriterInfiniteLoop.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,38 @@
+/*
+ * 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.ws.jaxrs.sample.exception.eps;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.core.Application;
+
+public class MalfunctionApplicationWriterInfiniteLoop extends Application {
+
+    @Override
+    public Set<Class<?>> getClasses() {
+        Set<Class<?>> classes = new HashSet<Class<?>>();
+        classes.add(MalfunctionResource.class);
+        classes.add(CustomMapper.class);
+        classes.add(CustomWriter.class);
+        return classes;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/MalfunctionBean.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/MalfunctionBean.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/MalfunctionBean.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/MalfunctionBean.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,24 @@
+/*
+ * 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.ws.jaxrs.sample.exception.eps;
+
+public class MalfunctionBean {
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/MalfunctionResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/MalfunctionResource.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/MalfunctionResource.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/exception/eps/MalfunctionResource.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,46 @@
+/*
+ * 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.ws.jaxrs.sample.exception.eps;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+
+@Path(value = "/malfunction")
+public class MalfunctionResource {
+
+    @GET
+    @Path(value = "/runtime")
+    public String get() {
+        return "BLAH!";
+    }
+
+    @POST
+    public void post(MalfunctionBean bean) {
+
+    }
+
+    @GET
+    @Path(value = "/bean")
+    public MalfunctionBean getBean() {
+        return new MalfunctionBean();
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/faults/FaultTests.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/faults/FaultTests.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/faults/FaultTests.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/faults/FaultTests.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,250 @@
+/*
+ * 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.ws.jaxrs.sample.faults;
+
+import java.io.StringWriter;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.HttpMethod;
+import javax.ws.rs.core.Application;
+
+import org.apache.cxf.jaxrs.provider.ProviderFactory;
+
+import com.ibm.ws.jaxrs.context.ContextConstants;
+import com.ibm.ws.jaxrs.context.RESTContext;
+import com.ibm.ws.jaxrs.context.RESTContextFactory;
+import com.ibm.ws.jaxrs.metadata.RESTMetaData;
+import com.ibm.ws.jaxrs.model.ApplicationProcessor;
+import com.ibm.ws.jaxrs.model.JAXRSInfoOutput;
+import com.ibm.ws.jaxrs.sample.customcontent.CarsTests.CarStringProvider;
+import com.ibm.ws.jaxrs.web.RESTServlet;
+import com.ibm.ws.jaxrs.web.ServletTestFramework;
+import com.ibm.ws.jaxrs.web.mock.ServletOutputStream;
+import com.ibm.ws.jaxrs.web.mock.ServletRequest;
+import com.ibm.ws.jaxrs.web.mock.ServletResponse;
+
+/**
+ * A suite of tests for fault processing in JAX-RS resources.  This
+ * tests standard types (RuntimeException, WebApplicationException)
+ * along with user generated exceptions and ExceptionMappingProviders.
+ *
+ */
+public class FaultTests extends ServletTestFramework {
+
+    private static final String URI_ROOT_RESOURCE = "/roster";
+
+    /**
+     * Tests error processing when the resource throws a RuntimeException
+     *
+     * - The exception should flow back from the resource through the servlet
+     * - A ServletException should be thrown to let the container handle it
+     * - No status code should be returned for this test (the container will
+     *   handle that)
+     *
+     * @throws Exception
+     */
+    public void testRuntimeException() throws Exception {
+        RESTServlet servlet = createServlet(RosterApplication.class.getName());
+
+        // Path to the invalid resource
+        String path = URI_ROOT_RESOURCE + "/runtimeException";
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                path, HttpMethod.GET);
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        // Do the invocation
+        Throwable error = null;
+        try {
+            servlet.doPost(request, response);
+        } catch (Throwable t) {
+            error = t;
+        }
+
+        // Make sure the servlet throws an exception
+        assertTrue("An exception should have been thrown.", error != null);
+        assertTrue("A javax.servlet.ServletException was expected.",
+                ServletException.class.isAssignableFrom(error.getClass()));
+    }
+
+    /**
+     * Tests error processing when a simple WebApplicationException is thrown
+     *
+     * - The application sets the response code
+     * - No content is provided
+     * - Should flow back like a normal Response
+     *
+     * @throws Exception
+     */
+    public void testWebApplicationException() throws Exception {
+        RESTServlet servlet = createServlet(RosterApplication.class.getName());
+
+        // Path to the invalid resource
+        String path = URI_ROOT_RESOURCE + "/webApplicationException";
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                path, HttpMethod.GET);
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        // Do the invocation
+        Throwable error = null;
+        try {
+            servlet.doPost(request, response);
+        } catch (Throwable t) {
+            error = t;
+            fail("An exception [" + error.getClass()
+                    + "] should NOT have been thrown.  "
+                    + "A response should be returned.");
+        }
+
+        // Check the status code
+        int status = response.getStatus();
+        assertTrue("The response status code [" + status
+                + "] did not match expected value ["
+                + HttpServletResponse.SC_INTERNAL_SERVER_ERROR + "]",
+                status == HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+    }
+
+    /**
+     * Test error processing when the WebApplicationException is created using a
+     * Response object.
+     *
+     * - Content should be extracted from the Response
+     * - The status code is set by the application
+     * - Should flow back like a normal Response
+     *
+     * @throws Exception
+     */
+    public void testFaultFromResponse() throws Exception {
+        RESTServlet servlet = createServlet(RosterApplication.class.getName());
+
+        // Path to the invalid resource
+        String path = URI_ROOT_RESOURCE + "/usingResponse";
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                path, HttpMethod.GET);
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        // Do the invocation
+        Throwable error = null;
+        try {
+            servlet.doPost(request, response);
+        } catch (Throwable t) {
+            error = t;
+            fail("An exception [" + error.getClass()
+                    + "] should NOT have been thrown.  "
+                    + "A response should be returned.");
+        }
+
+        assertTrue("An exception should NOT have been thrown.", error == null);
+
+        // Check the status code
+        int status = response.getStatus();
+        assertTrue("The response status code was incorrect.",
+                status == HttpServletResponse.SC_NOT_FOUND);
+
+        // Check the content
+        ServletOutputStream os = (ServletOutputStream) response
+                .getOutputStream();
+        assertTrue("The ServletOutputStream was null.", os != null);
+
+        StringWriter sw = os.getWriter();
+        String content = sw.toString();
+        assertTrue("The content was null.", content != null);
+        assertTrue("The content did not match expected value.  [" + content
+                + "]", content.equals("<error>simple server fault</error>"));
+    }
+
+    /**
+     * Test error processing when a custom ExceptionMappingProvider is used on the
+     * server.
+     *
+     * - The provider will wrapped the returned content with special tags
+     * - Similar to WebApplicationException(Response) functionality
+     *
+     * @throws Exception
+     */
+    public void testFaultFromProvider() throws Exception {
+        RESTServlet servlet = createServlet(RosterApplication.class.getName());
+
+        // Path to the invalid resource
+        String path = URI_ROOT_RESOURCE + "/usingProvider";
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                path, HttpMethod.GET);
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        RESTContext context = RESTContextFactory.createRequestContext();
+
+        ApplicationProcessor processor = new ApplicationProcessor(null, Thread
+                .currentThread().getContextClassLoader());
+        JAXRSInfoOutput output = processor
+                .processApplication(new Application() {
+
+                    @Override
+                    public Set<Class<?>> getClasses() {
+                        Set<Class<?>> clazzes = new HashSet<Class<?>>();
+                        clazzes.add(CarStringProvider.class);
+                        return clazzes;
+                    }
+
+                });
+
+        RESTMetaData metadata = new RESTMetaData();
+        metadata.getProviderInfoList().addAll(output.getProviderInfoList());
+
+        context.setProperty(ContextConstants.REST_METADATA, metadata);
+        context.setProperty(ContextConstants.INTEGRATION_REGISTRATION_KEY,
+                "faultProvider");
+
+        // Do the invocation
+        Throwable error = null;
+        ProviderFactory pf = null;
+        try {
+            pf = ProviderFactory.getInstance(context);
+            servlet.doPost(request, response);
+        } catch (Throwable t) {
+            error = t;
+            fail("An exception [" + error.getClass()
+                    + "] should NOT have been thrown.  "
+                    + "A response should be returned.");
+        }
+
+        // Validate the response code
+        int status = response.getStatus();
+        assertTrue("No status was returned.", status > 0);
+        assertTrue("The wrong status was returned.",
+                status == HttpServletResponse.SC_BAD_REQUEST);
+
+        // Validate the response content
+        ServletOutputStream sos = (ServletOutputStream) response
+                .getOutputStream();
+        assertTrue("The ServletOutputStream was null.", sos != null);
+
+        StringWriter sw = sos.getWriter();
+        String content = sw.toString();
+        assertTrue("The content was null.", content != null);
+        assertTrue("The content did not match expected value.  [" + content
+                + "]", content.equals("<error>server provider fault</error>"));
+    }
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/faults/ResponseHeadersTests.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/faults/ResponseHeadersTests.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/faults/ResponseHeadersTests.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/faults/ResponseHeadersTests.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,71 @@
+/*
+ * 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.ws.jaxrs.sample.faults;
+
+import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.HttpMethod;
+import javax.ws.rs.core.HttpHeaders;
+
+import com.ibm.ws.jaxrs.web.RESTServlet;
+import com.ibm.ws.jaxrs.web.ServletTestFramework;
+import com.ibm.ws.jaxrs.web.mock.ServletRequest;
+import com.ibm.ws.jaxrs.web.mock.ServletResponse;
+
+public class ResponseHeadersTests extends ServletTestFramework {
+
+    private static final String URI_ROOT_RESOURCE = "/roster";
+
+    /*
+     * Tests whether or not the Location info and appropriate status
+     * codes are returned when the user indicates a resource was created.
+     */
+    public void testLocationResponseHeader() throws Exception {
+        RESTServlet servlet = createServlet(RosterApplication.class.getName());
+
+        // The name of the entry that we want to add
+        String queryString = "name=Test%20Testerton";
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE, queryString, HttpMethod.POST);
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        // Do the invocation
+        try {
+            servlet.doPost(request, response);
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail();
+        }
+
+        // Check the content returned in the Location header
+        assertTrue(response.containsHeader(HttpHeaders.LOCATION));
+
+        String location = response.getHeader(HttpHeaders.LOCATION);
+        assertTrue(location.length() > 0);
+        assertTrue(location.endsWith(queryString));
+        assertTrue(location.lastIndexOf(queryString) == location
+                .indexOf(queryString));
+
+        // Check the status code
+        int status = response.getStatus();
+        assertTrue(status == HttpServletResponse.SC_CREATED);
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/faults/Roster.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/faults/Roster.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/faults/Roster.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/faults/Roster.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,114 @@
+/*
+ * 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.ws.jaxrs.sample.faults;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+
+import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Request;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+import javax.ws.rs.core.Response.Status;
+
+@Path(value = "/roster")
+public class Roster {
+
+    private static final ArrayList<String> roster = new ArrayList<String>();
+
+    {
+        roster.add("Fred Smith");
+        roster.add("Jane Smith");
+        roster.add("Jim Bob Duckworth");
+    }
+
+    private HttpServletResponse response;
+
+    public Roster(@Context HttpServletResponse httpResponse) {
+        response = httpResponse;
+    }
+
+    @GET
+    public String getRoster() {
+        return roster.toString();
+    }
+
+    @Path("/{name}")
+    @GET
+    public String findName(@PathParam(value = "name") String name) {
+        int i = roster.indexOf(name);
+        if (i >= 0) {
+            return roster.get(i);
+        } else {
+            if (name == null) {
+                ResponseBuilder builder = Response.status(Status.NOT_FOUND);
+                builder.entity("<error>the resource id was null</error>");
+                throw new WebApplicationException(builder.build());
+            } else if (name.equals("usingResponse")) {
+                ResponseBuilder builder = Response.status(Status.NOT_FOUND);
+                builder.entity("<error>simple server fault</error>");
+                throw new WebApplicationException(builder.build());
+            } else if (name.equals("usingProvider")) {
+                throw new RosterException("server provider fault");
+            } else if (name.equals("webApplicationException")) {
+                throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
+            } else if (name.equals("runtimeException")) {
+                throw new RuntimeException("generic server exception");
+            }
+
+            return null;
+        }
+    }
+
+    @POST
+    public Response addName(@Context Request req, @QueryParam(value = "name") String name) {
+        Response resp = null;
+        if (name != null && !roster.contains(name)) {
+            ResponseBuilder builder = Response.status(Status.CREATED);
+
+            // If we can, set the Location header to the URI of the
+            // new resource that was created.
+            try {
+                if (response != null) {
+                    String url = "http://localhost:9080/rest/roster?name="
+                            + name;
+
+                    URI newResourceURI = new URI(url.replaceAll(" ", "%20"));
+                    builder.location(newResourceURI);
+                }
+            } catch (URISyntaxException e) {
+                e.printStackTrace();
+            }
+
+            resp = builder.build();
+        }
+
+        return resp;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/faults/RosterApplication.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/faults/RosterApplication.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/faults/RosterApplication.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/faults/RosterApplication.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,35 @@
+/*
+ * 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.ws.jaxrs.sample.faults;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.core.Application;
+
+public class RosterApplication extends Application {
+
+    public Set<Class<?>> getClasses() {
+        Set<Class<?>> set = new HashSet<Class<?>>();
+        set.add(Roster.class);
+        set.add(RosterExceptionProvider.class);
+        return set;
+    }
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/faults/RosterException.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/faults/RosterException.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/faults/RosterException.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/faults/RosterException.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,28 @@
+/*
+ * 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.ws.jaxrs.sample.faults;
+
+public class RosterException extends RuntimeException {
+
+    public RosterException(String msg) {
+        super(msg);
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/faults/RosterExceptionProvider.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/faults/RosterExceptionProvider.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/faults/RosterExceptionProvider.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/faults/RosterExceptionProvider.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,38 @@
+/*
+ * 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.ws.jaxrs.sample.faults;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Provider;
+
+@Provider
+public class RosterExceptionProvider implements ExceptionMapper<RosterException> {
+
+    public Response toResponse(RosterException re) {
+        ResponseBuilder builder = Response.status(Status.BAD_REQUEST);
+        builder.entity("<error>" + re.getMessage() + "</error>");
+
+        return builder.build();
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/head/HeadApplication.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/head/HeadApplication.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/head/HeadApplication.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/head/HeadApplication.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,35 @@
+/*
+ * 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.ws.jaxrs.sample.head;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.core.Application;
+
+public class HeadApplication extends Application {
+
+    public Set<Class<?>> getClasses() {
+        Set<Class<?>> classes = new HashSet<Class<?>>();
+        classes.add(HeadResource.class);
+        return classes;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/head/HeadResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/head/HeadResource.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/head/HeadResource.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/head/HeadResource.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,45 @@
+/*
+ * 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.ws.jaxrs.sample.head;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Response;
+
+@Path("/method")
+public class HeadResource {
+
+    @GET
+    public Response getPlain() {
+        Response resp = Response.ok(HeadResource.class.getName()).build();
+        resp.getMetadata().putSingle("Invoked", "MethodResource.getPlain");
+        return resp;
+    }
+
+    @GET
+    @Produces(value = "text/html")
+    public Response getHtml() {
+        Response resp = Response.ok(HeadResource.class.getName()).build();
+        resp.getMetadata().putSingle("Invoked", "MethodResource.getHtml");
+        return resp;
+    }
+
+}



Mime
View raw message