1- package org .javawebstack .httpserver ;
1+ package org .javawebstack .http . router ;
22
33import org .javawebstack .abstractdata .*;
4- import org .javawebstack .httpserver .adapter .IHTTPSocket ;
5- import org .javawebstack .httpserver .util .MimeType ;
4+ import org .javawebstack .abstractdata .mapper .Mapper ;
5+ import org .javawebstack .http .router .adapter .IHTTPSocket ;
6+ import org .javawebstack .http .router .util .MimeType ;
67import org .javawebstack .validator .ValidationContext ;
78import org .javawebstack .validator .ValidationException ;
89import org .javawebstack .validator .ValidationResult ;
1112import java .io .ByteArrayOutputStream ;
1213import java .io .IOException ;
1314import java .io .InputStream ;
14- import java .net .Socket ;
1515import java .nio .charset .StandardCharsets ;
1616import java .util .*;
1717import java .util .stream .Collectors ;
@@ -25,16 +25,16 @@ public static Exchange current() {
2525 return exchanges .get ();
2626 }
2727
28- private final HTTPServer server ;
28+ private final HTTPRouter router ;
2929 private final HTTPMethod method ;
3030 private byte [] body = null ;
3131 private final Map <String , Object > pathVariables = new HashMap <>();
3232 private final AbstractObject queryParameters ;
3333 private final IHTTPSocket socket ;
3434 private final Map <String , Object > attributes = new HashMap <>();
3535
36- public Exchange (HTTPServer server , IHTTPSocket socket ) {
37- this .server = server ;
36+ public Exchange (HTTPRouter router , IHTTPSocket socket ) {
37+ this .router = router ;
3838 this .socket = socket ;
3939 this .method = getRequestMethodFromSocket (socket );
4040 this .queryParameters = AbstractElement .fromFormData (socket .getRequestQuery ()).object ();
@@ -74,11 +74,11 @@ public <T> T body(Class<T> clazz) {
7474 ValidationResult result = Validator .getValidator (clazz ).validate (new ValidationContext ().attrib ("exchange" , this ), request );
7575 if (!result .isValid ())
7676 throw new ValidationException (result );
77- return server . getAbstractMapper ().fromAbstract (request , clazz );
77+ return router . getMapper ().map (request , clazz );
7878 }
7979
80- public HTTPServer getServer () {
81- return server ;
80+ public HTTPRouter getRouter () {
81+ return router ;
8282 }
8383
8484 public HTTPMethod getMethod () {
@@ -236,7 +236,7 @@ public <T> T query(String name, Class<T> type) {
236236 }
237237
238238 public <T > T query (String name , Class <T > type , T defaultValue ) {
239- T t = new AbstractMapper ().fromAbstract (queryParameters .get (name , AbstractNull .INSTANCE ), type );
239+ T t = new Mapper ().map (queryParameters .get (name , AbstractNull .VALUE ), type );
240240 if (t == null )
241241 return defaultValue ;
242242 return t ;
@@ -264,7 +264,7 @@ public String bearerAuth() {
264264 }
265265
266266 public <T > T getBodyPath (String path , Class <T > clazz ) {
267- return server . getAbstractMapper ().fromAbstract (getBodyPathElement (path ), clazz );
267+ return router . getMapper ().map (getBodyPathElement (path ), clazz );
268268 }
269269
270270 public AbstractElement getBodyPathElement (String path ) {
@@ -290,7 +290,7 @@ protected static AbstractElement getPathElement(AbstractElement source, String p
290290 private HTTPMethod getRequestMethodFromSocket (IHTTPSocket socket ) {
291291 if ("websocket" .equalsIgnoreCase (socket .getRequestHeader ("upgrade" )))
292292 return HTTPMethod .WEBSOCKET ;
293- if (server .isFormMethods () && (socket .getRequestMethod () == HTTPMethod .GET || socket .getRequestMethod () == HTTPMethod .POST ) && getMimeType () == MimeType .X_WWW_FORM_URLENCODED ) {
293+ if (router .isFormMethods () && (socket .getRequestMethod () == HTTPMethod .GET || socket .getRequestMethod () == HTTPMethod .POST ) && getMimeType () == MimeType .X_WWW_FORM_URLENCODED ) {
294294 AbstractElement e = getBodyPathElement ("_method" );
295295 if (e != null ) {
296296 try {
0 commit comments