[ 
https://issues.apache.org/jira/browse/CAMEL-12057?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16276425#comment-16276425
 ] 

ASF GitHub Bot commented on CAMEL-12057:
----------------------------------------

oscerd closed pull request #2126: CAMEL-12057 Fixed missing encoding of query 
params
URL: https://github.com/apache/camel/pull/2126
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/components/camel-olingo2/camel-olingo2-api/src/main/java/org/apache/camel/component/olingo2/api/impl/Olingo2AppImpl.java
 
b/components/camel-olingo2/camel-olingo2-api/src/main/java/org/apache/camel/component/olingo2/api/impl/Olingo2AppImpl.java
index f4423b75f0a..f1198a0a26d 100644
--- 
a/components/camel-olingo2/camel-olingo2-api/src/main/java/org/apache/camel/component/olingo2/api/impl/Olingo2AppImpl.java
+++ 
b/components/camel-olingo2/camel-olingo2-api/src/main/java/org/apache/camel/component/olingo2/api/impl/Olingo2AppImpl.java
@@ -23,6 +23,7 @@
 import java.io.UnsupportedEncodingException;
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.net.URLEncoder;
 import java.nio.charset.Charset;
 import java.nio.charset.UnsupportedCharsetException;
 import java.util.ArrayList;
@@ -221,7 +222,7 @@ public void close() {
 
         final UriInfoWithType uriInfo = parseUri(edm, resourcePath, 
queryParams);
 
-        execute(new HttpGet(createUri(resourcePath, queryParams)), 
getResourceContentType(uriInfo),
+        execute(new HttpGet(createUri(resourcePath, 
encodeQueryParams(queryParams))), getResourceContentType(uriInfo),
             endpointHttpHeaders, new 
AbstractFutureCallback<T>(responseHandler) {
 
                 @Override
@@ -242,7 +243,7 @@ public void uread(final Edm edm, final String resourcePath, 
final Map<String, St
 
         final UriInfoWithType uriInfo = parseUri(edm, resourcePath, 
queryParams);
 
-        execute(new HttpGet(createUri(resourcePath, queryParams)), 
getResourceContentType(uriInfo),
+        execute(new HttpGet(createUri(resourcePath, 
encodeQueryParams(queryParams))), getResourceContentType(uriInfo),
             endpointHttpHeaders, new 
AbstractFutureCallback<InputStream>(responseHandler) {
 
                 @Override
@@ -255,6 +256,17 @@ public void onCompleted(HttpResponse result) throws 
IOException {
             });
     }
 
+    private Map<String, String> encodeQueryParams(Map<String, String> 
queryParams) {
+        Map<String, String> encodedQueryParams = queryParams;
+        if (queryParams != null) {
+            encodedQueryParams = new HashMap<String, 
String>(queryParams.size());
+            for (Map.Entry<String, String> entry : queryParams.entrySet()) {
+                encodedQueryParams.put(entry.getKey(), 
URLEncoder.encode(entry.getValue()));
+            }
+        }
+        return encodedQueryParams;
+    }
+
     private ContentType getResourceContentType(UriInfoWithType uriInfo) {
         ContentType resourceContentType;
         switch (uriInfo.getUriType()) {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Missing encoding for query params
> ---------------------------------
>
>                 Key: CAMEL-12057
>                 URL: https://issues.apache.org/jira/browse/CAMEL-12057
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-olingo2
>    Affects Versions: 2.20.1
>         Environment: spring-boot
>            Reporter: Przemek Kubicki
>             Fix For: 2.20.2
>
>
> Hi guys,
> i've a problem with making camel-olingo2 to work with $filter query parameter
> Here is my RouteBuilder situation
> {code:java}
> rest("/olingo2")
>                 .get("tickets").to("direct:olingo2/tickets");
>         from("direct:olingo2/tickets")
>                 .setHeader("CamelOlingo2.$filter", simple("ReporterEmail eq 
> 'u...@company.com'"))
>                 .setHeader("CamelOlingo2.$select", simple("ID,Name"))
>                 .to("olingo2://read/ServiceRequestCollection")
> {code}
> I get an exception while parsing endpoint URI (a space in uri)
> {{URISyntaxException: Illegal character in query at index 107: 
> https://myXXXXXX.crm.ondemand.com/sap/c4c/odata/v1/c4codata/ServiceRequestCollection/?$filter=ReporterEmail
>  eq 'u...@company.com'&$select=ID,Name
> }}
> It comes basically from Olingo2AppImpl:224
> I tried with
> {{ .setHeader("CamelOlingo2.$filter", 
> simple("reporteremail%20eq%20%27u...@company.com%27"))
> }}but then it fails in Olingo2AppImpl:222 while parsing filter expression.
> As a conclusion, at Olingo2AppImpl:224 queryParams should be encoded.
> here is my patch 
> https://github.com/przem/camel/commit/e239645cadd7130b27cb85bd713cb71140872865



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to