|
@@ -11,17 +11,39 @@ import org.voovan.tools.TEnv;
|
|
import org.voovan.tools.TObject;
|
|
import org.voovan.tools.TObject;
|
|
import org.voovan.tools.json.JSON;
|
|
import org.voovan.tools.json.JSON;
|
|
import org.voovan.tools.log.Logger;
|
|
import org.voovan.tools.log.Logger;
|
|
|
|
+import org.voovan.tools.reflect.TReflect;
|
|
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.util.Arrays;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
|
|
|
|
public class VoovanTFB {
|
|
public class VoovanTFB {
|
|
private static final byte[] HELLO_WORLD = "Hello, World!".getBytes();
|
|
private static final byte[] HELLO_WORLD = "Hello, World!".getBytes();
|
|
|
|
|
|
|
|
+ public static class Message {
|
|
|
|
+
|
|
|
|
+ private final String message;
|
|
|
|
+
|
|
|
|
+ public Message(String message) {
|
|
|
|
+ this.message = message;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public String getMessage() {
|
|
|
|
+ return message;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public int hashCode() {
|
|
|
|
+ return Objects.hash(message);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
public static void main(String[] args) {
|
|
public static void main(String[] args) {
|
|
|
|
+ TReflect.register(Message.class);
|
|
|
|
|
|
- WebServerConfig webServerConfig = WebContext.getWebServerConfig();
|
|
|
|
|
|
+ WebServerConfig webServerConfig = WebContext.buildWebServerConfig();
|
|
webServerConfig.setGzip(false);
|
|
webServerConfig.setGzip(false);
|
|
webServerConfig.setAccessLog(false);
|
|
webServerConfig.setAccessLog(false);
|
|
webServerConfig.setKeepAliveTimeout(1000);
|
|
webServerConfig.setKeepAliveTimeout(1000);
|
|
@@ -36,19 +58,20 @@ public class VoovanTFB {
|
|
//性能测试请求;
|
|
//性能测试请求;
|
|
webServer.get("/plaintext", new HttpRouter() {
|
|
webServer.get("/plaintext", new HttpRouter() {
|
|
public void process(HttpRequest req, HttpResponse resp) throws Exception {
|
|
public void process(HttpRequest req, HttpResponse resp) throws Exception {
|
|
- resp.header().put(HttpStatic.CONTENT_TYPE_STRING, "text/plain");
|
|
|
|
|
|
+ resp.header().put(HttpStatic.CONTENT_TYPE_STRING, HttpStatic.TEXT_PLAIN_STRING);
|
|
resp.write(HELLO_WORLD);
|
|
resp.write(HELLO_WORLD);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
-
|
|
|
|
//性能测试请求
|
|
//性能测试请求
|
|
webServer.get("/json", new HttpRouter() {
|
|
webServer.get("/json", new HttpRouter() {
|
|
public void process(HttpRequest req, HttpResponse resp) throws Exception {
|
|
public void process(HttpRequest req, HttpResponse resp) throws Exception {
|
|
- resp.header().put("Content-Type", "application/json");
|
|
|
|
- resp.write(JSON.toJSON(TObject.asMap("message", "Hello, World!")));
|
|
|
|
|
|
+ resp.header().put(HttpStatic.CONTENT_TYPE_STRING, HttpStatic.APPLICATION_JSON_STRING);
|
|
|
|
+ resp.write(JSON.toJSON(new Message("Hello, World!"), false, false));
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
- webServer.serve();
|
|
|
|
|
|
+ Logger.setEnable(true);
|
|
|
|
+
|
|
|
|
+ webServer.serve();
|
|
}
|
|
}
|
|
}
|
|
}
|