Commit 5fe55b47 by Nepxion

修正Hystrix下的Bug

parent 8ca832c9
...@@ -13,7 +13,7 @@ import org.apache.commons.lang3.builder.EqualsBuilder; ...@@ -13,7 +13,7 @@ import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.context.request.RequestAttributes;
public class RestStrategyContext { public class RestStrategyContext {
private static final ThreadLocal<RestStrategyContext> THREAD_LOCAL = new InheritableThreadLocal<RestStrategyContext>() { private static final ThreadLocal<RestStrategyContext> THREAD_LOCAL = new InheritableThreadLocal<RestStrategyContext>() {
...@@ -31,13 +31,13 @@ public class RestStrategyContext { ...@@ -31,13 +31,13 @@ public class RestStrategyContext {
THREAD_LOCAL.remove(); THREAD_LOCAL.remove();
} }
private ServletRequestAttributes requestAttributes; private RequestAttributes requestAttributes;
public ServletRequestAttributes getRequestAttributes() { public RequestAttributes getRequestAttributes() {
return requestAttributes; return requestAttributes;
} }
public void setRequestAttributes(ServletRequestAttributes requestAttributes) { public void setRequestAttributes(RequestAttributes requestAttributes) {
this.requestAttributes = requestAttributes; this.requestAttributes = requestAttributes;
} }
......
...@@ -25,9 +25,9 @@ public class ServiceStrategyContextHolder { ...@@ -25,9 +25,9 @@ public class ServiceStrategyContextHolder {
public ServletRequestAttributes getRestAttributes() { public ServletRequestAttributes getRestAttributes() {
Boolean hystrixThreadlocalSupported = environment.getProperty(StrategyConstant.SPRING_APPLICATION_STRATEGY_HYSTRIX_THREADLOCAL_SUPPORTED, Boolean.class, Boolean.FALSE); Boolean hystrixThreadlocalSupported = environment.getProperty(StrategyConstant.SPRING_APPLICATION_STRATEGY_HYSTRIX_THREADLOCAL_SUPPORTED, Boolean.class, Boolean.FALSE);
if (hystrixThreadlocalSupported) { if (hystrixThreadlocalSupported) {
return RestStrategyContext.getCurrentContext().getRequestAttributes(); return (ServletRequestAttributes) RestStrategyContext.getCurrentContext().getRequestAttributes();
} else { } else {
return (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes(); return (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
} }
} }
......
...@@ -12,8 +12,8 @@ package com.nepxion.discovery.plugin.strategy.service.wrapper; ...@@ -12,8 +12,8 @@ package com.nepxion.discovery.plugin.strategy.service.wrapper;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import com.nepxion.discovery.plugin.strategy.service.context.RestStrategyContext; import com.nepxion.discovery.plugin.strategy.service.context.RestStrategyContext;
import com.nepxion.discovery.plugin.strategy.wrapper.CallableWrapper; import com.nepxion.discovery.plugin.strategy.wrapper.CallableWrapper;
...@@ -21,7 +21,7 @@ import com.nepxion.discovery.plugin.strategy.wrapper.CallableWrapper; ...@@ -21,7 +21,7 @@ import com.nepxion.discovery.plugin.strategy.wrapper.CallableWrapper;
public class DefaultCallableWrapper implements CallableWrapper { public class DefaultCallableWrapper implements CallableWrapper {
@Override @Override
public <T> Callable<T> wrapCallable(Callable<T> delegate) { public <T> Callable<T> wrapCallable(Callable<T> delegate) {
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes(); RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
return new Callable<T>() { return new Callable<T>() {
@Override @Override
......
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