Return-Path: Delivered-To: apmail-incubator-wink-commits-archive@minotaur.apache.org Received: (qmail 56966 invoked from network); 23 Jun 2009 10:14:26 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 23 Jun 2009 10:14:26 -0000 Received: (qmail 72454 invoked by uid 500); 23 Jun 2009 10:14:37 -0000 Delivered-To: apmail-incubator-wink-commits-archive@incubator.apache.org Received: (qmail 72348 invoked by uid 500); 23 Jun 2009 10:14:36 -0000 Mailing-List: contact wink-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: wink-dev@incubator.apache.org Delivered-To: mailing list wink-commits@incubator.apache.org Delivered-To: moderator for wink-commits@incubator.apache.org Received: (qmail 93452 invoked by uid 99); 23 Jun 2009 05:40:06 -0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r787553 [19/34] - in /incubator/wink/contrib/ibm-jaxrs/tests: ./ fvt/ fvt/demo/ fvt/demo/jaxrs/ fvt/demo/jaxrs/cache/ fvt/demo/jaxrs/cache/server/ fvt/demo/jaxrs/cache/test/ fvt/demo/jaxrs/datasource/ fvt/demo/jaxrs/datasource/server/ fvt/d... Date: Tue, 23 Jun 2009 05:38:19 -0000 To: wink-commits@incubator.apache.org From: ngallardo@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090623053843.B6C6A23889DC@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreader/server/MessageBodyReaderGenericType.java URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreader/server/MessageBodyReaderGenericType.java?rev=787553&view=auto ============================================================================== --- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreader/server/MessageBodyReaderGenericType.java (added) +++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreader/server/MessageBodyReaderGenericType.java Tue Jun 23 05:37:57 2009 @@ -0,0 +1,127 @@ +/* + * 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 jaxrs.tests.providers.messagebodyreader.server; + +import java.io.IOException; +import java.io.InputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.List; + +import javax.ws.rs.Consumes; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.ext.MessageBodyReader; +import javax.ws.rs.ext.Provider; + +import org.apache.cxf.helpers.IOUtils; + +@Provider +@Consumes("custom/generic") +public class MessageBodyReaderGenericType implements MessageBodyReader { + + public boolean isReadable(Class arg0, Type arg1, Annotation[] arg2, MediaType arg3) { + if (List.class.isAssignableFrom(arg0)) { + if (arg1 instanceof ParameterizedType) { + ParameterizedType pt = (ParameterizedType) arg1; + Type rawType = pt.getRawType(); + if ((rawType instanceof Class) + && (List.class.isAssignableFrom((Class) rawType))) { + Type[] genericTypeArguments = pt.getActualTypeArguments(); + if (genericTypeArguments.length == 1) { + Class argType = (Class) genericTypeArguments[0]; + if (Integer.class.isAssignableFrom(argType) + || String.class.isAssignableFrom(argType)) { + return true; + } + } + } + } else if (arg1 instanceof Class) { + return true; + } + } + + if (arg1 instanceof Class) { + if (Integer.class.isAssignableFrom((Class) arg1)) { + return true; + } + } + return false; + } + + public Object readFrom(Class arg0, Type arg1, Annotation[] arg2, MediaType arg3, MultivaluedMap arg4, InputStream arg5) + throws IOException, WebApplicationException { + if (List.class.isAssignableFrom(arg0)) { + if (arg1 instanceof ParameterizedType) { + ParameterizedType pt = (ParameterizedType) arg1; + Type rawType = pt.getRawType(); + if ((rawType instanceof Class) + && (List.class.isAssignableFrom((Class) rawType))) { + Type[] genericTypeArguments = pt.getActualTypeArguments(); + if (genericTypeArguments.length == 1) { + Class argType = (Class) genericTypeArguments[0]; + if (Integer.class.isAssignableFrom(argType)) { + String str = IOUtils.toString(arg5); + String[] splitlines = str.split("\r\n"); + List ret = new ArrayList(); + for (String s : splitlines) { + ret.add(Integer.valueOf(s)); + } + return ret; + } else if (String.class.isAssignableFrom(argType)) { + String str = IOUtils.toString(arg5); + String[] splitlines = str.split("\r\n"); + List ret = new ArrayList(); + for (String s : splitlines) { + ret.add("str:" + s); + } + return ret; + } + } + } + } else if (arg1 instanceof Class) { + String str = IOUtils.toString(arg5); + String[] splitlines = str.split("\r\n"); + List ret = new ArrayList(); + for (String s : splitlines) { + ret.add("obj:" + s); + } + return ret; + } + } + + if (arg1 instanceof Class) { + if (Integer.class.isAssignableFrom((Class) arg1)) { + String str = IOUtils.toString(arg5); + String[] splitlines = str.split("\r\n"); + int sum = 0; + for (String s : splitlines) { + sum += Integer.valueOf(s).intValue(); + } + return Integer.valueOf(sum); + } + } + return null; + } + +} Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreader/server/MessageBodyReaderIsReadableThrowsRuntimeException.java URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreader/server/MessageBodyReaderIsReadableThrowsRuntimeException.java?rev=787553&view=auto ============================================================================== --- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreader/server/MessageBodyReaderIsReadableThrowsRuntimeException.java (added) +++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreader/server/MessageBodyReaderIsReadableThrowsRuntimeException.java Tue Jun 23 05:37:57 2009 @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package jaxrs.tests.providers.messagebodyreader.server; + +import java.io.IOException; +import java.io.InputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import javax.ws.rs.Consumes; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.ext.MessageBodyReader; +import javax.ws.rs.ext.Provider; + +@Provider +@Consumes("custom/runtimeexception") +public class MessageBodyReaderIsReadableThrowsRuntimeException implements MessageBodyReader { + + public boolean isReadable(Class arg0, Type arg1, Annotation[] arg2, MediaType arg3) { + throw new NullPointerException(); + } + + public Object readFrom(Class arg0, Type arg1, Annotation[] arg2, MediaType arg3, MultivaluedMap arg4, InputStream arg5) + throws IOException, WebApplicationException { + return null; + } + +} Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreader/server/MessageBodyReaderIsReadableThrowsWebAppException.java URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreader/server/MessageBodyReaderIsReadableThrowsWebAppException.java?rev=787553&view=auto ============================================================================== --- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreader/server/MessageBodyReaderIsReadableThrowsWebAppException.java (added) +++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreader/server/MessageBodyReaderIsReadableThrowsWebAppException.java Tue Jun 23 05:37:57 2009 @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package jaxrs.tests.providers.messagebodyreader.server; + +import java.io.IOException; +import java.io.InputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import javax.ws.rs.Consumes; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.ext.MessageBodyReader; +import javax.ws.rs.ext.Provider; + +@Provider +@Consumes("custom/webapplicationexception") +public class MessageBodyReaderIsReadableThrowsWebAppException implements MessageBodyReader { + + public boolean isReadable(Class arg0, Type arg1, Annotation[] arg2, MediaType arg3) { + throw new WebApplicationException(478); + } + + public Object readFrom(Class arg0, Type arg1, Annotation[] arg2, MediaType arg3, MultivaluedMap arg4, InputStream arg5) + throws IOException, WebApplicationException { + return null; + } + +} Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreader/server/MessageBodyReaderMediaTypeSet.java URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreader/server/MessageBodyReaderMediaTypeSet.java?rev=787553&view=auto ============================================================================== --- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreader/server/MessageBodyReaderMediaTypeSet.java (added) +++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreader/server/MessageBodyReaderMediaTypeSet.java Tue Jun 23 05:37:57 2009 @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package jaxrs.tests.providers.messagebodyreader.server; + +import java.io.IOException; +import java.io.InputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +import javax.ws.rs.Consumes; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.ext.MessageBodyReader; +import javax.ws.rs.ext.Provider; + +import org.apache.cxf.helpers.IOUtils; + +@Provider +@Consumes("custom/type") +public class MessageBodyReaderMediaTypeSet implements MessageBodyReader { + + public boolean isReadable(Class arg0, Type arg1, Annotation[] arg2, MediaType arg3) { + if (MediaType.valueOf("custom/type").isCompatible(arg3)) { + return true; + } + return false; + } + + public Set readFrom(Class arg0, Type arg1, Annotation[] arg2, MediaType arg3, MultivaluedMap arg4, InputStream arg5) + throws IOException, WebApplicationException { + String str = null; + try { + str = IOUtils.toString(arg5); + } catch (IOException e) { + throw new WebApplicationException(e); + } + return new HashSet(Arrays.asList(str.split("\r\n"))); + } + +} Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreader/server/MessageBodyReaderReadFromDifferent.java URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreader/server/MessageBodyReaderReadFromDifferent.java?rev=787553&view=auto ============================================================================== --- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreader/server/MessageBodyReaderReadFromDifferent.java (added) +++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreader/server/MessageBodyReaderReadFromDifferent.java Tue Jun 23 05:37:57 2009 @@ -0,0 +1,70 @@ +/* + * 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 jaxrs.tests.providers.messagebodyreader.server; + +import java.io.IOException; +import java.io.InputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import javax.ws.rs.Consumes; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.ext.MessageBodyReader; +import javax.ws.rs.ext.Provider; + +@Provider +@Consumes( { "custom/long", "custom/int", "custom/byte", "custom/short" }) +public class MessageBodyReaderReadFromDifferent implements MessageBodyReader { + + public boolean isReadable(Class arg0, Type arg1, Annotation[] arg2, MediaType arg3) { + if (Integer.class.isAssignableFrom(arg0) + || Long.class.isAssignableFrom(arg0) + || Byte.class.isAssignableFrom(arg0) + || Short.class.isAssignableFrom(arg0)) { + return true; + } + return false; + } + + public Number readFrom(Class arg0, Type arg1, Annotation[] arg2, MediaType arg3, MultivaluedMap arg4, InputStream arg5) + throws IOException, WebApplicationException { + if (arg0.isAssignableFrom(Long.class)) { + return Long.valueOf(Long.MAX_VALUE); + } + if (arg0.isAssignableFrom(Integer.class)) { + return Integer.valueOf(Integer.MAX_VALUE); + } + + for (Annotation ann : arg2) { + if (CustomAnnotation.class.equals(ann.annotationType())) { + return Short.valueOf(Short.MAX_VALUE); + } + } + + if (arg3.isCompatible(MediaType.valueOf("custom/byte"))) { + return Byte.valueOf(Byte.MAX_VALUE); + } + + return null; + } + +} Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreader/server/MessageBodyReaderThrowsExceptions.java URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreader/server/MessageBodyReaderThrowsExceptions.java?rev=787553&view=auto ============================================================================== --- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreader/server/MessageBodyReaderThrowsExceptions.java (added) +++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreader/server/MessageBodyReaderThrowsExceptions.java Tue Jun 23 05:37:57 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 jaxrs.tests.providers.messagebodyreader.server; + +import java.io.IOException; +import java.io.InputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; +import java.util.List; + +import javax.ws.rs.Consumes; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.ext.MessageBodyReader; +import javax.ws.rs.ext.Provider; + +import org.apache.cxf.helpers.IOUtils; + +@Provider +@Consumes("custom/exception") +public class MessageBodyReaderThrowsExceptions implements MessageBodyReader { + + public boolean isReadable(Class arg0, Type arg1, Annotation[] arg2, MediaType arg3) { + return true; + } + + public Object readFrom(Class arg0, Type arg1, Annotation[] arg2, MediaType arg3, MultivaluedMap arg4, InputStream arg5) + throws IOException, WebApplicationException { + String str = null; + try { + str = IOUtils.toString(arg5); + } catch (IOException e) { + throw new WebApplicationException(e); + } + + if ("ioexception".equals(str)) { + throw new IOException("Error"); + } else if ("webapplicationexception".equals(str)) { + throw new WebApplicationException(477); + } else if (str.startsWith("closeinput")) { + arg5.close(); + } else if ("thrownull".equals(str)) { + throw new NullPointerException(); + } + StringBuilder sb = new StringBuilder(str); + /* + * leave this with weird capitalization. header keys should not be case + * sensitive. + */ + List headerValues = arg4.get("myCuStomHeaderToAppend"); + if (headerValues != null) { + for (String value : headerValues) { + sb.append(value); + } + } + return sb.toString(); + } + +} Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreader/server/MyReaderAnnotation.java URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreader/server/MyReaderAnnotation.java?rev=787553&view=auto ============================================================================== --- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreader/server/MyReaderAnnotation.java (added) +++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreader/server/MyReaderAnnotation.java Tue Jun 23 05:37:57 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 jaxrs.tests.providers.messagebodyreader.server; + +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 }) +public @interface MyReaderAnnotation { + +} Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreader/server/ReaderResource.java URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreader/server/ReaderResource.java?rev=787553&view=auto ============================================================================== --- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreader/server/ReaderResource.java (added) +++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreader/server/ReaderResource.java Tue Jun 23 05:37:57 2009 @@ -0,0 +1,222 @@ +/* + * 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 jaxrs.tests.providers.messagebodyreader.server; + +import java.util.Deque; +import java.util.HashMap; +import java.util.List; +import java.util.Queue; +import java.util.Set; + +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.core.MediaType; + +@Path("jaxrs/tests/providers/messagebodyreader/reader") +public class ReaderResource { + + private static int counter = 0; + + @Path("requestcontenttype") + @POST + @Consumes(MediaType.WILDCARD) + public String postReaderNoGenericEntityWildcard(byte[] barr) { + return "hello world"; + } + + @Path("requestcontenttype") + @POST + @Consumes(MediaType.APPLICATION_OCTET_STREAM) + public String postReaderNoGenericEntityOctetStream(byte[] barr) { + return "invoked octet-stream method"; + } + + @Path("unexpectedclasstype") + @POST + public String postReaderNoGenericEntity(HashMap entity) { + return "hello"; + } + + @Path("classtype") + @POST + public String postReaderNoGenericEntity(Deque entity) { + StringBuilder sb = new StringBuilder(); + for (String s : entity) { + sb.append("echo:" + s); + } + return sb.toString(); + } + + @Path("nogenericentity") + @POST + public String postReaderNoGenericEntity(String str) { + return "echo:" + str; + } + + @Path("genericentityempty") + @POST + public String postReaderGenericEntityEmpty(Queue entity) { + StringBuilder sb = new StringBuilder(); + for (Object s : entity) { + sb.append(s.toString() + " there"); + } + return sb.toString(); + } + + @Path("genericentityqueuestring") + @POST + public String postReaderGenericEntityListString(Queue entity) { + StringBuilder sb = new StringBuilder(); + for (String s : entity) { + sb.append(s + " there"); + } + return sb.toString(); + } + + @Path("genericentityqueueobject") + @POST + public String postReaderGenericEntityListObject(Queue entity) { + StringBuilder sb = new StringBuilder(); + for (Object o : entity) { + sb.append(o + " there"); + } + return sb.toString(); + } + + @Path("notannotatedentity") + @POST + public String postResponseReaderNotAnnotated(List entity) { + StringBuilder sb = new StringBuilder(); + for (String s : entity) { + sb.append(s + " there"); + } + return sb.toString(); + } + + @Path("annotatedentity") + @POST + public String postResponseReaderAnnotated(@MyReaderAnnotation List entity) { + StringBuilder sb = new StringBuilder(); + for (String s : entity) { + sb.append(s + " there"); + } + return sb.toString(); + } + + @Path("multipleannotatedentity") + @POST + public String postResponseReaderAnnotatedMultipleTimes(@CustomAnnotation @MyReaderAnnotation List entity) { + StringBuilder sb = new StringBuilder(); + for (String s : entity) { + sb.append(s + " there"); + } + return sb.toString(); + } + + @Path("mediatype") + @POST + public String postReaderMediaType(Set entity) { + StringBuilder sb = new StringBuilder(); + for (String s : entity) { + sb.append(s + " there"); + } + return sb.toString(); + } + + @Path("readfrom") + @POST + public String postReaderReadFrom(String str) { + if ("clear".equals(str)) { + counter = -1; + } + ++counter; + return counter + "postReaderReadFrom:" + str; + } + + @Path("readdifferentlyinteger") + @POST + public String postReaderReadFromClass(Integer value) { + return "" + value; + } + + @Path("readdifferentlylong") + @POST + public String postReaderReadFromClass(Long value) { + return "" + value; + } + + @Path("readdifferentlyshort") + @POST + public String postReaderReadFromAnnotation(@CustomAnnotation Short value) { + return "" + value; + } + + @Path("readdifferentlyshortnoannotation") + @POST + public String postReaderReadFromNoAnnotation(Short value) { + return "" + value; + } + + @Path("readdifferentlybytemediatype") + @POST + public String postReaderReadFromMediaType(Byte value) { + return "" + value; + } + + @Path("readdifferentlygenericlist") + @POST + public String postReaderReadFromGenericType(List value) { + StringBuilder sb = new StringBuilder(); + sb.append("listnonspecified:"); + for (Object o : value) { + sb.append(o.toString()); + } + return sb.toString(); + } + + @Path("readdifferentlygenericliststring") + @POST + public String postReaderReadFromGenericTypeListString(List value) { + StringBuilder sb = new StringBuilder(); + sb.append("liststring:"); + for (String s : value) { + sb.append(s); + } + return sb.toString(); + } + + @Path("readdifferentlygenericlistinteger") + @POST + public String postReaderReadFromGenericTypeListInteger(List value) { + StringBuilder sb = new StringBuilder(); + sb.append("listinteger:"); + for (Integer i : value) { + sb.append(i.toString()); + } + return sb.toString(); + } + + @Path("readdifferentlygenericinteger") + @POST + public String postReaderReadFromGenericTypeInteger(Integer value) { + return "integer:" + value; + } +} Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreader/test/MessageBodyReaderTest.java URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreader/test/MessageBodyReaderTest.java?rev=787553&view=auto ============================================================================== --- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreader/test/MessageBodyReaderTest.java (added) +++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreader/test/MessageBodyReaderTest.java Tue Jun 23 05:37:57 2009 @@ -0,0 +1,1137 @@ +/* + * 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 jaxrs.tests.providers.messagebodyreader.test; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; + +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.ext.MessageBodyReader; + +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.HttpException; +import org.apache.commons.httpclient.methods.InputStreamRequestEntity; +import org.apache.commons.httpclient.methods.PostMethod; +import org.apache.commons.httpclient.methods.StringRequestEntity; + +import framework.defaults.test.FVTTestCase; + +public class MessageBodyReaderTest extends FVTTestCase { + + public static junit.framework.Test suite() { + return FVTTestCase.getTestSuite(MessageBodyReaderTest.class, + "jaxrs.tests.providers.messagebodyreader.server.Application"); + } + + /** + * Tests that an improperly formatted request content type is handled. + * + * @throws HttpException + * @throws IOException + */ + public void testReaderImproperlyFormattedContentType() + throws HttpException, IOException { + HttpClient client = new HttpClient(); + + PostMethod postMethod = new PostMethod( + getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/requestcontenttype"); + postMethod.setRequestEntity(new StringRequestEntity( + "Hello\r\nWorld\r\n", "", "UTF-8")); + try { + client.executeMethod(postMethod); + assertEquals(500, postMethod.getStatusCode()); + assertLogContainsException("java.lang.IllegalArgumentException"); + } finally { + postMethod.releaseConnection(); + } + } + + /** + * Tests that an empty request content type is handled. + * + * @throws HttpException + * @throws IOException + */ + public void testReaderNoContentType() throws HttpException, IOException { + HttpClient client = new HttpClient(); + + PostMethod postMethod = new PostMethod( + getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/requestcontenttype"); + byte[] requestContent = { 0, 0, 0 }; + postMethod.setRequestEntity(new InputStreamRequestEntity( + new ByteArrayInputStream(requestContent))); + try { + client.executeMethod(postMethod); + assertEquals(200, postMethod.getStatusCode()); + /* + * should only invoke hello world + */ + assertEquals("hello world", postMethod.getResponseBodyAsString()); + } finally { + postMethod.releaseConnection(); + } + } + + /** + * Tests that the + * {@link MessageBodyReader#isReadable(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 testReaderIsReadableUnexpectedClassType() throws HttpException, + IOException { + HttpClient client = new HttpClient(); + + PostMethod postMethod = new PostMethod( + getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/unexpectedclasstype"); + postMethod.setRequestEntity(new StringRequestEntity( + "Hello\r\nWorld\r\n", "text/plain", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(415, postMethod.getStatusCode()); + } finally { + postMethod.releaseConnection(); + } + } + + /** + * Tests that the + * {@link MessageBodyReader#isReadable(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 testReaderIsReadableExpectedClassType() throws HttpException, + IOException { + HttpClient client = new HttpClient(); + + PostMethod postMethod = new PostMethod(getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/classtype"); + postMethod.setRequestEntity(new StringRequestEntity( + "Hello\r\nWorld\r\n", "text/plain", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + assertEquals("echo:Helloecho:World", postMethod + .getResponseBodyAsString()); + } finally { + postMethod.releaseConnection(); + } + } + + /** + * Tests that the + * {@link MessageBodyReader#isReadable(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)} + * method works when there is no generic entity type. + * + * @throws HttpException + * @throws IOException + */ + public void testReaderIsReadableNoGenericEntityType() throws HttpException, + IOException { + HttpClient client = new HttpClient(); + + PostMethod postMethod = new PostMethod( + getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/nogenericentity"); + postMethod.setRequestEntity(new StringRequestEntity( + "Hello\r\nWorld\r\n", "text/plain", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + String response = postMethod.getResponseBodyAsString(); + assertEquals("echo:Hello\r\nWorld\r\n", response); + } finally { + postMethod.releaseConnection(); + } + } + + /** + * Tests that the + * {@link MessageBodyReader#isReadable(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)} + * method works when there is no argument type specified on the generic + * type. + * + * @throws HttpException + * @throws IOException + */ + public void testReaderIsReadableGenericEntityEmptyType() + throws HttpException, IOException { + HttpClient client = new HttpClient(); + + PostMethod postMethod = new PostMethod( + getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/genericentityempty"); + postMethod.setRequestEntity(new StringRequestEntity( + "Hello\r\nWorld\r\n", "text/plain", "UTF-8")); + try { + client.executeMethod(postMethod); + assertEquals(415, postMethod.getStatusCode()); + } finally { + postMethod.releaseConnection(); + } + } + + /** + * Tests that the + * {@link MessageBodyReader#isReadable(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 testReaderIsReadableGenericEntityTypeCorrect() + throws HttpException, IOException { + HttpClient client = new HttpClient(); + + PostMethod postMethod = new PostMethod( + getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/genericentityqueuestring"); + postMethod.setRequestEntity(new StringRequestEntity( + "Hello\r\nWorld\r\n", "text/plain", "UTF-8")); + try { + client.executeMethod(postMethod); + assertEquals(200, postMethod.getStatusCode()); + assertEquals("Hello thereWorld there", postMethod + .getResponseBodyAsString()); + } finally { + postMethod.releaseConnection(); + } + } + + /** + * Tests that the + * {@link MessageBodyReader#isReadable(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 testReaderIsReadableGenericEntityTypeIncorrect() + throws HttpException, IOException { + HttpClient client = new HttpClient(); + + PostMethod postMethod = new PostMethod( + getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/genericentityqueueobject"); + postMethod.setRequestEntity(new StringRequestEntity( + "Hello\r\nWorld\r\n", "text/plain", "UTF-8")); + try { + client.executeMethod(postMethod); + assertEquals(415, postMethod.getStatusCode()); + } finally { + postMethod.releaseConnection(); + } + } + + /** + * Tests that the + * {@link MessageBodyReader#isReadable(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)} + * method still works without an annotated entity parameter. + * + * @throws HttpException + * @throws IOException + */ + public void testReaderIsReadableEntityParameterNotAnnotated() + throws HttpException, IOException { + HttpClient client = new HttpClient(); + + PostMethod postMethod = new PostMethod( + getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/notannotatedentity"); + postMethod.setRequestEntity(new StringRequestEntity( + "Hello\r\nWorld\r\n", "text/plain", "UTF-8")); + postMethod.addRequestHeader("Accept", "text/plain"); + try { + client.executeMethod(postMethod); + + assertEquals(415, postMethod.getStatusCode()); + } finally { + postMethod.releaseConnection(); + } + } + + /** + * Tests that the + * {@link MessageBodyReader#isReadable(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 testReaderIsReadableEntityParameterAnnotated() + throws HttpException, IOException { + HttpClient client = new HttpClient(); + + PostMethod postMethod = new PostMethod( + getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/annotatedentity"); + postMethod.setRequestEntity(new StringRequestEntity( + "Hello\r\nWorld\r\n", "text/plain", "UTF-8")); + postMethod.addRequestHeader("Accept", "text/plain"); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + assertEquals("text/plain", postMethod.getResponseHeader( + "Content-Type").getValue()); + assertEquals("Hello thereWorld there", postMethod + .getResponseBodyAsString()); + } finally { + postMethod.releaseConnection(); + } + } + + /** + * Tests that the + * {@link MessageBodyReader#isReadable(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)} + * method is passed multiple annotations. + * + * @throws HttpException + * @throws IOException + */ + public void testReaderIsReadableEntityParameterAnnotatedMultiple() + throws HttpException, IOException { + HttpClient client = new HttpClient(); + + PostMethod postMethod = new PostMethod( + getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/multipleannotatedentity"); + postMethod.setRequestEntity(new StringRequestEntity( + "Hello\r\nWorld\r\n", "text/plain", "UTF-8")); + postMethod.addRequestHeader("Accept", "text/plain"); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + assertEquals("text/plain", postMethod.getResponseHeader( + "Content-Type").getValue()); + assertEquals("Hello thereWorld there", postMethod + .getResponseBodyAsString()); + } finally { + postMethod.releaseConnection(); + } + } + + /** + * Tests that the + * {@link MessageBodyReader#isReadable(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 testReaderIsReadableIncorrectMediaType() throws HttpException, + IOException { + HttpClient client = new HttpClient(); + + PostMethod postMethod = new PostMethod(getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/mediatype"); + postMethod.setRequestEntity(new StringRequestEntity( + "Hello\r\nWorld\r\n", "text/plain", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(415, postMethod.getStatusCode()); + } finally { + postMethod.releaseConnection(); + } + } + + /** + * Tests that the + * {@link MessageBodyReader#isReadable(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 testReaderIsReadableCorrectMediaType() throws HttpException, + IOException { + HttpClient client = new HttpClient(); + + PostMethod postMethod = new PostMethod(getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/mediatype"); + postMethod.setRequestEntity(new StringRequestEntity( + "Hello\r\nWorld\r\n", "custom/type", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + + String response = postMethod.getResponseBodyAsString(); + assertTrue(response, response.contains("Hello there")); + assertTrue(response, response.contains("World there")); + } finally { + postMethod.releaseConnection(); + } + } + + /** + * When a {@link RuntimeException} is propagated back from + * {@link MessageBodyReader#isReadable(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 testReaderIsReadableThrowsRuntimeException() + throws HttpException, IOException { + HttpClient client = new HttpClient(); + + PostMethod postMethod = new PostMethod(getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readfrom"); + postMethod.setRequestEntity(new StringRequestEntity("clear", + "custom/exception", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + + String response = postMethod.getResponseBodyAsString(); + assertEquals("0postReaderReadFrom:clear", response); + } finally { + postMethod.releaseConnection(); + } + + postMethod = new PostMethod(getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readfrom"); + postMethod.setRequestEntity(new StringRequestEntity("Hello World", + "custom/exception", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + + String response = postMethod.getResponseBodyAsString(); + assertEquals("1postReaderReadFrom:Hello World", response); + } finally { + postMethod.releaseConnection(); + } + + postMethod = new PostMethod(getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readfrom"); + postMethod.setRequestEntity(new StringRequestEntity("clear", + "custom/exception", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + + String response = postMethod.getResponseBodyAsString(); + assertEquals("0postReaderReadFrom:clear", response); + } finally { + postMethod.releaseConnection(); + } + + postMethod = new PostMethod(getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readfrom"); + postMethod.setRequestEntity(new StringRequestEntity("thrownull", + "custom/runtimeexception", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(500, postMethod.getStatusCode()); + + String response = postMethod.getResponseBodyAsString(); + assertLogContainsException(response, + "javax.servlet.ServletException"); + } finally { + postMethod.releaseConnection(); + } + + postMethod = new PostMethod(getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readfrom"); + postMethod.setRequestEntity(new StringRequestEntity("hello world", + "custom/exception", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + + String response = postMethod.getResponseBodyAsString(); + assertEquals("1postReaderReadFrom:hello world", response); + } finally { + postMethod.releaseConnection(); + } + } + + /** + * When a {@link WebApplicationException} is propagated back from + * {@link MessageBodyReader#isReadable(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 testReaderIsReadableThrowsWebApplicationException() + throws HttpException, IOException { + HttpClient client = new HttpClient(); + + PostMethod postMethod = new PostMethod(getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readfrom"); + postMethod.setRequestEntity(new StringRequestEntity("clear", + "custom/exception", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + + String response = postMethod.getResponseBodyAsString(); + assertEquals("0postReaderReadFrom:clear", response); + } finally { + postMethod.releaseConnection(); + } + + postMethod = new PostMethod(getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readfrom"); + postMethod.setRequestEntity(new StringRequestEntity("Hello World", + "custom/exception", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + + String response = postMethod.getResponseBodyAsString(); + assertEquals("1postReaderReadFrom:Hello World", response); + } finally { + postMethod.releaseConnection(); + } + + postMethod = new PostMethod(getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readfrom"); + postMethod.setRequestEntity(new StringRequestEntity("clear", + "custom/exception", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + + String response = postMethod.getResponseBodyAsString(); + assertEquals("0postReaderReadFrom:clear", response); + } finally { + postMethod.releaseConnection(); + } + + postMethod = new PostMethod(getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readfrom"); + postMethod.setRequestEntity(new StringRequestEntity("thrownull", + "custom/webapplicationexception", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(478, postMethod.getStatusCode()); + } finally { + postMethod.releaseConnection(); + } + + postMethod = new PostMethod(getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readfrom"); + postMethod.setRequestEntity(new StringRequestEntity("hello world", + "custom/exception", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + + String response = postMethod.getResponseBodyAsString(); + assertEquals("1postReaderReadFrom:hello world", response); + } finally { + postMethod.releaseConnection(); + } + } + + /** + * Tests that a + * {@link MessageBodyReader#readFrom(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType, javax.ws.rs.core.MultivaluedMap, InputStream)} + * can return a different object based on the class argument. + * + * @throws IOException + * @throws HttpException + */ + public void testReaderReadFromClassType() throws HttpException, IOException { + HttpClient client = new HttpClient(); + + PostMethod postMethod = new PostMethod( + getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readdifferentlylong"); + postMethod.setRequestEntity(new StringRequestEntity("empty", + "custom/long", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + String response = postMethod.getResponseBodyAsString(); + assertEquals("" + Long.MAX_VALUE, response); + } finally { + postMethod.releaseConnection(); + } + + postMethod = new PostMethod( + getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readdifferentlyinteger"); + postMethod.setRequestEntity(new StringRequestEntity("empty", + "custom/int", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + + String response = postMethod.getResponseBodyAsString(); + assertEquals("" + Integer.MAX_VALUE, response); + } finally { + postMethod.releaseConnection(); + } + } + + /** + * Tests that a + * {@link MessageBodyReader#readFrom(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType, javax.ws.rs.core.MultivaluedMap, InputStream)} + * can return a different object based on the generic type argument. + * + * @throws HttpException + * @throws IOException + */ + public void testReaderReadFromGenericType() throws HttpException, + IOException { + HttpClient client = new HttpClient(); + + PostMethod postMethod = new PostMethod( + getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readdifferentlygenericlist"); + postMethod.setRequestEntity(new StringRequestEntity( + "1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10", + "custom/generic", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + String response = postMethod.getResponseBodyAsString(); + assertEquals( + "listnonspecified:obj:1obj:2obj:3obj:4obj:5obj:6obj:7obj:8obj:9obj:10", + response); + } finally { + postMethod.releaseConnection(); + } + + postMethod = new PostMethod( + getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readdifferentlygenericliststring"); + postMethod.setRequestEntity(new StringRequestEntity( + "1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10", + "custom/generic", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + + String response = postMethod.getResponseBodyAsString(); + assertEquals( + "liststring:str:1str:2str:3str:4str:5str:6str:7str:8str:9str:10", + response); + } finally { + postMethod.releaseConnection(); + } + + postMethod = new PostMethod( + getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readdifferentlygenericlistinteger"); + postMethod.setRequestEntity(new StringRequestEntity( + "1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10", + "custom/generic", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + + String response = postMethod.getResponseBodyAsString(); + assertEquals("listinteger:12345678910", response); + } finally { + postMethod.releaseConnection(); + } + + postMethod = new PostMethod( + getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readdifferentlygenericinteger"); + postMethod.setRequestEntity(new StringRequestEntity( + "1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10", + "custom/generic", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + + String response = postMethod.getResponseBodyAsString(); + assertEquals("integer:55", response); + } finally { + postMethod.releaseConnection(); + } + } + + /** + * Tests that a + * {@link MessageBodyReader#readFrom(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType, javax.ws.rs.core.MultivaluedMap, InputStream)} + * can return a different object based on the annotations argument. + * + * @throws HttpException + * @throws IOException + */ + public void testReaderReadFromAnnotationType() throws HttpException, + IOException { + HttpClient client = new HttpClient(); + + PostMethod postMethod = new PostMethod( + getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readdifferentlyshort"); + postMethod.setRequestEntity(new StringRequestEntity("empty", + "custom/short", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + String response = postMethod.getResponseBodyAsString(); + assertEquals("" + Short.MAX_VALUE, response); + } finally { + postMethod.releaseConnection(); + } + + postMethod = new PostMethod( + getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readdifferentlyshortnoannotation"); + postMethod.setRequestEntity(new StringRequestEntity("empty", + "custom/short", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + + String response = postMethod.getResponseBodyAsString(); + assertEquals("null", response); + } finally { + postMethod.releaseConnection(); + } + } + + /** + * Tests that a + * {@link MessageBodyReader#readFrom(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType, javax.ws.rs.core.MultivaluedMap, InputStream)} + * can return a different object based on the media type argument. + * + * @throws HttpException + * @throws IOException + */ + public void testReaderReadFromMediaType() throws HttpException, IOException { + HttpClient client = new HttpClient(); + + PostMethod postMethod = new PostMethod( + getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readdifferentlybytemediatype"); + postMethod.setRequestEntity(new StringRequestEntity("empty", + "custom/int", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + String response = postMethod.getResponseBodyAsString(); + assertEquals("null", response); + } finally { + postMethod.releaseConnection(); + } + + postMethod = new PostMethod( + getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readdifferentlybytemediatype"); + postMethod.setRequestEntity(new StringRequestEntity("empty", + "custom/byte", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + + String response = postMethod.getResponseBodyAsString(); + assertEquals("" + Byte.MAX_VALUE, response); + } finally { + postMethod.releaseConnection(); + } + } + + /** + * Tests that a + * {@link MessageBodyReader#readFrom(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType, javax.ws.rs.core.MultivaluedMap, InputStream)} + * can use the HttpHeaders. + * + * @throws IOException + */ + public void testReaderReadFromGetHeader() throws HttpException, IOException { + HttpClient client = new HttpClient(); + + PostMethod postMethod = new PostMethod(getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readfrom"); + postMethod.setRequestEntity(new StringRequestEntity("clear", + "custom/exception", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + + String response = postMethod.getResponseBodyAsString(); + assertEquals("0postReaderReadFrom:clear", response); + } finally { + postMethod.releaseConnection(); + } + + postMethod = new PostMethod(getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readfrom"); + postMethod.setRequestEntity(new StringRequestEntity("Hello World!", + "custom/exception", "UTF-8")); + postMethod.addRequestHeader("myCustomHeaderToappend", "abcdefgh"); + postMethod.addRequestHeader("MYCUSTOMHEADERTOAPPEND", "wxyz"); + postMethod.addRequestHeader("mycustomheadertoappend", "12345"); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + + String response = postMethod.getResponseBodyAsString(); + assertEquals("1postReaderReadFrom:Hello World!abcdefghwxyz12345", + response); + } finally { + postMethod.releaseConnection(); + } + } + + /** + * Tests that calling {@link InputStream#close()} in the + * {@link MessageBodyReader#readFrom(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType, javax.ws.rs.core.MultivaluedMap, java.io.InputStream)} + * method will not cause errors. + * + * @throws IOException + * @throws HttpException + */ + public void testReaderReadFromCloseInputStream() throws HttpException, + IOException { + HttpClient client = new HttpClient(); + + PostMethod postMethod = new PostMethod(getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readfrom"); + postMethod.setRequestEntity(new StringRequestEntity("clear", + "custom/exception", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + + String response = postMethod.getResponseBodyAsString(); + assertEquals("0postReaderReadFrom:clear", response); + } finally { + postMethod.releaseConnection(); + } + + postMethod = new PostMethod(getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readfrom"); + postMethod.setRequestEntity(new StringRequestEntity("closeinput", + "custom/exception", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + + String response = postMethod.getResponseBodyAsString(); + assertEquals("1postReaderReadFrom:closeinput", response); + } finally { + postMethod.releaseConnection(); + } + } + + /** + * Tests that throwing a {@link RuntimeException} in the + * {@link MessageBodyReader#readFrom(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType, javax.ws.rs.core.MultivaluedMap, java.io.InputStream)} + * method will propagate the exception appropriately. + * + * @throws IOException + * @throws HttpException + */ + public void testReaderReadFromThrowsRuntimeException() + throws HttpException, IOException { + HttpClient client = new HttpClient(); + + PostMethod postMethod = new PostMethod(getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readfrom"); + postMethod.setRequestEntity(new StringRequestEntity("clear", + "custom/exception", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + + String response = postMethod.getResponseBodyAsString(); + assertEquals("0postReaderReadFrom:clear", response); + } finally { + postMethod.releaseConnection(); + } + + postMethod = new PostMethod(getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readfrom"); + postMethod.setRequestEntity(new StringRequestEntity("Hello World", + "custom/exception", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + + String response = postMethod.getResponseBodyAsString(); + assertEquals("1postReaderReadFrom:Hello World", response); + } finally { + postMethod.releaseConnection(); + } + + postMethod = new PostMethod(getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readfrom"); + postMethod.setRequestEntity(new StringRequestEntity("clear", + "custom/exception", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + + String response = postMethod.getResponseBodyAsString(); + assertEquals("0postReaderReadFrom:clear", response); + } finally { + postMethod.releaseConnection(); + } + + postMethod = new PostMethod(getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readfrom"); + postMethod.setRequestEntity(new StringRequestEntity("thrownull", + "custom/exception", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(500, postMethod.getStatusCode()); + + String response = postMethod.getResponseBodyAsString(); + assertLogContainsException(response, + "javax.servlet.ServletException"); + } finally { + postMethod.releaseConnection(); + } + + postMethod = new PostMethod(getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readfrom"); + postMethod.setRequestEntity(new StringRequestEntity("hello world", + "custom/exception", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + + String response = postMethod.getResponseBodyAsString(); + assertEquals("1postReaderReadFrom:hello world", response); + } finally { + postMethod.releaseConnection(); + } + } + + /** + * Tests that an IOException triggered by a + * {@link MessageBodyReader#readFrom(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType, javax.ws.rs.core.MultivaluedMap, java.io.InputStream)} + * will propagate appropriately. + * + * @throws HttpException + * @throws IOException + */ + public void testReaderReadFromThrowsIOException() throws HttpException, + IOException { + HttpClient client = new HttpClient(); + + PostMethod postMethod = new PostMethod(getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readfrom"); + postMethod.setRequestEntity(new StringRequestEntity("clear", + "custom/exception", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + + String response = postMethod.getResponseBodyAsString(); + assertEquals("0postReaderReadFrom:clear", response); + } finally { + postMethod.releaseConnection(); + } + + postMethod = new PostMethod(getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readfrom"); + postMethod.setRequestEntity(new StringRequestEntity("Hello World", + "custom/exception", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + + String response = postMethod.getResponseBodyAsString(); + assertEquals("1postReaderReadFrom:Hello World", response); + } finally { + postMethod.releaseConnection(); + } + + postMethod = new PostMethod(getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readfrom"); + postMethod.setRequestEntity(new StringRequestEntity("clear", + "custom/exception", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + + String response = postMethod.getResponseBodyAsString(); + assertEquals("0postReaderReadFrom:clear", response); + } finally { + postMethod.releaseConnection(); + } + + postMethod = new PostMethod(getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readfrom"); + postMethod.setRequestEntity(new StringRequestEntity("ioexception", + "custom/exception", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(500, postMethod.getStatusCode()); + + String response = postMethod.getResponseBodyAsString(); + assertLogContainsException(response, + "javax.servlet.ServletException"); + } finally { + postMethod.releaseConnection(); + } + + postMethod = new PostMethod(getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readfrom"); + postMethod.setRequestEntity(new StringRequestEntity("hello world", + "custom/exception", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + + String response = postMethod.getResponseBodyAsString(); + assertEquals("1postReaderReadFrom:hello world", response); + } finally { + postMethod.releaseConnection(); + } + } + + /** + * Tests that a WebApplicationException triggered by a + * {@link MessageBodyReader#readFrom(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType, javax.ws.rs.core.MultivaluedMap, java.io.InputStream)} + * will propagate appropriately. + * + * @throws HttpException + * @throws IOException + */ + public void testReaderReadFromThrowsWebApplicationException() + throws IOException { + HttpClient client = new HttpClient(); + + PostMethod postMethod = new PostMethod(getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readfrom"); + postMethod.setRequestEntity(new StringRequestEntity("clear", + "custom/exception", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + + String response = postMethod.getResponseBodyAsString(); + assertEquals("0postReaderReadFrom:clear", response); + } finally { + postMethod.releaseConnection(); + } + + postMethod = new PostMethod(getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readfrom"); + postMethod.setRequestEntity(new StringRequestEntity("Hello World", + "custom/exception", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + + String response = postMethod.getResponseBodyAsString(); + assertEquals("1postReaderReadFrom:Hello World", response); + } finally { + postMethod.releaseConnection(); + } + + postMethod = new PostMethod(getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readfrom"); + postMethod.setRequestEntity(new StringRequestEntity("clear", + "custom/exception", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + + String response = postMethod.getResponseBodyAsString(); + assertEquals("0postReaderReadFrom:clear", response); + } finally { + postMethod.releaseConnection(); + } + + postMethod = new PostMethod(getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readfrom"); + postMethod.setRequestEntity(new StringRequestEntity( + "webapplicationexception", "custom/exception", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(477, postMethod.getStatusCode()); + } finally { + postMethod.releaseConnection(); + } + + postMethod = new PostMethod(getBaseURI() + + "/jaxrs/tests/providers/messagebodyreader/reader/readfrom"); + postMethod.setRequestEntity(new StringRequestEntity("hello world", + "custom/exception", "UTF-8")); + try { + client.executeMethod(postMethod); + + assertEquals(200, postMethod.getStatusCode()); + + String response = postMethod.getResponseBodyAsString(); + assertEquals("1postReaderReadFrom:hello world", response); + } finally { + postMethod.releaseConnection(); + } + } +} Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreaderexceptions/buildTest.xml URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreaderexceptions/buildTest.xml?rev=787553&view=auto ============================================================================== --- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreaderexceptions/buildTest.xml (added) +++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreaderexceptions/buildTest.xml Tue Jun 23 05:37:57 2009 @@ -0,0 +1,24 @@ + + + + + + + Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreaderexceptions/server/Application.java URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreaderexceptions/server/Application.java?rev=787553&view=auto ============================================================================== --- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreaderexceptions/server/Application.java (added) +++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreaderexceptions/server/Application.java Tue Jun 23 05:37:57 2009 @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package jaxrs.tests.providers.messagebodyreaderexceptions.server; + +import java.util.HashSet; +import java.util.Set; + +public class Application extends javax.ws.rs.core.Application { + + @Override + public Set> getClasses() { + Set> clazzes = new HashSet>(); + clazzes.add(ExceptionResource.class); + clazzes.add(IOExceptionMapper.class); + clazzes.add(MyMessageBodyReader.class); + clazzes.add(NullPointerExceptionMapper.class); + return clazzes; + } + +} Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreaderexceptions/server/ExceptionResource.java URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreaderexceptions/server/ExceptionResource.java?rev=787553&view=auto ============================================================================== --- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreaderexceptions/server/ExceptionResource.java (added) +++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreaderexceptions/server/ExceptionResource.java Tue Jun 23 05:37:57 2009 @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package jaxrs.tests.providers.messagebodyreaderexceptions.server; + +import javax.ws.rs.POST; +import javax.ws.rs.Path; + +@Path("jaxrs/tests/providers/messagebodyreader/reader/messagebodyreaderexceptions") +public class ExceptionResource { + + @POST + public String echo(String input) { + return "echo:" + input; + } + +} Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreaderexceptions/server/IOExceptionMapper.java URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreaderexceptions/server/IOExceptionMapper.java?rev=787553&view=auto ============================================================================== --- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreaderexceptions/server/IOExceptionMapper.java (added) +++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreaderexceptions/server/IOExceptionMapper.java Tue Jun 23 05:37:57 2009 @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package jaxrs.tests.providers.messagebodyreaderexceptions.server; + +import java.io.IOException; + +import javax.ws.rs.core.Response; +import javax.ws.rs.ext.ExceptionMapper; +import javax.ws.rs.ext.Provider; + +@Provider +public class IOExceptionMapper implements ExceptionMapper { + + public Response toResponse(IOException arg0) { + return Response.status(455).entity("Invoked" + this.getClass().getName()).build(); + } + +} Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreaderexceptions/server/MyMessageBodyReader.java URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreaderexceptions/server/MyMessageBodyReader.java?rev=787553&view=auto ============================================================================== --- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreaderexceptions/server/MyMessageBodyReader.java (added) +++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreaderexceptions/server/MyMessageBodyReader.java Tue Jun 23 05:37:57 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 jaxrs.tests.providers.messagebodyreaderexceptions.server; + +import java.io.IOException; +import java.io.InputStream; +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.core.Response; +import javax.ws.rs.ext.MessageBodyReader; +import javax.ws.rs.ext.Provider; + +@Provider +public class MyMessageBodyReader implements MessageBodyReader { + + public boolean isReadable(Class arg0, Type arg1, Annotation[] arg2, MediaType arg3) { + if (arg3.isCompatible(new MediaType("readable", "throwruntime"))) { + throw new RuntimeException(); + } else if (arg3.isCompatible(new MediaType("readable", "thrownull"))) { + throw new NullPointerException(); + } else if (arg3.isCompatible(new MediaType("readable", "throwwebapplicationexception"))) { + throw new WebApplicationException(Response.status(499).entity("can not read type") + .build()); + } + + return arg0.equals(String.class); + } + + public Object readFrom(Class arg0, Type arg1, Annotation[] arg2, MediaType arg3, + MultivaluedMap arg4, InputStream arg5) throws IOException, + WebApplicationException { + if (arg3.isCompatible(new MediaType("readfrom", "thrownull"))) { + throw new NullPointerException(); + } else if (arg3.isCompatible(new MediaType("readfrom", "throwwebapplicationexception"))) { + throw new WebApplicationException(Response.status(498).entity("can not read type in readfrom") + .build()); + } else if (arg3.isCompatible(new MediaType("readfrom", "throwioexception"))) { + throw new IOException(); + } else if (arg3.isCompatible(new MediaType("readfrom", "throwruntime"))) { + throw new RuntimeException(); + } + return "read"; + } + +} Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreaderexceptions/server/NullPointerExceptionMapper.java URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreaderexceptions/server/NullPointerExceptionMapper.java?rev=787553&view=auto ============================================================================== --- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreaderexceptions/server/NullPointerExceptionMapper.java (added) +++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/providers/messagebodyreaderexceptions/server/NullPointerExceptionMapper.java Tue Jun 23 05:37:57 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 jaxrs.tests.providers.messagebodyreaderexceptions.server; + +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 { + + public Response toResponse(NullPointerException arg0) { + return Response.status(495).entity("Invoked" + this.getClass().getName()).type(MediaType.TEXT_PLAIN).build(); + } + +}