allthingssecurity commented on code in PR #27248:
URL: https://github.com/apache/camel/pull/27248#discussion_r4163517134


##########
docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_23.adoc:
##########
@@ -737,6 +737,13 @@ in the charset that the `Content-Type` declares, so the 
bytes match the header.
 the declared charset and read such a response as UTF-8 must now use the 
declared charset, and characters that the
 declared charset cannot represent are written as `?`.
 
+=== camel-coap - producer without a response

Review Comment:
   Done in 33b49cb674a7: the note is now a "Producer" paragraph (`==== 
Producer`) inside the existing `=== camel-coap` section, and the second heading 
is gone.
   
   _Claude Code on behalf of allthingssecurity_



##########
components/camel-coap/src/main/java/org/apache/camel/coap/CoAPProducer.java:
##########
@@ -76,14 +80,17 @@ public void process(Exchange exchange) throws Exception {
                 pingResponse = client.ping();
                 break;
             default:
-                break;
+                throw new IllegalArgumentException("Unsupported CoAP method: " 
+ method);
         }
 
         if (response != null) {
             CoAPHelper.convertCoapResponseToMessage(response, 
exchange.getOut());
+        } else if (!method.equals(CoAPConstants.METHOD_PING)) {
+            // the client returns null when no response was received (timeout, 
rejected or cancelled request)
+            throw new CamelExchangeException("No response received from CoAP 
server: " + client.getURI(), exchange);

Review Comment:
   Applied in 33b49cb674a7: the message is now `No response received from CoAP 
server for <method>: <URISupport.sanitizeUri(client.getURI())>` (`method` is 
the upper-cased method already in scope).
   
   _Claude Code on behalf of allthingssecurity_



##########
components/camel-coap/src/test/java/org/apache/camel/coap/CoAPProducerNoResponseTest.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.coap;
+
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.CamelExchangeException;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.AvailablePortFinder;
+import org.eclipse.californium.core.CoapClient;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The producer must fail the exchange when the CoAP server does not answer, 
instead of completing it with the request
+ * body.
+ */
+public class CoAPProducerNoResponseTest extends CoAPTestSupport {
+
+    // nothing listens on this port
+    @RegisterExtension
+    static AvailablePortFinder.Port unusedPort = AvailablePortFinder.find();
+
+    @BindToRegistry("noAnswerClient")
+    private final CoapClient noAnswerClient = new CoapClient(
+            String.format("coap://localhost:%d/TestResource", 
unusedPort.getPort())).setTimeout(500L);
+
+    @AfterEach
+    void shutdownClient() {
+        noAnswerClient.shutdown();
+    }
+
+    @Test
+    void testNoResponseFailsTheExchange() throws Exception {

Review Comment:
   Added in 33b49cb674a7 to `CoAPMethodTest`, against the running test server: 
`testCoAPMethodHeaderLowerCase` sends `"delete"` to the DELETE-only resource 
and gets `DELETE: /test/c`, and `testCoAPMethodHeaderUnknown` sends `"FETCH"` 
and checks the `IllegalArgumentException` (`Unsupported CoAP method: FETCH`). 
All 76 camel-coap tests pass.
   
   _Claude Code on behalf of allthingssecurity_



##########
components/camel-coap/src/test/java/org/apache/camel/coap/CoAPProducerNoResponseTest.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.coap;
+
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.CamelExchangeException;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.AvailablePortFinder;
+import org.eclipse.californium.core.CoapClient;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The producer must fail the exchange when the CoAP server does not answer, 
instead of completing it with the request
+ * body.
+ */
+public class CoAPProducerNoResponseTest extends CoAPTestSupport {
+
+    // nothing listens on this port
+    @RegisterExtension
+    static AvailablePortFinder.Port unusedPort = AvailablePortFinder.find();
+
+    @BindToRegistry("noAnswerClient")
+    private final CoapClient noAnswerClient = new CoapClient(
+            String.format("coap://localhost:%d/TestResource", 
unusedPort.getPort())).setTimeout(500L);
+
+    @AfterEach
+    void shutdownClient() {
+        noAnswerClient.shutdown();
+    }
+
+    @Test
+    void testNoResponseFailsTheExchange() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(0);
+
+        Exchange out = template.request("direct:start", e -> 
e.getIn().setBody("Hello"));
+
+        CamelExchangeException cause = 
assertInstanceOf(CamelExchangeException.class, out.getException());
+        assertTrue(cause.getMessage().startsWith("No response received from 
CoAP server"), cause.getMessage());
+        MockEndpoint.assertIsSatisfied(context);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                fromF("coap://localhost:%d/TestResource", 
PORT.getPort()).to("log:exch");

Review Comment:
   Removed in 33b49cb674a7.
   
   _Claude Code on behalf of allthingssecurity_



-- 
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