Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frameworks/Java/tio-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<tio-boot.version>1.9.7</tio-boot.version>
<tio-boot.version>1.9.8</tio-boot.version>


<main.class>com.litongjava.tio.http.server.MainApp</main.class>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import com.litongjava.tio.http.server.config.EhCachePluginConfig;
import com.litongjava.tio.http.server.config.EnjoyEngineConfig;
import com.litongjava.tio.http.server.config.MysqlDbConfig;
import com.litongjava.tio.http.server.controller.CacheHandler;
import com.litongjava.tio.http.server.controller.DbHandler;
import com.litongjava.tio.http.server.controller.IndexHandler;
import com.litongjava.tio.http.server.handler.CacheHandler;
import com.litongjava.tio.http.server.handler.DbHandler;
import com.litongjava.tio.http.server.handler.IndexHandler;
import com.litongjava.tio.http.server.router.HttpRequestRouter;
import com.litongjava.tio.utils.environment.EnvUtils;

Expand Down Expand Up @@ -38,7 +38,6 @@ public void config() throws Exception {
TioBootServer server = TioBootServer.me();
HttpRequestRouter requestRouter = server.getRequestRouter();
if (requestRouter != null) {
requestRouter.add("/", controller::index);
requestRouter.add("/plaintext", controller::plaintext);
requestRouter.add("/json", controller::json);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.litongjava.tio.http.server.controller;
package com.litongjava.tio.http.server.handler;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.litongjava.tio.http.server.controller;
package com.litongjava.tio.http.server.handler;

import java.util.ArrayList;
import java.util.Comparator;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
package com.litongjava.tio.http.server.controller;
package com.litongjava.tio.http.server.handler;

import com.alibaba.fastjson2.JSON;
import com.litongjava.tio.boot.http.TioRequestContext;
import com.litongjava.tio.http.common.HeaderName;
import com.litongjava.tio.http.common.HeaderValue;
import com.litongjava.tio.http.common.HttpRequest;
import com.litongjava.tio.http.common.HttpResponse;
import com.litongjava.tio.http.common.utils.MimeTypeUtils;
import com.litongjava.tio.http.server.model.Message;
import com.litongjava.tio.http.server.util.Resps;

/**
* ab -k -n1000000 -c10 http://127.0.0.1:8080/json
* ab -k -n1000000 -c10 http://127.0.0.1:8080/plaintext
*/
public class IndexHandler {
private static final String HELLO_WORLD_RN = "Hello, World!\r\n";

private static final String HELLO_WORLD = "Hello, World!";

private static final byte[] HELLO_WORLD_BYTES = HELLO_WORLD.getBytes();

public HttpResponse index(HttpRequest request) {
return Resps.txt(request, "tio-boot");
}
private static final byte[] HELLO_WORLD_BYTES = HELLO_WORLD_RN.getBytes();
private static byte[] JSON_BYTES = JSON.toJSONBytes(new Message(HELLO_WORLD));

public HttpResponse plaintext(HttpRequest request) {
HttpResponse response = TioRequestContext.getResponse();
response.setBody(HELLO_WORLD_BYTES);
response.addHeader(HeaderName.Content_Type, HeaderValue.Content_Type.TEXT_PLAIN_TXT);
String mimeTypeStr = MimeTypeUtils.getTextUTF8();
response.setContentType(mimeTypeStr);
return response;
}

public HttpResponse json(HttpRequest request) {
HttpResponse response = TioRequestContext.getResponse();
response.setBody(JSON.toJSONBytes(new Message(HELLO_WORLD)));
response.addHeader(HeaderName.Content_Type, HeaderValue.Content_Type.TEXT_PLAIN_JSON);
response.setBody(JSON_BYTES);
String mimeTypeStr = MimeTypeUtils.getJsonUTF8();
response.setContentType(mimeTypeStr);
return response;
}
}
4 changes: 3 additions & 1 deletion frameworks/Java/tio-boot/src/main/resources/app.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ server.port=8080

JDBC_URL=jdbc:mysql://tfb-database/hello_world
JDBC_USER=benchmarkdbuser
JDBC_PSWD=benchmarkdbpass
JDBC_PSWD=benchmarkdbpass

#--tio.core.diagnostic=true --server.http.request.printPacket=true
Loading