davsclaus commented on code in PR #26207: URL: https://github.com/apache/camel/pull/26207#discussion_r3977249008
########## components/camel-as2/camel-as2-component/src/test/java/org/apache/camel/component/as2/AS2AsyncMdnContextReuseTest.java: ########## @@ -0,0 +1,127 @@ +/* + * 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.as2; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.as2.api.AS2MediaType; +import org.apache.camel.component.as2.api.AS2MessageStructure; +import org.apache.camel.component.as2.api.AS2ServerConnection; +import org.apache.camel.component.as2.api.AS2SignatureAlgorithm; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.AvailablePortFinder; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +/** + * The AS2 request handler creates its {@code HttpContext} once per connection and reuses it for every request handled + * on that connection. A request that asks for an asynchronous MDN leaves the recipient address and the report on that + * context; a later request on the same connection that does not ask for one must not inherit them and trigger a second + * delivery (CAMEL-24435). + */ +public class AS2AsyncMdnContextReuseTest extends AbstractAS2ITSupport { + + @RegisterExtension + AvailablePortFinder.Port jettyPort = AvailablePortFinder.find(); + + private static final String EDI_MESSAGE = """ + UNB+UNOA:1+005435656:1+006415160:1+060515:1434+00000000000778' + UNH+00000000000117+INVOIC:D:97B:UN' + BGM+380+342459+9' + UNT+23+00000000000117' + UNZ+1+00000000000778' + """; + + private AS2ServerConnection serverConnection; + private int targetPort; + + @Override + public void setupResources() throws Exception { + serverConnection = new AS2ServerConnection( + "1.1", "AS2AsyncMdnContextReuseTest Server", "server.example.com", 0, + AS2SignatureAlgorithm.SHA256WITHRSA, null, null, null, "TBD", null, null, + null, null, null, "localhost"); + targetPort = serverConnection.getLocalPort(); + serverConnection.listen("/", new AS2AsyncMDNServerManagerIT.RequestHandler()); + } + + @Override + public void cleanupResources() { + if (serverConnection != null) { + serverConnection.close(); + } + } + + @Test + public void asyncMdnStateDoesNotLeakToTheNextRequestOnTheSameConnection() throws Exception { + MockEndpoint receipts = getMockEndpoint("mock:receipts"); + + // the first message asks for an asynchronous receipt, so exactly one MDN must be delivered + receipts.expectedMessageCount(1); + requestBodyAndHeaders("direct://SEND", EDI_MESSAGE, + as2Headers("http://localhost:" + jettyPort.getPort() + "/handle-receipts")); + receipts.setResultWaitTime(TimeUnit.SECONDS.toMillis(10)); Review Comment: Applied in 09518dc — `setResultWaitTime` now runs before `requestBodyAndHeaders`. Agreed it could not produce a false pass here, but the endpoint should be fully configured before the action that feeds it. _Claude Code on behalf of davsclaus_ ########## components/camel-as2/camel-as2-component/src/test/java/org/apache/camel/component/as2/AS2AsyncMdnContextReuseTest.java: ########## @@ -0,0 +1,127 @@ +/* + * 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.as2; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.as2.api.AS2MediaType; +import org.apache.camel.component.as2.api.AS2MessageStructure; +import org.apache.camel.component.as2.api.AS2ServerConnection; +import org.apache.camel.component.as2.api.AS2SignatureAlgorithm; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.AvailablePortFinder; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +/** + * The AS2 request handler creates its {@code HttpContext} once per connection and reuses it for every request handled + * on that connection. A request that asks for an asynchronous MDN leaves the recipient address and the report on that + * context; a later request on the same connection that does not ask for one must not inherit them and trigger a second + * delivery (CAMEL-24435). + */ +public class AS2AsyncMdnContextReuseTest extends AbstractAS2ITSupport { + + @RegisterExtension + AvailablePortFinder.Port jettyPort = AvailablePortFinder.find(); + + private static final String EDI_MESSAGE = """ + UNB+UNOA:1+005435656:1+006415160:1+060515:1434+00000000000778' + UNH+00000000000117+INVOIC:D:97B:UN' + BGM+380+342459+9' + UNT+23+00000000000117' + UNZ+1+00000000000778' + """; + + private AS2ServerConnection serverConnection; + private int targetPort; + + @Override + public void setupResources() throws Exception { + serverConnection = new AS2ServerConnection( + "1.1", "AS2AsyncMdnContextReuseTest Server", "server.example.com", 0, + AS2SignatureAlgorithm.SHA256WITHRSA, null, null, null, "TBD", null, null, + null, null, null, "localhost"); + targetPort = serverConnection.getLocalPort(); + serverConnection.listen("/", new AS2AsyncMDNServerManagerIT.RequestHandler()); + } + + @Override + public void cleanupResources() { + if (serverConnection != null) { + serverConnection.close(); + } + } + + @Test + public void asyncMdnStateDoesNotLeakToTheNextRequestOnTheSameConnection() throws Exception { Review Comment: Intentional, and consistent with the package. The `IT` suffix in `components/camel-as2/camel-as2-component` marks the tests that need the failsafe lifecycle; the self-contained ones that stand up their own `AS2ServerConnection` in `setupResources` already use the `Test` suffix and run under surefire — e.g. `AS2AsyncMdnBasicAuthHeaderTest`, `AS2BasicAuthHeaderTest`, `AS2ServerBasicAuthHeaderTest`, `AS2TokenAuthHeaderTest`, all of which likewise extend `AbstractAS2ITSupport`. This test follows that group, so no rename. _Claude Code on behalf of davsclaus_ -- 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]
