Skip to content

Commit

Permalink
Merge pull request #119 from swisspost/develop
Browse files Browse the repository at this point in the history
merge to master to trigger release
  • Loading branch information
dominik-cnx authored May 12, 2023
2 parents 63c85b5 + cc3d6c8 commit b0ad144
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.swisspush</groupId>
<artifactId>redisques</artifactId>
<version>3.0.25-SNAPSHOT</version>
<version>3.0.26-SNAPSHOT</version>
<name>redisques</name>
<description>
A highly scalable redis-persistent queuing system for vertx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.vertx.core.json.DecodeException;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import org.apache.commons.codec.binary.Base64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -27,6 +28,7 @@ public class HttpServerRequestUtil {
private static final String CONTENT_LENGTH = "Content-Length";
private static final String CONTENT_TYPE = "content-type";
private static final String APPLICATION_JSON = "application/json";
private static final Base64 apacheDecoder = new Base64();

/**
* Evaluates whether the provided request contains the provided url parameter and the value is either an empty
Expand Down Expand Up @@ -134,9 +136,9 @@ public static String decode(String encoded) {
String value = header.getString(1);
if (key.equalsIgnoreCase(CONTENT_TYPE) && (value.contains("text/") || value.contains(APPLICATION_JSON))) {
try {
object.put(PAYLOAD_OBJECT, new JsonObject(new String(object.getBinary(PAYLOAD), StandardCharsets.UTF_8)));
object.put(PAYLOAD_OBJECT, new JsonObject(new String(apacheDecoder.decode(object.getString(PAYLOAD)), StandardCharsets.UTF_8)));
} catch (DecodeException e) {
object.put(PAYLOAD_STRING, new String(object.getBinary(PAYLOAD), StandardCharsets.UTF_8));
object.put(PAYLOAD_STRING, new String(apacheDecoder.decode(object.getString(PAYLOAD)), StandardCharsets.UTF_8));
}
object.remove(PAYLOAD);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,39 @@ public void testExtractJsonArrayFromBody(TestContext context){
context.assertTrue(result.isErr());
context.assertEquals("no array called 'locks' found", result.getErr());
}

@Test
public void testBase64Decoder(TestContext context){
String testDataUrlEncoded = "{\n" +
" \"headers\": [\n" +
" [\n" +
" \"Content-Type\",\n" +
" \"application/json\"\n" +
" ],\n" +
" [\n" +
" \"Accept-Charset\",\n" +
" \"utf-8, iso-8859-1, utf-16, *;q=0.7\"\n" +
" ]\n" +
" ],\n" +
" \"queueTimestamp\": 1477983671291,\n" +
" \"payload\": \"5rWL6K-V\"\n" +
"}";
String testDataEncoded = "{\n" +
" \"headers\": [\n" +
" [\n" +
" \"Content-Type\",\n" +
" \"application/json\"\n" +
" ],\n" +
" [\n" +
" \"Accept-Charset\",\n" +
" \"utf-8, iso-8859-1, utf-16, *;q=0.7\"\n" +
" ]\n" +
" ],\n" +
" \"queueTimestamp\": 1477983671291,\n" +
" \"payload\": \"5rWL6K+V\"\n" +
"}";
String decodedUrlPayload = HttpServerRequestUtil.decode(testDataUrlEncoded);
String decodedPayload = HttpServerRequestUtil.decode(testDataEncoded);
context.assertEquals(decodedUrlPayload, decodedPayload);
}
}

0 comments on commit b0ad144

Please sign in to comment.