gnodet-bot commented on code in PR #29450:
URL: https://github.com/apache/camel/pull/29450#discussion_r4524279641


##########
components/camel-cxf/camel-cxf-soap/src/main/java/org/apache/camel/component/cxf/jaxws/CxfClientCallback.java:
##########
@@ -101,23 +111,46 @@ public void handleException(Map<String, Object> ctx, 
Throwable ex) {
                 camelExchange.setException(ex);
             }
         } finally {
-            // add cookies to the cookie store
-            if (endpoint.getCookieHandler() != null && 
cxfExchange.getInMessage() != null) {
-                try {
-                    Map<String, List<String>> cxfHeaders
-                            = CastUtils.cast((Map<?, ?>) 
cxfExchange.getInMessage().get(CxfConstants.PROTOCOL_HEADERS));
-                    endpoint.getCookieHandler().storeCookies(camelExchange, 
endpoint.getRequestUri(camelExchange), cxfHeaders);
-                } catch (IOException e) {
-                    LOG.error("Cannot store cookies", e);
-                }
-            }
-            // copy the context information and
-            // call camel callback
             // for one way messages callback is already called in
             // process method of org.apache.camel.component.cxf.CxfProducer
             if (!boi.getOperationInfo().isOneWay()) {
-                
endpoint.getCxfBinding().populateExchangeFromCxfResponse(camelExchange, 
cxfExchange, ctx);
-                camelAsyncCallback.done(false);
+                // always signal the Camel callback, even if cookie store or 
binding population throws,
+                // to prevent the calling thread from hanging in 
DefaultAsyncProcessorAwaitManager
+                try {
+                    // add cookies to the cookie store; catch Throwable so an 
unexpected runtime failure
+                    // does not prevent populateExchangeFromCxfResponse from 
running or done() from firing;
+                    // use suppressed to preserve the root transport/fault 
exception already on the exchange
+                    if (endpoint.getCookieHandler() != null && 
cxfExchange.getInMessage() != null) {
+                        try {
+                            Map<String, List<String>> cxfHeaders
+                                    = CastUtils.cast((Map<?, ?>) 
cxfExchange.getInMessage().get(CxfConstants.PROTOCOL_HEADERS));
+                            
endpoint.getCookieHandler().storeCookies(camelExchange, 
endpoint.getRequestUri(camelExchange),
+                                    cxfHeaders);
+                        } catch (Throwable e) {
+                            LOG.error("Cannot store cookies", e);
+                            Throwable root = camelExchange.getException();
+                            if (root != null) {
+                                root.addSuppressed(e);
+                            } else {
+                                camelExchange.setException(e);
+                            }
+                        }
+                    }
+                    // copy the context information
+                    try {
+                        
endpoint.getCxfBinding().populateExchangeFromCxfResponse(camelExchange, 
cxfExchange, ctx);
+                    } catch (Throwable t) {
+                        // preserve the root transport/fault exception; record 
the binding error as suppressed
+                        Exception cur = camelExchange.getException();
+                        if (cur != null) {
+                            cur.addSuppressed(t);
+                        } else {
+                            camelExchange.setException(t);

Review Comment:
   💡 **Low — missing self-suppression guard:** If 
`populateExchangeFromCxfResponse` rethrows the same exception object already on 
the exchange, `cur.addSuppressed(t)` where `cur == t` throws 
`IllegalArgumentException: Self-suppression not permitted` (documented Java 
behaviour). Add a `cur != t` guard:
   
   ```suggestion
                       } catch (Throwable t) {
                           // preserve the root transport/fault exception; 
record the binding error as suppressed
                           Exception cur = camelExchange.getException();
                           if (cur != null && cur != t) {
                               cur.addSuppressed(t);
                           } else if (cur == null) {
                               camelExchange.setException(t);
                           }
   ```



##########
components/camel-cxf/camel-cxf-soap/src/main/java/org/apache/camel/component/cxf/jaxws/CxfClientCallback.java:
##########
@@ -56,23 +55,34 @@ public void handleResponse(Map<String, Object> ctx, 
Object[] res) {
         try {
             super.handleResponse(ctx, res);
         } finally {
-            // add cookies to the cookie store
-            if (endpoint.getCookieHandler() != null && 
cxfExchange.getInMessage() != null) {
-                try {
-                    Map<String, List<String>> cxfHeaders
-                            = CastUtils.cast((Map<?, ?>) 
cxfExchange.getInMessage().get(CxfConstants.PROTOCOL_HEADERS));
-                    endpoint.getCookieHandler().storeCookies(camelExchange, 
endpoint.getRequestUri(camelExchange), cxfHeaders);
-                } catch (IOException e) {
-                    LOG.error("Cannot store cookies", e);
-                }
-            }
-            // bind the CXF response to Camel exchange and
-            // call camel callback
             // for one way messages callback is already called in
             // process method of org.apache.camel.component.cxf.CxfProducer
             if (!boi.getOperationInfo().isOneWay()) {
-                
endpoint.getCxfBinding().populateExchangeFromCxfResponse(camelExchange, 
cxfExchange, ctx);
-                camelAsyncCallback.done(false);
+                // always signal the Camel callback, even if cookie store or 
binding population throws,
+                // to prevent the calling thread from hanging in 
DefaultAsyncProcessorAwaitManager
+                try {
+                    // add cookies to the cookie store; catch Throwable so an 
unexpected runtime failure
+                    // does not prevent populateExchangeFromCxfResponse from 
running or done() from firing
+                    if (endpoint.getCookieHandler() != null && 
cxfExchange.getInMessage() != null) {
+                        try {
+                            Map<String, List<String>> cxfHeaders
+                                    = CastUtils.cast((Map<?, ?>) 
cxfExchange.getInMessage().get(CxfConstants.PROTOCOL_HEADERS));
+                            
endpoint.getCookieHandler().storeCookies(camelExchange, 
endpoint.getRequestUri(camelExchange),
+                                    cxfHeaders);
+                        } catch (Throwable e) {
+                            LOG.error("Cannot store cookies", e);
+                            camelExchange.setException(e);
+                        }
+                    }
+                    // bind the CXF response to Camel exchange
+                    try {
+                        
endpoint.getCxfBinding().populateExchangeFromCxfResponse(camelExchange, 
cxfExchange, ctx);
+                    } catch (Throwable t) {
+                        camelExchange.setException(t);

Review Comment:
   ⚠️ **Medium — silent exception overwrite:** If the cookie-store catch above 
already called `setException(e)`, this unconditional `setException(t)` discards 
that cookie error silently.
   
   `handleException` handles the same scenario correctly with `addSuppressed`. 
Suggest mirroring that pattern here:
   
   ```suggestion
                       } catch (Throwable t) {
                           Exception cur = camelExchange.getException();
                           if (cur != null) {
                               cur.addSuppressed(t);
                           } else {
                               camelExchange.setException(t);
                           }
   ```



##########
components/camel-cxf/camel-cxf-soap/src/test/java/org/apache/camel/component/cxf/jaxws/CxfClientCallbackTest.java:
##########
@@ -0,0 +1,279 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.cxf.jaxws;
+
+import java.net.URI;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.camel.AsyncCallback;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.cxf.common.CxfBinding;
+import org.apache.camel.http.base.cookie.CookieHandler;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.service.model.BindingOperationInfo;
+import org.apache.cxf.service.model.OperationInfo;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;

Review Comment:
   🔧 **Nit — inconsistent static imports:** `doThrow`, `mock`, and `when` are 
imported statically but `doAnswer` is used fully-qualified at 4 call sites 
(lines 96, 119, 181, 236). Add:
   
   ```suggestion
   import static org.mockito.Mockito.doThrow;
   import static org.mockito.Mockito.mock;
   import static org.mockito.Mockito.when;
   import static org.mockito.Mockito.doAnswer;
   ```
   
   Then replace `org.mockito.Mockito.doAnswer(` → `doAnswer(` at each usage.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to