You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2019/05/14 07:02:33 UTC
[servicecomb-java-chassis] 02/03: [SCB-1269][WIP][WEAK] delete
useless files
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch weak-contract-type
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
commit 69bf689c3ba70b58391f022b29cf0edcb1f4bd67
Author: wujimin <wu...@huawei.com>
AuthorDate: Thu Apr 25 11:09:28 2019 +0800
[SCB-1269][WIP][WEAK] delete useless files
---
.../arguments/ArgumentsMapperFactory.java | 256 ---------------------
.../JaxRSProducerArgumentsMapperFactory.java | 147 ------------
.../producer/ProducerArgumentsMapperFactory.java | 213 -----------------
.../ProducerSpringMVCQueryObjectMapper.java | 60 -----
.../SpringMVCProducerArgumentsMapperFactory.java | 94 --------
.../SwaggerArgumentToProducerBodyField.java | 62 -----
6 files changed, 832 deletions(-)
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/ArgumentsMapperFactory.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/ArgumentsMapperFactory.java
deleted file mode 100644
index 001f808..0000000
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/ArgumentsMapperFactory.java
+++ /dev/null
@@ -1,256 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.swagger.invocation.arguments;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.inject.Inject;
-import javax.ws.rs.CookieParam;
-import javax.ws.rs.FormParam;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.QueryParam;
-
-import org.apache.servicecomb.swagger.generator.core.utils.ParamUtils;
-import org.apache.servicecomb.swagger.invocation.InvocationType;
-import org.apache.servicecomb.swagger.invocation.converter.Converter;
-import org.apache.servicecomb.swagger.invocation.converter.ConverterMgr;
-import org.apache.servicecomb.swagger.invocation.converter.impl.ConverterCommon;
-import org.springframework.util.TypeUtils;
-import org.springframework.web.bind.annotation.CookieValue;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestAttribute;
-import org.springframework.web.bind.annotation.RequestHeader;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RequestPart;
-
-
-/**
- * @param <T> type of the generated ArgumentsMapper
- */
-public abstract class ArgumentsMapperFactory<T> {
- @Inject
- protected ConverterMgr converterMgr;
-
- protected InvocationType type;
-
- // key为ContextParameter
- private Map<Class<?>, ContextArgumentMapperFactory> factoryMap = new HashMap<>();
-
- public void setConverterMgr(ConverterMgr converterMgr) {
- this.converterMgr = converterMgr;
- }
-
- protected void createFactoryMap(List<ContextArgumentMapperFactory> factoryList) {
- factoryList.forEach(factory -> {
- factoryMap.put(factory.getContextClass(), factory);
- });
- }
-
- protected ContextArgumentMapperFactory findFactory(Type type) {
- if (type.getClass().equals(Class.class)) {
- return factoryMap.get((Class<?>) type);
- }
- return null;
- }
-
- protected void collectArgumentsMapper(ArgumentsMapperConfig config) {
- List<ProviderParameter> providerNormalParams = collectContextArgumentsMapper(config);
- if (providerNormalParams.isEmpty()) {
- return;
- }
-
- if (isSwaggerWrapBody(config, providerNormalParams)) {
- collectWrapBodyMapper(config, providerNormalParams);
- return;
- }
-
- collectSwaggerArgumentsMapper(config, providerNormalParams);
- }
-
- protected boolean isSwaggerWrapBody(ArgumentsMapperConfig config, List<ProviderParameter> providerNormalParams) {
- Method swaggerMethod = config.getSwaggerMethod();
- if (swaggerMethod.getParameterCount() != 1) {
- return false;
- }
-
- Type swaggerType = config.getSwaggerMethod().getGenericParameterTypes()[0];
- if (!swaggerType.getClass().equals(Class.class)) {
- return false;
- }
-
- Type firstProviderParam = providerNormalParams.get(0).getType();
- if (TypeUtils.isAssignable(firstProviderParam, swaggerType)) {
- return false;
- }
-
- // no public field, it's not rpc wrapper class
- if (((Class<?>) swaggerType).getFields().length == 0) {
- return false;
- }
-
- swaggerType = ((Class<?>) swaggerType).getFields()[0].getGenericType();
- Converter converter = converterMgr.findConverter(type, firstProviderParam, swaggerType);
- if (ConverterCommon.class.isInstance(converter)) {
- return false;
- }
- // 透明rpc的包装场景
- return true;
- }
-
- // 处理所有context类型的参数
- // 剩余的参数返回
- protected List<ProviderParameter> collectContextArgumentsMapper(ArgumentsMapperConfig config) {
- List<ProviderParameter> providerNormalParams = new ArrayList<>();
-
- final Annotation[][] parameterAnnotations = config.getProviderMethod().getParameterAnnotations();
- Type[] providerParameterTypes = config.getProviderMethod().getGenericParameterTypes();
- for (int providerIdx = 0; providerIdx < providerParameterTypes.length; providerIdx++) {
- Type parameterType = providerParameterTypes[providerIdx];
- ContextArgumentMapperFactory factory = findFactory(parameterType);
- if (factory != null) {
- ArgumentMapper mapper = factory.create(providerIdx);
- config.addArgumentMapper(mapper);
- continue;
- }
-
- ProviderParameter pp = new ProviderParameter(providerIdx, parameterType,
- retrieveVisibleParamName(config.getProviderMethod(), providerIdx))
- .setAnnotations(parameterAnnotations[providerIdx]);
- providerNormalParams.add(pp);
- }
-
- return providerNormalParams;
- }
-
- /**
- * Try to get the swagger param name of the corresponding producer/consumer method param
- * @param method producer/consumer method
- * @param paramIndex index of the producer/consumer method
- * @return the param name specified by param annotations, or the param name defined in code
- */
- public static String retrieveVisibleParamName(Method method, int paramIndex) {
- final Annotation[] annotations = method.getParameterAnnotations()[paramIndex];
- String paramName = null;
- for (Annotation annotation : annotations) {
- paramName = retrieveVisibleParamName(annotation);
- }
- if (null == paramName) {
- paramName = ParamUtils.getParameterName(method, paramIndex);
- }
- return paramName;
- }
-
- public static String retrieveVisibleParamName(Annotation annotation) {
- if (CookieParam.class.isInstance(annotation)) {
- return ((CookieParam) annotation).value();
- }
- if (CookieValue.class.isInstance(annotation)) {
- return ((CookieValue) annotation).name();
- }
- if (FormParam.class.isInstance(annotation)) {
- return ((FormParam) annotation).value();
- }
- if (HeaderParam.class.isInstance(annotation)) {
- return ((HeaderParam) annotation).value();
- }
- if (PathParam.class.isInstance(annotation)) {
- return ((PathParam) annotation).value();
- }
- if (PathVariable.class.isInstance(annotation)) {
- return ((PathVariable) annotation).value();
- }
- if (QueryParam.class.isInstance(annotation)) {
- return ((QueryParam) annotation).value();
- }
- if (RequestAttribute.class.isInstance(annotation)) {
- return ((RequestAttribute) annotation).name();
- }
- if (RequestHeader.class.isInstance(annotation)) {
- return ((RequestHeader) annotation).name();
- }
- if (RequestParam.class.isInstance(annotation)) {
- return ((RequestParam) annotation).name();
- }
- if (RequestPart.class.isInstance(annotation)) {
- return ((RequestPart) annotation).name();
- }
-
- return null;
- }
-
- protected void collectSwaggerArgumentsMapper(ArgumentsMapperConfig config,
- List<ProviderParameter> providerNormalParams) {
- Method swaggerMethod = config.getSwaggerMethod();
- Type[] swaggerParams = swaggerMethod.getGenericParameterTypes();
-
- // 普通场景,要求除了provider上的context,其他参数必须按顺序一一对应,provider上的有效参数可以与契约不一致
- int minParamCount = Math.min(providerNormalParams.size(), swaggerParams.length);
- for (int swaggerIdx = 0; swaggerIdx < minParamCount; swaggerIdx++) {
- ProviderParameter providerParameter = providerNormalParams.get(swaggerIdx);
- Type swaggerParameter = swaggerParams[swaggerIdx];
-
- Converter converter = converterMgr.findConverter(type, providerParameter.getType(), swaggerParameter);
- ArgumentMapper mapper =
- createArgumentMapperWithConverter(swaggerIdx, providerParameter.getIndex(), converter);
- config.addArgumentMapper(mapper);
- }
- }
-
- protected void collectWrapBodyMapper(ArgumentsMapperConfig config, List<ProviderParameter> providerNormalParams) {
- // 将provider的参数存入唯一swagger参数的field
- // 或是将唯一swagger参数的field存入provider参数
- Method swaggerMethod = config.getSwaggerMethod();
- Class<?> swaggerParam = swaggerMethod.getParameterTypes()[0];
- Field[] swaggerParamFields = swaggerParam.getFields();
-
- // 普通场景,要求除了provider上的context,其他参数必须按顺序一一对应,provider上的有效参数可以与契约不一致
- int minParamCount = Math.min(providerNormalParams.size(), swaggerParamFields.length);
-
- Map<Integer, FieldInfo> fieldMap = new HashMap<>();
- for (int swaggerIdx = 0; swaggerIdx < minParamCount; swaggerIdx++) {
- ProviderParameter providerParameter = providerNormalParams.get(swaggerIdx);
- Field swaggerField = swaggerParamFields[swaggerIdx];
- swaggerField.setAccessible(true);
-
- Converter converter = converterMgr.findConverter(type,
- providerParameter.getType(),
- swaggerField.getGenericType());
- FieldInfo info = new FieldInfo(swaggerField, converter);
- fieldMap.put(providerParameter.getIndex(), info);
- }
-
- ArgumentMapper bodyFieldArg = createBodyFieldArgMapper(config, fieldMap);
- config.addArgumentMapper(bodyFieldArg);
- }
-
- public abstract T createArgumentsMapper(ArgumentsMapperConfig config);
-
- protected abstract ArgumentMapper createArgumentMapperWithConverter(int swaggerIdx, int providerIdx,
- Converter converter);
-
- protected abstract ArgumentMapper createBodyFieldArgMapper(ArgumentsMapperConfig config,
- Map<Integer, FieldInfo> fieldMap);
-}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/JaxRSProducerArgumentsMapperFactory.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/JaxRSProducerArgumentsMapperFactory.java
deleted file mode 100644
index d0b84cd..0000000
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/JaxRSProducerArgumentsMapperFactory.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.swagger.invocation.arguments.producer;
-
-import static org.apache.servicecomb.swagger.generator.jaxrs.processor.annotation.BeanParamAnnotationProcessor.SETTER_METHOD_PREFIX;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-import javax.ws.rs.BeanParam;
-
-import org.apache.servicecomb.swagger.generator.jaxrs.processor.annotation.BeanParamAnnotationProcessor;
-import org.apache.servicecomb.swagger.invocation.arguments.ArgumentMapper;
-import org.apache.servicecomb.swagger.invocation.arguments.ArgumentsMapperConfig;
-import org.apache.servicecomb.swagger.invocation.arguments.ProviderParameter;
-import org.springframework.stereotype.Component;
-
-import io.swagger.models.parameters.Parameter;
-
-@Component
-public class JaxRSProducerArgumentsMapperFactory extends ProducerArgumentsMapperFactory {
- @Override
- public boolean canProcess(ArgumentsMapperConfig config) {
- return config.getSwaggerGeneratorContext().getClass().getCanonicalName().equals(
- "org.apache.servicecomb.swagger.generator.jaxrs.JaxrsSwaggerGeneratorContext");
- }
-
- @Override
- protected Set<String> findAggregatedParamNames(Map<String, ProviderParameter> providerParamMap,
- Map<String, ParamWrapper<Parameter>> swaggerParamMap) {
- Set<String> aggregatedParamNames = new HashSet<>();
- for (Entry<String, ProviderParameter> providerParameterEntry : providerParamMap.entrySet()) {
- if (null == providerParameterEntry.getValue().getAnnotations()) {
- // request body may have no annotation
- continue;
- }
- for (Annotation annotation : providerParameterEntry.getValue().getAnnotations()) {
- if (annotation instanceof BeanParam) {
- aggregatedParamNames.add(providerParameterEntry.getKey());
- }
- }
- }
-
- return aggregatedParamNames;
- }
-
- @Override
- protected void generateAggregatedParamMapper(ArgumentsMapperConfig config,
- Map<String, ProviderParameter> providerParamMap, Map<String, ParamWrapper<Parameter>> swaggerParamMap,
- Set<String> aggregatedParamNames) {
- for (String aggregatedProducerParamName : aggregatedParamNames) {
- ProviderParameter aggregatedParam = providerParamMap.get(aggregatedProducerParamName);
- // producer param name -> swagger param name
- Map<String, String> producerToSwaggerParamNameMapper = getProducerToSwaggerParamNameMap(aggregatedParam);
- // producer param name -> swagger param index
- Map<String, Integer> producerNameToSwaggerIndexMap = new HashMap<>(producerToSwaggerParamNameMapper.size());
- for (Entry<String, String> producerSwaggerNameMapEntry : producerToSwaggerParamNameMapper.entrySet()) {
- producerNameToSwaggerIndexMap.put(
- producerSwaggerNameMapEntry.getKey(),
- swaggerParamMap.get(producerSwaggerNameMapEntry.getValue()).getIndex());
- }
-
- // create&add aggregated param mapper
- ArgumentMapper mapper = new ProducerBeanParamMapper(producerNameToSwaggerIndexMap,
- aggregatedParam.getIndex(),
- aggregatedParam.getType());
- config.addArgumentMapper(mapper);
- }
- }
-
- /**
- * <pre>
- * public class AggregatedParam {
- * \@PathParam("pathSwaggerParam")
- * private String pathProducerParam;
- *
- * private String queryProducerParam;
- *
- * \@QueryParam(value = "querySwaggerParam")
- * public void setQueryProducerParam(String queryParam) {
- * this.queryProducerParam = queryParam;
- * }
- * }
- * </pre>
- * Given a BeanParam like above, will return a map like below:
- * {
- * "pathProducerParam" -> "pathSwaggerParam",
- * "queryProducerParam" -> "querySwaggerParam"
- * }
- */
- private Map<String, String> getProducerToSwaggerParamNameMap(ProviderParameter aggregatedParam) {
- Map<String, String> producerToSwaggerParamNameMapper = new HashMap<>();
- Class<?> aggregatedParamClazz = (Class<?>) aggregatedParam.getType();
- // map those params defined by BeanParam fields
- for (Field field : aggregatedParamClazz.getDeclaredFields()) {
- for (Annotation fieldAnnotation : field.getAnnotations()) {
- if (BeanParamAnnotationProcessor.SUPPORTED_PARAM_ANNOTATIONS.contains(fieldAnnotation.annotationType())) {
- producerToSwaggerParamNameMapper.put(
- field.getName(),
- retrieveVisibleParamName(fieldAnnotation));
- break;
- }
- }
- }
- // map those params defined by setter methods
- for (Method method : aggregatedParamClazz.getDeclaredMethods()) {
- final String methodName = method.getName();
- if (!methodName.startsWith(SETTER_METHOD_PREFIX)) {
- // only process setter methods
- continue;
- }
- // There should be one and only one param in a setter method
- for (Annotation setterAnnotation : method.getAnnotations()) {
- if (BeanParamAnnotationProcessor.SUPPORTED_PARAM_ANNOTATIONS.contains(setterAnnotation.annotationType())) {
- producerToSwaggerParamNameMapper.put(
- methodName.substring( // setParamName() -> "paramName"
- SETTER_METHOD_PREFIX.length(), SETTER_METHOD_PREFIX.length() + 1).toLowerCase()
- + methodName.substring(SETTER_METHOD_PREFIX.length() + 1),
- retrieveVisibleParamName(setterAnnotation));
- break;
- }
- }
- }
- return producerToSwaggerParamNameMapper;
- }
-}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerArgumentsMapperFactory.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerArgumentsMapperFactory.java
deleted file mode 100644
index 3423bed..0000000
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerArgumentsMapperFactory.java
+++ /dev/null
@@ -1,213 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.swagger.invocation.arguments.producer;
-
-import java.lang.reflect.Type;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-import javax.inject.Inject;
-
-import org.apache.servicecomb.swagger.generator.rest.RestSwaggerGeneratorContext;
-import org.apache.servicecomb.swagger.invocation.InvocationType;
-import org.apache.servicecomb.swagger.invocation.arguments.ArgumentMapper;
-import org.apache.servicecomb.swagger.invocation.arguments.ArgumentsMapperConfig;
-import org.apache.servicecomb.swagger.invocation.arguments.ArgumentsMapperFactory;
-import org.apache.servicecomb.swagger.invocation.arguments.ContextArgumentMapperFactory;
-import org.apache.servicecomb.swagger.invocation.arguments.FieldInfo;
-import org.apache.servicecomb.swagger.invocation.arguments.ProviderParameter;
-import org.apache.servicecomb.swagger.invocation.converter.Converter;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.context.annotation.Primary;
-import org.springframework.stereotype.Component;
-
-import io.swagger.models.parameters.Parameter;
-
-@Component
-@Primary
-public class ProducerArgumentsMapperFactory extends ArgumentsMapperFactory<ProducerArgumentsMapper> {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(ProducerArgumentsMapperFactory.class);
-
- public ProducerArgumentsMapperFactory() {
- type = InvocationType.PRODUCER;
- }
-
- @Inject
- @Qualifier("producer")
- public void setFactoryList(List<ContextArgumentMapperFactory> factoryList) {
- createFactoryMap(factoryList);
- }
-
- @Override
- public ProducerArgumentsMapper createArgumentsMapper(ArgumentsMapperConfig config) {
- collectArgumentsMapper(config);
- return new ProducerArgumentsMapper(config.getArgumentMapperList(),
- config.getProviderMethod().getParameterCount());
- }
-
- public boolean canProcess(ArgumentsMapperConfig config) {
- return false;
- }
-
- @Override
- protected void collectSwaggerArgumentsMapper(ArgumentsMapperConfig config,
- List<ProviderParameter> providerNormalParams) {
- if (!RestSwaggerGeneratorContext.class.isInstance(config.getSwaggerGeneratorContext())) {
- // POJO style provider does not support aggregated param
- super.collectSwaggerArgumentsMapper(config, providerNormalParams);
- return;
- }
-
- // JAX-RS and SpringMVC style provider support aggregated param, i.e. @BeanParam and query object, respectively
- Map<String, ProviderParameter> providerParamMap = getProviderParamMap(providerNormalParams);
- Map<String, ParamWrapper<Parameter>> swaggerParamMap = getSwaggerParamMap(config);
-
- Set<String> aggregatedParamNames = findAggregatedParamNames(providerParamMap, swaggerParamMap);
- if (aggregatedParamNames.isEmpty()) {
- // there is no aggregated param, run as 1-to-1 param mapping mode
- super.collectSwaggerArgumentsMapper(config, providerNormalParams);
- return;
- }
-
- // There is at lease one aggregated param, so the param mapping mode becomes to M-to-N
- // try to map params by name
- generateParamMapperByName(config, providerParamMap, swaggerParamMap, aggregatedParamNames);
- }
-
- private void generateParamMapperByName(ArgumentsMapperConfig config, Map<String, ProviderParameter> providerParamMap,
- Map<String, ParamWrapper<Parameter>> swaggerParamMap, Set<String> aggregatedParamNames) {
- LOGGER.info("mapping aggregated params: [{}]", aggregatedParamNames);
- generateAggregatedParamMapper(config, providerParamMap, swaggerParamMap, aggregatedParamNames);
- generateDefaultParamMapper(config, providerParamMap, swaggerParamMap, aggregatedParamNames);
- }
-
- /**
- * Generate default argument mappers. One swagger argument is mapped to one producer argument.
- */
- private void generateDefaultParamMapper(ArgumentsMapperConfig config, Map<String, ProviderParameter> providerParamMap,
- Map<String, ParamWrapper<Parameter>> swaggerParamMap, Set<String> aggregatedParamNames) {
- Type[] swaggerParamTypes = config.getSwaggerMethod().getGenericParameterTypes();
- for (Entry<String, ProviderParameter> providerParamEntry : providerParamMap.entrySet()) {
- if (aggregatedParamNames.contains(providerParamEntry.getKey())) {
- continue;
- }
-
- final int swaggerIdx = swaggerParamMap.get(providerParamEntry.getKey()).getIndex();
- Converter converter = converterMgr.findConverter(type, providerParamEntry.getValue().getType(),
- swaggerParamTypes[swaggerIdx]);
- ArgumentMapper mapper =
- createArgumentMapperWithConverter(swaggerIdx, providerParamEntry.getValue().getIndex(), converter);
- config.addArgumentMapper(mapper);
- }
- }
-
- /**
- * Generate argument mappers for aggregated params.
- * Collect related swagger params and map them to an aggregated param.
- * It's implemented by SpringMVC and JAX-RS.
- */
- protected void generateAggregatedParamMapper(ArgumentsMapperConfig config,
- Map<String, ProviderParameter> providerParamMap, Map<String, ParamWrapper<Parameter>> swaggerParamMap,
- Set<String> aggregatedParamNames) {
- // do nothing, not supported by default
- }
-
- protected Map<String, ParamWrapper<Parameter>> getSwaggerParamMap(ArgumentsMapperConfig config) {
- Map<String, ParamWrapper<Parameter>> swaggerParamMap = new HashMap<>();
- if (null == config.getSwaggerOperation() || null == config.getSwaggerOperation().getParameters()) {
- return swaggerParamMap;
- }
- List<Parameter> parameters = config.getSwaggerOperation().getParameters();
- for (int i = 0; i < parameters.size(); i++) {
- Parameter parameter = parameters.get(i);
- swaggerParamMap.put(parameter.getName(), new ParamWrapper<>(parameter).setIndex(i));
- }
- return swaggerParamMap;
- }
-
- protected Map<String, ProviderParameter> getProviderParamMap(List<ProviderParameter> providerNormalParams) {
- Map<String, ProviderParameter> providerParamMap = new HashMap<>(providerNormalParams.size());
- providerNormalParams.forEach(
- providerParameter -> providerParamMap.put(providerParameter.getName(), providerParameter));
- return providerParamMap;
- }
-
- /**
- * Find all aggregated params
- * @return the names of the aggregated params
- */
- protected Set<String> findAggregatedParamNames(Map<String, ProviderParameter> providerParamMap,
- Map<String, ParamWrapper<Parameter>> swaggerParamMap) {
- return Collections.emptySet();
- }
-
- @Override
- protected ArgumentMapper createArgumentMapperWithConverter(int swaggerIdx, int producerIdx, Converter converter) {
- return new ProducerArgumentSame(swaggerIdx, producerIdx, converter);
- }
-
- @Override
- protected ArgumentMapper createBodyFieldArgMapper(ArgumentsMapperConfig config,
- Map<Integer, FieldInfo> fieldMap) {
- return new SwaggerArgumentToProducerBodyField(fieldMap);
- }
-
- public static class ParamWrapper<T> {
- T param;
-
- int index;
-
- public ParamWrapper(T param) {
- this.param = param;
- }
-
- public T getParam() {
- return param;
- }
-
- public ParamWrapper<T> setParam(T param) {
- this.param = param;
- return this;
- }
-
- public int getIndex() {
- return index;
- }
-
- public ParamWrapper<T> setIndex(int index) {
- this.index = index;
- return this;
- }
-
- @Override
- public String toString() {
- final StringBuilder sb = new StringBuilder("ParamWrapper{");
- sb.append("param=").append(param);
- sb.append(", index=").append(index);
- sb.append('}');
- return sb.toString();
- }
- }
-}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerSpringMVCQueryObjectMapper.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerSpringMVCQueryObjectMapper.java
deleted file mode 100644
index 6f6a3ec..0000000
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerSpringMVCQueryObjectMapper.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.swagger.invocation.arguments.producer;
-
-import java.lang.reflect.Type;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-import org.apache.servicecomb.swagger.invocation.arguments.ArgumentMapper;
-import org.apache.servicecomb.swagger.invocation.converter.Converter;
-import org.apache.servicecomb.swagger.invocation.converter.impl.ConverterCommon;
-
-/**
- * Argument mapper for object params.
- * Collect all query swagger params as json and deserialize to object param.
- */
-public class ProducerSpringMVCQueryObjectMapper implements ArgumentMapper {
- private int producerIdx;
-
- private Map<String, Integer> swaggerParamIndexMap;
-
- private Converter converter;
-
- public ProducerSpringMVCQueryObjectMapper(Map<String, Integer> swaggerParamIndexMap, int producerIdx,
- Type producerParamType) {
- this.producerIdx = producerIdx;
- this.swaggerParamIndexMap = new HashMap<>();
- this.swaggerParamIndexMap.putAll(swaggerParamIndexMap);
- converter = new ConverterCommon(producerParamType);
- }
-
- @Override
- public void mapArgument(SwaggerInvocation invocation, Object[] producerArguments) {
- Map<String, Object> jsonMap = new HashMap<>(swaggerParamIndexMap.size());
-
- for (Entry<String, Integer> swaggerIndexEntry : swaggerParamIndexMap.entrySet()) {
- jsonMap.put(swaggerIndexEntry.getKey(), invocation.getSwaggerArgument(swaggerIndexEntry.getValue()));
- }
-
- final Object producerParam = converter.convert(jsonMap);
- producerArguments[producerIdx] = producerParam;
- }
-}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/SpringMVCProducerArgumentsMapperFactory.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/SpringMVCProducerArgumentsMapperFactory.java
deleted file mode 100644
index f7d1eda..0000000
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/SpringMVCProducerArgumentsMapperFactory.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.swagger.invocation.arguments.producer;
-
-import java.lang.reflect.Type;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-import org.apache.servicecomb.swagger.generator.core.utils.ParamUtils;
-import org.apache.servicecomb.swagger.invocation.arguments.ArgumentMapper;
-import org.apache.servicecomb.swagger.invocation.arguments.ArgumentsMapperConfig;
-import org.apache.servicecomb.swagger.invocation.arguments.ProviderParameter;
-import org.springframework.stereotype.Component;
-
-import io.swagger.converter.ModelConverters;
-import io.swagger.models.parameters.Parameter;
-import io.swagger.models.parameters.QueryParameter;
-import io.swagger.models.properties.Property;
-import io.swagger.models.properties.RefProperty;
-
-@Component
-public class SpringMVCProducerArgumentsMapperFactory extends ProducerArgumentsMapperFactory {
-
- @Override
- public boolean canProcess(ArgumentsMapperConfig config) {
- return config.getSwaggerGeneratorContext().getClass().getCanonicalName().equals(
- "org.apache.servicecomb.swagger.generator.springmvc.SpringmvcSwaggerGeneratorContext");
- }
-
- /**
- * Find all query object params
- * @return the names of the query object params
- */
- @Override
- protected Set<String> findAggregatedParamNames(Map<String, ProviderParameter> providerParamMap,
- Map<String, ParamWrapper<Parameter>> swaggerParamMap) {
- // find all reference type producer params, and exclude body param
- Set<String> queryObjectSet = new HashSet<>();
-
- for (Entry<String, ProviderParameter> paramEntry : providerParamMap.entrySet()) {
- Type paramType = paramEntry.getValue().getType();
- Property property = ModelConverters.getInstance().readAsProperty(paramType);
- if (RefProperty.class.isInstance(property)) {
- queryObjectSet.add(paramEntry.getKey());
- }
- }
-
- for (Entry<String, ParamWrapper<Parameter>> paramEntry : swaggerParamMap.entrySet()) {
- if (ParamUtils.isRealBodyParameter(paramEntry.getValue().getParam())) {
- queryObjectSet.remove(paramEntry.getKey());
- }
- }
-
- return queryObjectSet;
- }
-
- protected void generateAggregatedParamMapper(ArgumentsMapperConfig config,
- Map<String, ProviderParameter> providerParamMap, Map<String, ParamWrapper<Parameter>> swaggerParamMap,
- Set<String> aggregatedParamNames) {
- // collect all query params
- Map<String, Integer> querySwaggerParamsIndex = new HashMap<>();
- for (Entry<String, ParamWrapper<Parameter>> wrapperEntry : swaggerParamMap.entrySet()) {
- if (wrapperEntry.getValue().getParam() instanceof QueryParameter) {
- querySwaggerParamsIndex.put(wrapperEntry.getKey(), wrapperEntry.getValue().getIndex());
- }
- }
- // create mapper for each query objects
- for (String queryObjectName : aggregatedParamNames) {
- final ProviderParameter providerParameter = providerParamMap.get(queryObjectName);
- ArgumentMapper mapper = new ProducerSpringMVCQueryObjectMapper(querySwaggerParamsIndex,
- providerParameter.getIndex(),
- providerParameter.getType());
- config.addArgumentMapper(mapper);
- }
- }
-}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/SwaggerArgumentToProducerBodyField.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/SwaggerArgumentToProducerBodyField.java
deleted file mode 100644
index 8244b20..0000000
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/SwaggerArgumentToProducerBodyField.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.swagger.invocation.arguments.producer;
-
-import java.util.Map;
-import java.util.Map.Entry;
-
-import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-import org.apache.servicecomb.swagger.invocation.arguments.ArgumentMapper;
-import org.apache.servicecomb.swagger.invocation.arguments.FieldInfo;
-
-/**
- * 透明RPC的典型场景
- * 因为没有标注指明RESTful映射方式
- * 所以,所有参数被包装为一个class,每个参数是一个field
- * producer在处理时,需要将这些field取出来当作参数使用
- */
-public class SwaggerArgumentToProducerBodyField implements ArgumentMapper {
- // key为producerArgs的下标
- private Map<Integer, FieldInfo> fieldMap;
-
- public SwaggerArgumentToProducerBodyField(Map<Integer, FieldInfo> fieldMap) {
- this.fieldMap = fieldMap;
- }
-
- @Override
- public void mapArgument(SwaggerInvocation invocation, Object[] producerArguments) {
- Object body = invocation.getSwaggerArgument(0);
- if (body == null) {
- return;
- }
-
- try {
- for (Entry<Integer, FieldInfo> entry : fieldMap.entrySet()) {
- FieldInfo info = entry.getValue();
-
- Object fieldValue = info.getField().get(body);
- Object producerParam = info.getConverter().convert(fieldValue);
- producerArguments[entry.getKey()] = producerParam;
- }
- } catch (IllegalArgumentException e) {
- throw e;
- } catch (Throwable e) {
- throw new Error(e);
- }
- }
-}