I encountered a tricky problem when upgrading to CXF 2.2.6. I fixed the issue, but I'm submitting a brief summary of my solution, for the benefit of other developers who encounter a similar problem in the future.
When upgrading from CXF 2.2.3 to CXF 2.2.6, I started getting the following ClassCastException in AttachmentDeserializer: java.lang.ClassCastException: org.apache.cxf.helpers.LoadingByteArrayOutputStream$1 cannot be cast to org.apache.cxf.attachment.DelegatingInputStream at org.apache.cxf.attachment.AttachmentDeserializer.cacheStreamedAttachment s(AttachmentDeserializer.java:232) at org.apache.cxf.attachment.AttachmentDeserializer.readNext(AttachmentDese rializer.java:193) at org.apache.cxf.attachment.LazyAttachmentCollection$1.hasNext(LazyAttachm entCollection.java:94) at org.apache.cxf.transport.http.AbstractHTTPDestination.cacheInput(Abstrac tHTTPDestination.java:485) at org.apache.cxf.transport.http.AbstractHTTPDestination.flushHeaders(Abstr actHTTPDestination.java:506) at org.apache.cxf.transport.http.AbstractHTTPDestination$WrappedOutputStrea m.onFirstWrite(AbstractHTTPDestination.java:611) at org.apache.cxf.io.AbstractWrappedOutputStream.write(AbstractWrappedOutpu tStream.java:42) at org.apache.cxf.io.AbstractWrappedOutputStream.write(AbstractWrappedOutpu tStream.java:55) at org.apache.cxf.attachment.AttachmentSerializer.writeProlog(AttachmentSer ializer.java:143) at org.apache.cxf.interceptor.AttachmentOutInterceptor.handleMessage(Attach mentOutInterceptor.java:65) at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorC hain.java:243) This was caused because of one of my custom interceptors was trying to modify the attachments on an outgoing message. It did so by doing something like this: Collection<Attachment> attachments = message.getAttachments(); DataSource dataSource = new MyDataSource(myInputStream)); attachments.add(new AttachmentImpl(attachmentId, new DataHandler(dataSource)); The custom datasource caused problems for CXF's AttachmentSerializer class, which assumed in CXF 2.2.6 that all attachments would only use AttachmentDataSources. My custom attachment with its own kind of datasource broke this assumption. I was able to work around it by using this line instead: DataSource dataSource = new AttachmentDataSource(myInputStream)); - Aaron
