Author: dkulp
Date: Wed Jun 1 03:06:39 2011
New Revision: 1129987
URL: http://svn.apache.org/viewvc?rev=1129987&view=rev
Log:
[CXF-3477] Stick a better error message in (rather than an NPE) if an
attachment couldn't be found.
Modified:
cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/LazyDataSource.java
Modified:
cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/LazyDataSource.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/LazyDataSource.java?rev=1129987&r1=1129986&r2=1129987&view=diff
==============================================================================
---
cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/LazyDataSource.java
(original)
+++
cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/LazyDataSource.java
Wed Jun 1 03:06:39 2011
@@ -22,7 +22,9 @@ package org.apache.cxf.attachment;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.List;
import javax.activation.DataSource;
@@ -53,6 +55,27 @@ public class LazyDataSource implements D
}
}
}
+ if (dataSource == null) {
+ //couldn't find it, build up error message
+ List<String> ids = new ArrayList<String>(10);
+ for (Attachment a : attachments) {
+ ids.add(a.getId());
+ if (a.getId().equals(id)) {
+ this.dataSource = a.getDataHandler().getDataSource();
+ if (dataSource != null) {
+ ids = null;
+ break;
+ } else {
+ throw new IllegalStateException("Could not get
DataSource for "
+ + "attachment of id "
+ id);
+ }
+ }
+ }
+ if (ids != null) {
+ throw new IllegalStateException("No attachment for "
+ + " id " + id + " found in " +
ids);
+ }
+ }
}
public String getContentType() {