Merge branch 'master' into eureka

eureka
tanghc 5 years ago
commit 41a5a52641
  1. 1
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/ServiceContext.java
  2. 5
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/SpringMvcServiceConfiguration.java
  3. 9
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingHandlerMapping.java
  4. 7
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingStringValueResolver.java
  5. 14
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingStringValueResolverMVC.java

@ -13,6 +13,7 @@ public class ServiceContext extends ConcurrentHashMap<String, Object> {
public static final String REQUEST_KEY = "request"; public static final String REQUEST_KEY = "request";
public static final String RESPONSE_KEY = "response"; public static final String RESPONSE_KEY = "response";
public static final String OPEN_CONTEXT_KEY = "openContext"; public static final String OPEN_CONTEXT_KEY = "openContext";
public static final String SOP_MVC = "sop.mvc";
public static final String RESTFUL_KEY = "sop-restful"; public static final String RESTFUL_KEY = "sop-restful";

@ -1,6 +1,7 @@
package com.gitee.sop.servercommon.configuration; package com.gitee.sop.servercommon.configuration;
import com.gitee.sop.servercommon.bean.ServiceConfig; import com.gitee.sop.servercommon.bean.ServiceConfig;
import com.gitee.sop.servercommon.bean.ServiceContext;
import com.gitee.sop.servercommon.manager.EnvironmentContext; import com.gitee.sop.servercommon.manager.EnvironmentContext;
import com.gitee.sop.servercommon.manager.ServiceRouteController; import com.gitee.sop.servercommon.manager.ServiceRouteController;
import com.gitee.sop.servercommon.mapping.ApiMappingHandlerMapping; import com.gitee.sop.servercommon.mapping.ApiMappingHandlerMapping;
@ -22,6 +23,10 @@ import javax.annotation.PostConstruct;
@Slf4j @Slf4j
public class SpringMvcServiceConfiguration { public class SpringMvcServiceConfiguration {
static {
System.setProperty(ServiceContext.SOP_MVC, "true");
}
public SpringMvcServiceConfiguration() { public SpringMvcServiceConfiguration() {
ServiceConfig.getInstance().getI18nModules().add("i18n/isp/bizerror"); ServiceConfig.getInstance().getI18nModules().add("i18n/isp/bizerror");
} }

@ -3,6 +3,7 @@ package com.gitee.sop.servercommon.mapping;
import com.gitee.sop.servercommon.annotation.ApiAbility; import com.gitee.sop.servercommon.annotation.ApiAbility;
import com.gitee.sop.servercommon.annotation.ApiMapping; import com.gitee.sop.servercommon.annotation.ApiMapping;
import com.gitee.sop.servercommon.bean.ServiceConfig; import com.gitee.sop.servercommon.bean.ServiceConfig;
import com.gitee.sop.servercommon.bean.ServiceContext;
import org.springframework.core.PriorityOrdered; import org.springframework.core.PriorityOrdered;
import org.springframework.core.annotation.AnnotationUtils; import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.util.StringValueResolver; import org.springframework.util.StringValueResolver;
@ -18,13 +19,17 @@ import java.lang.reflect.Method;
public class ApiMappingHandlerMapping extends RequestMappingHandlerMapping implements PriorityOrdered { public class ApiMappingHandlerMapping extends RequestMappingHandlerMapping implements PriorityOrdered {
private static StringValueResolver stringValueResolver = new ApiMappingStringValueResolver(); private static StringValueResolver stringValueResolver = new ApiMappingStringValueResolver();
private static StringValueResolver stringValueResolverMVC = new ApiMappingStringValueResolverMVC();
@Override @Override
protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) { protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
String sopMvc = System.getProperty(ServiceContext.SOP_MVC);
boolean isMvc = sopMvc != null;
ApiMapping apiMapping = method.getAnnotation(ApiMapping.class); ApiMapping apiMapping = method.getAnnotation(ApiMapping.class);
ApiAbility apiAbility = method.getAnnotation(ApiAbility.class);
StringValueResolver valueResolver = null; StringValueResolver valueResolver = null;
if (apiMapping != null) { if (apiMapping != null || apiAbility != null) {
valueResolver = stringValueResolver; valueResolver = isMvc ? stringValueResolverMVC : stringValueResolver;
} }
this.setEmbeddedValueResolver(valueResolver); this.setEmbeddedValueResolver(valueResolver);
return super.getMappingForMethod(method, handlerType); return super.getMappingForMethod(method, handlerType);

@ -7,8 +7,13 @@ import org.springframework.util.StringValueResolver;
*/ */
public class ApiMappingStringValueResolver implements StringValueResolver { public class ApiMappingStringValueResolver implements StringValueResolver {
private static final String END = "/";
@Override @Override
public String resolveStringValue(String strVal) { public String resolveStringValue(String strVal) {
return strVal; if (strVal == null) {
return null;
}
return strVal + END;
} }
} }

@ -0,0 +1,14 @@
package com.gitee.sop.servercommon.mapping;
import org.springframework.util.StringValueResolver;
/**
* @author tanghc
*/
public class ApiMappingStringValueResolverMVC implements StringValueResolver {
@Override
public String resolveStringValue(String strVal) {
return strVal;
}
}
Loading…
Cancel
Save