企业级API网关
API網(wǎng)關(guān)就是用來代替控制器層 Controller,使用API網(wǎng)關(guān)直接調(diào)用Service層
在Service層加 @APIMapping
http://localhost:8080/api?method=XX¶m=XX
?
API store :? 存儲所有帶有APIMapping 的類
存儲的對像為 APIRunnable,
apiName, targetMethod, target,? 放到一個Map里
?
Controller
1. 接收HTTP參數(shù)
2. 把HTTP參數(shù)字符串封裝成java 對象
3. 調(diào)用服務(wù)方法
4, 將返回結(jié)果進(jìn)行Json序列化封裝
?
API網(wǎng)關(guān)要做的事情:
1. 驗證系統(tǒng)參數(shù)合法性
例如: apiName 或者 method 為空,則拋一個異常
2. 驗證業(yè)務(wù)參數(shù)合法性
3. 業(yè)務(wù)參數(shù)轉(zhuǎn)換成java 對象
4. 調(diào)用相對應(yīng)的Service類的方法
5. 拿到返回結(jié)果,封裝成json
6. 異常統(tǒng)一處理,封裝異常,返回
?
?
執(zhí)行順序:? PIGatewayServlet===>API handle ===> store
?
String name=applicationConext.getBeanDefinitionNames
Class<?> type= applicationContext.getType(name)
?
?
?
總結(jié)