From 7a870e2f11a98301c4c34f67ff143344ef4b94e6 Mon Sep 17 00:00:00 2001 From: Michael Wegener Date: Fri, 7 Jul 2017 13:45:55 +0200 Subject: [PATCH 1/4] bump version to 0.4.1-SNAPSHOT --- gdk-core/pom.xml | 2 +- gdk-maven-plugin/pom.xml | 4 ++-- pom.xml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gdk-core/pom.xml b/gdk-core/pom.xml index 99acb53..12e61ae 100644 --- a/gdk-core/pom.xml +++ b/gdk-core/pom.xml @@ -18,7 +18,7 @@ com.github.libgraviton gdk - 0.4.0 + 0.4.1-SNAPSHOT gdk-core gdk-core diff --git a/gdk-maven-plugin/pom.xml b/gdk-maven-plugin/pom.xml index e6d1196..83a6a52 100644 --- a/gdk-maven-plugin/pom.xml +++ b/gdk-maven-plugin/pom.xml @@ -6,7 +6,7 @@ com.github.libgraviton gdk - 0.4.0 + 0.4.1-SNAPSHOT gdk-maven-plugin maven-plugin @@ -34,7 +34,7 @@ com.github.libgraviton gdk-core - 0.4.0 + 0.4.1-SNAPSHOT org.jsonschema2pojo diff --git a/pom.xml b/pom.xml index 24b4e87..ebe9971 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.github.libgraviton gdk - 0.4.0 + 0.4.1-SNAPSHOT pom gdk Graviton Development Kit From 73d4f0b6732ca226b8e1f408d75dff41aa7a3980 Mon Sep 17 00:00:00 2001 From: Michael Wegener Date: Wed, 9 Aug 2017 15:20:35 +0200 Subject: [PATCH 2/4] add encoding for RQL queries --- .../libgraviton/gdk/api/query/rql/Rql.java | 27 +++++++++++++++++++ .../gdk/api/query/rql/RqlTest.java | 19 +++++++++++++ 2 files changed, 46 insertions(+) diff --git a/gdk-core/src/main/java/com/github/libgraviton/gdk/api/query/rql/Rql.java b/gdk-core/src/main/java/com/github/libgraviton/gdk/api/query/rql/Rql.java index 958b785..de2a5b7 100644 --- a/gdk-core/src/main/java/com/github/libgraviton/gdk/api/query/rql/Rql.java +++ b/gdk-core/src/main/java/com/github/libgraviton/gdk/api/query/rql/Rql.java @@ -9,7 +9,11 @@ import com.github.libgraviton.gdk.api.query.rql.statements.Limit; import com.github.libgraviton.gdk.api.query.rql.statements.Select; import com.github.libgraviton.gdk.data.GravitonBase; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; import java.text.DateFormat; import java.text.ParseException; import java.util.ArrayList; @@ -25,10 +29,28 @@ */ public class Rql extends Query { + private static final Logger LOG = LoggerFactory.getLogger(Rql.class); + + public static final String DEFAULT_ENCODING = "UTF-8"; + private Rql(List statements) { this.statements = statements; } + /** + * RQL encoding string according to https://github.com/xiag-ag/rql-parser + * + * @param input string to encode + * @return RQL encoded string + */ + public static String encode(String input, String encoding) throws UnsupportedEncodingException { + return URLEncoder.encode(input, encoding) + .replace("-", "%2D") + .replace("_", "%5F") + .replace(".", "%2E") + .replace("~", "%7E"); + } + public static class Builder { private Limit limit; @@ -120,6 +142,11 @@ protected List getQueryStatementsFromNode(JsonNode node, DateFor try { dateFormat.parse(value); } catch (ParseException e) { + try { + value = encode(value, DEFAULT_ENCODING); + } catch (UnsupportedEncodingException uee) { + LOG.warn("Unsupported encoding '" + DEFAULT_ENCODING + "', using unencoded value '" + value + "'."); + } value = "string:" + value; } diff --git a/gdk-core/src/test/java/com/github/libgraviton/gdk/api/query/rql/RqlTest.java b/gdk-core/src/test/java/com/github/libgraviton/gdk/api/query/rql/RqlTest.java index 3bdc16c..3b8e5d9 100644 --- a/gdk-core/src/test/java/com/github/libgraviton/gdk/api/query/rql/RqlTest.java +++ b/gdk-core/src/test/java/com/github/libgraviton/gdk/api/query/rql/RqlTest.java @@ -5,6 +5,7 @@ import com.github.libgraviton.gdk.util.PropertiesLoader; import org.junit.Test; +import java.io.UnsupportedEncodingException; import java.util.Arrays; import java.util.Calendar; import java.util.Properties; @@ -65,4 +66,22 @@ public void testAddRqlStatements() { String expectedRql = "?limit(2,3)&select(attribute1)"; assertEquals(expectedRql, rql1.generate()); } + + @Test + public void testEncodeSuccessfully() throws UnsupportedEncodingException { + String unencoded = "http://a-host/endpoint?query=123_5.6~7"; + String encoded = "http%3A%2F%2Fa%2Dhost%2Fendpoint%3Fquery%3D123%5F5%2E6%7E7"; + assertEquals(encoded, Rql.encode(unencoded, Rql.DEFAULT_ENCODING)); + } + + @Test + public void testEncodeUnchanged() throws UnsupportedEncodingException { + String unencoded = "asdf123"; + assertEquals(unencoded, Rql.encode(unencoded, Rql.DEFAULT_ENCODING)); + } + + @Test(expected = UnsupportedEncodingException.class) + public void testEncodeUnsupportedEncoding() throws UnsupportedEncodingException { + Rql.encode("asdf123", "non-existing-encoding"); + } } From 9da12cfade8e37dccf459b5426413f350722c5d7 Mon Sep 17 00:00:00 2001 From: Michael Wegener Date: Wed, 9 Aug 2017 15:54:19 +0200 Subject: [PATCH 3/4] fix javadoc --- .../main/java/com/github/libgraviton/gdk/api/query/rql/Rql.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gdk-core/src/main/java/com/github/libgraviton/gdk/api/query/rql/Rql.java b/gdk-core/src/main/java/com/github/libgraviton/gdk/api/query/rql/Rql.java index de2a5b7..5f15ea0 100644 --- a/gdk-core/src/main/java/com/github/libgraviton/gdk/api/query/rql/Rql.java +++ b/gdk-core/src/main/java/com/github/libgraviton/gdk/api/query/rql/Rql.java @@ -41,7 +41,9 @@ private Rql(List statements) { * RQL encoding string according to https://github.com/xiag-ag/rql-parser * * @param input string to encode + * @param encoding encoding * @return RQL encoded string + * @throws UnsupportedEncodingException if the named encoding is not supported */ public static String encode(String input, String encoding) throws UnsupportedEncodingException { return URLEncoder.encode(input, encoding) From 3068738436e1c6da73ccb03c59c906b980d52c52 Mon Sep 17 00:00:00 2001 From: Michael Wegener Date: Wed, 9 Aug 2017 15:54:36 +0200 Subject: [PATCH 4/4] bump version to 0.4.1 --- gdk-core/pom.xml | 2 +- gdk-maven-plugin/pom.xml | 4 ++-- pom.xml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gdk-core/pom.xml b/gdk-core/pom.xml index 12e61ae..fc23b27 100644 --- a/gdk-core/pom.xml +++ b/gdk-core/pom.xml @@ -18,7 +18,7 @@ com.github.libgraviton gdk - 0.4.1-SNAPSHOT + 0.4.1 gdk-core gdk-core diff --git a/gdk-maven-plugin/pom.xml b/gdk-maven-plugin/pom.xml index 83a6a52..d4cf7e8 100644 --- a/gdk-maven-plugin/pom.xml +++ b/gdk-maven-plugin/pom.xml @@ -6,7 +6,7 @@ com.github.libgraviton gdk - 0.4.1-SNAPSHOT + 0.4.1 gdk-maven-plugin maven-plugin @@ -34,7 +34,7 @@ com.github.libgraviton gdk-core - 0.4.1-SNAPSHOT + 0.4.1 org.jsonschema2pojo diff --git a/pom.xml b/pom.xml index ebe9971..6783382 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.github.libgraviton gdk - 0.4.1-SNAPSHOT + 0.4.1 pom gdk Graviton Development Kit