This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 543a1f3 CAMEL-16197: camel-cxf - Should ensure CXF attachment that
are cached to temp disk should be closed/deleted when UoW is done so CXF does
not leak files.
543a1f3 is described below
commit 543a1f3f0d0e782b1bd61d6d4e98b6b831746546
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Mar 24 19:54:57 2021 +0100
CAMEL-16197: camel-cxf - Should ensure CXF attachment that are cached to
temp disk should be closed/deleted when UoW is done so CXF does not leak files.
---
.../apache/camel/component/cxf/CxfConsumer.java | 29 ++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git
a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java
index 58096c7..0469fb1 100644
---
a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java
+++
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java
@@ -16,10 +16,13 @@
*/
package org.apache.camel.component.cxf;
+import java.io.InputStream;
import java.lang.reflect.Method;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
+import javax.activation.DataHandler;
import javax.xml.ws.WebFault;
import org.w3c.dom.Element;
@@ -27,18 +30,22 @@ import org.w3c.dom.Element;
import org.apache.camel.AsyncCallback;
import org.apache.camel.ExchangePattern;
import org.apache.camel.ExchangeTimedOutException;
+import org.apache.camel.ExtendedExchange;
import org.apache.camel.Processor;
import org.apache.camel.Suspendable;
import org.apache.camel.component.cxf.common.message.CxfConstants;
import org.apache.camel.component.cxf.interceptors.UnitOfWorkCloserInterceptor;
import org.apache.camel.component.cxf.util.CxfUtils;
import org.apache.camel.support.DefaultConsumer;
+import org.apache.camel.support.SynchronizationAdapter;
+import org.apache.camel.util.IOHelper;
import org.apache.camel.util.ObjectHelper;
import org.apache.cxf.continuations.Continuation;
import org.apache.cxf.continuations.ContinuationProvider;
import org.apache.cxf.endpoint.Server;
import org.apache.cxf.frontend.ServerFactoryBean;
import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.Attachment;
import org.apache.cxf.message.Exchange;
import org.apache.cxf.message.FaultMode;
import org.apache.cxf.message.Message;
@@ -303,6 +310,28 @@ public class CxfConsumer extends DefaultConsumer
implements Suspendable {
// put the context into camelExchange
camelExchange.setProperty(CxfConstants.JAXWS_CONTEXT, context);
+ // add UoW done to avoid CXF file leaks
+ camelExchange.adapt(ExtendedExchange.class).addOnCompletion(new
SynchronizationAdapter() {
+ @Override
+ public void onDone(org.apache.camel.Exchange exchange) {
+ // CXF may leak temporary cached attachments to temp
folder that has not been in use
+ Collection<Attachment> atts =
cxfExchange.getInMessage().getAttachments();
+ if (atts != null) {
+ for (Attachment att : atts) {
+ DataHandler dh = att.getDataHandler();
+ if (dh != null) {
+ try {
+ InputStream is = dh.getInputStream();
+ IOHelper.close(is);
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+ }
+ }
+ }
+ });
+
// we want to handle the UoW
try {
CxfConsumer.this.createUoW(camelExchange);