This is an automated email from the ASF dual-hosted git repository.
amccright pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/master by this push:
new e1b76aa Check for subclasses of WebApplicationException for immediate
responses
e1b76aa is described below
commit e1b76aacfda66cbb8e36485e9d8220babdc00ac1
Author: Andy McCright <[email protected]>
AuthorDate: Tue Feb 6 20:59:30 2018 -0600
Check for subclasses of WebApplicationException for immediate responses
The JAX-RS spec says that a WAE or subclass that contains a response
with an entity should return that response. WAEs were processed
correctly - this fix ensures that subclasses are also processed
correctly.
---
.../org/apache/cxf/jaxrs/utils/ExceptionUtils.java | 2 +-
.../apache/cxf/jaxrs/utils/ExceptionUtilsTest.java | 71 ++++++++++++++++++++++
2 files changed, 72 insertions(+), 1 deletion(-)
diff --git
a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ExceptionUtils.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ExceptionUtils.java
index 5f6e429..5e8b014 100644
---
a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ExceptionUtils.java
+++
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ExceptionUtils.java
@@ -67,7 +67,7 @@ public final class ExceptionUtils {
}
Message inMessage = currentMessage.getExchange().getInMessage();
Response response = null;
- if (ex.getClass() == WebApplicationException.class) {
+ if (ex instanceof WebApplicationException) {
WebApplicationException webEx = (WebApplicationException)ex;
if (webEx.getResponse().hasEntity()
&& webEx.getCause() == null
diff --git
a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/ExceptionUtilsTest.java
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/ExceptionUtilsTest.java
new file mode 100644
index 0000000..124569f
--- /dev/null
+++
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/ExceptionUtilsTest.java
@@ -0,0 +1,71 @@
+/**
+ * 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.jaxrs.utils;
+
+import javax.ws.rs.BadRequestException;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.apache.cxf.jaxrs.provider.ServerProviderFactory;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.ExchangeImpl;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageImpl;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+
+
+public class ExceptionUtilsTest extends Assert {
+
+ @Test
+ public void testConvertFaultToResponseWAEWithResponse() {
+ Message m = createMessage();
+ WebApplicationException wae = new
WebApplicationException(Response.ok("_fromWAE_",
+
MediaType.TEXT_PLAIN_TYPE).build());
+ Response r = ExceptionUtils.convertFaultToResponse(wae, m);
+ assertEquals(200, r.getStatus());
+ assertEquals(MediaType.TEXT_PLAIN_TYPE, r.getMediaType());
+ assertEquals("_fromWAE_", r.readEntity(String.class));
+ }
+
+ @Test
+ public void testConvertFaultToResponseWAESubClassWithResponse() {
+ Message m = createMessage();
+ BadRequestException wae = new BadRequestException(Response.status(400)
+
.type(MediaType.TEXT_HTML)
+
.entity("<em>fromBRE</em>")
+ .build());
+ Response r = ExceptionUtils.convertFaultToResponse(wae, m);
+ assertEquals(400, r.getStatus());
+ assertEquals(MediaType.TEXT_HTML_TYPE, r.getMediaType());
+ assertEquals("<em>fromBRE</em>", r.readEntity(String.class));
+ }
+
+ private Message createMessage() {
+ Message m = new MessageImpl();
+ Exchange e = new ExchangeImpl();
+ m.setExchange(e);
+ e.setInMessage(m);
+ e.put("org.apache.cxf.jaxrs.provider.ServerProviderFactory",
ServerProviderFactory.getInstance());
+ return m;
+ }
+}
--
To stop receiving notification emails like this one, please contact
[email protected].