You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2012/10/30 14:39:27 UTC
svn commit: r1403692 - in /cxf/trunk:
rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/
systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
systests/jaxrs/src/test/resources/jaxrs/WEB-INF/
Author: sergeyb
Date: Tue Oct 30 13:39:26 2012
New Revision: 1403692
URL: http://svn.apache.org/viewvc?rev=1403692&view=rev
Log:
Initial commit for fixing the issue with the WebApplicationExceptions losing the original exceptions in some cases
Added:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/CustomWebApplicationExceptionMapper.java (with props)
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/InternalServerErrorExceptionMapper.java (with props)
Modified:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=1403692&r1=1403691&r2=1403692&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java Tue Oct 30 13:39:26 2012
@@ -1353,15 +1353,16 @@ public final class JAXRSUtils {
ProviderFactory factory = ProviderFactory.getInstance(inMessage);
ExceptionMapper<T> mapper = factory.createExceptionMapper(ex, inMessage);
if (mapper != null) {
- if (ex.getClass() == WebApplicationException.class
- && mapper.getClass() != WebApplicationExceptionMapper.class) {
+ if (!WebApplicationExceptionMapper.class.isAssignableFrom(mapper.getClass())
+ && WebApplicationException.class.isAssignableFrom(ex.getClass())) {
+
WebApplicationException webEx = (WebApplicationException)ex;
Class<?> exceptionClass = getWebApplicationExceptionClass(webEx.getResponse(),
WebApplicationException.class);
if (exceptionClass != WebApplicationException.class) {
try {
- Constructor<?> ctr = exceptionClass.getConstructor(Response.class);
- ex = (T)ctr.newInstance(webEx.getResponse());
+ Constructor<?> ctr = exceptionClass.getConstructor(Response.class, Throwable.class);
+ ex = (T)ctr.newInstance(webEx.getResponse(), webEx.getCause());
} catch (Exception ex2) {
ex2.printStackTrace();
return Response.serverError().build();
Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java?rev=1403692&r1=1403691&r2=1403692&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java Tue Oct 30 13:39:26 2012
@@ -28,6 +28,7 @@ import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
+import javax.ws.rs.InternalServerErrorException;
import javax.ws.rs.MatrixParam;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
@@ -75,6 +76,18 @@ public class BookStoreSpring {
}
@GET
+ @Path("/books/webex")
+ public Books getBookWebEx() {
+ throw new WebApplicationException(new RuntimeException("Book web exception"));
+ }
+
+ @GET
+ @Path("/books/webex2")
+ public Books getBookWebEx2() {
+ throw new InternalServerErrorException(new RuntimeException("Book web exception"));
+ }
+
+ @GET
@Path("/books/list/{id}")
public Books getBookAsJsonList(@PathParam("id") Long id) {
return new Books(books.get(id));
Added: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/CustomWebApplicationExceptionMapper.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/CustomWebApplicationExceptionMapper.java?rev=1403692&view=auto
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/CustomWebApplicationExceptionMapper.java (added)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/CustomWebApplicationExceptionMapper.java Tue Oct 30 13:39:26 2012
@@ -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.cxf.systest.jaxrs;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+
+import org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper;
+
+public class CustomWebApplicationExceptionMapper extends WebApplicationExceptionMapper
+ implements ExceptionMapper<WebApplicationException> {
+
+ public Response toResponse(WebApplicationException exception) {
+ if (exception.getResponse().getStatus() == 500) {
+ return Response.status(500).type("text/plain")
+ .entity(exception.getCause().getMessage()).build();
+ } else {
+ return super.toResponse(exception);
+ }
+ }
+
+}
Propchange: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/CustomWebApplicationExceptionMapper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/CustomWebApplicationExceptionMapper.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/InternalServerErrorExceptionMapper.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/InternalServerErrorExceptionMapper.java?rev=1403692&view=auto
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/InternalServerErrorExceptionMapper.java (added)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/InternalServerErrorExceptionMapper.java Tue Oct 30 13:39:26 2012
@@ -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.cxf.systest.jaxrs;
+
+import javax.ws.rs.InternalServerErrorException;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+
+public class InternalServerErrorExceptionMapper
+ implements ExceptionMapper<InternalServerErrorException> {
+
+ public Response toResponse(InternalServerErrorException exception) {
+ return Response.status(500).type("text/plain")
+ .entity(exception.getCause().getMessage()).build();
+ }
+
+}
Propchange: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/InternalServerErrorExceptionMapper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/InternalServerErrorExceptionMapper.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java?rev=1403692&r1=1403691&r2=1403692&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java Tue Oct 30 13:39:26 2012
@@ -31,6 +31,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import javax.ws.rs.InternalServerErrorException;
import javax.ws.rs.core.Response;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@@ -67,7 +68,7 @@ public class JAXRSClientServerSpringBook
public static void startServers() throws Exception {
AbstractResourceInfo.clearAllMaps();
assertTrue("server did not launch correctly",
- launchServer(BookServerSpring.class));
+ launchServer(BookServerSpring.class, true));
createStaticBus();
}
@@ -82,6 +83,40 @@ public class JAXRSClientServerSpringBook
}
@Test
+ public void testGetBookWebEx() throws Exception {
+ final String address = "http://localhost:" + PORT + "/the/thebooks/bookstore/books/webex";
+ doTestGetBookWebEx(address);
+
+ }
+
+ @Test
+ public void testGetBookWebEx3() throws Exception {
+ final String address = "http://localhost:" + PORT + "/the/thebooks3/bookstore/books/webex";
+ doTestGetBookWebEx(address);
+
+ }
+
+ @Test
+ public void testGetBookWebEx4() throws Exception {
+ final String address = "http://localhost:" + PORT + "/the/thebooks3/bookstore/books/webex2";
+ doTestGetBookWebEx(address);
+
+ }
+
+ private void doTestGetBookWebEx(String address) throws Exception {
+ WebClient wc = WebClient.create(address);
+ WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(10000000L);
+ try {
+ wc.accept("text/plain", "application/json").get(Book.class);
+ fail("InternalServerErrorException is expected");
+ } catch (InternalServerErrorException ex) {
+ String errorMessage = ex.getResponse().readEntity(String.class);
+ assertEquals("Book web exception", errorMessage);
+ }
+
+ }
+
+ @Test
public void testPostGeneratedBook() throws Exception {
String baseAddress = "http://localhost:" + PORT + "/the/generated";
JAXBElementProvider<?> provider = new JAXBElementProvider<Object>();
Modified: cxf/trunk/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml?rev=1403692&r1=1403691&r2=1403692&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml (original)
+++ cxf/trunk/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml Tue Oct 30 13:39:26 2012
@@ -70,6 +70,7 @@ http://cxf.apache.org/schemas/core.xsd">
<jaxrs:providers>
<ref bean="jaxbProvider"/>
<ref bean="jsonProvider"/>
+ <bean class="org.apache.cxf.systest.jaxrs.CustomWebApplicationExceptionMapper"/>
</jaxrs:providers>
</jaxrs:server>
@@ -82,6 +83,7 @@ http://cxf.apache.org/schemas/core.xsd">
<jaxrs:providers>
<ref bean="jaxbProvider"/>
<ref bean="jsonProvider"/>
+ <bean class="org.apache.cxf.systest.jaxrs.InternalServerErrorExceptionMapper"/>
</jaxrs:providers>
<jaxrs:features>
<cxf:logging/>