提交 e3194413 编写于 作者: zhouweidong's avatar zhouweidong

Resource扩展、FeignClient附加header及token

上级 6afd510d
......@@ -13,6 +13,7 @@ import org.springframework.boot.SpringApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.context.annotation.ComponentScan;
import java.util.List;
@Slf4j
......@@ -34,6 +35,11 @@ import java.util.List;
org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration.class,
</#if>
})
@ComponentScan(basePackages = {"${pub.getPKGCodeName()}"}
// ,excludeFilters={
// @ComponentScan.Filter(type= org.springframework.context.annotation.FilterType.REGEX,pattern="${pub.getPKGCodeName()}.xxx.rest.xxx"),
// }
)
@Import({
org.springframework.cloud.openfeign.FeignClientsConfiguration.class
})
......
......@@ -250,7 +250,11 @@ public class ${itemCodeName}Resource {
}
<#elseif deaction.codeName?lower_case == 'checkkey'>
<#if noDEPrefield>
<@outputHasAnyAuthorityAnnotation '${sys.codeName}-${de.codeName}-${deaction.codeName}-all'/>
<#else>
@PreAuthorize("hasPermission('','checkkey',{'${deStorageMode}',this.${itemCodeNameLC}Mapping,#${itemCodeNameLC}dto})")
</#if>
@ApiOperation(value = "${deaction.getLogicName()}", tags = {"${itemCodeName}" }, notes = "${deaction.getLogicName()}")
@RequestMapping(method = RequestMethod.${reqMtd}, value = "${fullPath}/${deactionCodeName?lower_case}")
public ResponseEntity<Boolean> checkKey(${etParams}) {
......
<#ibiztemplate>
TARGET=PSSYSTEM
</#ibiztemplate>
package ${pub.getPKGCodeName()}.util.web;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
/**
* feign请求拦截器
* 拦截所有使用feign发出的请求,附加原始请求Header参数及Token
*/
@Configuration
public class FeignRequestInterceptor implements RequestInterceptor {
private final Logger logger = LoggerFactory.getLogger(getClass());
@Override
public void apply(RequestTemplate requestTemplate) {
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
if(requestAttributes!=null){
HttpServletRequest request = requestAttributes.getRequest();
Enumeration<String> headerNames = request.getHeaderNames();
if (headerNames != null) {
while (headerNames.hasMoreElements()) {
String name = headerNames.nextElement();
String values = request.getHeader(name);
requestTemplate.header(name, values);
}
logger.info("feign interceptor header:{}",requestTemplate);
}
}
}
}
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册