1.1 --- a/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java Thu Jan 31 18:45:00 2013 +0100
1.2 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java Thu Jan 31 19:21:37 2013 +0100
1.3 @@ -168,7 +168,7 @@
1.4 if (ic.httpPath.equals(request.getRequestURI())) {
1.5 LOG.log(Level.INFO, "Serving HttpResource for {0}", request.getRequestURI());
1.6 response.setContentType(ic.httpType);
1.7 - response.getWriter().write(ic.httpContent);
1.8 + copyStream(ic.httpContent, response.getOutputStream(), null);
1.9 }
1.10 }
1.11 }
2.1 --- a/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/InvocationContext.java Thu Jan 31 18:45:00 2013 +0100
2.2 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/InvocationContext.java Thu Jan 31 19:21:37 2013 +0100
2.3 @@ -18,6 +18,7 @@
2.4 package org.apidesign.bck2brwsr.launcher;
2.5
2.6 import java.io.IOException;
2.7 +import java.io.InputStream;
2.8 import java.util.concurrent.CountDownLatch;
2.9 import java.util.concurrent.TimeUnit;
2.10
2.11 @@ -33,7 +34,7 @@
2.12 private String result;
2.13 private Throwable exception;
2.14 String html;
2.15 - String httpContent;
2.16 + InputStream httpContent;
2.17 String httpType;
2.18 String httpPath;
2.19
2.20 @@ -54,7 +55,7 @@
2.21 /** HTTP resource to be available during execution. An invocation may
2.22 * perform an HTTP query and obtain a resource relative to the page.
2.23 */
2.24 - public void setHttpResource(String relativePath, String mimeType, String content) {
2.25 + public void setHttpResource(String relativePath, String mimeType, InputStream content) {
2.26 if (relativePath == null || mimeType == null || content == null) {
2.27 throw new NullPointerException();
2.28 }
3.1 --- a/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/HttpResource.java Thu Jan 31 18:45:00 2013 +0100
3.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/HttpResource.java Thu Jan 31 19:21:37 2013 +0100
3.3 @@ -34,6 +34,10 @@
3.4 String path();
3.5 /** the content of the HttpResource */
3.6 String content();
3.7 + /** resource relative to the class that should be used instead of <code>content</code>.
3.8 + * Leave content equal to empty string.
3.9 + */
3.10 + String resource() default "";
3.11 /** mime type of the resource */
3.12 String mimeType();
3.13 }
4.1 --- a/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/Bck2BrwsrCase.java Thu Jan 31 18:45:00 2013 +0100
4.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/Bck2BrwsrCase.java Thu Jan 31 19:21:37 2013 +0100
4.3 @@ -17,9 +17,11 @@
4.4 */
4.5 package org.apidesign.bck2brwsr.vmtest.impl;
4.6
4.7 +import java.io.ByteArrayInputStream;
4.8 import java.io.File;
4.9 import java.io.FileWriter;
4.10 import java.io.IOException;
4.11 +import java.io.InputStream;
4.12 import java.lang.reflect.Constructor;
4.13 import java.lang.reflect.InvocationTargetException;
4.14 import java.lang.reflect.Method;
4.15 @@ -60,7 +62,13 @@
4.16 c.setHtmlFragment(html.value());
4.17 }
4.18 if (http != null) {
4.19 - c.setHttpResource(http.path(), http.mimeType(), http.content());
4.20 + if (!http.content().isEmpty()) {
4.21 + InputStream is = new ByteArrayInputStream(http.content().getBytes("UTF-8"));
4.22 + c.setHttpResource(http.path(), http.mimeType(), is);
4.23 + } else {
4.24 + InputStream is = m.getDeclaringClass().getResourceAsStream(http.resource());
4.25 + c.setHttpResource(http.path(), http.mimeType(), is);
4.26 + }
4.27 }
4.28 String res = c.invoke();
4.29 value = res;
5.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/HttpResourceTest.java Thu Jan 31 18:45:00 2013 +0100
5.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/HttpResourceTest.java Thu Jan 31 19:21:37 2013 +0100
5.3 @@ -55,7 +55,7 @@
5.4 return msg;
5.5 }
5.6
5.7 - @HttpResource(path = "/bytes", content = "\u00fe", mimeType = "x-application/binary")
5.8 + @HttpResource(path = "/bytes", content = "", resource = "0xfe", mimeType = "x-application/binary")
5.9 @BrwsrTest
5.10 public void testReadByte() throws Exception {
5.11 URL url = new URL("http:/bytes");
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/vmtest/src/test/resources/org/apidesign/bck2brwsr/tck/0xfe Thu Jan 31 19:21:37 2013 +0100
6.3 @@ -0,0 +1,1 @@
6.4 +þ
6.5 \ No newline at end of file