|
| 1 | +package dependency; |
| 2 | + |
| 3 | +import webserver.RegisterHandlerImpl; |
| 4 | +import webserver.exception.ExceptionHandlerMapping; |
| 5 | +import webserver.exception.handler.ErrorExceptionHandler; |
| 6 | +import webserver.exception.handler.ServiceExceptionHandler; |
| 7 | +import webserver.exception.handler.UnhandledErrorHandler; |
| 8 | +import webserver.http.request.HttpBufferedReaderRequestConverter; |
| 9 | +import webserver.http.request.HttpRequestConverter; |
| 10 | +import webserver.http.response.HttpBufferedStreamResponseConverter; |
| 11 | +import webserver.http.response.HttpResponseConverter; |
| 12 | +import webserver.web.WasServlet; |
| 13 | +import webserver.web.handler.StaticContentHandler; |
| 14 | +import webserver.web.handler.WebHandler; |
| 15 | +import webserver.web.handler.response.handler.StaticContentResponseHandler; |
| 16 | +import webserver.web.handler.response.handler.ViewResponseHandler; |
| 17 | +import webserver.web.handler.response.handler.WebHandlerResponseHandler; |
| 18 | + |
| 19 | +import java.util.List; |
| 20 | + |
| 21 | +public class AppConfig { |
| 22 | + //Http |
| 23 | + public HttpBufferedReaderRequestConverter httpBufferedReaderRequestConverter(){ |
| 24 | + return new HttpBufferedReaderRequestConverter(); |
| 25 | + } |
| 26 | + |
| 27 | + public HttpBufferedStreamResponseConverter httpBufferedStreamResponseConverter(){ |
| 28 | + return new HttpBufferedStreamResponseConverter(); |
| 29 | + } |
| 30 | + |
| 31 | + public HttpRequestConverter httpRequestConverter(){ |
| 32 | + return httpBufferedReaderRequestConverter(); |
| 33 | + } |
| 34 | + public HttpResponseConverter httpResponseConverter(){ |
| 35 | + return httpBufferedStreamResponseConverter(); |
| 36 | + } |
| 37 | + |
| 38 | + |
| 39 | + //Web |
| 40 | + public WasServlet wasServlet(){ |
| 41 | + return new WasServlet( |
| 42 | + webHandlerList(), |
| 43 | + webHandlerResponseHandlerList() |
| 44 | + ); |
| 45 | + } |
| 46 | + |
| 47 | + private List<WebHandler> webHandlerList(){ |
| 48 | + return List.of( |
| 49 | + staticContentHandler(), |
| 50 | + registerHandlerImpl() |
| 51 | + ); |
| 52 | + } |
| 53 | + private RegisterHandlerImpl registerHandlerImpl(){ |
| 54 | + return new RegisterHandlerImpl(); |
| 55 | + } |
| 56 | + |
| 57 | + private List<WebHandlerResponseHandler> webHandlerResponseHandlerList(){ |
| 58 | + return List.of( |
| 59 | + staticContentResponseHandler(), |
| 60 | + viewResponseHandler() |
| 61 | + ); |
| 62 | + } |
| 63 | + private StaticContentHandler staticContentHandler(){ |
| 64 | + return new StaticContentHandler(); |
| 65 | + } |
| 66 | + private ViewResponseHandler viewResponseHandler(){ |
| 67 | + return new ViewResponseHandler(); |
| 68 | + } |
| 69 | + private StaticContentResponseHandler staticContentResponseHandler(){ |
| 70 | + return new StaticContentResponseHandler(); |
| 71 | + } |
| 72 | + |
| 73 | + |
| 74 | + //Exception |
| 75 | + public ExceptionHandlerMapping exceptionHandlerMapping(){ |
| 76 | + return new ExceptionHandlerMapping( |
| 77 | + List.of( |
| 78 | + serviceExceptionHandler(), |
| 79 | + errorExceptionHandler(), |
| 80 | + unhandledErrorHandler() |
| 81 | + ) |
| 82 | + ); |
| 83 | + } |
| 84 | + |
| 85 | + private ServiceExceptionHandler serviceExceptionHandler(){ |
| 86 | + return new ServiceExceptionHandler(); |
| 87 | + } |
| 88 | + private UnhandledErrorHandler unhandledErrorHandler(){ |
| 89 | + return new UnhandledErrorHandler(); |
| 90 | + } |
| 91 | + private ErrorExceptionHandler errorExceptionHandler(){ |
| 92 | + return new ErrorExceptionHandler(); |
| 93 | + } |
| 94 | +} |
0 commit comments