Author: dkulp
Date: Tue Jul 28 15:48:16 2009
New Revision: 798575
URL: http://svn.apache.org/viewvc?rev=798575&view=rev
Log:
Merged revisions 798561 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r798561 | dkulp | 2009-07-28 11:26:25 -0400 (Tue, 28 Jul 2009) | 2 lines
Update to really allow streaming of mtom attachments with jaxb
Also close the underlying stream
........
Modified:
cxf/branches/2.2.x-fixes/ (props changed)
cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java
cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/DelegatingInputStream.java
cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/LazyAttachmentCollection.java
cxf/branches/2.2.x-fixes/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java
cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jms/JMSClientServerTest.java
cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java
Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jul 28 15:48:16 2009
@@ -1 +1 @@
-/cxf/trunk:782728-782730,783097,783294,783396,784059,784181-784184,784893,784895,785279-785282,785468,785621,785624,785651,785734,785866,786142,786271-786272,786395,786512,786514,786582-786583,786638,786647,786850,787200,787269,787277-787279,787290-787291,787305,787323,787366,787849,788030,788060,788187,788444,788451,788703,788752,788774,788819-788820,789013,789371,789387,789420,789527-789530,789704-789705,789788,789811,789896-789901,790074,790094,790134,790188,790294,790553,790637-790644,790868,791301,791354,791538,791753,791947,792007,792096,792183,792261-792265,792271,792604,792683-792685,792975,792985,793059,793570,794297,794396,794680,794728,794771,794778-794780,794892,795044,795104,795160,795583,795907,796022-796023,796352,796593,796741,796780,796994-796997,797117,797159,797192,797194,797231-797233,797442,797505,797517,797534,797581-797583,797587,797640,797651,797699,797882-797883,798344-798346,798363,798461,798533,798551
+/cxf/trunk:782728-782730,783097,783294,783396,784059,784181-784184,784893,784895,785279-785282,785468,785621,785624,785651,785734,785866,786142,786271-786272,786395,786512,786514,786582-786583,786638,786647,786850,787200,787269,787277-787279,787290-787291,787305,787323,787366,787849,788030,788060,788187,788444,788451,788703,788752,788774,788819-788820,789013,789371,789387,789420,789527-789530,789704-789705,789788,789811,789896-789901,790074,790094,790134,790188,790294,790553,790637-790644,790868,791301,791354,791538,791753,791947,792007,792096,792183,792261-792265,792271,792604,792683-792685,792975,792985,793059,793570,794297,794396,794680,794728,794771,794778-794780,794892,795044,795104,795160,795583,795907,796022-796023,796352,796593,796741,796780,796994-796997,797117,797159,797192,797194,797231-797233,797442,797505,797517,797534,797581-797583,797587,797640,797651,797699,797882-797883,798344-798346,798363,798461,798533,798551,798561
Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified:
cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java?rev=798575&r1=798574&r2=798575&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java
(original)
+++
cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java
Tue Jul 28 15:48:16 2009
@@ -31,17 +31,35 @@
public class AttachmentDataSource implements DataSource {
private final String ct;
- private final CachedOutputStream cache;
+ private CachedOutputStream cache;
+ private InputStream ins;
+ private DelegatingInputStream lastIns;
public AttachmentDataSource(String ctParam, InputStream inParam) throws
IOException {
this.ct = ctParam;
- cache = new CachedOutputStream();
- IOUtils.copy(inParam, cache);
- cache.lockOutputStream();
+ ins = inParam;
}
+ public boolean isCached() {
+ return cache != null;
+ }
+
public void hold() {
- cache.holdTempFile();
+ try {
+ if (cache == null) {
+ cache = new CachedOutputStream();
+ IOUtils.copy(ins, cache);
+ cache.lockOutputStream();
+ cache.holdTempFile();
+ ins.close();
+ ins = null;
+ if (lastIns != null) {
+ lastIns.setInputStream(cache.getInputStream());
+ }
+ }
+ } catch (IOException e) {
+ //shouldn't happen
+ }
}
public void release() {
cache.releaseTempFileHold();
@@ -53,9 +71,14 @@
public InputStream getInputStream() {
try {
- return new DelegatingInputStream(cache.getInputStream());
+ if (cache != null) {
+ return cache.getInputStream();
+ }
+ if (ins instanceof DelegatingInputStream) {
+ lastIns = (DelegatingInputStream)ins;
+ }
+ return ins;
} catch (IOException e) {
- e.printStackTrace();
return null;
}
}
Modified:
cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java?rev=798575&r1=798574&r2=798575&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
(original)
+++
cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
Tue Jul 28 15:48:16 2009
@@ -58,6 +58,8 @@
private int pbAmount = 2048;
private PushbackInputStream stream;
+ private int createCount;
+ private int closedCount;
private byte boundary[];
@@ -122,7 +124,9 @@
throw new RuntimeException(e);
}
- body = new DelegatingInputStream(new
MimeBodyPartInputStream(stream, boundary, pbAmount));
+ body = new DelegatingInputStream(new
MimeBodyPartInputStream(stream, boundary, pbAmount),
+ this);
+ createCount++;
message.setContent(InputStream.class, body);
}
}
@@ -199,13 +203,15 @@
&& !((DelegatingInputStream) body).isClosed()) {
cache((DelegatingInputStream) body, true);
- message.setContent(InputStream.class, body);
}
for (Attachment a : attachments.getLoadedAttachments()) {
DataSource s = a.getDataHandler().getDataSource();
- if (!(s instanceof AttachmentDataSource)) {
- //AttachementDataSource objects are already cached
+ if (s instanceof AttachmentDataSource) {
+ if (!((AttachmentDataSource)s).isCached()) {
+ cache((DelegatingInputStream) s.getInputStream(), false);
+ }
+ } else {
cache((DelegatingInputStream) s.getInputStream(), false);
}
}
@@ -279,7 +285,9 @@
*/
private Attachment createAttachment(InternetHeaders headers) throws
IOException {
InputStream partStream =
- new DelegatingInputStream(new MimeBodyPartInputStream(stream,
boundary, pbAmount));
+ new DelegatingInputStream(new MimeBodyPartInputStream(stream,
boundary, pbAmount),
+ this);
+ createCount++;
return AttachmentUtil.createAttachment(partStream, headers);
}
@@ -290,4 +298,11 @@
public void setLazyLoading(boolean lazyLoading) {
this.lazyLoading = lazyLoading;
}
+
+ public void markClosed(DelegatingInputStream delegatingInputStream) throws
IOException {
+ closedCount++;
+ if (closedCount == createCount && !attachments.hasNext()) {
+ stream.close();
+ }
+ }
}
Modified:
cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/DelegatingInputStream.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/DelegatingInputStream.java?rev=798575&r1=798574&r2=798575&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/DelegatingInputStream.java
(original)
+++
cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/DelegatingInputStream.java
Tue Jul 28 15:48:16 2009
@@ -25,19 +25,24 @@
final class DelegatingInputStream extends InputStream {
private InputStream is;
+ private AttachmentDeserializer deserializer;
private boolean isClosed;
/**
* @param source
*/
- DelegatingInputStream(InputStream is) {
+ DelegatingInputStream(InputStream is, AttachmentDeserializer ads) {
this.is = is;
+ deserializer = ads;
}
@Override
public void close() throws IOException {
is.close();
isClosed = true;
+ if (!isClosed) {
+ deserializer.markClosed(this);
+ }
}
public boolean isClosed() {
Modified:
cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/LazyAttachmentCollection.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/LazyAttachmentCollection.java?rev=798575&r1=798574&r2=798575&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/LazyAttachmentCollection.java
(original)
+++
cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/LazyAttachmentCollection.java
Tue Jul 28 15:48:16 2009
@@ -58,6 +58,15 @@
throw new RuntimeException(e);
}
}
+ public boolean hasNext() throws IOException {
+ Attachment a = deserializer.readNext();
+ if (a != null) {
+ attachments.add(a);
+ return true;
+ }
+ return false;
+ }
+
public Iterator<Attachment> iterator() {
return new Iterator<Attachment>() {
Modified:
cxf/branches/2.2.x-fixes/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java?rev=798575&r1=798574&r2=798575&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java
(original)
+++
cxf/branches/2.2.x-fixes/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java
Tue Jul 28 15:48:16 2009
@@ -20,7 +20,6 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.io.FileInputStream;
import java.io.InputStream;
import java.io.PushbackInputStream;
import java.util.Collection;
@@ -76,11 +75,6 @@
InputStream attIs = a.getDataHandler().getInputStream();
- // We need to cache the InputStream for reusing the
AttachmentDataSource
- //assertTrue(((DelegatingInputStream) attIs).getInputStream()
instanceof MimeBodyPartInputStream);
- assertTrue(((DelegatingInputStream) attIs).getInputStream() instanceof
ByteArrayInputStream);
- assertTrue(((DelegatingInputStream) attBody).getInputStream()
instanceof ByteArrayInputStream);
-
// check the cached output stream
ByteArrayOutputStream out = new ByteArrayOutputStream();
IOUtils.copy(attBody, out);
@@ -125,11 +119,6 @@
InputStream attIs = a.getDataHandler().getInputStream();
- // We need to cache the InputStream for reusing the
AttachmentDataSource
- //assertTrue(((DelegatingInputStream) attIs).getInputStream()
instanceof MimeBodyPartInputStream);
- assertTrue(((DelegatingInputStream) attIs).getInputStream() instanceof
ByteArrayInputStream);
- assertTrue(((DelegatingInputStream) attBody).getInputStream()
instanceof ByteArrayInputStream);
-
// check the cached output stream
ByteArrayOutputStream out = new ByteArrayOutputStream();
IOUtils.copy(attBody, out);
@@ -174,12 +163,6 @@
InputStream attIs = a.getDataHandler().getInputStream();
- // We need to cache the InputStream for reusing the
AttachmentDataSource
- //assertTrue(((DelegatingInputStream) attIs).getInputStream()
instanceof MimeBodyPartInputStream);
- assertTrue(((DelegatingInputStream) attIs).getInputStream() instanceof
ByteArrayInputStream);
-
- assertTrue(((DelegatingInputStream) attBody).getInputStream()
instanceof ByteArrayInputStream);
-
// check the cached output stream
ByteArrayOutputStream out = new ByteArrayOutputStream();
IOUtils.copy(attBody, out);
@@ -222,11 +205,6 @@
InputStream attIs = a.getDataHandler().getInputStream();
- // We need to cache the InputStream for reusing the
AttachmentDataSource
- //assertTrue(((DelegatingInputStream) attIs).getInputStream()
instanceof MimeBodyPartInputStream);
- assertTrue(((DelegatingInputStream) attIs).getInputStream() instanceof
ByteArrayInputStream);
- assertTrue(((DelegatingInputStream) attBody).getInputStream()
instanceof ByteArrayInputStream);
-
// check the cached output stream
ByteArrayOutputStream out = new ByteArrayOutputStream();
IOUtils.copy(attBody, out);
@@ -274,11 +252,12 @@
InputStream attIs = a.getDataHandler().getInputStream();
- // We need to cache the InputStream for reusing the
AttachmentDataSource
- //assertTrue(((DelegatingInputStream) attIs).getInputStream()
instanceof MimeBodyPartInputStream);
- assertTrue(((DelegatingInputStream) attIs).getInputStream() instanceof
ByteArrayInputStream);
- assertTrue(((DelegatingInputStream) attBody).getInputStream()
instanceof FileInputStream);
+ assertFalse(itr.hasNext());
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ IOUtils.copy(attIs, out);
+ assertTrue(out.size() > 1000);
+
}
Modified:
cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=798575&r1=798574&r2=798575&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
(original)
+++
cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
Tue Jul 28 15:48:16 2009
@@ -100,6 +100,7 @@
private static final Logger LOG = LogUtils.getL7dLogger(JAXRSUtils.class);
private static final ResourceBundle BUNDLE =
BundleUtils.getBundle(JAXRSUtils.class);
private static final String PROPOGATE_EXCEPTION =
"org.apache.cxf.propogate.exception";
+ private static final String FORM_PARAM_MAP = JAXRSUtils.class.getName() +
".FORM_DATA";
private JAXRSUtils() {
}
@@ -592,19 +593,25 @@
MessageContext mc = new MessageContextImpl(m);
MediaType mt = mc.getHttpHeaders().getMediaType();
- MultivaluedMap<String, String> params = new MetadataMap<String,
String>();
+ @SuppressWarnings("unchecked")
+ MultivaluedMap<String, String> params = (MultivaluedMap<String,
String>)m.get(FORM_PARAM_MAP);
- if (mt == null ||
mt.isCompatible(MediaType.APPLICATION_FORM_URLENCODED_TYPE)) {
- String body =
(String)m.get("org.apache.cxf.jaxrs.provider.form.body");
- if (body == null) {
- body = FormUtils.readBody(m.getContent(InputStream.class));
- m.put("org.apache.cxf.jaxrs.provider.form.body", body);
+ if (params == null) {
+ params = new MetadataMap<String, String>();
+ m.put(FORM_PARAM_MAP, params);
+
+ if (mt == null ||
mt.isCompatible(MediaType.APPLICATION_FORM_URLENCODED_TYPE)) {
+ String body =
(String)m.get("org.apache.cxf.jaxrs.provider.form.body");
+ if (body == null) {
+ body = FormUtils.readBody(m.getContent(InputStream.class));
+ m.put("org.apache.cxf.jaxrs.provider.form.body", body);
+ }
+ HttpServletRequest request =
(HttpServletRequest)m.get(AbstractHTTPDestination.HTTP_REQUEST);
+ FormUtils.populateMapFromString(params, (String)body, decode,
request);
+ } else {
+ MultipartBody body = AttachmentUtils.getMultipartBody(mc);
+ FormUtils.populateMapFromMultipart(params, body, decode);
}
- HttpServletRequest request =
(HttpServletRequest)m.get(AbstractHTTPDestination.HTTP_REQUEST);
- FormUtils.populateMapFromString(params, (String)body, decode,
request);
- } else {
- MultipartBody body = AttachmentUtils.getMultipartBody(mc);
- FormUtils.populateMapFromMultipart(params, body, decode);
}
if ("".equals(key)) {
Modified:
cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jms/JMSClientServerTest.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jms/JMSClientServerTest.java?rev=798575&r1=798574&r2=798575&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jms/JMSClientServerTest.java
(original)
+++
cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jms/JMSClientServerTest.java
Tue Jul 28 15:48:16 2009
@@ -52,6 +52,7 @@
import
org.apache.cxf.hello_world_jms.HelloWorldServiceRuntimeCorrelationIDDynamicPrefix;
import
org.apache.cxf.hello_world_jms.HelloWorldServiceRuntimeCorrelationIDStaticPrefix;
import org.apache.cxf.hello_world_jms.NoSuchCodeLitFault;
+import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.jms_mtom.JMSMTOMPortType;
import org.apache.cxf.jms_mtom.JMSMTOMService;
import org.apache.cxf.service.model.EndpointInfo;
@@ -901,7 +902,8 @@
handler1.value = new DataHandler(fileURL);
int size = handler1.value.getInputStream().available();
mtom.testDataHandler(name, handler1);
- int size2 = handler1.value.getInputStream().available();
- assertTrue("The response file is not same with the sent file.", size
== size2);
+
+ byte bytes[] =
IOUtils.readBytesFromStream(handler1.value.getInputStream());
+ assertEquals("The response file is not same with the sent file.",
size, bytes.length);
}
}
Modified:
cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java?rev=798575&r1=798574&r2=798575&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java
(original)
+++
cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java
Tue Jul 28 15:48:16 2009
@@ -30,11 +30,11 @@
import javax.xml.ws.Holder;
import javax.xml.ws.soap.SOAPBinding;
-import org.apache.axiom.attachments.utils.IOUtils;
import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.endpoint.ClientImpl;
+import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsClientProxy;
@@ -89,7 +89,6 @@
((BindingProvider)mtomPort).getRequestContext().put("schema-validation-enabled",
Boolean.TRUE);
-
param.value = new DataHandler(new ByteArrayDataSource(data,
"application/octet-stream"));
Holder<String> name = new Holder<String>("call detail");
mtomPort.testXop(name, param);
@@ -97,7 +96,7 @@
assertNotNull(param.value);
InputStream in = param.value.getInputStream();
- byte bytes[] = IOUtils.getStreamAsByteArray(in);
+ byte bytes[] = IOUtils.readBytesFromStream(in);
assertEquals(data.length, bytes.length);
in.close();
@@ -108,10 +107,9 @@
assertNotNull(param.value);
in = param.value.getInputStream();
- bytes = IOUtils.getStreamAsByteArray(in);
+ bytes = IOUtils.readBytesFromStream(in);
assertEquals(data.length, bytes.length);
in.close();
-
} catch (UndeclaredThrowableException ex) {
throw (Exception)ex.getCause();
}