This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 83f0195b46b Fixed NPE in salesforce-component when no response body in
DefaultRawClient (#16497)
83f0195b46b is described below
commit 83f0195b46bc2cb262787fa942427f8715b4b021
Author: baconberry <[email protected]>
AuthorDate: Tue Dec 10 14:37:36 2024 +0100
Fixed NPE in salesforce-component when no response body in DefaultRawClient
(#16497)
---
.../internal/client/DefaultRawClient.java | 4 +++
.../internal/client/DefaultRawClientTest.java | 41 ++++++++++++++++++++++
2 files changed, 45 insertions(+)
diff --git
a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/internal/client/DefaultRawClient.java
b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/internal/client/DefaultRawClient.java
index cfbec34cf85..610b8c320e6 100644
---
a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/internal/client/DefaultRawClient.java
+++
b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/internal/client/DefaultRawClient.java
@@ -54,6 +54,10 @@ public class DefaultRawClient extends AbstractClientBase
implements RawClient {
@Override
protected SalesforceException createRestException(Response response,
InputStream responseContent) {
+ if (responseContent == null) {
+ return new SalesforceException(
+ "Unexpected error: " + response.getReason() + ", with
content: null", response.getStatus());
+ }
String message = null;
try {
message = IOUtils.toString(responseContent,
StandardCharsets.UTF_8);
diff --git
a/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/internal/client/DefaultRawClientTest.java
b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/internal/client/DefaultRawClientTest.java
new file mode 100644
index 00000000000..20010e240f8
--- /dev/null
+++
b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/internal/client/DefaultRawClientTest.java
@@ -0,0 +1,41 @@
+/*
+ * 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.salesforce.internal.client;
+
+import org.apache.camel.component.salesforce.SalesforceHttpClient;
+import org.apache.camel.component.salesforce.SalesforceLoginConfig;
+import org.apache.camel.component.salesforce.api.SalesforceException;
+import org.apache.camel.component.salesforce.internal.SalesforceSession;
+import org.eclipse.jetty.client.Response;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.mockito.Mockito.mock;
+
+public class DefaultRawClientTest {
+
+ @Test
+ public void shouldNotThrowNPEWhenNoResponseContent() throws
SalesforceException {
+ var client = new DefaultRawClient(
+ mock(SalesforceHttpClient.class), "",
mock(SalesforceSession.class), new SalesforceLoginConfig());
+
+ var response = mock(Response.class);
+ var resultException = client.createRestException(response, null);
+ assertInstanceOf(SalesforceException.class, resultException);
+ }
+
+}