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/07/12 05:34:38 UTC
svn commit: r793265 [2/2] - in
/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src:
main/java/org/apache/wink/jaxrs/test/providers/exceptionmappers/
main/java/org/apache/wink/jaxrs/test/providers/excep...
Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/exceptionmappers/nullconditions/GuestbookResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/exceptionmappers/nullconditions/GuestbookResource.java?rev=793265&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/exceptionmappers/nullconditions/GuestbookResource.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/exceptionmappers/nullconditions/GuestbookResource.java Sun Jul 12 03:34:31 2009
@@ -0,0 +1,104 @@
+/*
+ * 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.jaxrs.test.providers.exceptionmappers.nullconditions;
+
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+
+@Path("guestbooknullconditions")
+public class GuestbookResource {
+
+ @GET
+ @Path("emptywebappexception")
+ public String exception() {
+ throw new WebApplicationException();
+ }
+
+ @GET
+ @Path("webappexceptionwithcause")
+ public String exceptionWithCause() {
+ throw new WebApplicationException(new GuestbookException(
+ "Threw checked exception"));
+ }
+
+ @POST
+ @Path("webappexceptionwithcauseandstatus")
+ public String exceptionWithCauseAndStatus() {
+ throw new WebApplicationException(new GuestbookException(
+ "Threw checked exception"), 499);
+ }
+
+ @PUT
+ @Path("webappexceptionwithcauseandresponse")
+ public String exceptionWithCauseAndResponse() {
+ Response resp = Response.status(Status.NOT_ACCEPTABLE).entity(
+ "Entity inside response").build();
+ throw new WebApplicationException(new GuestbookException(
+ "Threw checked exception"), resp);
+ }
+
+ @DELETE
+ @Path("webappexceptionwithcauseandresponsestatus")
+ public String exceptionWithCauseAndResponseStatus() {
+ throw new WebApplicationException(new GuestbookException(
+ "Threw checked exception"), Response.Status.BAD_REQUEST);
+ }
+
+ @GET
+ @Path("exceptionmappernull")
+ public String exceptionMapperReturnNull() {
+ throw new GuestbookNullException("Should not see me");
+ }
+
+ @POST
+ @Path("exceptionmapperthrowsexception")
+ public String exceptionMapperThrowsException()
+ throws GuestbookThrowException {
+ throw new GuestbookThrowException("Re-throw an exception");
+ }
+
+ @POST
+ @Path("exceptionmapperthrowserror")
+ public String exceptionMapperThrowsError() throws GuestbookThrowException {
+ throw new GuestbookThrowException("Re-throw an error");
+ }
+
+ @PUT
+ @Path("throwableexceptionmapper")
+ public String throwableExceptionMapper() throws GuestbookThrowable {
+ throw new GuestbookThrowable();
+ }
+
+ @DELETE
+ @Path("throwsthrowable")
+ public String throwThrowable() throws Throwable {
+ throw new Throwable("Throwable was thrown") {
+
+ private static final long serialVersionUID = 1L;
+
+ };
+ }
+}
Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/exceptionmappers/nullconditions/GuestbookRuntimeExceptionMapper.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/exceptionmappers/nullconditions/GuestbookRuntimeExceptionMapper.java?rev=793265&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/exceptionmappers/nullconditions/GuestbookRuntimeExceptionMapper.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/exceptionmappers/nullconditions/GuestbookRuntimeExceptionMapper.java Sun Jul 12 03:34:31 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.jaxrs.test.providers.exceptionmappers.nullconditions;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+
+public class GuestbookRuntimeExceptionMapper implements ExceptionMapper<RuntimeException> {
+
+ public Response toResponse(RuntimeException arg0) {
+ return Response.serverError().entity("RuntimeExceptionMapper was used")
+ .build();
+ }
+
+}
Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/exceptionmappers/nullconditions/GuestbookThrowException.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/exceptionmappers/nullconditions/GuestbookThrowException.java?rev=793265&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/exceptionmappers/nullconditions/GuestbookThrowException.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/exceptionmappers/nullconditions/GuestbookThrowException.java Sun Jul 12 03:34:31 2009
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.wink.jaxrs.test.providers.exceptionmappers.nullconditions;
+
+public class GuestbookThrowException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+
+ public GuestbookThrowException() {
+ super();
+ }
+
+ public GuestbookThrowException(String message) {
+ super(message);
+ }
+
+ public GuestbookThrowException(Throwable cause) {
+ super(cause);
+ }
+
+ public GuestbookThrowException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/exceptionmappers/nullconditions/GuestbookThrowExceptionMapper.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/exceptionmappers/nullconditions/GuestbookThrowExceptionMapper.java?rev=793265&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/exceptionmappers/nullconditions/GuestbookThrowExceptionMapper.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/exceptionmappers/nullconditions/GuestbookThrowExceptionMapper.java Sun Jul 12 03:34:31 2009
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.wink.jaxrs.test.providers.exceptionmappers.nullconditions;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Provider;
+
+@Provider
+public class GuestbookThrowExceptionMapper implements ExceptionMapper<GuestbookThrowException> {
+
+ public Response toResponse(GuestbookThrowException arg0) {
+ /*
+ * throwing exception/error in here should cause a HTTP 500 status to
+ * occur
+ */
+
+ if (arg0.getMessage().contains("exception")) {
+ throw new GuestbookNullException();
+ } else {
+ throw new Error("error");
+ }
+
+ // TODO: throw this inside a subresource locator
+ }
+
+}
Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/exceptionmappers/nullconditions/GuestbookThrowable.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/exceptionmappers/nullconditions/GuestbookThrowable.java?rev=793265&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/exceptionmappers/nullconditions/GuestbookThrowable.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/exceptionmappers/nullconditions/GuestbookThrowable.java Sun Jul 12 03:34:31 2009
@@ -0,0 +1,26 @@
+/*
+ * 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.jaxrs.test.providers.exceptionmappers.nullconditions;
+
+public class GuestbookThrowable extends Throwable {
+
+ private static final long serialVersionUID = 1L;
+
+}
Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/exceptionmappers/nullconditions/GuestbookThrowableMapper.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/exceptionmappers/nullconditions/GuestbookThrowableMapper.java?rev=793265&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/exceptionmappers/nullconditions/GuestbookThrowableMapper.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/exceptionmappers/nullconditions/GuestbookThrowableMapper.java Sun Jul 12 03:34:31 2009
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.wink.jaxrs.test.providers.exceptionmappers.nullconditions;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Provider;
+
+@Provider
+public class GuestbookThrowableMapper implements ExceptionMapper<GuestbookThrowable> {
+
+ public Response toResponse(GuestbookThrowable arg0) {
+ return Response.serverError().entity("Throwable mapper used").build();
+ }
+
+}
Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/subresource/Application.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/subresource/Application.java?rev=793265&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/subresource/Application.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/subresource/Application.java Sun Jul 12 03:34:31 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.jaxrs.test.providers.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-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/subresource/Comment.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/subresource/Comment.java?rev=793265&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/subresource/Comment.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/subresource/Comment.java Sun Jul 12 03:34:31 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.jaxrs.test.providers.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-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/subresource/CommentData.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/subresource/CommentData.java?rev=793265&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/subresource/CommentData.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/subresource/CommentData.java Sun Jul 12 03:34:31 2009
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.wink.jaxrs.test.providers.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).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-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/subresource/CommentError.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/subresource/CommentError.java?rev=793265&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/subresource/CommentError.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/subresource/CommentError.java Sun Jul 12 03:34:31 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.jaxrs.test.providers.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-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/subresource/GuestbookDatabase.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/subresource/GuestbookDatabase.java?rev=793265&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/subresource/GuestbookDatabase.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/subresource/GuestbookDatabase.java Sun Jul 12 03:34:31 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.jaxrs.test.providers.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-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/subresource/GuestbookException.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/subresource/GuestbookException.java?rev=793265&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/subresource/GuestbookException.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/subresource/GuestbookException.java Sun Jul 12 03:34:31 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.jaxrs.test.providers.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-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/subresource/GuestbookResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/subresource/GuestbookResource.java?rev=793265&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/subresource/GuestbookResource.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/subresource/GuestbookResource.java Sun Jul 12 03:34:31 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.jaxrs.test.providers.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-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/subresource/ObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/subresource/ObjectFactory.java?rev=793265&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/subresource/ObjectFactory.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/subresource/ObjectFactory.java Sun Jul 12 03:34:31 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.jaxrs.test.providers.subresource;
+
+import javax.xml.bind.annotation.XmlRegistry;
+
+@XmlRegistry
+public class ObjectFactory {
+
+ public CommentError createCommentError() {
+ return new CommentError();
+ }
+
+ public Comment createComment() {
+ return new Comment();
+ }
+
+}
Modified: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/webapp/WEB-INF/web.xml?rev=793265&r1=793264&r2=793265&view=diff
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/webapp/WEB-INF/web.xml (original)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/webapp/WEB-INF/web.xml Sun Jul 12 03:34:31 2009
@@ -17,6 +17,7 @@
specific language governing permissions and limitations
under the License.
-->
+
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
@@ -84,6 +85,60 @@
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
+ <servlet>
+ <servlet-name>ExceptionMapperMappedProviders</servlet-name>
+ <servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.apache.wink.jaxrs.test.providers.exceptionmappers.mapped.GuestbookApplication</param-value>
+ </init-param>
+ <init-param>
+ <param-name>requestProcessorAttribute</param-name>
+ <param-value>requestProcessorAttribute_exceptionmappers</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet>
+ <servlet-name>ExceptionMapperNoMapper</servlet-name>
+ <servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.apache.wink.jaxrs.test.providers.exceptionmappers.nomapper.GuestbookApplication</param-value>
+ </init-param>
+ <init-param>
+ <param-name>requestProcessorAttribute</param-name>
+ <param-value>requestProcessorAttribute_noexceptionmappers</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet>
+ <servlet-name>ExceptionMapperNull</servlet-name>
+ <servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.apache.wink.jaxrs.test.providers.exceptionmappers.nullconditions.Application</param-value>
+ </init-param>
+ <init-param>
+ <param-name>requestProcessorAttribute</param-name>
+ <param-value>requestProcessorAttribute_nullconditions</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet>
+ <servlet-name>SubresourceExceptions</servlet-name>
+ <servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.apache.wink.jaxrs.test.providers.subresource.Application</param-value>
+ </init-param>
+ <init-param>
+ <param-name>requestProcessorAttribute</param-name>
+ <param-value>requestProcessorAttribute_subresourceexceptions</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
<servlet-mapping>
<servlet-name>MessageBodyReaders</servlet-name>
<url-pattern>/readers/*</url-pattern>
@@ -104,4 +159,20 @@
<servlet-name>StandardEntityProviders</servlet-name>
<url-pattern>/standard/*</url-pattern>
</servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>ExceptionMapperMappedProviders</servlet-name>
+ <url-pattern>/exceptionsmapped/*</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>ExceptionMapperNoMapper</servlet-name>
+ <url-pattern>/exceptionsnomapper/*</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>ExceptionMapperNull</servlet-name>
+ <url-pattern>/exceptionsnull/*</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>SubresourceExceptions</servlet-name>
+ <url-pattern>/subresourceexceptions/*</url-pattern>
+ </servlet-mapping>
</web-app>
Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/exceptionmappers/mapped/JAXRSExceptionsMappedProvidersTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/exceptionmappers/mapped/JAXRSExceptionsMappedProvidersTest.java?rev=793265&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/exceptionmappers/mapped/JAXRSExceptionsMappedProvidersTest.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/exceptionmappers/mapped/JAXRSExceptionsMappedProvidersTest.java Sun Jul 12 03:34:31 2009
@@ -0,0 +1,249 @@
+/*
+ * 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.jaxrs.test.providers.exceptionmappers.mapped;
+
+import javax.ws.rs.core.Response.Status;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.DeleteMethod;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.PutMethod;
+import org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.apache.wink.test.integration.ServerEnvironmentInfo;
+
+public class JAXRSExceptionsMappedProvidersTest extends TestCase {
+
+ public String getBaseURI() {
+ return ServerEnvironmentInfo.getBaseURI() + "/exceptionsmapped" + "/guestbookmapped";
+ }
+
+ /**
+ * Test the positive workflow where a comment with a message and author is
+ * successfully posted to the Guestbook.
+ *
+ * @throws Exception
+ */
+ public void testRegularWorkflow() throws Exception {
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod = new PostMethod(getBaseURI());
+ postMethod
+ .setRequestEntity(new StringRequestEntity(
+ "<comment><message>Hello World!</message><author>Anonymous</author></comment>",
+ "text/xml", null));
+ client.executeMethod(postMethod);
+ assertEquals(201, postMethod.getStatusCode());
+ String newPostURILocation = postMethod.getResponseHeader("Location").getValue();
+
+ GetMethod getMethod = new GetMethod(newPostURILocation);
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><comment><author>Anonymous</author><id>1</id><message>Hello World!</message></comment>",
+ getMethod.getResponseBodyAsString());
+ }
+
+ /**
+ * Tests a method that throws an emptily constructed
+ * <code>WebApplicationException</code>.
+ *
+ * @throws Exception
+ */
+ public void testWebApplicationExceptionDefaultMappedProvider() throws Exception {
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod = new PostMethod(getBaseURI());
+ postMethod
+ .setRequestEntity(new StringRequestEntity("<comment></comment>", "text/xml", null));
+ client.executeMethod(postMethod);
+ assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), postMethod.getStatusCode());
+ assertEquals(getBaseURI(), postMethod.getResponseHeader("ExceptionPage").getValue());
+ assertEquals("", postMethod.getResponseBodyAsString());
+ }
+
+ /**
+ * Tests a method that throws a <code>WebApplicationException</code> with an
+ * integer status code.
+ *
+ * @throws Exception
+ */
+ public void testWebApplicationExceptionStatusCodeSetMappedProvider() throws Exception {
+ HttpClient client = new HttpClient();
+ PostMethod postMethod = new PostMethod(getBaseURI());
+ postMethod
+ .setRequestEntity(new StringRequestEntity(
+ "<comment><message>Suppose to fail with missing author.</message></comment>",
+ "text/xml", null));
+ client.executeMethod(postMethod);
+ assertEquals(497, postMethod.getStatusCode());
+ assertEquals(getBaseURI(), postMethod.getResponseHeader("ExceptionPage").getValue());
+ assertEquals("", postMethod.getResponseBodyAsString());
+ }
+
+ /**
+ * Tests a method that throws a <code>WebApplicationException</code> with a
+ * Response.Status set.
+ *
+ * @throws Exception
+ */
+ public void testWebApplicationExceptionResponseStatusSetMappedProvider() throws Exception {
+ HttpClient client = new HttpClient();
+ PostMethod postMethod = new PostMethod(getBaseURI());
+ postMethod.setRequestEntity(new StringRequestEntity("", "text/xml", null));
+ client.executeMethod(postMethod);
+ assertEquals(496, postMethod.getStatusCode());
+ assertEquals(getBaseURI(), postMethod.getResponseHeader("ExceptionPage").getValue());
+ assertEquals("", postMethod.getResponseBodyAsString());
+ }
+
+ /**
+ * Tests a method that throws a <code>WebApplicationException</code> with a
+ * Response with an entity (which will not get mapped via an exception mapper).
+ *
+ * @throws Exception
+ */
+ public void testWebApplicationExceptionResponseWithEntitySetMappedProvider() throws Exception {
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod = new PostMethod(getBaseURI());
+ postMethod
+ .setRequestEntity(new StringRequestEntity(
+ "<comment><author>Anonymous</author></comment>",
+ "text/xml", null));
+ client.executeMethod(postMethod);
+ assertEquals(400, postMethod.getStatusCode());
+ assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><commenterror><message>Missing the message in the comment.</message></commenterror>",
+ postMethod.getResponseBodyAsString());
+ }
+
+ /**
+ * Tests a method that throws a <code>WebApplicationException</code> with a
+ * Response with no entity (which will not get mapped via an exception mapper).
+ *
+ * @throws Exception
+ */
+ public void testWebApplicationExceptionResponseWithNoEntitySetMappedProvider() throws Exception {
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod = new PostMethod(getBaseURI());
+ postMethod
+ .setRequestEntity(new StringRequestEntity(
+ "<comment><message>throwemptywebappexception</message><author>Anonymous</author></comment>",
+ "text/xml", null));
+ client.executeMethod(postMethod);
+ assertEquals(491, postMethod.getStatusCode());
+ assertEquals("Some message", postMethod.getResponseHeader("throwemptyentitywebappexception").getValue());
+ assertEquals(getBaseURI(), postMethod.getResponseHeader("ExceptionPage").getValue());
+ assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><commenterror><message>WebApplicationExceptionMapProvider set message</message></commenterror>",
+ postMethod.getResponseBodyAsString());
+ }
+
+ /**
+ * Tests a method that throws a subclass of
+ * <code>WebApplicationException</code> with a Response.
+ *
+ * @throws Exception
+ */
+ public void testCustomWebApplicationExceptionMappedProvider() throws Exception {
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod = new PostMethod(getBaseURI());
+ postMethod
+ .setRequestEntity(new StringRequestEntity(
+ "<comment><message></message><author></author></comment>",
+ "text/xml", null));
+ client.executeMethod(postMethod);
+ assertEquals(498, postMethod.getStatusCode());
+ assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><commenterror><message>Cannot post an invalid message.</message></commenterror>",
+ postMethod.getResponseBodyAsString());
+ }
+
+ /**
+ * Tests a method that throws a runtime exception.
+ *
+ * @throws Exception
+ */
+ public void testRuntimeExceptionMappedProvider() throws Exception {
+ HttpClient client = new HttpClient();
+
+ /*
+ * abcd is an invalid ID so a NumberFormatException will be thrown in
+ * the resource
+ */
+ DeleteMethod postMethod = new DeleteMethod(getBaseURI() + "/abcd");
+ client.executeMethod(postMethod);
+ assertEquals(450, postMethod.getStatusCode());
+ String responseBody = postMethod.getResponseBodyAsString();
+ assertTrue(responseBody,
+ "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><commenterror><message>For input string: \"abcd\"</message></commenterror>"
+ .equals(responseBody) || "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><commenterror><message>For input string: "abcd"</message></commenterror>"
+ .equals(responseBody));
+ }
+
+ /**
+ * Tests a method that throws a NullPointerException inside a called method.
+ *
+ * @throws Exception
+ */
+ public void testNullPointerExceptionMappedProvider() throws Exception {
+ HttpClient client = new HttpClient();
+
+ DeleteMethod postMethod = new DeleteMethod(getBaseURI() + "/10000");
+ client.executeMethod(postMethod);
+ assertEquals(451, postMethod.getStatusCode());
+ assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><commenterror><message>The comment did not previously exist.</message></commenterror>",
+ postMethod.getResponseBodyAsString());
+ }
+
+ /**
+ * Tests a method that throws an error.
+ *
+ * @throws Exception
+ */
+ public void testErrorMappedProvider() throws Exception {
+ HttpClient client = new HttpClient();
+
+ DeleteMethod postMethod = new DeleteMethod(getBaseURI() + "/-99999");
+ client.executeMethod(postMethod);
+ assertEquals(453, postMethod.getStatusCode());
+ assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><commenterror><message>Simulated error</message></commenterror>",
+ postMethod.getResponseBodyAsString());
+ }
+
+ /**
+ * Tests a method that throws a checked exception.
+ *
+ * @throws Exception
+ */
+ public void testCheckExceptionMappedProvider() throws Exception {
+ HttpClient client = new HttpClient();
+
+ PutMethod putMethod = new PutMethod(getBaseURI() + "/-99999");
+ putMethod
+ .setRequestEntity(new StringRequestEntity(
+ "<comment><id></id><message></message><author></author></comment>",
+ "text/xml", null));
+ client.executeMethod(putMethod);
+ assertEquals(454, putMethod.getStatusCode());
+ assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><commenterror><message>Unexpected ID.</message></commenterror>",
+ putMethod.getResponseBodyAsString());
+ }
+}
Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/exceptionmappers/nomapper/JAXRSExceptionsNoMapperTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/exceptionmappers/nomapper/JAXRSExceptionsNoMapperTest.java?rev=793265&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/exceptionmappers/nomapper/JAXRSExceptionsNoMapperTest.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/exceptionmappers/nomapper/JAXRSExceptionsNoMapperTest.java Sun Jul 12 03:34:31 2009
@@ -0,0 +1,233 @@
+/*
+ * 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.jaxrs.test.providers.exceptionmappers.nomapper;
+
+import javax.ws.rs.core.Response.Status;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.DeleteMethod;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.PutMethod;
+import org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.apache.wink.test.integration.ServerEnvironmentInfo;
+
+/**
+ * Tests exception throwing without any exception mapping providers.
+ */
+public class JAXRSExceptionsNoMapperTest extends TestCase {
+
+ public String getBaseURI() {
+ return ServerEnvironmentInfo.getBaseURI() + "/exceptionsnomapper" + "/guestbooknomap";
+ }
+
+ /**
+ * Test the positive workflow where a comment with a message and author is
+ * successfully posted to the Guestbook.
+ *
+ * @throws Exception
+ */
+ public void testRegularWorkflow() throws Exception {
+ /* FIXME: this is not a repeatable test */
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod = new PostMethod(getBaseURI());
+ postMethod
+ .setRequestEntity(new StringRequestEntity(
+ "<comment><message>Hello World!</message><author>Anonymous</author></comment>",
+ "text/xml", null));
+ client.executeMethod(postMethod);
+ assertEquals(201, postMethod.getStatusCode());
+ String newPostURILocation = postMethod.getResponseHeader("Location")
+ .getValue();
+
+ GetMethod getMethod = new GetMethod(newPostURILocation);
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals(
+ "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><comment><author>Anonymous</author><id>1</id><message>Hello World!</message></comment>",
+ getMethod.getResponseBodyAsString());
+ }
+
+ /**
+ * Tests a method that throws an emptily constructed
+ * <code>WebApplicationException</code>.
+ *
+ * @throws Exception
+ */
+ public void testWebApplicationExceptionDefaultNoMappingProvider()
+ throws Exception {
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod = new PostMethod(getBaseURI());
+ postMethod.setRequestEntity(new StringRequestEntity(
+ "<comment></comment>", "text/xml", null));
+ client.executeMethod(postMethod);
+ assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), postMethod
+ .getStatusCode());
+ assertEquals("", postMethod.getResponseBodyAsString());
+ }
+
+ /**
+ * Tests a method that throws a <code>WebApplicationException</code> with an
+ * integer status code.
+ *
+ * @throws Exception
+ */
+ public void testWebApplicationExceptionStatusCodeSetNoMappingProvider()
+ throws Exception {
+ HttpClient client = new HttpClient();
+ PostMethod postMethod = new PostMethod(getBaseURI());
+ postMethod
+ .setRequestEntity(new StringRequestEntity(
+ "<comment><message>Suppose to fail with missing author.</message></comment>",
+ "text/xml", null));
+ client.executeMethod(postMethod);
+ assertEquals(499, postMethod.getStatusCode());
+ assertEquals("", postMethod.getResponseBodyAsString());
+ }
+
+ /**
+ * Tests a method that throws a <code>WebApplicationException</code> with a
+ * Response.Status set.
+ *
+ * @throws Exception
+ */
+ public void testWebApplicationExceptionResponseStatusSetNoMappingProvider()
+ throws Exception {
+ HttpClient client = new HttpClient();
+ PostMethod postMethod = new PostMethod(getBaseURI());
+ postMethod.setRequestEntity(new StringRequestEntity("", "text/xml",
+ null));
+ client.executeMethod(postMethod);
+ assertEquals(Status.BAD_REQUEST.getStatusCode(), postMethod
+ .getStatusCode());
+ assertEquals("", postMethod.getResponseBodyAsString());
+ }
+
+ /**
+ * Tests a method that throws a <code>WebApplicationException</code> with a
+ * Response.
+ *
+ * @throws Exception
+ */
+ public void testWebApplicationExceptionResponseSetNoMappingProvider()
+ throws Exception {
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod = new PostMethod(getBaseURI());
+ postMethod.setRequestEntity(new StringRequestEntity(
+ "<comment><author>Anonymous</author></comment>", "text/xml",
+ null));
+ client.executeMethod(postMethod);
+ assertEquals(Status.BAD_REQUEST.getStatusCode(), postMethod
+ .getStatusCode());
+ assertEquals(
+ "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><commenterror><message>Missing the message in the comment.</message></commenterror>",
+ postMethod.getResponseBodyAsString());
+ }
+
+ /**
+ * Tests a method that throws a subclass of
+ * <code>WebApplicationException</code> with a Response.
+ *
+ * @throws Exception
+ */
+ public void testCustomWebApplicationExceptionNoMappingProvider()
+ throws Exception {
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod = new PostMethod(getBaseURI());
+ postMethod.setRequestEntity(new StringRequestEntity(
+ "<comment><message></message><author></author></comment>",
+ "text/xml", null));
+ client.executeMethod(postMethod);
+ assertEquals(498, postMethod.getStatusCode());
+ assertEquals(
+ "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><commenterror><message>Cannot post an invalid message.</message></commenterror>",
+ postMethod.getResponseBodyAsString());
+ }
+
+ /**
+ * Tests a method that throws a runtime exception.
+ *
+ * @throws Exception
+ */
+ public void testRuntimeExceptionNoMappingProvider() throws Exception {
+ HttpClient client = new HttpClient();
+
+ /*
+ * abcd is an invalid ID so a NumberFormatException will be thrown in
+ * the resource
+ */
+ DeleteMethod postMethod = new DeleteMethod(getBaseURI() + "/abcd");
+ client.executeMethod(postMethod);
+ assertEquals(500, postMethod.getStatusCode());
+// assertLogContainsException("java.lang.NumberFormatException: For input string: \"abcd\"");
+ }
+
+ /**
+ * Tests a method that throws a NullPointerException inside a called method.
+ *
+ * @throws Exception
+ */
+ public void testNullPointerExceptionNoMappingProvider() throws Exception {
+ HttpClient client = new HttpClient();
+
+ DeleteMethod postMethod = new DeleteMethod(getBaseURI() + "/10000");
+ client.executeMethod(postMethod);
+ assertEquals(500, postMethod.getStatusCode());
+// assertLogContainsException("java.lang.NullPointerException: The comment did not previously exist.");
+ }
+
+ /**
+ * Tests a method that throws an error.
+ *
+ * @throws Exception
+ */
+ public void testErrorNoMappingProvider() throws Exception {
+ HttpClient client = new HttpClient();
+
+ DeleteMethod postMethod = new DeleteMethod(getBaseURI() + "/-99999");
+ client.executeMethod(postMethod);
+ assertEquals(500, postMethod.getStatusCode());
+// assertLogContainsException("java.lang.Error: Simulated error");
+ }
+
+ /**
+ * Tests a method that throws a checked exception.
+ *
+ * @throws Exception
+ */
+ public void testCheckExceptionNoMappingProvider() throws Exception {
+ HttpClient client = new HttpClient();
+
+ PutMethod putMethod = new PutMethod(getBaseURI() + "/-99999");
+ putMethod
+ .setRequestEntity(new StringRequestEntity(
+ "<comment><id></id><message></message><author></author></comment>",
+ "text/xml", null));
+ client.executeMethod(putMethod);
+ assertEquals(500, putMethod.getStatusCode());
+// assertLogContainsException("jaxrs.tests.exceptions.nomapping.server.GuestbookException: Unexpected ID.");
+ }
+}
Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/exceptionmappers/nullconditions/JAXRSExceptionsNullConditionsTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/exceptionmappers/nullconditions/JAXRSExceptionsNullConditionsTest.java?rev=793265&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/exceptionmappers/nullconditions/JAXRSExceptionsNullConditionsTest.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/exceptionmappers/nullconditions/JAXRSExceptionsNullConditionsTest.java Sun Jul 12 03:34:31 2009
@@ -0,0 +1,236 @@
+/*
+ * 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.jaxrs.test.providers.exceptionmappers.nullconditions;
+
+import javax.ws.rs.core.Response;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.DeleteMethod;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.PutMethod;
+import org.apache.wink.test.integration.ServerEnvironmentInfo;
+
+/**
+ * Tests various default null conditions and error paths when exceptions are
+ * thrown in resource methods.
+ */
+public class JAXRSExceptionsNullConditionsTest extends TestCase {
+
+ public String getBaseURI() {
+ return ServerEnvironmentInfo.getBaseURI() + "/exceptionsnull" + "/guestbooknullconditions";
+ }
+
+ /**
+ * Tests that an empty constructor constructed
+ * <code>WebApplicationException</code> will return status 500 and no
+ * response body by default.
+ *
+ * @throws Exception
+ */
+ public void testEmptyWebException() throws Exception {
+ HttpClient client = new HttpClient();
+
+ GetMethod getMethod = new GetMethod(getBaseURI() + "/emptywebappexception");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(500, getMethod.getStatusCode());
+ assertEquals("", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that a <code>WebApplicationException</code> constructed with a
+ * cause will return status 500 and no response body by default.
+ *
+ * @throws Exception
+ */
+ public void testWebExceptionWithCause() throws Exception {
+ HttpClient client = new HttpClient();
+
+ GetMethod getMethod = new GetMethod(getBaseURI() + "/webappexceptionwithcause");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(500, getMethod.getStatusCode());
+ assertEquals("", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that a <code>WebApplicationException</code> constructed with a
+ * cause and status will return status and no response body by default.
+ *
+ * @throws Exception
+ */
+ public void testWebExceptionWithCauseAndStatus() throws Exception {
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod = new PostMethod(getBaseURI() + "/webappexceptionwithcauseandstatus");
+ try {
+ client.executeMethod(postMethod);
+ assertEquals(499, postMethod.getStatusCode());
+ assertEquals("", postMethod.getResponseBodyAsString());
+ } finally {
+ postMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that a <code>WebApplicationException</code> constructed with a
+ * cause and response will return the Response entity by default.
+ *
+ * @throws Exception
+ */
+ public void testWebExceptionWithCauseAndResponse() throws Exception {
+ HttpClient client = new HttpClient();
+
+ PutMethod putMethod = new PutMethod(getBaseURI() + "/webappexceptionwithcauseandresponse");
+ try {
+ client.executeMethod(putMethod);
+ assertEquals(Response.Status.NOT_ACCEPTABLE.getStatusCode(), putMethod.getStatusCode());
+ assertEquals("Entity inside response", putMethod.getResponseBodyAsString());
+ } finally {
+ putMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that a <code>WebApplicationException</code> constructed with a
+ * cause and response status will return the response status and empty
+ * response body by default.
+ *
+ * @throws Exception
+ */
+ public void testWebExceptionWithCauseAndResponseStatus() throws Exception {
+ HttpClient client = new HttpClient();
+
+ DeleteMethod deleteMethod =
+ new DeleteMethod(getBaseURI() + "/webappexceptionwithcauseandresponsestatus");
+ try {
+ client.executeMethod(deleteMethod);
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), deleteMethod.getStatusCode());
+ assertEquals("", deleteMethod.getResponseBodyAsString());
+ } finally {
+ deleteMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that a <code>ExceptionMapper</code> that returns null should see a
+ * HTTP 204 status.
+ *
+ * @throws Exception
+ */
+ public void testExceptionMapperReturnNull() throws Exception {
+ HttpClient client = new HttpClient();
+
+ GetMethod getMethod = new GetMethod(getBaseURI() + "/exceptionmappernull");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(Response.Status.NO_CONTENT.getStatusCode(), getMethod.getStatusCode());
+ assertEquals(null, getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that a <code>ExceptionMapper</code> that throws an exception or
+ * error should see a HTTP 500 status error and empty response.
+ *
+ * @throws Exception
+ */
+ public void testExceptionMapperThrowsException() throws Exception {
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod = new PostMethod(getBaseURI() + "/exceptionmapperthrowsexception");
+ try {
+ client.executeMethod(postMethod);
+ assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), postMethod
+ .getStatusCode());
+ assertEquals("", postMethod.getResponseBodyAsString());
+ } finally {
+ postMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that a <code>ExceptionMapper</code> that throws an error should see
+ * a HTTP 500 status error and unknown response.
+ *
+ * @throws Exception
+ */
+ public void testExceptionMapperThrowsError() throws Exception {
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod = new PostMethod(getBaseURI() + "/exceptionmapperthrowserror");
+ try {
+ client.executeMethod(postMethod);
+ assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), postMethod
+ .getStatusCode());
+ } finally {
+ postMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that a <code>ExceptionMapper</code> can catch a generic Throwable.
+ *
+ * @throws Exception
+ */
+ public void testExceptionMapperForSpecificThrowable() throws Exception {
+ HttpClient client = new HttpClient();
+
+ PutMethod putMethod = new PutMethod(getBaseURI() + "/throwableexceptionmapper");
+ try {
+ client.executeMethod(putMethod);
+ assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), putMethod
+ .getStatusCode());
+ assertEquals("Throwable mapper used", putMethod.getResponseBodyAsString());
+ } finally {
+ putMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that a Throwable can propagate throughout the code.
+ *
+ * @throws Exception
+ */
+ public void testThrowableCanBeThrown() throws Exception {
+ HttpClient client = new HttpClient();
+
+ DeleteMethod deleteMethod = new DeleteMethod(getBaseURI() + "/throwsthrowable");
+ try {
+ client.executeMethod(deleteMethod);
+ assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), deleteMethod
+ .getStatusCode());
+ // assertLogContainsException("jaxrs.tests.exceptions.nullconditions.server.GuestbookResource$1: Throwable was thrown");
+ } finally {
+ deleteMethod.releaseConnection();
+ }
+ }
+}
Modified: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/standard/JAXRSMultivaluedMapTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/standard/JAXRSMultivaluedMapTest.java?rev=793265&r1=793264&r2=793265&view=diff
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/standard/JAXRSMultivaluedMapTest.java (original)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/standard/JAXRSMultivaluedMapTest.java Sun Jul 12 03:34:31 2009
@@ -127,7 +127,7 @@
postMethod.setRequestEntity(new StringRequestEntity("tuv=wxyz&abcd=",
"application/x-www-form-urlencoded",
"UTF-8"));
- postMethod.addRequestHeader("Accept", "text/plain");
+ postMethod.addRequestHeader("Accept", "not/expected");
try {
client.executeMethod(postMethod);
Modified: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/standard/JAXRSSourceTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/standard/JAXRSSourceTest.java?rev=793265&r1=793264&r2=793265&view=diff
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/standard/JAXRSSourceTest.java (original)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/standard/JAXRSSourceTest.java Sun Jul 12 03:34:31 2009
@@ -135,7 +135,7 @@
.setRequestEntity(new StringRequestEntity(
"<message><user>user1</user><password>user1pwd</password></message>",
"application/xml", "UTF-8"));
- postMethod.addRequestHeader("Accept", "text/plain");
+ postMethod.addRequestHeader("Accept", "not/expected");
try {
client.executeMethod(postMethod);
Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/subresources/JAXRSExceptionsSubresourcesTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/subresources/JAXRSExceptionsSubresourcesTest.java?rev=793265&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/subresources/JAXRSExceptionsSubresourcesTest.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/subresources/JAXRSExceptionsSubresourcesTest.java Sun Jul 12 03:34:31 2009
@@ -0,0 +1,132 @@
+/*
+ * 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.jaxrs.test.providers.subresources;
+
+import javax.ws.rs.core.Response.Status;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.DeleteMethod;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.PutMethod;
+import org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.apache.wink.test.integration.ServerEnvironmentInfo;
+
+public class JAXRSExceptionsSubresourcesTest extends TestCase {
+
+ public String getBaseURI() {
+ return ServerEnvironmentInfo.getBaseURI() + "/subresourceexceptions/guestbooksubresources";
+ }
+
+ /**
+ * Test the positive workflow where a comment with a message and author is
+ * successfully posted to the Guestbook.
+ *
+ * @throws Exception
+ */
+ public void testRegularWorkflow() throws Exception {
+ HttpClient client = new HttpClient();
+ PostMethod postMethod = new PostMethod(getBaseURI() + "/commentdata");
+ try {
+ postMethod
+ .setRequestEntity(new StringRequestEntity(
+ "<comment><id>10000</id><author>Anonymous</author><message>Hi there</message></comment>",
+ "text/xml", null));
+ client.executeMethod(postMethod);
+ assertEquals(201, postMethod.getStatusCode());
+ } finally {
+ postMethod.releaseConnection();
+ }
+ String postURILocation = postMethod.getResponseHeader("Location").getValue();
+
+ GetMethod getMethod = new GetMethod(postURILocation);
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><comment><author>Anonymous</author><id>10000</id><message>Hi there</message></comment>",
+ getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Test that a <code>WebApplicationException</code> thrown from a
+ * sub-resource is still processed properly.
+ *
+ * @throws Exception
+ */
+ public void testWebApplicationException() throws Exception {
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod = new PostMethod(getBaseURI() + "/commentdata");
+ try {
+ postMethod.setRequestEntity(new StringRequestEntity("<comment></comment>", "text/xml",
+ null));
+// postMethod.addRequestHeader("Accept", "text/xml");
+ client.executeMethod(postMethod);
+ assertEquals(Status.BAD_REQUEST.getStatusCode(), postMethod.getStatusCode());
+ assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><commenterror><message>Please include a comment ID, a message, and your name.</message></commenterror>",
+ postMethod.getResponseBodyAsString());
+ } finally {
+ postMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Test that a checked exception is processed properly.
+ *
+ * @throws Exception
+ */
+ public void testCheckedException() throws Exception {
+ HttpClient client = new HttpClient();
+
+ PutMethod putMethod = new PutMethod(getBaseURI() + "/commentdata");
+ try {
+ putMethod.setRequestEntity(new StringRequestEntity("<comment></comment>", "text/xml",
+ null));
+ client.executeMethod(putMethod);
+ assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), putMethod.getStatusCode());
+ // assertLogContainsException("jaxrs.tests.exceptions.subresources.server.GuestbookException: Unexpected ID.");
+ } finally {
+ putMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Test the positive workflow where a comment with a message and author is
+ * successfully posted to the Guestbook.
+ *
+ * @throws Exception
+ */
+ public void testRuntimeException() throws Exception {
+ HttpClient client = new HttpClient();
+ DeleteMethod deleteMethod = new DeleteMethod(getBaseURI() + "/commentdata/afdsfsdf");
+ try {
+ client.executeMethod(deleteMethod);
+ assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), deleteMethod.getStatusCode());
+ // assertLogContainsException("java.lang.NumberFormatException: For input string: \"afdsfsdf\"");
+ } finally {
+ deleteMethod.releaseConnection();
+ }
+ }
+}