-
Notifications
You must be signed in to change notification settings - Fork 302
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
83 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package web.org.springframework.web; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
|
||
public interface Handler { | ||
|
||
Object handle(HttpServletRequest request, HttpServletResponse response) throws Exception; | ||
} |
21 changes: 21 additions & 0 deletions
21
mvc/src/main/java/web/org/springframework/web/HandlerAdapters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package web.org.springframework.web; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import webmvc.org.springframework.web.servlet.mvc.handlermapping.HandlerAdapter; | ||
|
||
public class HandlerAdapters { | ||
|
||
private final List<HandlerAdapter> handlerAdapters = new ArrayList<>(); | ||
|
||
public void add(HandlerAdapter handlerAdapter) { | ||
handlerAdapters.add(handlerAdapter); | ||
} | ||
|
||
public HandlerAdapter findHandlerAdapter(Handler handler) { | ||
return handlerAdapters.stream() | ||
.filter(adapter -> adapter.supports(handler)) | ||
.findFirst() | ||
.orElseThrow(() -> new IllegalArgumentException("handlerAdapter를 찾을 수 없습니다. handler: " + handler)); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
mvc/src/main/java/web/org/springframework/web/HandlerMappings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package web.org.springframework.web; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import webmvc.org.springframework.web.servlet.mvc.handlermapping.HandlerMapping; | ||
|
||
public class HandlerMappings { | ||
|
||
private final List<HandlerMapping> mappings = new ArrayList<>(); | ||
|
||
void add(HandlerMapping handlerMapping) { | ||
mappings.add(handlerMapping); | ||
} | ||
|
||
public Optional<Handler> findHandler(HttpServletRequest request) { | ||
for (HandlerMapping handlerMapping : mappings) { | ||
Optional<Handler> handler = handlerMapping.getHandler(request); | ||
if (handler.isPresent()) { | ||
return handler; | ||
} | ||
} | ||
return Optional.empty(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters