Skip to content
This repository has been archived by the owner on Apr 28, 2020. It is now read-only.

Commit

Permalink
Merge pull request #12 from fiskaly/Fix-Rerouting
Browse files Browse the repository at this point in the history
Fix rerouting
  • Loading branch information
auxdevelopment committed Sep 13, 2019
2 parents 7ef83ad + ba6d2ee commit 14de565
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,30 @@ private String signTransaction(String requestBody) throws IOException {
return mapper.writeValueAsString(resultMap.get("result"));
}

String rewriteRoute(String sourceUrl) {
List<String> parts = new LinkedList<>(Arrays.asList(sourceUrl.split("\\?")));

String host = parts.remove(0);
String queryList = String.join("?", parts);

if (!queryList.isEmpty()) {
queryList = "?" + queryList;
}

String targetUrl = host + "/log" + queryList;

return targetUrl;
}


private Request createReroutedRequest(Request request) {
String originalUrl = request
String sourceUrl = request
.url()
.toString();

List<String> parts = new LinkedList<>(Arrays.asList(originalUrl.split("\\?")));

String host = parts.remove(0);
String newUrl = host + "/log" + String.join("?", parts);

HttpUrl url = HttpUrl.parse(newUrl);
String targetUrl = rewriteRoute(sourceUrl);

HttpUrl url = HttpUrl.parse(targetUrl);

request = request
.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.fiskaly.kassensichv.client.interceptors;

import org.junit.Test;

import static org.junit.Assert.*;

public class TransactionInterceptorTest {

@Test
public void rewriteRoute() {
TransactionInterceptor interceptor =
new TransactionInterceptor(null);

String targetUrl = interceptor.rewriteRoute(
"https://kassensichv.io/api/v0/tss/" +
"0e709b9a-9e09-4d48-9680-c1810a1e45c3/tx/" +
"e09bf758-d9a2-449e-bb34-af6815d76389?last_revision=1");

assertEquals(
"https://kassensichv.io/api/v0/tss/0e709b9a-9e09-4d48-9680-c1810a1e45c3" +
"/tx/e09bf758-d9a2-449e-bb34-af6815d76389/log?last_revision=1",
targetUrl
);

targetUrl = interceptor.rewriteRoute(
"https://kassensichv.io/api/v0/tss/" +
"0e709b9a-9e09-4d48-9680-c1810a1e45c3/tx/" +
"e09bf758-d9a2-449e-bb34-af6815d76389?last_revision=1?something_else=2");

assertEquals(
"https://kassensichv.io/api/v0/tss/0e709b9a-9e09-4d48-9680-c1810a1e45c3" +
"/tx/e09bf758-d9a2-449e-bb34-af6815d76389/log?last_revision=1?something_else=2",
targetUrl
);

targetUrl = interceptor.rewriteRoute(
"https://kassensichv.io/api/v0/tss/" +
"0e709b9a-9e09-4d48-9680-c1810a1e45c3/tx/" +
"e09bf758-d9a2-449e-bb34-af6815d76389");

assertEquals(
"https://kassensichv.io/api/v0/tss/0e709b9a-9e09-4d48-9680-c1810a1e45c3" +
"/tx/e09bf758-d9a2-449e-bb34-af6815d76389/log",
targetUrl
);
}
}

0 comments on commit 14de565

Please sign in to comment.