记得上下班打卡 | git大法好,push需谨慎

Commit 1482b2cb authored by 张国柄's avatar 张国柄

feign:去除TOKEN拦截处理逻辑;

parent 1b20afd3
...@@ -147,6 +147,7 @@ global-auth: ...@@ -147,6 +147,7 @@ global-auth:
- ${liquidnet.info.context}/performance/calendar - ${liquidnet.info.context}/performance/calendar
- ${liquidnet.info.context}/performance/calendarPerformances - ${liquidnet.info.context}/performance/calendarPerformances
- ${liquidnet.info.context}/performance/* - ${liquidnet.info.context}/performance/*
- ${liquidnet.info.context}/myPerformance/*
# ----------------------------------------------------------- # -----------------------------------------------------------
......
package com.liquidnet.service.feign.kylin.api; package com.liquidnet.service.feign.kylin.api;
import com.liquidnet.service.base.ResponseDto; import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.feign.kylin.config.SecuringRequestInterceptor;
import com.liquidnet.service.kylin.dto.vo.mongo.KylinPerformanceVo; import com.liquidnet.service.kylin.dto.vo.mongo.KylinPerformanceVo;
import feign.hystrix.FallbackFactory; import feign.hystrix.FallbackFactory;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
...@@ -25,8 +24,7 @@ import java.util.List; ...@@ -25,8 +24,7 @@ import java.util.List;
@FeignClient(name = "liquidnet-service-kylin", @FeignClient(name = "liquidnet-service-kylin",
contextId = "FeignKylinForChimeClient", path = "", contextId = "FeignKylinForChimeClient", path = "",
url = "${liquidnet.service.kylin.url}", url = "${liquidnet.service.kylin.url}",
fallback = FallbackFactory.Default.class, fallback = FallbackFactory.Default.class)
configuration = SecuringRequestInterceptor.class)
public interface FeignKylinForChimeClient { public interface FeignKylinForChimeClient {
@GetMapping("myPerformance/performancesList") @GetMapping("myPerformance/performancesList")
ResponseDto<List<KylinPerformanceVo>> myPerformancesList(); ResponseDto<List<KylinPerformanceVo>> myPerformancesList();
......
package com.liquidnet.service.feign.kylin.config; //package com.liquidnet.service.feign.kylin.config;
//
import feign.RequestInterceptor; //import feign.RequestInterceptor;
import feign.RequestTemplate; //import feign.RequestTemplate;
import org.springframework.stereotype.Component; //import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder; //import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes; //import org.springframework.web.context.request.ServletRequestAttributes;
//
import javax.servlet.http.HttpServletRequest; //import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration; //import java.util.Enumeration;
//
/** ///**
* @author AnJiabin <anjiabin@zhengzai.tv> // * @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0 // * @version V1.0
* @Description: 解决feign调用传递header问题 // * @Description: 解决feign调用传递header问题
* @class: SecuringRequestInterceptor // * @class: SecuringRequestInterceptor
* @Package com.liquidnet.service.chime.config // * @Package com.liquidnet.service.chime.config
* @Copyright: LightNet @ Copyright (c) 2021 // * @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/9/11 19:22 // * @date 2021/9/11 19:22
*/ // */
@Component //@Component
public class SecuringRequestInterceptor implements RequestInterceptor { //public class SecuringRequestInterceptor implements RequestInterceptor {
@Override // @Override
public void apply(RequestTemplate requestTemplate) { // public void apply(RequestTemplate requestTemplate) {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder // ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder
.getRequestAttributes(); // .getRequestAttributes();
HttpServletRequest request = attributes.getRequest(); // HttpServletRequest request = attributes.getRequest();
Enumeration<String> headerNames = request.getHeaderNames(); // Enumeration<String> headerNames = request.getHeaderNames();
if (headerNames != null) { // if (headerNames != null) {
while (headerNames.hasMoreElements()) { // while (headerNames.hasMoreElements()) {
String name = headerNames.nextElement(); // String name = headerNames.nextElement();
String values = request.getHeader(name); // String values = request.getHeader(name);
requestTemplate.header(name, values); // requestTemplate.header(name, values);
} // }
} // }
} // }
} //}
\ No newline at end of file \ No newline at end of file
package com.liquidnet.service.executor.main.handler; package com.liquidnet.service.executor.main.handler;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.base.ResponseDto; import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.feign.kylin.task.FeignPlatformAlipayBackClient; import com.liquidnet.service.feign.kylin.task.FeignPlatformAlipayBackClient;
import com.liquidnet.service.feign.platform.task.FeignPlatformCandyTaskClient; import com.liquidnet.service.feign.platform.task.FeignPlatformCandyTaskClient;
...@@ -27,9 +28,14 @@ public class PlatformTaskHandler { ...@@ -27,9 +28,14 @@ public class PlatformTaskHandler {
try { try {
String result = feignPlatformAlipayBackClient.alipayActiveCallback().getData(); String result = feignPlatformAlipayBackClient.alipayActiveCallback().getData();
log.info("alipayActiveCallback:结果:"+result); log.info("alipayActiveCallback:结果:"+result);
return ReturnT.SUCCESS; ReturnT<String> success = ReturnT.SUCCESS;
success.setContent(result);
return success;
} catch (Exception e) { } catch (Exception e) {
return ReturnT.FAIL; log.error("exception of handler:{}", e.getMessage(), e);
ReturnT<String> fail = ReturnT.FAIL;
fail.setMsg(e.getLocalizedMessage());
return fail;
} }
} }
...@@ -38,11 +44,14 @@ public class PlatformTaskHandler { ...@@ -38,11 +44,14 @@ public class PlatformTaskHandler {
public ReturnT<String> candyCouponMgtIssueCoupons() { public ReturnT<String> candyCouponMgtIssueCoupons() {
try { try {
ResponseDto<String> dto = feignPlatformCandyTaskClient.mgtIssueCoupons(); ResponseDto<String> dto = feignPlatformCandyTaskClient.mgtIssueCoupons();
log.info("result of handler:{}", dto.toJson()); String dtoStr = JsonUtils.toJson(dto);
return new ReturnT<>(dto.toJson()); log.info("result of handler:{}", dtoStr);
return new ReturnT<>(dtoStr);
} catch (Exception e) { } catch (Exception e) {
log.error("exception of handler:{}", e.getMessage(), e); log.error("exception of handler:{}", e.getMessage(), e);
return ReturnT.FAIL; ReturnT<String> fail = ReturnT.FAIL;
fail.setMsg(e.getLocalizedMessage());
return fail;
} }
} }
...@@ -51,11 +60,14 @@ public class PlatformTaskHandler { ...@@ -51,11 +60,14 @@ public class PlatformTaskHandler {
public ReturnT<String> candyCouponDueProcessForRedeem() { public ReturnT<String> candyCouponDueProcessForRedeem() {
try { try {
ResponseDto<String> dto = feignPlatformCandyTaskClient.dueProcessForRedeem(); ResponseDto<String> dto = feignPlatformCandyTaskClient.dueProcessForRedeem();
log.info("result of handler:{}", dto.toJson()); String dtoStr = JsonUtils.toJson(dto);
return new ReturnT<>(dto.toJson()); log.info("result of handler:{}", dtoStr);
return new ReturnT<>(dtoStr);
} catch (Exception e) { } catch (Exception e) {
log.error("exception of handler:{}", e.getMessage(), e); log.error("exception of handler:{}", e.getMessage(), e);
return ReturnT.FAIL; ReturnT<String> fail = ReturnT.FAIL;
fail.setMsg(e.getLocalizedMessage());
return fail;
} }
} }
...@@ -64,11 +76,14 @@ public class PlatformTaskHandler { ...@@ -64,11 +76,14 @@ public class PlatformTaskHandler {
public ReturnT<String> candyCouponDueProcessForCommon() { public ReturnT<String> candyCouponDueProcessForCommon() {
try { try {
ResponseDto<String> dto = feignPlatformCandyTaskClient.dueProcessForCommon(); ResponseDto<String> dto = feignPlatformCandyTaskClient.dueProcessForCommon();
log.info("result of handler:{}", dto.toJson()); String dtoStr = JsonUtils.toJson(dto);
return new ReturnT<>(dto.toJson()); log.info("result of handler:{}", dtoStr);
return new ReturnT<>(dtoStr);
} catch (Exception e) { } catch (Exception e) {
log.error("exception of handler:{}", e.getMessage(), e); log.error("exception of handler:{}", e.getMessage(), e);
return ReturnT.FAIL; ReturnT<String> fail = ReturnT.FAIL;
fail.setMsg(e.getLocalizedMessage());
return fail;
} }
} }
...@@ -77,11 +92,14 @@ public class PlatformTaskHandler { ...@@ -77,11 +92,14 @@ public class PlatformTaskHandler {
public ReturnT<String> candyCouponDueProcessForUser() { public ReturnT<String> candyCouponDueProcessForUser() {
try { try {
ResponseDto<String> dto = feignPlatformCandyTaskClient.dueProcessForUser(); ResponseDto<String> dto = feignPlatformCandyTaskClient.dueProcessForUser();
log.info("result of handler:{}", dto.toJson()); String dtoStr = JsonUtils.toJson(dto);
return new ReturnT<>(dto.toJson()); log.info("result of handler:{}", dtoStr);
return new ReturnT<>(dtoStr);
} catch (Exception e) { } catch (Exception e) {
log.error("exception of handler:{}", e.getMessage(), e); log.error("exception of handler:{}", e.getMessage(), e);
return ReturnT.FAIL; ReturnT<String> fail = ReturnT.FAIL;
fail.setMsg(e.getLocalizedMessage());
return fail;
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment