You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2020/11/25 05:08:54 UTC
[camel] branch master updated: CAMEL-15890: camel-salesforce: URLs
for Composite APIs not encoded correctly (#4676)
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 8330bbd CAMEL-15890: camel-salesforce: URLs for Composite APIs not encoded correctly (#4676)
8330bbd is described below
commit 8330bbddb57c4b649b7e6b7741260a85c38bcd0d
Author: Jeremy Ross <je...@jeremyross.org>
AuthorDate: Tue Nov 24 23:08:40 2020 -0600
CAMEL-15890: camel-salesforce: URLs for Composite APIs not encoded correctly (#4676)
---
.../salesforce/api/dto/composite/SObjectBatch.java | 5 ++--
.../api/dto/composite/SObjectComposite.java | 7 +++---
.../component/salesforce/api/utils/UrlUtils.java | 29 ++++++++++++++++++++++
.../salesforce/CompositeApiIntegrationTest.java | 17 ++++++++++---
.../ROOT/pages/camel-3x-upgrade-guide-3_7.adoc | 4 +++
docs/user-manual/modules/ROOT/pages/team.adoc | 1 +
6 files changed, 54 insertions(+), 9 deletions(-)
diff --git a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/composite/SObjectBatch.java b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/composite/SObjectBatch.java
index ce7479f..c6fbf97 100644
--- a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/composite/SObjectBatch.java
+++ b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/composite/SObjectBatch.java
@@ -18,8 +18,6 @@ package org.apache.camel.component.salesforce.api.dto.composite;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -34,6 +32,7 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamOmitField;
import org.apache.camel.component.salesforce.api.dto.AbstractDescribedSObjectBase;
import org.apache.camel.component.salesforce.api.dto.AbstractSObjectBase;
+import org.apache.camel.component.salesforce.api.utils.UrlUtils;
import org.apache.camel.component.salesforce.api.utils.Version;
import static org.apache.camel.util.ObjectHelper.notNull;
@@ -378,7 +377,7 @@ public final class SObjectBatch implements Serializable {
String rowBaseUrl(final String type, final String fieldName, final String fieldValue) {
try {
return apiPrefix + "/sobjects/" + notEmpty(type, SOBJECT_TYPE_PARAM) + "/" + notEmpty(fieldName, "fieldName") + "/"
- + URLEncoder.encode(notEmpty(fieldValue, "fieldValue"), StandardCharsets.UTF_8.name());
+ + UrlUtils.encodePath(notEmpty(fieldValue, "fieldValue"));
} catch (final UnsupportedEncodingException e) {
throw new IllegalStateException(e);
}
diff --git a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/composite/SObjectComposite.java b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/composite/SObjectComposite.java
index c12dafd..b3acaa3 100644
--- a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/composite/SObjectComposite.java
+++ b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/composite/SObjectComposite.java
@@ -34,6 +34,7 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamOmitField;
import org.apache.camel.component.salesforce.api.dto.AbstractDescribedSObjectBase;
import org.apache.camel.component.salesforce.api.dto.AbstractSObjectBase;
+import org.apache.camel.component.salesforce.api.utils.UrlUtils;
import org.apache.camel.component.salesforce.api.utils.Version;
import org.apache.camel.component.salesforce.internal.PayloadFormat;
@@ -48,8 +49,8 @@ import static org.apache.camel.util.StringHelper.notEmpty;
* reference ID that maps to the subrequest’s response. You can then refer to the ID in the url or body fields of later
* subrequests by using a JavaScript-like reference notation. Most requests that are supported in the Composite batch
* API the helper builder methods are provided. For batch requests that do not have their corresponding helper builder
- * method, use {@link #addGeneric(Method, String)} or {@link #addGeneric(Method, String, Object)} methods. To build the
- * batch use: <blockquote>
+ * method, use {@link #addGeneric(Method, String, String)} or {@link #addGeneric(Method, String, Object, String)}
+ * methods. To build the batch use: <blockquote>
*
* <pre>
* {@code
@@ -367,7 +368,7 @@ public final class SObjectComposite implements Serializable {
String rowBaseUrl(final String type, final String fieldName, final String fieldValue) {
try {
return apiPrefix + "/sobjects/" + notEmpty(type, SOBJECT_TYPE_PARAM) + "/" + notEmpty(fieldName, "fieldName") + "/"
- + URLEncoder.encode(notEmpty(fieldValue, "fieldValue"), StandardCharsets.UTF_8.name());
+ + UrlUtils.encodePath(notEmpty(fieldValue, "fieldValue"));
} catch (final UnsupportedEncodingException e) {
throw new IllegalStateException(e);
}
diff --git a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/UrlUtils.java b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/UrlUtils.java
new file mode 100644
index 0000000..4645259
--- /dev/null
+++ b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/UrlUtils.java
@@ -0,0 +1,29 @@
+/*
+ * 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.api.utils;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+
+public class UrlUtils {
+
+ // Encode the URL up to the point of the query. Do not pass the query portion into this method.
+ public static String encodePath(String path) throws UnsupportedEncodingException {
+ return URLEncoder.encode(path, StandardCharsets.UTF_8.name()).replace("+", "%20");
+ }
+}
diff --git a/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/CompositeApiIntegrationTest.java b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/CompositeApiIntegrationTest.java
index 3606672..0d3a317 100644
--- a/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/CompositeApiIntegrationTest.java
+++ b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/CompositeApiIntegrationTest.java
@@ -34,6 +34,7 @@ import org.apache.camel.component.salesforce.api.dto.composite.SObjectCompositeR
import org.apache.camel.component.salesforce.api.dto.composite.SObjectCompositeResult;
import org.apache.camel.component.salesforce.api.utils.Version;
import org.apache.camel.component.salesforce.dto.generated.Account;
+import org.apache.camel.component.salesforce.dto.generated.Line_Item__c;
import org.apache.camel.test.junit5.params.Parameter;
import org.apache.camel.test.junit5.params.Parameterized;
import org.apache.camel.test.junit5.params.Parameters;
@@ -124,13 +125,13 @@ public class CompositeApiIntegrationTest extends AbstractSalesforceTestBase {
@Test
public void shouldSupportObjectCreation() {
- final SObjectComposite compoiste = new SObjectComposite(version, true);
+ final SObjectComposite composite = new SObjectComposite(version, true);
final Account newAccount = new Account();
newAccount.setName("Account created from Composite batch API");
- compoiste.addCreate(newAccount, "CreateAccountReferenceId");
+ composite.addCreate(newAccount, "CreateAccountReferenceId");
- final SObjectCompositeResponse response = testComposite(compoiste);
+ final SObjectCompositeResponse response = testComposite(composite);
assertResponseContains(response, "id");
}
@@ -167,6 +168,16 @@ public class CompositeApiIntegrationTest extends AbstractSalesforceTestBase {
}
@Test
+ public void shouldSupportObjectUpserts() {
+ final SObjectComposite composite = new SObjectComposite(version, true);
+
+ final Line_Item__c li = new Line_Item__c();
+ composite.addUpsertByExternalId("Line_Item__c", "Name", "AC12345", li,
+ "UpsertLineItemReferenceId");
+ testComposite(composite);
+ }
+
+ @Test
public void shouldSupportQuery() {
final SObjectComposite composite = new SObjectComposite(version, true);
composite.addQuery("SELECT Id, Name FROM Account", "SelectQueryReferenceId");
diff --git a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_7.adoc b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_7.adoc
index aa0cb98..484f6f1 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_7.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_7.adoc
@@ -278,3 +278,7 @@ supported and can be set via the `apiVersion` component option.
The `packages` option must be set if using the XML `format` option. This change is a result of
adopting XStream's Security Framework.
+
+CAMEL-15890 fixed a bug in which values for External Ids that contained spaces would have spaces converted to "+". This has been fixed.
+However, any such values that now have the plus sign in salesforce will no longer match as Camel will now preserve the space. Therefore
+you may need to have a transformation that explicility covnerts spaces to "+" if you need to preserve the old behavior.
diff --git a/docs/user-manual/modules/ROOT/pages/team.adoc b/docs/user-manual/modules/ROOT/pages/team.adoc
index 8c54968..2eb11df 100644
--- a/docs/user-manual/modules/ROOT/pages/team.adoc
+++ b/docs/user-manual/modules/ROOT/pages/team.adoc
@@ -122,6 +122,7 @@ added.
|Jérôme Delagnes |
|Jeff Sparkes |
|Jeff Lansing |SYS Technologies
+|Jeremy Ross |Elevation Solutions
|Jeremy Volkman |
|Joe Fernandez |TTM
|John Heitmann |