Author: sergeyb
Date: Tue Oct 16 16:38:02 2012
New Revision: 1398878
URL: http://svn.apache.org/viewvc?rev=1398878&view=rev
Log:
Merged revisions 1398302 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r1398302 | sergeyb | 2012-10-15 15:27:07 +0100 (Mon, 15 Oct 2012) | 1 line
[CXF-4563] Fixing the way empty responses are read on the client side
........
Modified:
cxf/branches/2.6.x-fixes/ (props changed)
cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/Nullable.java
cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractConfigurableProvider.java
cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
Merged /cxf/trunk:r1398302
Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified:
cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/Nullable.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/Nullable.java?rev=1398878&r1=1398877&r2=1398878&view=diff
==============================================================================
---
cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/Nullable.java
(original)
+++
cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/Nullable.java
Tue Oct 16 16:38:02 2012
@@ -32,7 +32,7 @@ import java.lang.annotation.Target;
* injected instead
*
*/
-@Target(ElementType.PARAMETER)
+@Target({ElementType.PARAMETER, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
public @interface Nullable {
}
Modified:
cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractConfigurableProvider.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractConfigurableProvider.java?rev=1398878&r1=1398877&r2=1398878&view=diff
==============================================================================
---
cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractConfigurableProvider.java
(original)
+++
cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractConfigurableProvider.java
Tue Oct 16 16:38:02 2012
@@ -22,6 +22,7 @@ package org.apache.cxf.jaxrs.provider;
import java.util.List;
import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MultivaluedMap;
import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
@@ -148,16 +149,25 @@ public abstract class AbstractConfigurab
protected boolean isPayloadEmpty(HttpHeaders headers) {
if (headers != null) {
- List<String> values =
headers.getRequestHeader(HttpHeaders.CONTENT_LENGTH);
- if (values.size() == 1) {
+ return isPayloadEmpty(headers.getRequestHeaders());
+ } else {
+ return false;
+ }
+ }
+
+ protected boolean isPayloadEmpty(MultivaluedMap<String, String> headers) {
+ if (headers != null) {
+ String value = headers.getFirst(HttpHeaders.CONTENT_LENGTH);
+ if (value != null) {
try {
- Long len = Long.valueOf(values.get(0));
+ Long len = Long.valueOf(value);
return len <= 0;
} catch (NumberFormatException ex) {
// ignore
}
}
}
+
return false;
}
}
Modified:
cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java?rev=1398878&r1=1398877&r2=1398878&view=diff
==============================================================================
---
cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
(original)
+++
cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
Tue Oct 16 16:38:02 2012
@@ -200,10 +200,6 @@ public abstract class AbstractJAXBProvid
jaxbElementClassMap = map;
}
- protected boolean isPayloadEmpty() {
- return mc != null ? isPayloadEmpty(mc.getHttpHeaders()) : false;
- }
-
protected void reportEmptyContentLength() {
String message = new org.apache.cxf.common.i18n.Message("EMPTY_BODY",
BUNDLE).toString();
LOG.warning(message);
Modified:
cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java?rev=1398878&r1=1398877&r2=1398878&view=diff
==============================================================================
---
cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
(original)
+++
cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
Tue Oct 16 16:38:02 2012
@@ -141,7 +141,7 @@ public class JAXBElementProvider<T> exte
public T readFrom(Class<T> type, Type genericType, Annotation[] anns,
MediaType mt,
MultivaluedMap<String, String> headers, InputStream is)
throws IOException {
- if (isPayloadEmpty()) {
+ if (isPayloadEmpty(headers)) {
if (AnnotationUtils.getAnnotation(anns, Nullable.class) != null) {
return null;
} else {
Modified:
cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java?rev=1398878&r1=1398877&r2=1398878&view=diff
==============================================================================
---
cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
(original)
+++
cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
Tue Oct 16 16:38:02 2012
@@ -181,13 +181,14 @@ public final class ProviderFactory {
Message responseMessage = isRequestor ? m.getExchange().getInMessage()
:
m.getExchange().getOutMessage();
if (responseMessage != null) {
- if (!responseMessage.containsKey(Message.CONTENT_TYPE)) {
+ Object ctProperty = responseMessage.get(Message.CONTENT_TYPE);
+ if (ctProperty == null) {
List<MediaType> accepts =
requestHeaders.getAcceptableMediaTypes();
if (accepts.size() > 0) {
mt = accepts.get(0);
}
} else {
- mt =
MediaType.valueOf(responseMessage.get(Message.CONTENT_TYPE).toString());
+ mt = MediaType.valueOf(ctProperty.toString());
}
} else {
mt = requestHeaders.getMediaType();
Modified:
cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java?rev=1398878&r1=1398877&r2=1398878&view=diff
==============================================================================
---
cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
(original)
+++
cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
Tue Oct 16 16:38:02 2012
@@ -194,7 +194,7 @@ public class JSONProvider<T> extends Abs
MultivaluedMap<String, String> headers, InputStream is)
throws IOException {
- if (isPayloadEmpty()) {
+ if (isPayloadEmpty(headers)) {
if (AnnotationUtils.getAnnotation(anns, Nullable.class) != null) {
return null;
} else {
Modified:
cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=1398878&r1=1398877&r2=1398878&view=diff
==============================================================================
---
cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++
cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Tue Oct 16 16:38:02 2012
@@ -1063,6 +1063,37 @@ public class JAXRSClientServerBookTest e
assertEquals(444L, book.getId());
}
+ @Test(expected = ClientException.class)
+ public void testEmptyJSON() {
+ doTestEmptyResponse("application/json");
+ }
+
+ @Test(expected = ClientException.class)
+ public void testEmptyJAXB() {
+ doTestEmptyResponse("application/xml");
+ }
+
+ private void doTestEmptyResponse(String mt) {
+ WebClient wc = WebClient.create("http://localhost:" + PORT +
"/bookstore/emptybook");
+ WebClient.getConfig(wc).getInInterceptors().add(new
ReplaceStatusInterceptor());
+ wc.accept(mt);
+ wc.get(Book.class);
+ }
+
+ @Test(expected = ClientException.class)
+ public void testEmptyResponseProxy() {
+ BookStore store = JAXRSClientFactory.create("http://localhost:" +
PORT, BookStore.class);
+ WebClient.getConfig(store).getInInterceptors().add(new
ReplaceStatusInterceptor());
+ store.getEmptyBook();
+ }
+
+ @Test
+ public void testEmptyResponseProxyNullable() {
+ BookStore store = JAXRSClientFactory.create("http://localhost:" +
PORT, BookStore.class);
+ WebClient.getConfig(store).getInInterceptors().add(new
ReplaceStatusInterceptor());
+ assertNull(store.getEmptyBookNullable());
+ }
+
@Test
public void testFormattedJSON() {
WebClient wc = WebClient.create("http://localhost:" + PORT +
"/bookstore/books/123");
@@ -1889,4 +1920,14 @@ public class JAXRSClientServerBookTest e
}
}
+ public static class ReplaceStatusInterceptor extends
AbstractPhaseInterceptor<Message> {
+ public ReplaceStatusInterceptor() {
+ super(Phase.READ);
+ }
+
+ public void handleMessage(Message message) throws Fault {
+ message.getExchange().put(Message.RESPONSE_CODE, 200);
+ }
+ }
+
}