[RequestHandlerFilter]
→ API 내장되어 있는 Handler를 여기서 **process**로 실행시켜준다.
package com.ktds.act.apigw.filter;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.cloud.gateway.support.NotFoundException;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import com.ktds.act.apigw.api.db.entity.AdmApiDply;
import com.ktds.act.apigw.filter.model.AgwErrorDto;
import com.ktds.act.apigw.filter.error.exception.InternalRuntimeException;
import com.ktds.act.apigw.filter.model.TransactionDto;
import com.ktds.act.apigw.handler.HandlerFactory;
import lombok.extern.slf4j.Slf4j;
import reactor.core.publisher.Mono;
@Component
@Slf4j
public class RequestHandlerFilter implements GlobalFilter, Ordered {
public static final String REQUEST_HANDLER = "REQUEST-HANDLER";
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
**//PreFilter에서 받아온 Transaction을 여기서 깐다. (작업을 시작하기 위해)**
TransactionDto transaction = (TransactionDto) exchange.getAttribute(TransactionDto.TRANSACTION);
//Thread.currentThread().setName(transaction.getComn().getTxId());
log.info("RequestHandlerFilter.filter - Start");
**//transaction객체에서 배포된 API를 받아온다.**
AdmApiDply api = transaction.getComn().getApi();
if(api == null) { **//받아온 api가 null일때 에러 반환해줘야 하니까. (Not Found)**
transaction.setError(AgwErrorDto.NOT_FOUND);
exchange.getAttributes().put(TransactionDto.TRANSACTION, transaction);
return Mono.error(new NotFoundException(AgwErrorDto.NOT_FOUND.getErrMsg()));
}
try { **//HandlerFactory에서 Handler를 다 뽑아와서 process로 돌린다.**
HandlerFactory.process(REQUEST_HANDLER, exchange, transaction);
} catch (InternalRuntimeException e) {
return Mono.error(e);
}
log.info("RequestHandlerFilter.filter - End");
return chain.filter(exchange);
}
@Override
public int getOrder() {
return 3;
}
}