From d06ca2d2a2a31756f190e0a982f97e73ae0b08fd Mon Sep 17 00:00:00 2001 From: Jaroslav Tulach Date: Sun, 6 Sep 2015 10:42:10 +0200 Subject: [PATCH 1/3] The $ substitution should happen when processing the URL. When text/plain MIME type is requested, return plain String, not a JSON object. --- .../org/teavm/html4j/test/KnockoutFXTest.java | 40 +++++++++++++++++-- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/teavm-html4j/src/test/java/org/teavm/html4j/test/KnockoutFXTest.java b/teavm-html4j/src/test/java/org/teavm/html4j/test/KnockoutFXTest.java index 50fc1bb75..3134c453c 100644 --- a/teavm-html4j/src/test/java/org/teavm/html4j/test/KnockoutFXTest.java +++ b/teavm-html4j/src/test/java/org/teavm/html4j/test/KnockoutFXTest.java @@ -41,7 +41,7 @@ public final class KnockoutFXTest extends KnockoutTCK implements Transfer { private static Class browserClass; private static Fn.Presenter browserContext; private KO4J ko4j = new KO4J(); - private Map urlMap = new HashMap<>(); + private final Map urlMap = new HashMap<>(); public KnockoutFXTest() { } @@ -112,7 +112,7 @@ public final class KnockoutFXTest extends KnockoutTCK implements Transfer { public URI prepareURL(String content, String mimeType, String[] parameters) { try { String url = "http://localhost/dynamic/" + urlMap.size(); - urlMap.put(url, content); + urlMap.put(url, new Request(content, mimeType, parameters)); return new URI(url); } catch (URISyntaxException ex) { throw new IllegalStateException(ex); @@ -140,10 +140,30 @@ public final class KnockoutFXTest extends KnockoutTCK implements Transfer { throw new IllegalArgumentException("This mock does not support JSONP calls"); } String url = call.composeURL(null); - String data = urlMap.get(url); + Request data = urlMap.get(url); if (data != null) { + String content = data.content; + for (int i = 0;; i++) { + String find = "$" + i; + int at = content.indexOf(find); + if (at == -1) { + break; + } + String value = data.parameters[i]; + if (value.equals("http.method")) { + value = call.getMethod(); + } + if (value.equals("http.requestBody")) { + value = call.getMessage(); + } + content = content.substring(0, at) + value + content.substring(at + find.length()); + } try { - call.notifySuccess(toJSON(new ByteArrayInputStream(data.getBytes()))); + if (data.mimeType.equals("text/plain")) { + call.notifySuccess(content); + } else { + call.notifySuccess(toJSON(new ByteArrayInputStream(content.getBytes()))); + } } catch (IOException e) { call.notifyError(e); } @@ -151,4 +171,16 @@ public final class KnockoutFXTest extends KnockoutTCK implements Transfer { call.notifyError(new IllegalStateException()); } } + + private static final class Request { + final String content; + final String mimeType; + final String[] parameters; + + public Request(String content, String mimeType, String[] parameters) { + this.content = content; + this.mimeType = mimeType; + this.parameters = parameters; + } + } } From c5452d405cbb80a479873c6793d2b6c8b31f666c Mon Sep 17 00:00:00 2001 From: Jaroslav Tulach Date: Sun, 6 Sep 2015 11:35:27 +0200 Subject: [PATCH 2/3] Handle the headers as introduced in HTML/Java version 1.2 --- .../test/java/org/teavm/html4j/test/KnockoutFXTest.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/teavm-html4j/src/test/java/org/teavm/html4j/test/KnockoutFXTest.java b/teavm-html4j/src/test/java/org/teavm/html4j/test/KnockoutFXTest.java index 3134c453c..a03433314 100644 --- a/teavm-html4j/src/test/java/org/teavm/html4j/test/KnockoutFXTest.java +++ b/teavm-html4j/src/test/java/org/teavm/html4j/test/KnockoutFXTest.java @@ -150,6 +150,14 @@ public final class KnockoutFXTest extends KnockoutTCK implements Transfer { break; } String value = data.parameters[i]; + if (value.startsWith("http.header.")) { + String header = value.substring(12); + int line = call.getHeaders().indexOf(header); + int end = call.getHeaders().indexOf("\n", line); + if (line >= 0 && end > line) { + value = call.getHeaders().substring(line + header.length() + 1, end).trim(); + } + } if (value.equals("http.method")) { value = call.getMethod(); } From 3aa4edd1326929e3a31402e0b282212a12829c37 Mon Sep 17 00:00:00 2001 From: Jaroslav Tulach Date: Sun, 6 Sep 2015 11:35:45 +0200 Subject: [PATCH 3/3] Update to version 1.2 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5bc9cf01f..16e2f03b9 100644 --- a/pom.xml +++ b/pom.xml @@ -66,7 +66,7 @@ UTF-8 https://oss.sonatype.org/content/repositories/snapshots/ - 1.1 + 1.2 9.2.1.v20140609 1.7.7 1.9.3