You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wink.apache.org by bl...@apache.org on 2009/08/07 05:10:46 UTC
svn commit: r801869 [16/21] - in /incubator/wink/trunk:
wink-integration-test/
wink-integration-test/wink-server-integration-test-support/
wink-integration-test/wink-server-integration-test-support/src/main/java/org/apache/wink/test/integration/
wink-i...
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/test/java/org/apache/wink/itest/writers/JAXRSMessageBodyWritersTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/test/java/org/apache/wink/itest/writers/JAXRSMessageBodyWritersTest.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/test/java/org/apache/wink/itest/writers/JAXRSMessageBodyWritersTest.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/test/java/org/apache/wink/itest/writers/JAXRSMessageBodyWritersTest.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,691 @@
+/*
+ * 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 org.apache.wink.itest.writers;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.MessageBodyWriter;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.wink.test.integration.ServerEnvironmentInfo;
+
+public class JAXRSMessageBodyWritersTest extends TestCase {
+
+ public String getBaseURI() {
+ return ServerEnvironmentInfo.getBaseURI() + "/writers";
+ }
+
+ /**
+ * Tests that if a {@link Response} object sets its media type, it is passed
+ * correctly to the {@link MessageBodyWriter}.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testReturnContentTypeSetOnResponse() throws HttpException, IOException {
+ /*
+ * and maybe the content type isn't supported by the writer i.e.
+ * text/abcd and String
+ */
+ HttpClient client = new HttpClient();
+
+ GetMethod getMethod =
+ new GetMethod(
+ getBaseURI() + "/jaxrs/tests/providers/messagebodywriter/classtype?type=sourcecontenttype");
+ try {
+ client.executeMethod(getMethod);
+
+ assertEquals(500, getMethod.getStatusCode());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod =
+ new GetMethod(
+ getBaseURI() + "/jaxrs/tests/providers/messagebodywriter/classtype?type=source");
+ try {
+ client.executeMethod(getMethod);
+
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", getMethod
+ .getResponseBodyAsString());
+ assertEquals("text/xml", getMethod.getResponseHeader("Content-Type").getValue());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod =
+ new GetMethod(
+ getBaseURI() + "/jaxrs/tests/providers/messagebodywriter/classtype?type=stringcontenttype");
+ try {
+ client.executeMethod(getMethod);
+
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("str:foobarcontenttype", getMethod.getResponseBodyAsString());
+
+ String contentType =
+ (getMethod.getResponseHeader("Content-Type") == null) ? null : getMethod
+ .getResponseHeader("Content-Type").getValue();
+ assertNotNull(contentType, contentType);
+ assertEquals("21", getMethod.getResponseHeader("Content-Length").getValue());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod =
+ new GetMethod(
+ getBaseURI() + "/jaxrs/tests/providers/messagebodywriter/classtype?type=string");
+ try {
+ client.executeMethod(getMethod);
+
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("str:foobar", getMethod.getResponseBodyAsString());
+
+ String contentType =
+ (getMethod.getResponseHeader("Content-Type") == null) ? null : getMethod
+ .getResponseHeader("Content-Type").getValue();
+ assertNotNull(contentType, contentType);
+ assertEquals("10", getMethod.getResponseHeader("Content-Length").getValue());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ //
+ // public void testMediaTypeIntersection() {
+ // fail();
+ // }
+ //
+ // public void
+ // testMediaTypeCanBePassedThroughWithoutAddedOrRemovedParameters() {
+ // fail();
+ // }
+ //
+ // public void testProducesOnClassInsteadOfMethod() {
+ // fail();
+ // }
+
+ /**
+ * Tests that
+ * {@link MessageBodyWriter#getSize(Object, Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)}
+ * if the Content-Length given is less than what is actually written, that
+ * the full content is still sent.
+ */
+ public void testContentLengthLessThanWritten() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+
+ GetMethod getMethod =
+ new GetMethod(
+ getBaseURI() + "/jaxrs/tests/providers/messagebodywriter/contentlength?mt=length/shorter");
+ try {
+ client.executeMethod(getMethod);
+
+ assertEquals(200, getMethod.getStatusCode());
+ InputStream is = getMethod.getResponseBodyAsStream();
+ int read = is.read();
+ for (int c = 0; read != -1; ++c, read = is.read()) {
+ assertEquals(c % 256, read);
+ }
+ assertEquals("length/shorter", getMethod.getResponseHeader("Content-Type").getValue());
+ assertEquals("99990", getMethod.getResponseHeader("Content-Length").getValue());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that
+ * {@link MessageBodyWriter#getSize(Object, Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)}
+ * if the Content-Length given is less than what is actually written, that
+ * the full content is still sent.
+ */
+ public void testContentLengthClassCorrect() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+
+ GetMethod getMethod =
+ new GetMethod(
+ getBaseURI() + "/jaxrs/tests/providers/messagebodywriter/contentlength?class=Vector");
+ try {
+ client.executeMethod(getMethod);
+
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("vector:HelloThere", getMethod.getResponseBodyAsString());
+
+ String contentType =
+ (getMethod.getResponseHeader("Content-Type") == null) ? null : getMethod
+ .getResponseHeader("Content-Type").getValue();
+ assertNotNull(contentType, contentType);
+ assertEquals("17", getMethod.getResponseHeader("Content-Length").getValue());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that
+ * {@link MessageBodyWriter#getSize(Object, Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)}
+ * uses the correct generic type.
+ */
+ public void testContentLengthGenericEntityCorrect() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+
+ GetMethod getMethod =
+ new GetMethod(
+ getBaseURI() + "/jaxrs/tests/providers/messagebodywriter/contentlength?class=ListInteger");
+ try {
+ client.executeMethod(getMethod);
+
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("listinteger:12", getMethod.getResponseBodyAsString());
+
+ String contentType =
+ (getMethod.getResponseHeader("Content-Type") == null) ? null : getMethod
+ .getResponseHeader("Content-Type").getValue();
+ assertNotNull(contentType, contentType);
+ assertEquals("14", getMethod.getResponseHeader("Content-Length").getValue());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that
+ * {@link MessageBodyWriter#getSize(Object, Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)}
+ * uses the correct generic type.
+ */
+ public void testContentLengthAnnotationsCorrect() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+
+ GetMethod getMethod =
+ new GetMethod(
+ getBaseURI() + "/jaxrs/tests/providers/messagebodywriter/contentlength?class=String");
+ try {
+ client.executeMethod(getMethod);
+
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("string:hello there", getMethod.getResponseBodyAsString());
+
+ String contentType =
+ (getMethod.getResponseHeader("Content-Type") == null) ? null : getMethod
+ .getResponseHeader("Content-Type").getValue();
+ assertNotNull(contentType, contentType);
+ assertEquals("18", getMethod.getResponseHeader("Content-Length").getValue());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that
+ * {@link MessageBodyWriter#getSize(Object, Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)}
+ * if the Content-Length given is greater than what is actually written,
+ * that the full content is still sent.
+ */
+ public void testContentLengthGreaterThanWritten() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+
+ GetMethod getMethod =
+ new GetMethod(
+ getBaseURI() + "/jaxrs/tests/providers/messagebodywriter/contentlength?mt=length/longer");
+ try {
+ client.executeMethod(getMethod);
+
+ assertEquals(200, getMethod.getStatusCode());
+
+ InputStream is = getMethod.getResponseBodyAsStream();
+ int read = is.read();
+ for (int c = 0; read != -1; ++c, read = is.read()) {
+ assertEquals(c % 256, read);
+ }
+ assertEquals("length/longer", getMethod.getResponseHeader("Content-Type").getValue());
+ assertEquals("100010", getMethod.getResponseHeader("Content-Length").getValue());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that
+ * {@link MessageBodyWriter#getSize(Object, Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)}
+ * if the Content-Length given is -1 than the Content-Length is not sent.
+ */
+ public void testLessThanNegativeOneContentLength() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+
+ GetMethod getMethod =
+ new GetMethod(getBaseURI() + "/jaxrs/tests/providers/messagebodywriter/contentlength");
+ try {
+ client.executeMethod(getMethod);
+
+ assertEquals(200, getMethod.getStatusCode());
+ InputStream is = getMethod.getResponseBodyAsStream();
+ int read = is.read();
+ for (int c = 0; read != -1; ++c, read = is.read()) {
+ assertEquals(c % 256, read);
+ }
+
+ String contentType =
+ (getMethod.getResponseHeader("Content-Type") == null) ? null : getMethod
+ .getResponseHeader("Content-Type").getValue();
+ assertNotNull(contentType, contentType);
+ assertNull((getMethod.getResponseHeader("Content-Length") == null) ? "" : getMethod
+ .getResponseHeader("Content-Length").getValue(), getMethod
+ .getResponseHeader("Content-Length"));
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * */
+ public void testGiveAcceptTypeWildcardGetConcreteTypeBack() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+
+ GetMethod getMethod =
+ new GetMethod(getBaseURI() + "/jaxrs/tests/providers/messagebodywriter/concretetype");
+ getMethod.addRequestHeader("Accept", "*/*");
+ try {
+ client.executeMethod(getMethod);
+
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("Hello there", getMethod.getResponseBodyAsString());
+
+ String contentType =
+ (getMethod.getResponseHeader("Content-Type") == null) ? null : getMethod
+ .getResponseHeader("Content-Type").getValue();
+ assertNotNull(contentType, contentType);
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod =
+ new GetMethod(getBaseURI() + "/jaxrs/tests/providers/messagebodywriter/concretetype");
+ try {
+ client.executeMethod(getMethod);
+
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("Hello there", getMethod.getResponseBodyAsString());
+
+ String contentType =
+ (getMethod.getResponseHeader("Content-Type") == null) ? null : getMethod
+ .getResponseHeader("Content-Type").getValue();
+ assertNotNull(contentType, contentType);
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod =
+ new GetMethod(getBaseURI() + "/jaxrs/tests/providers/messagebodywriter/concretetype");
+ getMethod.addRequestHeader("Accept", "text/plain");
+ try {
+ client.executeMethod(getMethod);
+
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("Hello there", getMethod.getResponseBodyAsString());
+ assertEquals("text/plain", getMethod.getResponseHeader("Content-Type").getValue());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod =
+ new GetMethod(getBaseURI() + "/jaxrs/tests/providers/messagebodywriter/concretetype");
+ getMethod.addRequestHeader("Accept", "text/xml");
+ try {
+ client.executeMethod(getMethod);
+
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("Hello there", getMethod.getResponseBodyAsString());
+ assertEquals("text/xml", getMethod.getResponseHeader("Content-Type").getValue());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ //
+ // public void testIsWritableReturnRealTypeInMethod() {
+ // fail();
+ // }
+ //
+ // public void testIsWritableReturnGenericEntityTypeInMethod() {
+ // fail();
+ // }
+ //
+ // public void testIsWritableReturnGenericTypeInResponse() {
+ // fail();
+ // }
+ //
+ // public void testIsWritableReturnRealTypeInResponse() {
+ // fail();
+ // }
+
+ /**
+ * Tests that the
+ * {@link MessageBodyWriter#isWriteable(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)}
+ * method receives the correct class type.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testWriterIsWritableUnexpectedClassType() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+
+ GetMethod getMethod =
+ new GetMethod(
+ getBaseURI() + "/jaxrs/tests/providers/messagebodywriter/classtype?type=hashmap");
+ try {
+ client.executeMethod(getMethod);
+
+ assertEquals(500, getMethod.getStatusCode());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that the
+ * {@link MessageBodyWriter#isWriteable(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)}
+ * method receives the correct class type.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testWriterIsWritableExpectedClassType() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+
+ GetMethod getMethod =
+ new GetMethod(
+ getBaseURI() + "/jaxrs/tests/providers/messagebodywriter/classtype?type=deque");
+ try {
+ client.executeMethod(getMethod);
+
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("deque:str:foostr:bar", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that the
+ * {@link MessageBodyWriter#isWriteable(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)}
+ * method returns true when the expected argument type is specified on the
+ * generic type.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testWriterIsWritableGenericEntityTypeCorrect() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod =
+ new PostMethod(
+ getBaseURI() + "/jaxrs/tests/providers/messagebodywriter/genericentity?query=setstring");
+ try {
+ client.executeMethod(postMethod);
+ assertEquals(200, postMethod.getStatusCode());
+ assertEquals("set<string>:helloworld", postMethod.getResponseBodyAsString());
+ } finally {
+ postMethod.releaseConnection();
+ }
+
+ postMethod =
+ new PostMethod(
+ getBaseURI() + "/jaxrs/tests/providers/messagebodywriter/genericentity?query=setinteger");
+ try {
+ client.executeMethod(postMethod);
+ assertEquals(200, postMethod.getStatusCode());
+ assertEquals("set<integer>:12", postMethod.getResponseBodyAsString());
+ } finally {
+ postMethod.releaseConnection();
+ }
+
+ postMethod =
+ new PostMethod(
+ getBaseURI() + "/jaxrs/tests/providers/messagebodywriter/nogenericentity?query=setstring");
+ try {
+ client.executeMethod(postMethod);
+ assertEquals(200, postMethod.getStatusCode());
+ assertEquals("set:helloworld", postMethod.getResponseBodyAsString());
+ } finally {
+ postMethod.releaseConnection();
+ }
+
+ postMethod =
+ new PostMethod(
+ getBaseURI() + "/jaxrs/tests/providers/messagebodywriter/nogenericentity?query=setinteger");
+ try {
+ client.executeMethod(postMethod);
+ assertEquals(200, postMethod.getStatusCode());
+ assertEquals("set:12", postMethod.getResponseBodyAsString());
+ } finally {
+ postMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that the
+ * {@link MessageBodyWriter#isWriteable(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)}
+ * method returns false when an unexpected argument type is specified on the
+ * generic type.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testWriterIsWritableGenericEntityTypeIncorrect() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod =
+ new PostMethod(
+ getBaseURI() + "/jaxrs/tests/providers/messagebodywriter/genericentity?query=setshort");
+ try {
+ client.executeMethod(postMethod);
+ assertEquals(500, postMethod.getStatusCode());
+ } finally {
+ postMethod.releaseConnection();
+ }
+
+ postMethod =
+ new PostMethod(
+ getBaseURI() + "/jaxrs/tests/providers/messagebodywriter/nogenericentity?query=setshort");
+ try {
+ client.executeMethod(postMethod);
+ assertEquals(200, postMethod.getStatusCode());
+ assertEquals("set:12", postMethod.getResponseBodyAsString());
+ } finally {
+ postMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that the
+ * {@link MessageBodyWriter#isWriteable(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)}
+ * method is passed a single annotation.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testWriterIsWritableNotAnnotated() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+
+ GetMethod getMethod =
+ new GetMethod(getBaseURI() + "/jaxrs/tests/providers/messagebodywriter/notannotated");
+ try {
+ client.executeMethod(getMethod);
+
+ assertEquals(500, getMethod.getStatusCode());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that the
+ * {@link MessageBodyWriter#isWriteable(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)}
+ * method is passed a single annotation.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testWriterIsWritableAnnotated() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+
+ GetMethod getMethod =
+ new GetMethod(getBaseURI() + "/jaxrs/tests/providers/messagebodywriter/annotated");
+ try {
+ client.executeMethod(getMethod);
+
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("getannotation:foobar", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ PostMethod postMethod =
+ new PostMethod(getBaseURI() + "/jaxrs/tests/providers/messagebodywriter/annotated");
+ try {
+ client.executeMethod(postMethod);
+
+ assertEquals(200, postMethod.getStatusCode());
+ assertEquals("postannotation:foobar", postMethod.getResponseBodyAsString());
+ } finally {
+ postMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that the
+ * {@link MessageBodyWriter#isWriteable(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)}
+ * method is passed an incompatiable media type and does not return true.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testWriterIsWritableIncorrectMediaType() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod =
+ new PostMethod(
+ getBaseURI() + "/jaxrs/tests/providers/messagebodywriter/mediatype?mt=custom/incorrect");
+ try {
+ client.executeMethod(postMethod);
+
+ assertEquals(500, postMethod.getStatusCode());
+ } finally {
+ postMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that the
+ * {@link MessageBodyWriter#isWriteable(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)}
+ * method is passed the expected media type and reads the data.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testWriterIsWritableCorrectMediaType() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod =
+ new PostMethod(
+ getBaseURI() + "/jaxrs/tests/providers/messagebodywriter/mediatype?mt=custom/correct");
+ try {
+ client.executeMethod(postMethod);
+
+ assertEquals(200, postMethod.getStatusCode());
+ assertEquals("mediatype:foo=bar", postMethod.getResponseBodyAsString());
+ } finally {
+ postMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * When a {@link RuntimeException} is propagated back from
+ * {@link MessageBodyWriter#isWriteable(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)}
+ * , verify that the exception is handled appropriately.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testWriterIsWritableThrowsRuntimeException() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod =
+ new PostMethod(
+ getBaseURI() + "/jaxrs/tests/providers/messagebodywriter/throwsexception?mt=throw/runtime");
+ try {
+ client.executeMethod(postMethod);
+
+ assertEquals(500, postMethod.getStatusCode());
+ // assertLogContainsException("javax.servlet.ServletException");
+ } finally {
+ postMethod.releaseConnection();
+ }
+
+ postMethod =
+ new PostMethod(
+ getBaseURI() + "/jaxrs/tests/providers/messagebodywriter/throwsexception?mt=throw/nullpointer");
+ try {
+ client.executeMethod(postMethod);
+
+ assertEquals(500, postMethod.getStatusCode());
+ // assertLogContainsException("javax.servlet.ServletException");
+ } finally {
+ postMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * When a {@link WebApplicationException} is propagated back from
+ * {@link MessageBodyWriter#isWriteable(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)}
+ * , verify that the exception is handled appropriately.
+ *
+ * @throws IOException
+ * @throws HttpException
+ */
+ public void testWriterIsWritableThrowsWebApplicationException() throws HttpException,
+ IOException {
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod =
+ new PostMethod(
+ getBaseURI() + "/jaxrs/tests/providers/messagebodywriter/throwsexception?mt=throw/webapplicationexception");
+ try {
+ client.executeMethod(postMethod);
+
+ assertEquals("throwiswritableexception", postMethod.getResponseBodyAsString());
+ assertEquals(461, postMethod.getStatusCode());
+
+ } finally {
+ postMethod.releaseConnection();
+ }
+ }
+ //
+ // public void testThrowingExceptionAfterContentFlushed() {
+ // fail();
+ // }
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/pom.xml
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/pom.xml?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/pom.xml (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/pom.xml Fri Aug 7 03:10:22 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.
+-->
+<project>
+ <parent>
+ <artifactId>wink-itest</artifactId>
+ <groupId>org.apache.wink</groupId>
+ <version>0.1-incubating-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>wink-itest-targeting</artifactId>
+ <packaging>war</packaging>
+ <name>wink-jaxrs-test-targeting Maven Webapp</name>
+</project>
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/addressbook/Address.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/addressbook/Address.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/addressbook/Address.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/addressbook/Address.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,130 @@
+/*
+ * 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 org.apache.wink.itest.addressbook;
+
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+
+public class Address {
+
+ private String entryName;
+
+ private String zipCode;
+
+ private String streetAddress;
+
+ private String city;
+
+ private String state;
+
+ private String country;
+
+ public Address(String entryName,
+ String zipCode,
+ String streetAddress,
+ String city,
+ String state,
+ String country) {
+ this.entryName = entryName;
+ this.zipCode = zipCode;
+ this.streetAddress = streetAddress;
+ this.city = city;
+ this.state = state;
+ this.country = country;
+ }
+
+ @GET
+ @Produces(value = {"text/xml"})
+ public String get() {
+ return toString();
+ }
+
+ @DELETE
+ public void removeAddress(@PathParam(value = "entryName") String entryName) {
+ AddressBook.db.removeAddress(entryName);
+ }
+
+ public String getEntryName() {
+ return entryName;
+ }
+
+ public void setEntryName(String entryName) {
+ this.entryName = entryName;
+ }
+
+ public String getZipCode() {
+ return zipCode;
+ }
+
+ public void setZipCode(String zipCode) {
+ this.zipCode = zipCode;
+ }
+
+ public String getStreetAddress() {
+ return streetAddress;
+ }
+
+ public void setStreetAddress(String streetAddress) {
+ this.streetAddress = streetAddress;
+ }
+
+ public String getCity() {
+ return city;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+ public String getState() {
+ return state;
+ }
+
+ public void setState(String state) {
+ this.state = state;
+ }
+
+ public String getCountry() {
+ return country;
+ }
+
+ public void setCountry(String country) {
+ this.country = country;
+ }
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append("Entry Name: " + entryName);
+ sb.append("\n");
+ sb.append("Street Address: " + streetAddress);
+ sb.append("\n");
+ sb.append("City: " + city);
+ sb.append("\n");
+ sb.append("Zip Code: " + zipCode);
+ sb.append("\n");
+ sb.append("State: " + state);
+ sb.append("\n");
+ sb.append("Country: " + country);
+ return sb.toString();
+ }
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/addressbook/AddressApplication.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/addressbook/AddressApplication.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/addressbook/AddressApplication.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/addressbook/AddressApplication.java Fri Aug 7 03:10:22 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 org.apache.wink.itest.addressbook;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.core.Application;
+
+public class AddressApplication extends Application {
+
+ public Set<Class<?>> getClasses() {
+ Set<Class<?>> set = new HashSet<Class<?>>();
+ set.add(AddressBook.class);
+ return set;
+ }
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/addressbook/AddressBook.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/addressbook/AddressBook.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/addressbook/AddressBook.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/addressbook/AddressBook.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,139 @@
+/*
+ * 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 org.apache.wink.itest.addressbook;
+
+import java.util.Iterator;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+
+@Path(value = "/unittests/addresses")
+public class AddressBook {
+
+ public static AddressBookDatabase db = AddressBookDatabase.getInstance();
+
+ private @Context
+ HttpServletRequest request;
+
+ public static Address defaultAddress =
+ new Address("defaultAddress", "12345",
+ "1 Mopac Loop", "Austin",
+ "TX", "US");
+
+ public AddressBook() {
+ db.storeAddress(defaultAddress.getEntryName(), defaultAddress);
+ }
+
+ @Path("/{entryName}")
+ public Object getAddress(@PathParam(value = "entryName") String entryName) {
+ Address addr = db.getAddress(entryName);
+ return addr;
+ }
+
+ @GET
+ @Produces(value = {"text/xml"})
+ public Response getAddresses() {
+ Response resp = null;
+ if (request.getMethod().equalsIgnoreCase("HEAD")) {
+ ResponseBuilder builder = Response.ok();
+ resp = builder.build();
+ resp.getMetadata().putSingle("head-matched", "true");
+ } else {
+ StringBuffer sb = new StringBuffer();
+ Iterator<Address> addressIter = db.getAddresses();
+ while (addressIter.hasNext()) {
+ sb.append(addressIter.next().toString());
+ sb.append("\n");
+ }
+ ResponseBuilder builder = Response.ok(sb.toString());
+ resp = builder.build();
+ }
+ return resp;
+ }
+
+ @POST
+ public void createAddress(@QueryParam(value = "entryName") String entryName,
+ @QueryParam(value = "zipCode") String zipCode,
+ @QueryParam(value = "streetAddress") String streetAddress,
+ @QueryParam(value = "city") String city,
+ @QueryParam(value = "state") String state,
+ @QueryParam(value = "country") String country) {
+ Address address = new Address(entryName, zipCode, streetAddress, city, state, country);
+ db.storeAddress(entryName, address);
+ }
+
+ @POST
+ @Consumes(value = {"text/xml"})
+ @Path(value = "/fromBody")
+ public void createAddressFromBody(String input) {
+ String[] inputs = input.split("&");
+ String entryName = inputs[0];
+ String zipCode = inputs[1];
+ String streetAddress = inputs[2];
+ String city = inputs[3];
+ String state = inputs[4];
+ String country = inputs[5];
+ Address address = new Address(entryName, zipCode, streetAddress, city, state, country);
+ db.storeAddress(entryName, address);
+ }
+
+ @PUT
+ public void updateAddress(@QueryParam(value = "entryName") String entryName,
+ @QueryParam(value = "zipCode") String zipCode,
+ @QueryParam(value = "streetAddress") String streetAddress,
+ @QueryParam(value = "city") String city,
+ @QueryParam(value = "state") String state,
+ @QueryParam(value = "country") String country) {
+ Address address = db.getAddress(entryName);
+ if (address == null) {
+ address = new Address(entryName, zipCode, streetAddress, city, state, country);
+ db.storeAddress(entryName, address);
+ } else {
+ address.setCity(city);
+ address.setCountry(country);
+ address.setState(state);
+ address.setStreetAddress(streetAddress);
+ address.setZipCode(zipCode);
+ }
+ }
+
+ @GET
+ @Path(value = "/invalidNonPublic")
+ void invalidNonPublic() {
+
+ }
+
+ @POST
+ @Path("/clear")
+ public void clearEntries() {
+ AddressBookDatabase.clearEntries();
+ }
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/addressbook/AddressBookDatabase.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/addressbook/AddressBookDatabase.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/addressbook/AddressBookDatabase.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/addressbook/AddressBookDatabase.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,68 @@
+/*
+ * 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 org.apache.wink.itest.addressbook;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * Sample that will mock a database for the AddressBook resource
+ */
+public class AddressBookDatabase {
+
+ private static Map<String, Address> addressMap;
+
+ private static AddressBookDatabase instance;
+
+ private AddressBookDatabase() {
+ addressMap = new HashMap<String, Address>();
+ }
+
+ public static AddressBookDatabase getInstance() {
+ if (instance == null) {
+ instance = new AddressBookDatabase();
+ }
+ return instance;
+ }
+
+ public Address getAddress(String entryName) {
+ return addressMap.get(entryName);
+ }
+
+ public void storeAddress(String entryName, Address address) {
+ addressMap.put(entryName, address);
+ }
+
+ public Iterator<Address> getAddresses() {
+ return addressMap.values().iterator();
+ }
+
+ public void removeAddress(String entryName) {
+ addressMap.remove(entryName);
+ }
+
+ public static void clearEntries() {
+ if (addressMap != null) {
+ addressMap.clear();
+ }
+ }
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/cache/Application.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/cache/Application.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/cache/Application.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/cache/Application.java Fri Aug 7 03:10:22 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 org.apache.wink.itest.cache;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.wink.itest.cache.NewsResource;
+
+public class Application extends javax.ws.rs.core.Application {
+
+ public Set<Class<?>> getClasses() {
+ Set<Class<?>> set = new HashSet<Class<?>>();
+ set.add(NewsResource.class);
+ return set;
+ }
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/cache/NewsResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/cache/NewsResource.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/cache/NewsResource.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/cache/NewsResource.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,149 @@
+/*
+ * 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 org.apache.wink.itest.cache;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+import java.util.TimeZone;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.EntityTag;
+import javax.ws.rs.core.Request;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+
+@Path("/news")
+public class NewsResource {
+
+ private static final DateFormat format =
+ new SimpleDateFormat(
+ "EEE, dd MMM yyyy HH:mm:ss zzz",
+ Locale.ENGLISH);
+ static {
+ format.setLenient(false);
+ format.setTimeZone(TimeZone.getTimeZone("GMT"));
+ }
+
+ @Context
+ private Request request;
+
+ private static Map<String, StoryRecord> stories = new HashMap<String, StoryRecord>();
+
+ @GET
+ @Produces(value = "text/xml")
+ @Path(value = "/{title}")
+ public Response getNewsStory(@PathParam(value = "title") String title) {
+ StoryRecord record = stories.get(title);
+
+ // if no record, return 404
+ if (record == null) {
+ return Response.status(404).build();
+ }
+ NewsStory story = record.getStory();
+
+ EntityTag recordETag =
+ EntityTag.valueOf("\"" + String.valueOf(record.getRevision().hashCode()) + "\"");
+
+ String lastModified = story.getUpdatedDate();
+ Date date = null;
+
+ try {
+ format.setTimeZone(TimeZone.getTimeZone("GMT"));
+ date = format.parse(lastModified);
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+
+ ResponseBuilder builder = null;
+ if (date != null) {
+ builder = request.evaluatePreconditions(date, recordETag);
+ } else {
+ builder = request.evaluatePreconditions(recordETag);
+ }
+
+ if (builder != null) {
+ Response response = builder.build();
+ response.getMetadata().putSingle("Content-Length", 0);
+ return response;
+ }
+
+ // otherwise return the entity
+ builder = Response.ok();
+ builder.entity(story);
+ return builder.build();
+ }
+
+ @POST
+ public Response addNewsStory(NewsStory story) {
+ String date =
+ format.format(Calendar.getInstance(TimeZone.getTimeZone("America/Austin")).getTime());
+ story.setPostedDate(date);
+ story.setUpdatedDate(date);
+ StoryRecord record = new StoryRecord(story);
+ stories.put(record.getKey(), record);
+ ResponseBuilder builder = Response.ok();
+
+ // let's put an ETag in here so clients can send an 'If-Match'
+ EntityTag eTag =
+ EntityTag.valueOf("\"" + String.valueOf(record.getRevision().hashCode()) + "\"");
+ builder.tag(eTag);
+ Response resp = builder.build();
+ resp.getMetadata().putSingle("Location", "/" + story.getTitle());
+ resp.getMetadata().putSingle("Last-Modified", story.getUpdatedDate());
+ return resp;
+ }
+
+ @PUT
+ public Response updateNewsStory(NewsStory story) {
+ StoryRecord record = stories.get(story.getTitle());
+ if (record == null) {
+ record = new StoryRecord(story);
+ } else {
+ record.updateStory(story);
+ }
+ ResponseBuilder builder = Response.ok();
+
+ // let's put an ETag in here so clients can send an 'If-Match'
+ EntityTag eTag =
+ EntityTag.valueOf("\"" + String.valueOf(record.getRevision().hashCode()) + "\"");
+ builder.tag(eTag);
+ Response response = builder.build();
+ response.getMetadata().putSingle("Last-Modified", record.getStory().getUpdatedDate());
+ return response;
+ }
+
+ @POST
+ @Path("/clear")
+ public void clearRecords() {
+ stories.clear();
+ }
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/cache/NewsStory.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/cache/NewsStory.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/cache/NewsStory.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/cache/NewsStory.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,67 @@
+/*
+ * 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 org.apache.wink.itest.cache;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "story", namespace = "http://com.ibm.jaxrs.sample.cache")
+public class NewsStory {
+
+ private String title;
+
+ private String content;
+
+ private String postedDate;
+
+ private String updatedDate;
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public String getContent() {
+ return content;
+ }
+
+ public void setContent(String content) {
+ this.content = content;
+ }
+
+ public String getPostedDate() {
+ return postedDate;
+ }
+
+ public void setPostedDate(String postedDate) {
+ this.postedDate = postedDate;
+ }
+
+ public String getUpdatedDate() {
+ return updatedDate;
+ }
+
+ public void setUpdatedDate(String updatedDate) {
+ this.updatedDate = updatedDate;
+ }
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/cache/ObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/cache/ObjectFactory.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/cache/ObjectFactory.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/cache/ObjectFactory.java Fri Aug 7 03:10:22 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 org.apache.wink.itest.cache;
+
+import javax.xml.bind.annotation.XmlRegistry;
+
+@XmlRegistry
+public class ObjectFactory {
+
+ public NewsStory createNewsStory() {
+ return new NewsStory();
+ }
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/cache/StoryRecord.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/cache/StoryRecord.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/cache/StoryRecord.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/cache/StoryRecord.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,74 @@
+/*
+ * 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 org.apache.wink.itest.cache;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Locale;
+import java.util.TimeZone;
+
+public class StoryRecord {
+
+ private static final DateFormat formatter =
+ new SimpleDateFormat(
+ "EEE, dd MMM yyyy HH:mm:ss zzz",
+ Locale.ENGLISH);
+ static {
+ formatter.setLenient(false);
+ formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
+ }
+
+ private NewsStory story;
+
+ private int revision;
+
+ public StoryRecord(NewsStory story) {
+ this.story = story;
+ revision = 100;
+ }
+
+ public NewsStory getStory() {
+ return story;
+ }
+
+ public Integer getRevision() {
+ return revision;
+ }
+
+ public void updateRevision() {
+ revision++;
+ }
+
+ public String getKey() {
+ return story.getTitle();
+ }
+
+ public void updateStory(NewsStory story) {
+ this.story.setContent(story.getContent());
+ this.story.setTitle(story.getTitle());
+ String date =
+ formatter
+ .format(Calendar.getInstance(TimeZone.getTimeZone("America/Austin")).getTime());
+ this.story.setUpdatedDate(date);
+ revision++;
+ }
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentencoding/ByteContentEncodedGZIPReader.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentencoding/ByteContentEncodedGZIPReader.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentencoding/ByteContentEncodedGZIPReader.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentencoding/ByteContentEncodedGZIPReader.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,85 @@
+/*
+ * 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 org.apache.wink.itest.contentencoding;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.List;
+import java.util.zip.GZIPInputStream;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.Provider;
+import javax.ws.rs.ext.Providers;
+
+@Provider
+public class ByteContentEncodedGZIPReader implements MessageBodyReader<byte[]> {
+
+ @Context
+ private HttpHeaders headers;
+
+ public boolean isReadable(Class<?> type,
+ Type genericType,
+ Annotation[] annotations,
+ MediaType mediaType) {
+ if (type != byte[].class || !MediaType.TEXT_PLAIN_TYPE.isCompatible(mediaType)) {
+ return false;
+ }
+ List<String> contentEncodingValues = headers.getRequestHeader("Content-Encoding");
+ String contentEncoding = null;
+ if (contentEncodingValues.size() == 1) {
+ contentEncoding = contentEncodingValues.get(0);
+ }
+ if (contentEncoding != null && "gzip".equals(contentEncoding)) {
+ return true;
+ }
+ return false;
+ }
+
+ @Context
+ private Providers providers;
+
+ public byte[] readFrom(Class<byte[]> type,
+ Type genericType,
+ Annotation[] annotations,
+ MediaType mediaType,
+ MultivaluedMap<String, String> httpHeaders,
+ final InputStream entityStream) throws IOException,
+ WebApplicationException {
+ MessageBodyReader<byte[]> strReader =
+ providers.getMessageBodyReader(byte[].class,
+ byte[].class,
+ annotations,
+ MediaType.APPLICATION_XML_TYPE);
+ return strReader.readFrom(type,
+ genericType,
+ annotations,
+ mediaType,
+ httpHeaders,
+ new GZIPInputStream(entityStream));
+ }
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentencoding/ByteContentEncodedGZIPWriter.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentencoding/ByteContentEncodedGZIPWriter.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentencoding/ByteContentEncodedGZIPWriter.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentencoding/ByteContentEncodedGZIPWriter.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,99 @@
+/*
+ * 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 org.apache.wink.itest.contentencoding;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.List;
+import java.util.zip.GZIPOutputStream;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+import javax.ws.rs.ext.Providers;
+
+@Provider
+public class ByteContentEncodedGZIPWriter implements MessageBodyWriter<byte[]> {
+
+ @Context
+ private HttpHeaders headers;
+
+ public long getSize(byte[] t,
+ Class<?> type,
+ Type genericType,
+ Annotation[] annotations,
+ MediaType mediaType) {
+ return -1;
+ }
+
+ public boolean isWriteable(Class<?> type,
+ Type genericType,
+ Annotation[] annotations,
+ MediaType mediaType) {
+ if (type != byte[].class || !MediaType.TEXT_PLAIN_TYPE.equals(mediaType)) {
+ return false;
+ }
+
+ List<String> contentEncodingValues = headers.getRequestHeader("Accept-Encoding");
+ if (contentEncodingValues != null && contentEncodingValues.contains("gzip")) {
+ /*
+ * this in real code should check lower and uppercase gzip with
+ * quality factors in play
+ */
+ return true;
+ }
+ return false;
+ }
+
+ @Context
+ private Providers providers;
+
+ public void writeTo(byte[] t,
+ Class<?> type,
+ Type genericType,
+ Annotation[] annotations,
+ MediaType mediaType,
+ MultivaluedMap<String, Object> httpHeaders,
+ OutputStream entityStream) throws IOException, WebApplicationException {
+ httpHeaders.putSingle("Content-Encoding", "gzip");
+ MessageBodyWriter<byte[]> strReader =
+ providers.getMessageBodyWriter(byte[].class,
+ byte[].class,
+ annotations,
+ MediaType.APPLICATION_XML_TYPE);
+ GZIPOutputStream gzipOut = new GZIPOutputStream(entityStream);
+ strReader.writeTo(t,
+ byte[].class,
+ byte[].class,
+ annotations,
+ mediaType,
+ httpHeaders,
+ gzipOut);
+ gzipOut.finish();
+ gzipOut.flush();
+ }
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentencoding/ContentEncodingApplication.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentencoding/ContentEncodingApplication.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentencoding/ContentEncodingApplication.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentencoding/ContentEncodingApplication.java Fri Aug 7 03:10:22 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 org.apache.wink.itest.contentencoding;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.core.Application;
+
+public class ContentEncodingApplication extends Application {
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ Set<Class<?>> classes = new HashSet<Class<?>>();
+ classes.add(MirrorResource.class);
+ classes.add(StringContentEncodedGzip.class);
+ classes.add(ByteContentEncodedGZIPReader.class);
+ classes.add(ByteContentEncodedGZIPWriter.class);
+ return classes;
+ }
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentencoding/MirrorResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentencoding/MirrorResource.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentencoding/MirrorResource.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentencoding/MirrorResource.java Fri Aug 7 03:10:22 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 org.apache.wink.itest.contentencoding;
+
+import java.io.UnsupportedEncodingException;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+@Path("/bigbook")
+public class MirrorResource {
+
+ @POST
+ @Consumes("text/plain")
+ @Produces("text/plain")
+ public String postBigBook(String postingBigBook) throws UnsupportedEncodingException {
+ return postingBigBook + "helloworld";
+ }
+
+ @POST
+ @Path("/mirror")
+ @Produces("text/plain")
+ public byte[] postBigBook(byte[] postingBigBook) throws UnsupportedEncodingException {
+ return postingBigBook;
+ }
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentencoding/StringContentEncodedGzip.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentencoding/StringContentEncodedGzip.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentencoding/StringContentEncodedGzip.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentencoding/StringContentEncodedGzip.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,84 @@
+/*
+ * 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 org.apache.wink.itest.contentencoding;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.List;
+import java.util.zip.GZIPInputStream;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.Provider;
+import javax.ws.rs.ext.Providers;
+
+@Provider
+public class StringContentEncodedGzip implements MessageBodyReader<String> {
+
+ @Context
+ private HttpHeaders headers;
+
+ public boolean isReadable(Class<?> type,
+ Type genericType,
+ Annotation[] annotations,
+ MediaType mediaType) {
+ if (type != String.class || !MediaType.TEXT_PLAIN_TYPE.isCompatible(mediaType)) {
+ return false;
+ }
+ List<String> contentEncodingValues = headers.getRequestHeader("Content-Encoding");
+ String contentEncoding = null;
+ if (contentEncodingValues.size() == 1) {
+ contentEncoding = contentEncodingValues.get(0);
+ }
+ if (contentEncoding != null && "gzip".equals(contentEncoding)) {
+ return true;
+ }
+ return false;
+ }
+
+ @Context
+ private Providers providers;
+
+ public String readFrom(Class<String> type,
+ Type genericType,
+ Annotation[] annotations,
+ MediaType mediaType,
+ MultivaluedMap<String, String> httpHeaders,
+ InputStream entityStream) throws IOException, WebApplicationException {
+ MessageBodyReader<String> strReader =
+ providers.getMessageBodyReader(String.class,
+ String.class,
+ annotations,
+ MediaType.APPLICATION_XML_TYPE);
+ return strReader.readFrom(type,
+ genericType,
+ annotations,
+ mediaType,
+ httpHeaders,
+ new GZIPInputStream(entityStream));
+ }
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentnegotiation/Application.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentnegotiation/Application.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentnegotiation/Application.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentnegotiation/Application.java Fri Aug 7 03:10:22 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 org.apache.wink.itest.contentnegotiation;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class Application extends javax.ws.rs.core.Application {
+
+ public Set<Class<?>> getClasses() {
+ Set<Class<?>> set = new HashSet<Class<?>>();
+ set.add(CustomerService.class);
+ return set;
+ }
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentnegotiation/Customer.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentnegotiation/Customer.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentnegotiation/Customer.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentnegotiation/Customer.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,62 @@
+/*
+ * 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.
+ */
+
+/**
+ * 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 org.apache.wink.itest.contentnegotiation;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "Customer")
+public class Customer {
+ private long id;
+ private String name;
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentnegotiation/CustomerService.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentnegotiation/CustomerService.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentnegotiation/CustomerService.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentnegotiation/CustomerService.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,88 @@
+/*
+ * 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.
+ */
+
+/**
+ * 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 org.apache.wink.itest.contentnegotiation;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+@Path("/customerservice/")
+public class CustomerService {
+ long currentId = 123;
+ Map<Long, Customer> customers = new HashMap<Long, Customer>();
+
+ public CustomerService() {
+ init();
+ }
+
+ @GET
+ @Path("/customers/{id}/")
+ public Customer getCustomer(@PathParam("id") String id) {
+ System.out.println("----invoking getCustomer, Customer id is: " + id);
+ long idNumber = Long.parseLong(id);
+ Customer c = customers.get(idNumber);
+ return c;
+ }
+
+ @GET
+ @Produces("application/json")
+ @Path("/customers/{id}/")
+ public JSONObject getCustomerInJSON(@PathParam("id") String id) throws JSONException {
+ System.out.println("----invoking getCustomer, Customer id is: " + id);
+ JSONObject jObj = new JSONObject();
+ long idNumber = Long.parseLong(id);
+ jObj.put("id", customers.get(idNumber).getId());
+ jObj.put("name", customers.get(idNumber).getName());
+ return jObj;
+ }
+
+ final void init() {
+ Customer c = new Customer();
+ c.setName("John");
+ c.setId(123);
+ customers.put(c.getId(), c);
+ }
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentnegotiation/ObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentnegotiation/ObjectFactory.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentnegotiation/ObjectFactory.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentnegotiation/ObjectFactory.java Fri Aug 7 03:10:22 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 org.apache.wink.itest.contentnegotiation;
+
+import javax.xml.bind.annotation.XmlRegistry;
+
+@XmlRegistry
+public class ObjectFactory {
+
+ public Customer createCustomer() {
+ return new Customer();
+ }
+
+}
Copied: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentnegotiation/jaxb.index (from r801788, incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/main/java/org/apache/wink/jaxrs/test/contentnegotiation/jaxb.index)
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentnegotiation/jaxb.index?p2=incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/java/org/apache/wink/itest/contentnegotiation/jaxb.index&p1=incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/main/java/org/apache/wink/jaxrs/test/contentnegotiation/jaxb.index&r1=801788&r2=801869&rev=801869&view=diff
==============================================================================
(empty)