Skip to content

Commit

Permalink
♻️ refactoring http handler
Browse files Browse the repository at this point in the history
  • Loading branch information
hellokaton committed Jun 15, 2018
1 parent 2619a09 commit 1018463
Show file tree
Hide file tree
Showing 18 changed files with 640 additions and 554 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/blade/mvc/Const.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public interface Const {
int DEFAULT_SERVER_PORT = 9000;
String DEFAULT_SERVER_ADDRESS = "0.0.0.0";
String LOCAL_IP_ADDRESS = "127.0.0.1";
String VERSION = "2.0.8-RELEASE";
String VERSION = "2.0.8.RELEASE";
String WEB_JARS = "/webjars/";
String CLASSPATH = BladeKit.getCurrentClassPath();
String CONTENT_TYPE_HTML = "text/html; charset=UTF-8";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.blade.exception.NotFoundException;
import com.blade.exception.ValidatorException;
import com.blade.mvc.WebContext;
import com.blade.mvc.http.RawBody;
import com.blade.mvc.http.Request;
import com.blade.mvc.http.Response;
import com.blade.mvc.ui.HtmlCreator;
Expand Down Expand Up @@ -137,7 +138,7 @@ protected void renderPage(Response response, ModelAndView modelAndView) {
WebContext.blade().templateEngine().render(modelAndView, sw);
ByteBuf buffer = Unpooled.wrappedBuffer(sw.toString().getBytes("utf-8"));
FullHttpResponse fullHttpResponse = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.valueOf(response.statusCode()), buffer);
response.send(fullHttpResponse);
response.body(new RawBody(fullHttpResponse));
} catch (Exception e) {
log.error("Render view error", e);
}
Expand Down
336 changes: 0 additions & 336 deletions src/main/java/com/blade/mvc/handler/RequestExecution.java

This file was deleted.

7 changes: 7 additions & 0 deletions src/main/java/com/blade/mvc/http/Body.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.blade.mvc.http;

public interface Body {

<T> T write(BodyWriter<T> writer);

}
15 changes: 15 additions & 0 deletions src/main/java/com/blade/mvc/http/BodyWriter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.blade.mvc.http;

public interface BodyWriter<T> {

T onText(StringBody body);

T onStream(StreamBody body);

T onView(ViewBody body);

T onEmpty(EmptyBody emptyBody);

T onRawBody(RawBody body);

}
Loading

0 comments on commit 1018463

Please sign in to comment.