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 [12/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/main/java/org/apache/wink/itest/standard/ArrayUtils.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/ArrayUtils.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/ArrayUtils.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/ArrayUtils.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,52 @@
+/*
+ * 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.standard;
+
+public class ArrayUtils {
+
+ /**
+ * copyOf performs the very same function that JDK6 java.util.Arrays.copyOf
+ * performs. We need it here to support JDK5
+ *
+ * @param buffer
+ * @param size
+ * @return
+ */
+ public static byte[] copyOf(byte[] buffer, int size) {
+ byte[] copy = new byte[size];
+ System.arraycopy(buffer, 0, copy, 0, Math.min(buffer.length, size));
+ return copy;
+ }
+
+ /**
+ * copyOf performs the very same function that JDK6 java.util.Arrays.copyOf
+ * performs. We need it here to support JDK5
+ *
+ * @param buffer
+ * @param size
+ * @return
+ */
+ public static char[] copyOf(char[] buffer, int size) {
+ char[] copy = new char[size];
+ System.arraycopy(buffer, 0, copy, 0, Math.min(buffer.length, size));
+ return copy;
+ }
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/BytesArrayResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/BytesArrayResource.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/BytesArrayResource.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/BytesArrayResource.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,48 @@
+/*
+ * 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.standard;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Response;
+
+@Path("providers/standard/bytesarray")
+public class BytesArrayResource {
+
+ private byte[] barr = null;
+
+ @GET
+ public Response getByteArray() {
+ return Response.ok(barr).build();
+ }
+
+ @POST
+ public byte[] postByteArray(byte[] bytearray) {
+ return bytearray;
+ }
+
+ @PUT
+ public void putByteArray(byte[] bytearray) {
+ barr = bytearray;
+ }
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/DSResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/DSResource.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/DSResource.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/DSResource.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.wink.itest.standard;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.activation.DataSource;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+
+@Path(value = "/dstest")
+public class DSResource {
+
+ @POST
+ public Response post(DataSource dataSource) {
+ Response resp = null;
+ try {
+ InputStream inputStream = dataSource.getInputStream();
+ byte[] inputBytes = new byte[inputStream.available()];
+ int next = inputStream.read();
+ int i = 0;
+ while (next != -1) {
+ if (i == inputBytes.length) {
+ inputBytes = ArrayUtils.copyOf(inputBytes, 2 * i);
+ }
+ inputBytes[i] = (byte)next;
+ next = inputStream.read();
+ i++;
+ }
+ TestDataSource entity =
+ new TestDataSource(inputBytes, dataSource.getName(), dataSource.getContentType());
+ ResponseBuilder rb = Response.ok();
+ rb.entity(entity);
+ resp = rb.build();
+ } catch (Exception e) {
+ ResponseBuilder rb = Response.serverError();
+ resp = rb.build();
+ }
+ return resp;
+ }
+
+ public class TestDataSource implements DataSource {
+
+ private byte[] inputBytes;
+
+ private String name;
+
+ private String contentType;
+
+ public TestDataSource(byte[] inputBytes, String name, String contentType) {
+ this.inputBytes = inputBytes;
+ this.name = name;
+ this.contentType = contentType;
+ }
+
+ public String getContentType() {
+ return contentType;
+ }
+
+ public InputStream getInputStream() throws IOException {
+ return new ByteArrayInputStream(inputBytes);
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public OutputStream getOutputStream() throws IOException {
+ return null;
+ }
+
+ }
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/DataSourceResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/DataSourceResource.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/DataSourceResource.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/DataSourceResource.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,55 @@
+/*
+ * 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.standard;
+
+import javax.activation.DataSource;
+import javax.activation.FileDataSource;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Response;
+
+@Path("providers/standard/datasource")
+public class DataSourceResource {
+
+ private DataSource ds = null;
+
+ @GET
+ public Response getDataSource() {
+ return Response.ok(ds).build();
+ }
+
+ @POST
+ public DataSource postDataSource(DataSource ds) {
+ return ds;
+ }
+
+ @PUT
+ public void putDataSource(DataSource ds) {
+ this.ds = ds;
+ }
+
+ @POST
+ @Path("subclass/should/fail")
+ public DataSource postDataSource(FileDataSource ds) {
+ return ds;
+ }
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/FileResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/FileResource.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/FileResource.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/FileResource.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.wink.itest.standard;
+
+import java.io.File;
+import java.io.IOException;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Response;
+
+@Path("providers/standard/file")
+public class FileResource {
+
+ private static File f;
+
+ @POST
+ public File postFile(File f) {
+ return f;
+ }
+
+ @GET
+ public Response getFile() {
+ return Response.ok(FileResource.f).build();
+ }
+
+ @PUT
+ public void putFile(File f) throws IOException {
+ FileResource.f = f;
+ }
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/InputStreamResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/InputStreamResource.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/InputStreamResource.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/InputStreamResource.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,66 @@
+/*
+ * 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.standard;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Response;
+
+@Path("providers/standard/inputstream")
+public class InputStreamResource {
+
+ private byte[] barr = null;
+
+ @GET
+ public Response getInputStream() {
+ return Response.ok(new ByteArrayInputStream(barr)).build();
+ }
+
+ @POST
+ public InputStream postInputStream(InputStream is) {
+ return is;
+ }
+
+ @POST
+ @Path("/subclasses/shouldfail")
+ public ByteArrayInputStream postInputStream(ByteArrayInputStream is) {
+ return is;
+ }
+
+ @PUT
+ public void putInputStream(InputStream is) throws IOException {
+ byte[] buffer = new byte[(is.available() <= 0) ? 1 : is.available()];
+ int read = 0;
+ int offset = 0;
+ while ((read = is.read(buffer, offset, buffer.length - offset)) != -1) {
+ offset += read;
+ if (offset >= buffer.length) {
+ buffer = ArrayUtils.copyOf(buffer, buffer.length * 2);
+ }
+ }
+ barr = ArrayUtils.copyOf(buffer, offset);
+ }
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/MultiValuedMapResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/MultiValuedMapResource.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/MultiValuedMapResource.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/MultiValuedMapResource.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,64 @@
+/*
+ * 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.standard;
+
+import java.io.IOException;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+
+@Path("providers/standard/multivaluedmap")
+public class MultiValuedMapResource {
+
+ private MultivaluedMap<String, String> formData = null;
+
+ @GET
+ public Response getMultivaluedMap() {
+ return Response.ok(formData).build();
+ }
+
+ @POST
+ @Produces("application/x-www-form-urlencoded")
+ public MultivaluedMap<String, String> postMultivaluedMap(MultivaluedMap<String, String> map) {
+ return map;
+ }
+
+ @POST
+ @Path("/noproduces")
+ public MultivaluedMap<String, String> postMultivaluedMapNoProduces(MultivaluedMap<String, String> map) {
+ return map;
+ }
+
+ @POST
+ @Path("/subclasses/shouldfail")
+ public MultivaluedMap<String, Object> postMultivaluedMapWithNotRightTypes(MultivaluedMap<String, Object> map) {
+ return map;
+ }
+
+ @PUT
+ public void putMultivaluedMap(MultivaluedMap<String, String> map) throws IOException {
+ formData = map;
+ }
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/ReaderResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/ReaderResource.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/ReaderResource.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/ReaderResource.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.standard;
+
+import java.io.BufferedReader;
+import java.io.CharArrayReader;
+import java.io.IOException;
+import java.io.Reader;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Response;
+
+@Path("providers/standard/reader")
+public class ReaderResource {
+
+ private char[] carr = null;
+
+ @GET
+ public Response getReader() {
+ return Response.ok(new BufferedReader(new CharArrayReader(carr))).build();
+ }
+
+ @POST
+ public Reader postReader(Reader reader) {
+ return reader;
+ }
+
+ @POST
+ @Path("/subclasses/shouldfail")
+ public BufferedReader postReader(BufferedReader br) {
+ return br;
+ }
+
+ @PUT
+ public void putReader(Reader is) throws IOException {
+ char[] buffer = new char[1];
+ int read = 0;
+ int offset = 0;
+ while ((read = is.read(buffer, offset, buffer.length - offset)) != -1) {
+ offset += read;
+ if (offset >= buffer.length) {
+ buffer = ArrayUtils.copyOf(buffer, buffer.length * 2);
+ }
+ }
+ carr = ArrayUtils.copyOf(buffer, offset);
+ }
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/SourceResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/SourceResource.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/SourceResource.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/SourceResource.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,73 @@
+/*
+ * 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.standard;
+
+import java.io.IOException;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Response;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+
+@Path("providers/standard/source")
+public class SourceResource {
+
+ private static Source source = null;
+
+ @GET
+ @Produces("text/xml")
+ public Response getSource() {
+ return Response.ok(source).type("text/xml").build();
+ }
+
+ @POST
+ public Source postSource(Source src) {
+ return src;
+ }
+
+ public static class UnsupportedSourceSubclass implements Source {
+
+ public String getSystemId() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void setSystemId(String systemId) {
+ // TODO Auto-generated method stub
+
+ }
+
+ }
+
+ @POST
+ @Path("/subclasses/shouldfail")
+ public UnsupportedSourceSubclass postReader(UnsupportedSourceSubclass saxSource) {
+ return saxSource;
+ }
+
+ @PUT
+ public void putSource(DOMSource source) throws IOException {
+ this.source = source;
+ }
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/StreamingOutputResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/StreamingOutputResource.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/StreamingOutputResource.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/standard/StreamingOutputResource.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,77 @@
+/*
+ * 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.standard;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.StreamingOutput;
+
+@Path("providers/standard/streamingoutput")
+public class StreamingOutputResource {
+
+ private byte[] barr = null;
+
+ @GET
+ public Response getStreamingOutputStream() {
+ return Response.ok(new StreamingOutput() {
+
+ public void write(OutputStream arg0) throws IOException, WebApplicationException {
+ arg0.write(barr);
+ }
+
+ }).build();
+ }
+
+ @POST
+ public StreamingOutput postInputStream(final InputStream is) {
+ return new StreamingOutput() {
+
+ public void write(OutputStream arg0) throws IOException, WebApplicationException {
+ int read = 0;
+ while ((read = is.read()) != -1) {
+ arg0.write(read);
+ }
+ }
+
+ };
+ }
+
+ @PUT
+ public void putInputStream(InputStream is) throws IOException {
+ byte[] buffer = new byte[(is.available() <= 0) ? 1 : is.available()];
+ int read = 0;
+ int offset = 0;
+ while ((read = is.read(buffer, offset, buffer.length - offset)) != -1) {
+ offset += read;
+ if (offset >= buffer.length) {
+ buffer = ArrayUtils.copyOf(buffer, buffer.length * 2);
+ }
+ }
+ barr = ArrayUtils.copyOf(buffer, offset);
+ }
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/subresource/Application.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/subresource/Application.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/subresource/Application.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/subresource/Application.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,34 @@
+/*
+ * 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.subresource;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class Application extends javax.ws.rs.core.Application {
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ Set<Class<?>> clazzes = new HashSet<Class<?>>();
+ clazzes.add(GuestbookResource.class);
+ return clazzes;
+ }
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/subresource/Comment.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/subresource/Comment.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/subresource/Comment.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/subresource/Comment.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,58 @@
+/*
+ * 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.subresource;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "comment")
+public class Comment {
+
+ private Integer id;
+
+ private String message;
+
+ private String author;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ @XmlElement(nillable = false)
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ public String getAuthor() {
+ return author;
+ }
+
+ public void setAuthor(String author) {
+ this.author = author;
+ }
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/subresource/CommentData.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/subresource/CommentData.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/subresource/CommentData.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/subresource/CommentData.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,109 @@
+/*
+ * 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.subresource;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.core.Response.Status;
+
+public class CommentData {
+
+ final private String commentId;
+
+ public CommentData(String id) {
+ this.commentId = id;
+ }
+
+ @GET
+ @Produces("text/xml")
+ public Response retrieveComment() {
+ if (commentId == null) {
+ return Response.status(Status.NOT_FOUND).build();
+ }
+
+ Comment existingComment =
+ GuestbookDatabase.getGuestbook().getComment(Integer.valueOf(commentId));
+ if (existingComment == null) {
+ return Response.status(Status.NOT_FOUND).build();
+ }
+ return Response.ok(existingComment).build();
+ }
+
+ @POST
+ @Produces("text/xml")
+ @Consumes("text/xml")
+ public Response createComment(Comment comment, @Context UriInfo uriInfo) {
+ /*
+ * If no comment data was sent, then return a bad request.
+ */
+ if (comment == null) {
+ throw new WebApplicationException(Response.Status.BAD_REQUEST);
+ }
+
+ if (comment.getId() == null || comment.getMessage() == null || comment.getAuthor() == null) {
+ CommentError commentError = new CommentError();
+ commentError.setErrorMessage("Please include a comment ID, a message, and your name.");
+ Response resp =
+ Response.status(Response.Status.BAD_REQUEST).entity(commentError)
+ .type("application/xml").build();
+ throw new WebApplicationException(resp);
+ }
+
+ GuestbookDatabase.getGuestbook().storeComment(comment);
+ try {
+ return Response.created(new URI(uriInfo.getAbsolutePath() + "/" + comment.getId()))
+ .entity(comment).build();
+ } catch (URISyntaxException e) {
+ e.printStackTrace();
+ throw new WebApplicationException(e);
+ }
+ }
+
+ @PUT
+ public Response updateComment(Comment comment) throws GuestbookException {
+ if (comment.getId() == null || !Integer.valueOf(commentId).equals(comment.getId())) {
+ throw new GuestbookException("Unexpected ID.");
+ }
+
+ Comment existingComment =
+ GuestbookDatabase.getGuestbook().getComment(Integer.valueOf(comment.getId()));
+ if (existingComment == null) {
+ throw new GuestbookException("Cannot find existing comment to update.");
+ }
+ GuestbookDatabase.getGuestbook().storeComment(comment);
+ return Response.ok(comment).build();
+ }
+
+ @DELETE
+ public void deleteComment() {
+ GuestbookDatabase.getGuestbook().deleteComment(Integer.valueOf(commentId));
+ }
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/subresource/CommentError.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/subresource/CommentError.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/subresource/CommentError.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/subresource/CommentError.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.subresource;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "commenterror")
+public class CommentError {
+
+ private String errorMessage;
+
+ public String getErrorMessage() {
+ return errorMessage;
+ }
+
+ @XmlElement(name = "message")
+ public void setErrorMessage(String errorMessage) {
+ this.errorMessage = errorMessage;
+ }
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/subresource/GuestbookDatabase.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/subresource/GuestbookDatabase.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/subresource/GuestbookDatabase.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/subresource/GuestbookDatabase.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.subresource;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * A simple in-memory data store.
+ */
+public class GuestbookDatabase {
+
+ private static GuestbookDatabase guestbook = new GuestbookDatabase();
+
+ private Map<Integer, Comment> comments =
+ Collections
+ .synchronizedMap(new HashMap<Integer, Comment>());
+
+ private int counter = 0;
+
+ private GuestbookDatabase() {
+ /* private singleton constructor */
+ }
+
+ public static GuestbookDatabase getGuestbook() {
+ return guestbook;
+ }
+
+ public Comment getComment(Integer id) {
+ return comments.get(id);
+ }
+
+ public void storeComment(Comment c) {
+ comments.put(c.getId(), c);
+ }
+
+ public Collection<Integer> getCommentKeys() {
+ return comments.keySet();
+ }
+
+ public void deleteComment(Integer id) {
+ if (id == -99999) {
+ throw new Error("Simulated error");
+ }
+
+ if (comments.remove(id) == null) {
+ throw new NullPointerException("The comment did not previously exist.");
+ }
+ }
+
+ public synchronized int getAndIncrementCounter() {
+ ++counter;
+ return counter;
+ }
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/subresource/GuestbookException.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/subresource/GuestbookException.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/subresource/GuestbookException.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/subresource/GuestbookException.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,42 @@
+/*
+ * 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.subresource;
+
+public class GuestbookException extends Exception {
+
+ private static final long serialVersionUID = -1975560538784455458L;
+
+ public GuestbookException() {
+ super();
+ }
+
+ public GuestbookException(String message) {
+ super(message);
+ }
+
+ public GuestbookException(Throwable cause) {
+ super(cause);
+ }
+
+ public GuestbookException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/subresource/GuestbookResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/subresource/GuestbookResource.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/subresource/GuestbookResource.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/subresource/GuestbookResource.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,57 @@
+/*
+ * 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.subresource;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+
+@Path("guestbooksubresources")
+public class GuestbookResource {
+ //
+ // @Path("commentdata/{commentid}")
+ // @Produces(value = { "text/xml" })
+ // public CommentData resolveComment() {
+ // return new CommentData(aCommentId, null);
+ // }
+
+ @Path("commentdata/{commentid}")
+ public Object resolveComment(@PathParam("commentid") String aCommentId) {
+ return new CommentData(aCommentId);
+ }
+
+ @Path("commentdata")
+ public Object resolveComment() {
+ return new CommentData(null);
+ }
+
+ @GET
+ @Path("somecomment")
+ @Produces("text/xml")
+ public Object getComment(Comment c2) {
+ Comment c = new Comment();
+ c.setAuthor("Anonymous");
+ c.setId(10);
+ c.setMessage("Hello World!");
+ return c;
+ }
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/subresource/ObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/subresource/ObjectFactory.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/subresource/ObjectFactory.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/subresource/ObjectFactory.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.subresource;
+
+import javax.xml.bind.annotation.XmlRegistry;
+
+@XmlRegistry
+public class ObjectFactory {
+
+ public CommentError createCommentError() {
+ return new CommentError();
+ }
+
+ public Comment createComment() {
+ return new Comment();
+ }
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writerexceptions/Application.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writerexceptions/Application.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writerexceptions/Application.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writerexceptions/Application.java Fri Aug 7 03:10:22 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 org.apache.wink.itest.writerexceptions;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class Application extends javax.ws.rs.core.Application {
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ Set<Class<?>> clazzes = new HashSet<Class<?>>();
+ clazzes.add(ExceptionResource.class);
+ clazzes.add(IOExceptionMapper.class);
+ clazzes.add(MyMessageBodyWriterForStrings.class);
+ clazzes.add(NullPointerExceptionMapper.class);
+ return clazzes;
+ }
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writerexceptions/ExceptionResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writerexceptions/ExceptionResource.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writerexceptions/ExceptionResource.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writerexceptions/ExceptionResource.java Fri Aug 7 03:10:22 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 org.apache.wink.itest.writerexceptions;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+
+@Path("jaxrs/tests/providers/messagebodywriter/writer/messagebodywriterexceptions")
+public class ExceptionResource {
+
+ @POST
+ public String echo(String input) {
+ return "echo:" + input;
+ }
+
+ @GET
+ public Object something() {
+ return new Object();
+ }
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writerexceptions/IOExceptionMapper.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writerexceptions/IOExceptionMapper.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writerexceptions/IOExceptionMapper.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writerexceptions/IOExceptionMapper.java Fri Aug 7 03:10:22 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 org.apache.wink.itest.writerexceptions;
+
+import java.io.IOException;
+
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Provider;
+
+@Provider
+public class IOExceptionMapper implements ExceptionMapper<IOException> {
+
+ public Response toResponse(IOException arg0) {
+ return Response.status(455).entity("Invoked" + this.getClass().getName())
+ .type(MediaType.TEXT_PLAIN).build();
+ }
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writerexceptions/MyMessageBodyWriterForStrings.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writerexceptions/MyMessageBodyWriterForStrings.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writerexceptions/MyMessageBodyWriterForStrings.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writerexceptions/MyMessageBodyWriterForStrings.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,110 @@
+/*
+ * 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.writerexceptions;
+
+import java.io.IOException;
+import java.io.OutputStream;
+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.core.Response;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+
+@Provider
+@Produces(value = {"getsize/*", "writable/*", "writeto/*", "writetoafterwritten/*"})
+public class MyMessageBodyWriterForStrings implements MessageBodyWriter<String> {
+
+ public long getSize(String arg0, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4) {
+ if (arg4.isCompatible(new MediaType("getsize", "throwruntime"))) {
+ throw new RuntimeException();
+ } else if (arg4.isCompatible(new MediaType("getsize", "thrownull"))) {
+ throw new NullPointerException();
+ } else if (arg4.isCompatible(new MediaType("getsize", "throwwebapplicationexception"))) {
+ throw new WebApplicationException(Response.status(499).entity("can not write type")
+ .type("text/plain").build());
+ }
+
+ return -1;
+ }
+
+ public boolean isWriteable(Class<?> arg0, Type arg1, Annotation[] arg2, MediaType arg3) {
+ if (arg3.isCompatible(new MediaType("writable", "throwruntime"))) {
+ throw new RuntimeException();
+ } else if (arg3.isCompatible(new MediaType("writable", "thrownull"))) {
+ throw new NullPointerException();
+ } else if (arg3.isCompatible(new MediaType("writable", "throwwebapplicationexception"))) {
+ throw new WebApplicationException(Response.status(499).entity("can not write type")
+ .type("text/plain").build());
+ }
+
+ if (arg3.getType().equals("writeto") || arg3.getType().equals("getsize")
+ || arg3.getType().equals("writetoafterwritten")) {
+ return true;
+ }
+
+ return false;
+ }
+
+ public void writeTo(String arg0,
+ Class<?> arg1,
+ Type arg2,
+ Annotation[] arg3,
+ MediaType arg4,
+ MultivaluedMap<String, Object> arg5,
+ OutputStream arg6) throws IOException, WebApplicationException {
+ if (arg4.isCompatible(new MediaType("writeto", "thrownull"))) {
+ throw new NullPointerException();
+ } else if (arg4.isCompatible(new MediaType("writeto", "throwwebapplicationexception"))) {
+ throw new WebApplicationException(Response.status(498)
+ .entity("can not write type in writeto").type("text/plain").build());
+ } else if (arg4.isCompatible(new MediaType("writeto", "throwioexception"))) {
+ throw new IOException();
+ } else if (arg4.isCompatible(new MediaType("writeto", "throwruntime"))) {
+ throw new RuntimeException();
+ }
+
+ arg6.write("written".getBytes());
+ arg6.flush();
+ arg6.flush();
+ arg6.flush();
+
+ if (arg4.isCompatible(new MediaType("writetoafterwritten", "thrownull"))) {
+ throw new NullPointerException();
+ } else if (arg4.isCompatible(new MediaType("writetoafterwritten",
+ "throwwebapplicationexception"))) {
+ throw new WebApplicationException(Response.status(498)
+ .entity("can not write type in writeto").type("text/plain").build());
+ } else if (arg4.isCompatible(new MediaType("writetoafterwritten", "throwioexception"))) {
+ throw new IOException();
+ } else if (arg4.isCompatible(new MediaType("writetoafterwritten", "throwruntime"))) {
+ throw new RuntimeException();
+ }
+
+ arg6.write("writtensomemore".getBytes());
+ arg6.flush();
+
+ }
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writerexceptions/NullPointerExceptionMapper.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writerexceptions/NullPointerExceptionMapper.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writerexceptions/NullPointerExceptionMapper.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writerexceptions/NullPointerExceptionMapper.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.writerexceptions;
+
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Provider;
+
+@Provider
+public class NullPointerExceptionMapper implements ExceptionMapper<NullPointerException> {
+
+ public Response toResponse(NullPointerException arg0) {
+ return Response.status(495).entity("Invoked" + this.getClass().getName())
+ .type(MediaType.TEXT_PLAIN).build();
+ }
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/Application.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/Application.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/Application.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/Application.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,49 @@
+/*
+ * 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.util.HashSet;
+import java.util.Set;
+
+public class Application extends javax.ws.rs.core.Application {
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ Set<Class<?>> clazzes = new HashSet<Class<?>>();
+ clazzes.add(WriterResource.class);
+ return clazzes;
+ }
+
+ @Override
+ public Set<Object> getSingletons() {
+ Set<Object> objs = new HashSet<Object>();
+ objs.add(new MessageBodyWriterIsWritableClassDeque());
+ objs.add(new MessageBodyWriterIsWritableGenericEntitySetString());
+ objs.add(new MessageBodyWriterIsWritableGenericEntitySetInteger());
+ objs.add(new MessageBodyWriterIsWritableSet());
+ objs.add(new MessageBodyWriterIsWritableGetAnnotated());
+ objs.add(new MessageBodyWriterIsWritablePostAnnotated());
+ objs.add(new MessageBodyWriterIsWritableMediaTypeHashMap());
+ objs.add(new MessageBodyWriterIsWritableThrowsExceptions());
+ objs.add(new MessageBodyWriterContentLength());
+ objs.add(new MessageBodyWriterByteArrayContentLength());
+ return objs;
+ }
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/ArrayDeque.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/ArrayDeque.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/ArrayDeque.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/ArrayDeque.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,51 @@
+/*
+ * 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.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * this class is a dummy class to fill in for the ArrayDeque we were originally
+ * using from JDK6.
+ *
+ * @param <T>
+ */
+public class ArrayDeque<T> implements Deque<T> {
+
+ List<T> list = null;
+
+ public ArrayDeque() {
+ list = new ArrayList<T>();
+ }
+
+ public ArrayDeque(List<T> asList) {
+ list = asList;
+ }
+
+ public Iterator<T> iterator() {
+ return list.iterator();
+ }
+
+ public void add(T item) {
+ list.add(item);
+ }
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/CustomAnnotation.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/CustomAnnotation.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/CustomAnnotation.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/CustomAnnotation.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,32 @@
+/*
+ * 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.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(value = {ElementType.FIELD, ElementType.LOCAL_VARIABLE, ElementType.PARAMETER,
+ ElementType.METHOD})
+public @interface CustomAnnotation {
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/Deque.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/Deque.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/Deque.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/Deque.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,29 @@
+/*
+ * 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;
+
+/**
+ * this class is a dummy class to fill in for the Deque we were originally using
+ * from JDK6.
+ *
+ * @param <T>
+ */
+public interface Deque<T> extends Queue<T> {
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterByteArrayContentLength.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterByteArrayContentLength.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterByteArrayContentLength.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterByteArrayContentLength.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,76 @@
+/*
+ * 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.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+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
+public class MessageBodyWriterByteArrayContentLength implements MessageBodyWriter<byte[]> {
+
+ public long getSize(byte[] t,
+ Class<?> type,
+ Type genericType,
+ Annotation[] annotations,
+ MediaType mediaType) {
+ if (type.equals(byte[].class)) {
+ byte[] barr = (byte[])t;
+ if (mediaType.equals(new MediaType("length", "shorter"))) {
+ return barr.length - 10;
+ } else if (mediaType.equals(new MediaType("length", "longer"))) {
+ return barr.length + 10;
+ }
+ return -1;
+ }
+ return -1;
+ }
+
+ public boolean isWriteable(Class<?> type,
+ Type genericType,
+ Annotation[] annotations,
+ MediaType mediaType) {
+ if (type.equals(byte[].class)) {
+ return true;
+ }
+ return false;
+ }
+
+ public void writeTo(byte[] t,
+ Class<?> type,
+ Type genericType,
+ Annotation[] annotations,
+ MediaType mediaType,
+ MultivaluedMap<String, Object> httpHeaders,
+ OutputStream entityStream) throws IOException, WebApplicationException {
+ httpHeaders.putSingle("MyHeader", "used");
+ if (type.equals(byte[].class)) {
+ entityStream.write((byte[])t);
+ }
+ }
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterContentLength.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterContentLength.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterContentLength.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterContentLength.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,168 @@
+/*
+ * 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.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Vector;
+
+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
+public class MessageBodyWriterContentLength implements MessageBodyWriter<Object> {
+
+ public long getSize(Object arg0, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4) {
+
+ if (arg1.equals(Vector.class) && arg2.equals(Vector.class)) {
+ return 17;
+ }
+
+ if (arg1.equals(ArrayList.class)) {
+ if (arg2 instanceof ParameterizedType) {
+ ParameterizedType pt = (ParameterizedType)arg2;
+ if (pt.getRawType().equals(List.class)) {
+ if (pt.getActualTypeArguments().length == 1 && pt.getActualTypeArguments()[0]
+ .equals(Integer.class)) {
+ return 14;
+ // return true;
+ }
+ }
+ }
+
+ if (arg1.equals(ArrayList.class)) {
+ // return true;
+ }
+ }
+
+ if (arg1.equals(String.class)) {
+ boolean isGetFound = false;
+ for (Annotation ann : arg3) {
+ if (ann.annotationType().equals(CustomAnnotation.class)) {
+ isGetFound = true;
+ }
+ }
+
+ if (isGetFound) {
+ return 18;
+ }
+ }
+ return -1;
+ }
+
+ public boolean isWriteable(Class<?> arg0, Type arg1, Annotation[] arg2, MediaType arg3) {
+ if (arg0.equals(Vector.class)) {
+ return true;
+ }
+
+ if (arg0.equals(ArrayList.class)) {
+ if (arg1 instanceof ParameterizedType) {
+ ParameterizedType pt = (ParameterizedType)arg1;
+ if (pt.getRawType().equals(List.class)) {
+ if (pt.getActualTypeArguments().length == 1 && pt.getActualTypeArguments()[0]
+ .equals(Integer.class)) {
+ return true;
+ }
+ }
+ }
+
+ if (arg1.equals(ArrayList.class)) {
+ return true;
+ }
+ }
+
+ if (arg1.equals(String.class)) {
+ if (arg2 != null) {
+ for (Annotation ann : arg2) {
+ if (ann.annotationType().equals(CustomAnnotation.class)) {
+ return true;
+ }
+ }
+ }
+ }
+
+ return false;
+ }
+
+ public void writeTo(Object arg0,
+ Class<?> arg1,
+ Type arg2,
+ Annotation[] arg3,
+ MediaType arg4,
+ MultivaluedMap<String, Object> arg5,
+ OutputStream arg6) throws IOException, WebApplicationException {
+ if (arg1.equals(Vector.class)) {
+ Writer writer = new OutputStreamWriter(arg6);
+ writer.write("vector:");
+ Vector vec = (Vector)arg0;
+ for (Object o : vec) {
+ writer.write(o.toString());
+ }
+ writer.flush();
+ } else if (arg1.equals(ArrayList.class)) {
+ if (arg2 instanceof ParameterizedType) {
+ ParameterizedType pt = (ParameterizedType)arg2;
+ if (pt.getRawType().equals(List.class)) {
+ if (pt.getActualTypeArguments().length == 1 && pt.getActualTypeArguments()[0]
+ .equals(Integer.class)) {
+ Writer writer = new OutputStreamWriter(arg6);
+ writer.write("listinteger:");
+ List list = (List)arg0;
+ for (Object o : list) {
+ writer.write(o.toString());
+ }
+ writer.flush();
+ }
+ }
+ }
+ } else if (arg1.equals(String.class)) {
+ boolean isCustomAnnotationFound = false;
+ for (Annotation ann : arg3) {
+ if (ann.annotationType().equals(CustomAnnotation.class)) {
+ isCustomAnnotationFound = true;
+ }
+ }
+
+ if (isCustomAnnotationFound) {
+ arg6.write("string:".getBytes());
+ arg6.write(((String)arg0).getBytes());
+ }
+ } else {
+ Writer writer = new OutputStreamWriter(arg6);
+ writer.write("getannotation:");
+ List list = (List)arg0;
+ for (Object o : list) {
+ writer.write(o.toString());
+ }
+ writer.flush();
+ }
+ }
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterIsWritableClassDeque.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterIsWritableClassDeque.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterIsWritableClassDeque.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterIsWritableClassDeque.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,64 @@
+/*
+ * 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.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+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
+public class MessageBodyWriterIsWritableClassDeque implements MessageBodyWriter<Object> {
+
+ public long getSize(Object arg0, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4) {
+ return -1;
+ }
+
+ public boolean isWriteable(Class<?> arg0, Type arg1, Annotation[] arg2, MediaType arg3) {
+ if (Deque.class.isAssignableFrom(arg0)) {
+ return true;
+ }
+ return false;
+ }
+
+ public void writeTo(Object arg0,
+ Class<?> arg1,
+ Type arg2,
+ Annotation[] arg3,
+ MediaType arg4,
+ MultivaluedMap<String, Object> arg5,
+ OutputStream arg6) throws IOException, WebApplicationException {
+ Writer writer = new OutputStreamWriter(arg6);
+ Deque d = (Deque)arg0;
+ writer.write("deque:");
+ for (Object o : d) {
+ writer.write(o.toString());
+ }
+ writer.flush();
+ }
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterIsWritableGenericEntitySetInteger.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterIsWritableGenericEntitySetInteger.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterIsWritableGenericEntitySetInteger.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterIsWritableGenericEntitySetInteger.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,82 @@
+/*
+ * 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.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+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
+public class MessageBodyWriterIsWritableGenericEntitySetInteger implements
+ MessageBodyWriter<Object> {
+
+ public long getSize(Object arg0, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4) {
+ return -1;
+ }
+
+ public boolean isWriteable(Class<?> arg0, Type arg1, Annotation[] arg2, MediaType arg3) {
+ if (arg0.isAssignableFrom(HashSet.class)) {
+ if (arg1 instanceof ParameterizedType) {
+ ParameterizedType pt = (ParameterizedType)arg1;
+ Type[] args = pt.getActualTypeArguments();
+ if (args.length == 1 && args[0].equals(Integer.class)) {
+ if (pt.getRawType().equals(Set.class)) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ @SuppressWarnings("unchecked")
+ public void writeTo(Object arg0,
+ Class<?> arg1,
+ Type arg2,
+ Annotation[] arg3,
+ MediaType arg4,
+ MultivaluedMap<String, Object> arg5,
+ OutputStream arg6) throws IOException, WebApplicationException {
+ Writer writer = new OutputStreamWriter(arg6);
+ Set<Integer> s = (Set<Integer>)arg0;
+ writer.write("set<integer>:");
+ List<Integer> list = new ArrayList<Integer>(s);
+ Collections.sort(list);
+ for (Object o : list) {
+ writer.write(o.toString());
+ }
+ writer.flush();
+ }
+}