Browse Source

PR #655 - Add some improvements as in PR #636 (Grizzly)

Martin Tzvetanov Grigorov 11 years ago
parent
commit
d9f3ca8a77
1 changed files with 8 additions and 3 deletions
  1. 8 3
      wicket/src/main/java/hellowicket/plaintext/HelloTextResource.java

+ 8 - 3
wicket/src/main/java/hellowicket/plaintext/HelloTextResource.java

@@ -1,5 +1,7 @@
 package hellowicket.plaintext;
 
+import java.nio.charset.Charset;
+
 import org.apache.wicket.request.resource.AbstractResource;
 
 /**
@@ -10,15 +12,18 @@ public class HelloTextResource extends AbstractResource
 {
   private static final long serialVersionUID = 1L;
 
+  private static final String CONTENT_TYPE = "text/plain";
+  private static final byte[] DATA = "Hello, World!".getBytes(Charset.forName("UTF-8"));
+
   protected ResourceResponse newResourceResponse(Attributes attributes)
   {
     ResourceResponse response = new ResourceResponse();
-    response.setContentType("text/plain");
-    response.setContentLength(13);
+    response.setContentType(CONTENT_TYPE);
+    response.setContentLength(DATA.length);
     response.setWriteCallback(new WriteCallback() {
       public void writeData(Attributes attributes)
       {
-        attributes.getResponse().write("Hello, World!");
+        attributes.getResponse().write(DATA);
       }
     });
     return response;