Commit 80beb50b by Nepxion

增加StrategyContextHolder接口

parent b2c62347
......@@ -13,13 +13,16 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.server.ServerWebExchange;
public class GatewayStrategyContextHolder {
import com.nepxion.discovery.plugin.strategy.context.StrategyContextHolder;
public class GatewayStrategyContextHolder implements StrategyContextHolder {
private static final Logger LOG = LoggerFactory.getLogger(GatewayStrategyContextHolder.class);
public ServerWebExchange getExchange() {
return GatewayStrategyContext.getCurrentContext().getExchange();
}
@Override
public String getHeader(String name) {
ServerWebExchange exchange = getExchange();
if (exchange == null) {
......
......@@ -18,7 +18,9 @@ import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
public class ServiceStrategyContextHolder {
import com.nepxion.discovery.plugin.strategy.context.StrategyContextHolder;
public class ServiceStrategyContextHolder implements StrategyContextHolder {
private static final Logger LOG = LoggerFactory.getLogger(ServiceStrategyContextHolder.class);
public ServletRequestAttributes getRestAttributes() {
......@@ -34,6 +36,7 @@ public class ServiceStrategyContextHolder {
return RpcStrategyContext.getCurrentContext().getAttributes();
}
@Override
public String getHeader(String name) {
ServletRequestAttributes attributes = getRestAttributes();
if (attributes == null) {
......
......@@ -18,9 +18,10 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.nepxion.discovery.plugin.strategy.context.StrategyContextHolder;
import com.netflix.zuul.context.RequestContext;
public class ZuulStrategyContextHolder {
public class ZuulStrategyContextHolder implements StrategyContextHolder {
private static final Logger LOG = LoggerFactory.getLogger(ZuulStrategyContextHolder.class);
public HttpServletRequest getRequest() {
......@@ -36,6 +37,7 @@ public class ZuulStrategyContextHolder {
return RequestContext.getCurrentContext().getZuulRequestHeaders();
}
@Override
public String getHeader(String name) {
HttpServletRequest request = getRequest();
if (request == null) {
......
package com.nepxion.discovery.plugin.strategy.context;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
public interface StrategyContextHolder {
String getHeader(String name);
}
\ No newline at end of file
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