davsclaus commented on code in PR #27168: URL: https://github.com/apache/camel/pull/27168#discussion_r4155221662
########## components/camel-odata/src/test/java/org/apache/camel/component/odata/ODataEndpointTest.java: ########## @@ -0,0 +1,95 @@ +/* + * 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.odata; + +import java.net.URI; + +import org.apache.camel.support.jsse.SSLContextParameters; +import org.apache.camel.test.junit6.CamelTestSupport; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class ODataEndpointTest extends CamelTestSupport { + + @Test + void testEndpointUriConfiguration() throws Exception { + ODataEndpoint endpoint = context.getEndpoint( + "odata:http://localhost:8080/odata/Products", ODataEndpoint.class); + + assertNotNull(endpoint); + assertEquals(new URI("http://localhost:8080/odata/Products"), endpoint.getHttpUri()); + assertNotNull(endpoint.createProducer()); + } + + @Test + void testEndpointWithQueryParameters() throws Exception { + ODataEndpoint endpoint = context.getEndpoint( + "odata:http://localhost:8080/odata/Products?top=10&filter=Name%20eq%20'Test'", ODataEndpoint.class); + + assertNotNull(endpoint); + assertEquals(new URI("http://localhost:8080/odata/Products"), endpoint.getHttpUri()); + assertEquals(10, endpoint.getConfiguration().getTop()); + assertEquals("Name eq 'Test'", endpoint.getConfiguration().getFilter()); + } + + @Test + void testEndpointSchemeAndMetadata() throws Exception { + ODataEndpoint endpoint = context.getEndpoint( + "odata:http://localhost:8080/odata/Products", ODataEndpoint.class); + + assertEquals("odata", endpoint.getEndpointKey().split(":")[0]); + assertEquals("odata://http://localhost:8080/odata/Products", endpoint.getEndpointUri()); + } + + @Test + void testSecretMaskingInUriAndToString() { + String rawUri + = "odata:http://localhost:8080/odata/Products?authUsername=user&authPassword=secretPassword&authBearerToken=myToken"; + ODataEndpoint endpoint = context.getEndpoint(rawUri, ODataEndpoint.class); + + assertNotNull(endpoint); + + // toString() must mask secrets + String toString = endpoint.toString(); + assertFalse(toString.contains("secretPassword"), "toString() should not reveal authPassword"); + assertFalse(toString.contains("myToken"), "toString() should not reveal authBearerToken"); + assertTrue(toString.contains("authPassword=xxxxxx") || toString.contains("authPassword=******")); + + // Check URISupport sanitization directly if testing Camel's URI masking utility + String sanitizedUri = org.apache.camel.util.URISupport.sanitizeUri(endpoint.getEndpointUri()); Review Comment: Small: please import `org.apache.camel.util.URISupport` instead of using the fully qualified name (CLAUDE.md, Import Style). ########## components/camel-odata/src/main/java/org/apache/camel/component/odata/ODataProducer.java: ########## @@ -0,0 +1,296 @@ +/* + * 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.odata; + +import java.net.URI; +import java.nio.charset.StandardCharsets; +import java.util.Base64; +import java.util.LinkedHashMap; +import java.util.Map; + +import org.apache.camel.Endpoint; +import org.apache.camel.Exchange; +import org.apache.camel.Producer; +import org.apache.camel.component.http.HttpConstants; +import org.apache.camel.support.DefaultProducer; +import org.apache.camel.support.MessageHelper; +import org.apache.camel.support.jsse.SSLContextParameters; +import org.apache.camel.support.service.ServiceHelper; +import org.apache.camel.util.URISupport; + +public class ODataProducer extends DefaultProducer { + + private final ODataEndpoint endpoint; + private Producer httpProducer; + + public ODataProducer(ODataEndpoint endpoint) { + super(endpoint); + this.endpoint = endpoint; + } + + @Override + protected void doStart() throws Exception { + super.doStart(); + + URI uri = endpoint.getHttpUri(); + String httpUri = uri.toString(); + + if (httpUri.contains("?")) { + httpUri += "&throwExceptionOnFailure=true"; + } else { + httpUri += "?throwExceptionOnFailure=true"; + } + + ODataConfiguration config = endpoint.getConfiguration(); + Map<String, Object> httpParameters = new LinkedHashMap<>(); + + if (config != null) { + SSLContextParameters sslParams = endpoint.getSslContextParameters(); + if (sslParams == null && endpoint.isUseGlobalSslContextParameters()) { + sslParams = endpoint.getCamelContext().getSSLContextParameters(); + } + if (sslParams != null) { + httpParameters.put("sslContextParameters", sslParams); + } + } + + Endpoint httpEndpoint = endpoint.getCamelContext() Review Comment: `CamelContext.getEndpoint(uri, parameters)` only uses `parameters` when the endpoint is created: the lookup is keyed by the normalized URI alone (`AbstractCamelContext.doGetEndpoint`). So two odata endpoints with the same base URL but different `sslContextParameters` (or one using the global SSL context and one not) share whichever HTTP endpoint was created first, and the second endpoint's TLS settings are silently ignored. A user's own `https://...?throwExceptionOnFailure=true` endpoint would collide the same way. Creating a private HTTP endpoint avoids the cache, e.g. ```java Component http = getEndpoint().getCamelContext().getComponent(uri.getScheme()); httpEndpoint = http.createEndpoint(httpUri, httpParameters); ServiceHelper.startService(httpEndpoint); ``` and stop it in `doStop()`. A test with two endpoints on the same URL, one with a trust store and one without, would cover it. -- 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]
