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


##########
components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/internal/client/AbstractClientBase.java:
##########
@@ -178,6 +179,48 @@ protected Request getRequest(String method, String url, 
Map<String, List<String>
         return request;
     }
 
+    /**
+     * Resolves the request URL for a path that is relative to the configured 
Salesforce instance and verifies that it
+     * stays on that instance. The {@code relativePath} must be an absolute 
path (it has to begin with a single
+     * {@code /}), and the fully resolved URL must keep the scheme, host and 
port of the configured instance URL.
+     * Operations that build a request URL by appending a caller-supplied path 
onto {@link #instanceUrl} use this to
+     * keep the request on the configured instance.
+     *
+     * @param  relativePath        the path to append to the configured 
instance URL
+     * @return                     the fully resolved request URL
+     * @throws SalesforceException if {@code relativePath} is not an absolute 
path on the configured instance
+     */
+    protected String resolveInstanceUrl(String relativePath) throws 
SalesforceException {
+        if (relativePath == null || !relativePath.startsWith("/") || 
relativePath.startsWith("//")) {
+            throw new SalesforceException(
+                    "Request path must be an absolute path on the configured 
Salesforce instance: " + relativePath);
+        }
+        final String requestUrl = instanceUrl + relativePath;

Review Comment:
   ⚠️ **NPE on null `instanceUrl`**: When `instanceUrl` is null (login hasn't 
completed yet), `new URI(instanceUrl)` two lines below throws 
`NullPointerException` — not caught by the `catch (URISyntaxException)`. A 
guard here would fail with a clear `SalesforceException` instead (as @davsclaus 
noted).
   
   ```suggestion
           }
           if (instanceUrl == null) {
               throw new SalesforceException("Instance URL is not set (login 
may not have completed yet)");
           }
           final String requestUrl = instanceUrl + relativePath;
   ```



##########
components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/internal/client/DefaultRestClient.java:
##########
@@ -630,6 +639,18 @@ private String urlEncode(String query) throws 
UnsupportedEncodingException {
         return encodedQuery;
     }
 
+    private String encodePathSegment(String value) {
+        if (value == null || value.isEmpty()) {
+            throw new IllegalArgumentException("The record id must not be null 
or empty");

Review Comment:
   💡 **Inconsistent error propagation**: `encodePathSegment` throws unchecked 
`IllegalArgumentException` for null/empty id. Every other error path in this 
class — `query()`, `queryMore()`, `makeRequest()` — routes exceptions through 
the `ResponseCallback` as `SalesforceException`. The four callers outside 
`updateSObjectMultipart` (`getSObject`, `updateSObject`, `deleteSObject`, 
`getBlobField`) let this propagate unchecked.
   
   Before this PR, a null `id` caused a `NullPointerException`, so this is an 
improvement; but `SalesforceException` routed through the callback would be 
fully consistent. Can be addressed in a follow-up.



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