Author: sergeyb
Date: Fri Jan 18 16:20:01 2013
New Revision: 1435225
URL: http://svn.apache.org/viewvc?rev=1435225&view=rev
Log:
Merged revisions 1435111 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r1435111 | sergeyb | 2013-01-18 12:31:48 +0000 (Fri, 18 Jan 2013) | 1 line
[CXF-4760] Optional support for setting Content-Length in the binary provider
........
Modified:
cxf/branches/2.7.x-fixes/ (props changed)
cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/BinaryDataProvider.java
cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
Merged /cxf/trunk:r1435111
Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Fri Jan 18 16:20:01 2013
@@ -1 +1 @@
-/cxf/trunk:1-1430398,1430564,1430881-1430882,1430905,1430965,1430976,1431315,1431604-1431607,1432070,1432236,1432798,1433007,1433033,1433135,1433305,1433347,1433895,1434042,1434124,1434564,1435034
+/cxf/trunk:1-1430398,1430564,1430881-1430882,1430905,1430965,1430976,1431315,1431604-1431607,1432070,1432236,1432798,1433007,1433033,1433135,1433305,1433347,1433895,1434042,1434124,1434564,1435034,1435111
Modified:
cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java?rev=1435225&r1=1435224&r2=1435225&view=diff
==============================================================================
---
cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
(original)
+++
cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
Fri Jan 18 16:20:01 2013
@@ -305,6 +305,9 @@ public final class ResponseImpl extends
if (responseMessage != null && entity instanceof InputStream) {
MediaType mediaType = getMediaType();
+ if (mediaType == null) {
+ mediaType = MediaType.WILDCARD_TYPE;
+ }
List<ReaderInterceptor> readers =
ProviderFactory.getInstance(responseMessage)
.createMessageBodyReaderInterceptor(cls, t, anns, mediaType,
Modified:
cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/BinaryDataProvider.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/BinaryDataProvider.java?rev=1435225&r1=1435224&r2=1435225&view=diff
==============================================================================
---
cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/BinaryDataProvider.java
(original)
+++
cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/BinaryDataProvider.java
Fri Jan 18 16:20:01 2013
@@ -52,7 +52,8 @@ public class BinaryDataProvider<T> exten
private static final String HTTP_RANGE_PROPERTY = "http.range.support";
private static final int BUFFER_SIZE = 4096;
-
+ private boolean reportByteArraySize;
+
public boolean isReadable(Class<?> type, Type genericType, Annotation[]
annotations, MediaType mt) {
return byte[].class.isAssignableFrom(type)
|| InputStream.class.isAssignableFrom(type)
@@ -77,7 +78,7 @@ public class BinaryDataProvider<T> exten
public long getSize(T t, Class<?> type, Type genericType, Annotation[]
annotations, MediaType mt) {
// TODO: if it's a range request, then we should probably always
return -1 and set
// Content-Length and Content-Range in handleRangeRequest
- if (byte[].class.isAssignableFrom(t.getClass())) {
+ if (reportByteArraySize &&
byte[].class.isAssignableFrom(t.getClass())) {
return ((byte[])t).length;
}
return -1;
@@ -158,4 +159,7 @@ public class BinaryDataProvider<T> exten
}
}
+ public void setReportByteArraySize(boolean report) {
+ this.reportByteArraySize = report;
+ }
}
Modified:
cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=1435225&r1=1435224&r2=1435225&view=diff
==============================================================================
---
cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
(original)
+++
cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
Fri Jan 18 16:20:01 2013
@@ -1218,6 +1218,12 @@ public final class JAXRSUtils {
first.aroundWriteTo(context);
} else {
MessageBodyWriter<Object> writer =
((WriterInterceptorMBW)writers.get(0)).getMBW();
+ if (type == byte[].class) {
+ long size = writer.getSize(entity, type, genericType,
annotations, mediaType);
+ if (size != -1) {
+ httpHeaders.putSingle(HttpHeaders.CONTENT_LENGTH,
Long.toString(size));
+ }
+ }
writer.writeTo(entity, type, genericType, annotations, mediaType,
httpHeaders, entityStream);
}
Modified:
cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java?rev=1435225&r1=1435224&r2=1435225&view=diff
==============================================================================
---
cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
(original)
+++
cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
Fri Jan 18 16:20:01 2013
@@ -61,6 +61,7 @@ public class BookServer extends Abstract
BinaryDataProvider<Object> p = new BinaryDataProvider<Object>();
p.setProduceMediaTypes(Collections.singletonList("application/bar"));
p.setEnableBuffering(true);
+ p.setReportByteArraySize(true);
providers.add(p);
JAXBElementProvider<?> jaxbProvider = new
JAXBElementProvider<Object>();
Map<String, String> jaxbElementClassMap = new HashMap<String,
String>();
Modified:
cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=1435225&r1=1435224&r2=1435225&view=diff
==============================================================================
---
cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
(original)
+++
cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
Fri Jan 18 16:20:01 2013
@@ -133,6 +133,14 @@ public class BookStore {
}
@GET
+ @Path("/booknames/123")
+ @Produces("application/bar")
+ public byte[] getBookName123() {
+ Long l = Long.parseLong("123");
+ return books.get(l).getName().getBytes();
+ }
+
+ @GET
@Path("/beanparam")
@Produces("application/xml")
public Book getBeanParamBook(@BeanParam BookBean bean) {
Modified:
cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=1435225&r1=1435224&r2=1435225&view=diff
==============================================================================
---
cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++
cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Fri Jan 18 16:20:01 2013
@@ -35,6 +35,7 @@ import javax.ws.rs.NotAcceptableExceptio
import javax.ws.rs.ServerErrorException;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.client.ClientException;
+import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
@@ -84,6 +85,21 @@ public class JAXRSClientServerBookTest e
}
@Test
+ public void testGetBookNameAsByteArray() {
+ String address = "http://localhost:" + PORT +
"/bookstore/booknames/123";
+ WebClient wc = WebClient.create(address);
+
WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(1000000);
+
+ Response r = wc.accept("application/bar").get();
+ String name = r.readEntity(String.class);
+ assertEquals("CXF in Action", name);
+ String lengthStr = r.getHeaderString(HttpHeaders.CONTENT_LENGTH);
+ assertNotNull(lengthStr);
+ long length = Long.valueOf(lengthStr);
+ assertEquals(name.length(), length);
+ }
+
+ @Test
public void testGetChapterFromSelectedBook() {
String address = "http://localhost:" + PORT +
"/bookstore/books/id=le=123/chapter/1";
doTestGetChapterFromSelectedBook(address);