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:31 UTC

[servicecomb-java-chassis] branch weak-contract-type updated (d0bafd8 -> 6516edb)

This is an automated email from the ASF dual-hosted git repository.

liubao pushed a change to branch weak-contract-type
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git.


    from d0bafd8  [SCB-1268][WIP][WEAK] update UT
     new 8bc9ed5  [SCB-1269][WIP][WEAK] swaggerProducer arguments not depend on swagger interface
     new 69bf689  [SCB-1269][WIP][WEAK] delete useless files
     new 6516edb  [SCB-1269][WIP][WEAK] update UT

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../swagger/engine/SwaggerEnvironment.java         |  67 +++---
 .../swagger/engine/SwaggerProducer.java            |  17 +-
 .../swagger/engine/SwaggerProducerOperation.java   |  21 +-
 .../swagger/invocation/SwaggerInvocation.java      |   5 +
 .../arguments/ArgumentsMapperFactory.java          | 256 ---------------------
 ...pper.java => ContextArgumentMapperFactory.java} |   6 +-
 .../JaxRSProducerArgumentsMapperFactory.java       | 147 ------------
 .../arguments/producer/ProducerArgumentSame.java   |   9 +-
 .../producer/ProducerArgumentsMapper.java          |   4 +-
 .../producer/ProducerArgumentsMapperCreator.java   |  94 ++++++++
 .../producer/ProducerArgumentsMapperFactory.java   | 213 -----------------
 .../producer/ProducerBeanParamMapper.java          |  55 +++--
 .../ProducerContextArgumentMapperFactory.java}     |   4 +-
 .../producer/ProducerInvocationContextMapper.java  |   1 -
 .../ProducerInvocationContextMapperFactory.java    |   8 +-
 .../ProducerSpringMVCQueryObjectMapper.java        |  60 -----
 .../SpringMVCProducerArgumentsMapperFactory.java   |  94 --------
 .../SwaggerArgumentToProducerBodyField.java        |  62 -----
 ...ava => SwaggerBodyFieldToProducerArgument.java} |  24 +-
 ...s.producer.ProducerContextArgumentMapperFactory |   2 +-
 .../JaxRSProducerArgumentsMapperFactoryTest.java   | 229 ------------------
 .../producer/ProducerBeanParamMapperTest.java      | 146 ------------
 .../ProducerSpringMVCQueryObjectMapperTest.java    | 183 ---------------
 .../invocation/arguments/producer/TestJaxrs.java   |  76 ++++++
 .../invocation/arguments/producer/TestPojo.java    |  83 +++++++
 .../arguments/producer/TestSpringmvc.java          |  75 ++++++
 26 files changed, 426 insertions(+), 1515 deletions(-)
 delete mode 100644 swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/ArgumentsMapperFactory.java
 copy swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/{ArgumentMapper.java => ContextArgumentMapperFactory.java} (83%)
 delete mode 100644 swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/JaxRSProducerArgumentsMapperFactory.java
 create mode 100644 swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerArgumentsMapperCreator.java
 delete mode 100644 swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerArgumentsMapperFactory.java
 copy swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/{consumer/ConsumerContextArgumentMapperFactory.java => producer/ProducerContextArgumentMapperFactory.java} (87%)
 delete mode 100644 swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerSpringMVCQueryObjectMapper.java
 delete mode 100644 swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/SpringMVCProducerArgumentsMapperFactory.java
 delete mode 100644 swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/SwaggerArgumentToProducerBodyField.java
 copy swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/{ProducerArgumentSame.java => SwaggerBodyFieldToProducerArgument.java} (65%)
 copy common/common-rest/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.filter.HttpServerFilter => swagger/swagger-invocation/invocation-core/src/main/resources/META-INF/services/org.apache.servicecomb.swagger.invocation.arguments.producer.ProducerContextArgumentMapperFactory (88%)
 delete mode 100644 swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/JaxRSProducerArgumentsMapperFactoryTest.java
 delete mode 100644 swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerBeanParamMapperTest.java
 delete mode 100644 swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerSpringMVCQueryObjectMapperTest.java
 create mode 100644 swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/TestJaxrs.java
 create mode 100644 swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/TestPojo.java
 create mode 100644 swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/TestSpringmvc.java


[servicecomb-java-chassis] 02/03: [SCB-1269][WIP][WEAK] delete useless files

Posted by li...@apache.org.
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);
-    }
-  }
-}


[servicecomb-java-chassis] 03/03: [SCB-1269][WIP][WEAK] update UT

Posted by li...@apache.org.
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 6516edbad7f1f0caec96ca5ca6eb201fa0ceeeba
Author: wujimin <wu...@huawei.com>
AuthorDate: Thu Apr 25 11:23:27 2019 +0800

    [SCB-1269][WIP][WEAK] update UT
---
 .../JaxRSProducerArgumentsMapperFactoryTest.java   | 229 ---------------------
 .../producer/ProducerBeanParamMapperTest.java      | 146 -------------
 .../ProducerSpringMVCQueryObjectMapperTest.java    | 183 ----------------
 .../invocation/arguments/producer/TestJaxrs.java   |  76 +++++++
 .../invocation/arguments/producer/TestPojo.java    |  83 ++++++++
 .../arguments/producer/TestSpringmvc.java          |  75 +++++++
 6 files changed, 234 insertions(+), 558 deletions(-)

diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/JaxRSProducerArgumentsMapperFactoryTest.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/JaxRSProducerArgumentsMapperFactoryTest.java
deleted file mode 100644
index 7519203..0000000
--- a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/JaxRSProducerArgumentsMapperFactoryTest.java
+++ /dev/null
@@ -1,229 +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.annotation.Annotation;
-import java.lang.reflect.Method;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import javax.servlet.http.Part;
-import javax.ws.rs.BeanParam;
-import javax.ws.rs.CookieParam;
-import javax.ws.rs.DefaultValue;
-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.jaxrs.JaxrsSwaggerGeneratorContext;
-import org.apache.servicecomb.swagger.generator.pojo.PojoSwaggerGeneratorContext;
-import org.apache.servicecomb.swagger.invocation.arguments.ArgumentsMapperConfig;
-import org.apache.servicecomb.swagger.invocation.arguments.ProviderParameter;
-import org.apache.servicecomb.swagger.invocation.arguments.producer.ProducerArgumentsMapperFactory.ParamWrapper;
-import org.hamcrest.Matchers;
-import org.junit.Assert;
-import org.junit.Test;
-
-import io.swagger.models.parameters.CookieParameter;
-import io.swagger.models.parameters.FormParameter;
-import io.swagger.models.parameters.HeaderParameter;
-import io.swagger.models.parameters.Parameter;
-import io.swagger.models.parameters.PathParameter;
-import io.swagger.models.parameters.QueryParameter;
-import mockit.Deencapsulation;
-
-public class JaxRSProducerArgumentsMapperFactoryTest {
-
-  private final JaxRSProducerArgumentsMapperFactory producerArgumentsMapperFactory = new JaxRSProducerArgumentsMapperFactory();
-
-  @Test
-  public void canProcess() {
-    ArgumentsMapperConfig argumentsMapperConfig = new ArgumentsMapperConfig();
-
-    argumentsMapperConfig.setSwaggerGeneratorContext(new JaxrsSwaggerGeneratorContext());
-    Assert.assertTrue(producerArgumentsMapperFactory.canProcess(argumentsMapperConfig));
-
-    argumentsMapperConfig.setSwaggerGeneratorContext(new PojoSwaggerGeneratorContext());
-    Assert.assertFalse(producerArgumentsMapperFactory.canProcess(argumentsMapperConfig));
-  }
-
-  @Test
-  public void findAggregatedParamNames() throws NoSuchMethodException {
-    Map<String, ProviderParameter> providerParamMap = new HashMap<>();
-    providerParamMap.put("qqq", new ProviderParameter(1, String.class, "qqq"));
-    Method aggregatedTestParamMethod = AggregatedParamProvider.class
-        .getMethod("aggregatedParamTest", AggregatedTestParam.class);
-    Annotation beanParamAnnotation = aggregatedTestParamMethod.getParameterAnnotations()[0][0];
-    providerParamMap.put("aggregatedTestParam",
-        new ProviderParameter(0, AggregatedTestParam.class, "aggregatedTestParam")
-            .setAnnotations(new Annotation[] {beanParamAnnotation}));
-
-    Map<String, ParamWrapper<Parameter>> swaggerParamMap = new HashMap<>();
-    Parameter swaggerParam = new PathParameter().name("pathSwaggerParam");
-    swaggerParamMap.put("pathSwaggerParam", new ParamWrapper<>(swaggerParam).setIndex(0));
-    swaggerParam = new HeaderParameter().name("headerSwaggerParam");
-    swaggerParamMap.put("headerSwaggerParam", new ParamWrapper<>(swaggerParam).setIndex(1));
-    swaggerParam = new CookieParameter().name("intSwaggerVal");
-    swaggerParamMap.put("intSwaggerVal", new ParamWrapper<>(swaggerParam).setIndex(2));
-    swaggerParam = new FormParameter().name("longSwaggerVal");
-    swaggerParamMap.put("longSwaggerVal", new ParamWrapper<>(swaggerParam).setIndex(3));
-    swaggerParam = new QueryParameter().name("querySwaggerParam");
-    swaggerParamMap.put("querySwaggerParam", new ParamWrapper<>(swaggerParam).setIndex(4));
-    swaggerParam = new FormParameter().name("uploadSwaggerParam");
-    swaggerParamMap.put("uploadSwaggerParam", new ParamWrapper<>(swaggerParam).setIndex(5));
-    swaggerParam = new QueryParameter().name("qqq");
-    swaggerParamMap.put("qqq", new ParamWrapper<>(swaggerParam).setIndex(6));
-
-    Set<String> aggregatedParamNames = producerArgumentsMapperFactory
-        .findAggregatedParamNames(providerParamMap, swaggerParamMap);
-    Assert.assertThat(aggregatedParamNames, Matchers.contains("aggregatedTestParam"));
-  }
-
-  @Test
-  public void generateAggregatedParamMapper() throws NoSuchMethodException {
-    Map<String, ProviderParameter> providerParamMap = new HashMap<>();
-    providerParamMap.put("qqq", new ProviderParameter(1, String.class, "qqq"));
-    Method aggregatedTestParamMethod = AggregatedParamProvider.class
-        .getMethod("aggregatedParamTest", AggregatedTestParam.class);
-    Annotation beanParamAnnotation = aggregatedTestParamMethod.getParameterAnnotations()[0][0];
-    providerParamMap.put("aggregatedTestParam",
-        new ProviderParameter(0, AggregatedTestParam.class, "aggregatedTestParam")
-            .setAnnotations(new Annotation[] {beanParamAnnotation}));
-
-    Map<String, ParamWrapper<Parameter>> swaggerParamMap = new HashMap<>();
-    Parameter swaggerParam = new PathParameter().name("pathSwaggerParam");
-    swaggerParamMap.put("pathSwaggerParam", new ParamWrapper<>(swaggerParam).setIndex(0));
-    swaggerParam = new HeaderParameter().name("headerSwaggerParam");
-    swaggerParamMap.put("headerSwaggerParam", new ParamWrapper<>(swaggerParam).setIndex(1));
-    swaggerParam = new CookieParameter().name("intSwaggerVal");
-    swaggerParamMap.put("intSwaggerVal", new ParamWrapper<>(swaggerParam).setIndex(2));
-    swaggerParam = new FormParameter().name("longSwaggerVal");
-    swaggerParamMap.put("longSwaggerVal", new ParamWrapper<>(swaggerParam).setIndex(3));
-    swaggerParam = new QueryParameter().name("querySwaggerParam");
-    swaggerParamMap.put("querySwaggerParam", new ParamWrapper<>(swaggerParam).setIndex(4));
-    swaggerParam = new FormParameter().name("uploadSwaggerParam");
-    swaggerParamMap.put("uploadSwaggerParam", new ParamWrapper<>(swaggerParam).setIndex(5));
-    swaggerParam = new QueryParameter().name("qqq");
-    swaggerParamMap.put("qqq", new ParamWrapper<>(swaggerParam).setIndex(6));
-
-    Set<String> aggregatedParamNames = new HashSet<>();
-    aggregatedParamNames.add("aggregatedTestParam");
-    ArgumentsMapperConfig argumentsMapperConfig = new ArgumentsMapperConfig();
-    producerArgumentsMapperFactory.generateAggregatedParamMapper(
-        argumentsMapperConfig, providerParamMap, swaggerParamMap, aggregatedParamNames);
-
-    Assert.assertEquals(1, argumentsMapperConfig.getArgumentMapperList().size());
-    Assert.assertEquals(ProducerBeanParamMapper.class, argumentsMapperConfig.getArgumentMapperList().get(0).getClass());
-    ProducerBeanParamMapper producerBeanParamMapper =
-        (ProducerBeanParamMapper) argumentsMapperConfig.getArgumentMapperList().get(0);
-    Assert.assertEquals(Integer.valueOf(0), Deencapsulation.getField(producerBeanParamMapper, "producerIdx"));
-    Map<String, Integer> swaggerParamIndexMap =
-        Deencapsulation.getField(producerBeanParamMapper, "swaggerParamIndexMap");
-    Assert.assertEquals(Integer.valueOf(0), swaggerParamIndexMap.get("pathParam"));
-    Assert.assertEquals(Integer.valueOf(1), swaggerParamIndexMap.get("headerParam"));
-    Assert.assertEquals(Integer.valueOf(2), swaggerParamIndexMap.get("intVal"));
-    Assert.assertEquals(Integer.valueOf(3), swaggerParamIndexMap.get("longVal"));
-    Assert.assertEquals(Integer.valueOf(4), swaggerParamIndexMap.get("q"));
-    Assert.assertEquals(Integer.valueOf(5), swaggerParamIndexMap.get("uploaded"));
-  }
-
-  static class AggregatedParamProvider {
-    public String aggregatedParamTest(@BeanParam AggregatedTestParam aggregatedTestParam) {
-      return null;
-    }
-  }
-
-  static class AggregatedTestParam {
-    @PathParam("pathSwaggerParam")
-    private String pathParam;
-
-    private String queryParam;
-
-    @DefaultValue("defaultHeader")
-    @HeaderParam(value = "headerSwaggerParam")
-    private String headerParam;
-
-    @CookieParam("intSwaggerVal")
-    private int intVal;
-
-    @FormParam("longSwaggerVal")
-    private long longVal;
-
-    private Part uploaded;
-
-    public String getPathParam() {
-      return pathParam;
-    }
-
-    public AggregatedTestParam setPathParam(String pathParam) {
-      this.pathParam = pathParam;
-      return this;
-    }
-
-    public String getQ() {
-      return queryParam;
-    }
-
-    @DefaultValue("defaultQuery")
-    @QueryParam(value = "querySwaggerParam")
-    public AggregatedTestParam setQ(String queryParam) {
-      this.queryParam = queryParam;
-      return this;
-    }
-
-    public String getHeaderParam() {
-      return headerParam;
-    }
-
-    public AggregatedTestParam setHeaderParam(String headerParam) {
-      this.headerParam = headerParam;
-      return this;
-    }
-
-    public int getIntVal() {
-      return intVal;
-    }
-
-    public AggregatedTestParam setIntVal(int intVal) {
-      this.intVal = intVal;
-      return this;
-    }
-
-    public long getLongVal() {
-      return longVal;
-    }
-
-    public AggregatedTestParam setLongVal(long longVal) {
-      this.longVal = longVal;
-      return this;
-    }
-
-    public Part getUploaded() {
-      return uploaded;
-    }
-
-    @FormParam("uploadSwaggerParam")
-    public AggregatedTestParam setUploaded(Part uploaded) {
-      this.uploaded = uploaded;
-      return this;
-    }
-  }
-}
\ No newline at end of file
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerBeanParamMapperTest.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerBeanParamMapperTest.java
deleted file mode 100644
index 81c8d35..0000000
--- a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerBeanParamMapperTest.java
+++ /dev/null
@@ -1,146 +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.Date;
-import java.util.HashMap;
-import java.util.Objects;
-
-import javax.servlet.http.Part;
-
-import org.apache.servicecomb.foundation.common.part.AbstractPart;
-import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-import org.apache.servicecomb.swagger.invocation.arguments.ArgumentMapper;
-import org.apache.servicecomb.swagger.invocation.arguments.producer.ProducerSpringMVCQueryObjectMapperTest.RecursiveParam;
-import org.apache.servicecomb.swagger.invocation.arguments.producer.ProducerSpringMVCQueryObjectMapperTest.TestParam;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class ProducerBeanParamMapperTest {
-
-  @Test
-  public void mapArgument() {
-    final HashMap<String, Integer> producerNameToSwaggerIndexMap = new HashMap<>();
-    producerNameToSwaggerIndexMap.put("name", 2);
-    producerNameToSwaggerIndexMap.put("age", 0);
-    ArgumentMapper argumentMapper = new ProducerBeanParamMapper(producerNameToSwaggerIndexMap, 0, TestParam.class);
-    SwaggerInvocation swaggerInvocation = new SwaggerInvocation();
-    swaggerInvocation.setSwaggerArguments(new Object[] {22, "abc", "nameTest"});
-
-    final Object[] producerArguments = new Object[1];
-    argumentMapper.mapArgument(swaggerInvocation, producerArguments);
-    Assert.assertEquals(producerArguments[0], new TestParam().setName("nameTest").setAge(22));
-  }
-
-  @Test
-  public void mapArgumentOnRecursiveParam() {
-    final HashMap<String, Integer> producerNameToSwaggerIndexMap = new HashMap<>();
-    producerNameToSwaggerIndexMap.put("num", 0);
-    producerNameToSwaggerIndexMap.put("str", 1);
-    producerNameToSwaggerIndexMap.put("date", 2);
-    ArgumentMapper argumentMapper = new ProducerBeanParamMapper(producerNameToSwaggerIndexMap, 1,
-        RecursiveParam.class);
-    SwaggerInvocation swaggerInvocation = new SwaggerInvocation();
-    final Date testDate = new Date();
-    swaggerInvocation.setSwaggerArguments(new Object[] {2, "str0_0", testDate});
-
-    final Object[] producerArguments = new Object[2];
-    argumentMapper.mapArgument(swaggerInvocation, producerArguments);
-    Assert.assertNull(producerArguments[0]);
-    Assert.assertEquals(producerArguments[1], new RecursiveParam().setNum(2).setStr("str0_0").setDate(testDate));
-  }
-
-  @Test
-  public void mapArgumentWithPart() {
-    final HashMap<String, Integer> producerNameToSwaggerIndexMap = new HashMap<>();
-    producerNameToSwaggerIndexMap.put("up", 0);
-    producerNameToSwaggerIndexMap.put("str", 2);
-    producerNameToSwaggerIndexMap.put("longValue", 3);
-    ArgumentMapper argumentMapper = new ProducerBeanParamMapper(producerNameToSwaggerIndexMap, 0,
-        TestParamWithPart.class);
-    SwaggerInvocation swaggerInvocation = new SwaggerInvocation();
-    final AbstractPart uploadedFile = new AbstractPart();
-    swaggerInvocation.setSwaggerArguments(new Object[] {uploadedFile, 123L, "testString", 12L});
-
-    final Object[] producerArguments = new Object[2];
-    argumentMapper.mapArgument(swaggerInvocation, producerArguments);
-    Assert.assertEquals(producerArguments[0], new TestParamWithPart("testString", 12L, uploadedFile));
-    Assert.assertSame(((TestParamWithPart) producerArguments[0]).getUp(), uploadedFile);
-    Assert.assertNull(producerArguments[1]);
-  }
-
-  static class TestParamWithPart {
-    private String str;
-
-    private long longValue;
-
-    private Part uploaded;
-
-    public TestParamWithPart() {
-    }
-
-    public TestParamWithPart(String str, long longValue, Part uploaded) {
-      this.str = str;
-      this.longValue = longValue;
-      this.uploaded = uploaded;
-    }
-
-    public String getStr() {
-      return str;
-    }
-
-    public void setStr(String str) {
-      this.str = str;
-    }
-
-    public long getLongValue() {
-      return longValue;
-    }
-
-    public void setLongValue(long longValue) {
-      this.longValue = longValue;
-    }
-
-    public Part getUp() {
-      return uploaded;
-    }
-
-    public void setUp(Part uploaded) {
-      this.uploaded = uploaded;
-    }
-
-    @Override
-    public boolean equals(Object o) {
-      if (this == o) {
-        return true;
-      }
-      if (o == null || getClass() != o.getClass()) {
-        return false;
-      }
-      TestParamWithPart that = (TestParamWithPart) o;
-      return longValue == that.longValue &&
-          Objects.equals(str, that.str) &&
-          Objects.equals(uploaded, that.uploaded);
-    }
-
-    @Override
-    public int hashCode() {
-      return Objects.hash(str, longValue, uploaded);
-    }
-  }
-}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerSpringMVCQueryObjectMapperTest.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerSpringMVCQueryObjectMapperTest.java
deleted file mode 100644
index fea80f2..0000000
--- a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerSpringMVCQueryObjectMapperTest.java
+++ /dev/null
@@ -1,183 +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.Date;
-import java.util.HashMap;
-import java.util.Objects;
-
-import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-import org.apache.servicecomb.swagger.invocation.arguments.ArgumentMapper;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class ProducerSpringMVCQueryObjectMapperTest {
-
-  @Test
-  public void mapArgument() {
-    final HashMap<String, Integer> swaggerParamIndexMap = new HashMap<>();
-    swaggerParamIndexMap.put("name", 0);
-    swaggerParamIndexMap.put("age", 1);
-    ArgumentMapper argumentMapper = new ProducerSpringMVCQueryObjectMapper(swaggerParamIndexMap, 0, TestParam.class);
-    SwaggerInvocation swaggerInvocation = new SwaggerInvocation();
-    swaggerInvocation.setSwaggerArguments(new Object[] {"nameTest", 22});
-
-    final Object[] producerArguments = new Object[1];
-    argumentMapper.mapArgument(swaggerInvocation, producerArguments);
-    Assert.assertEquals(producerArguments[0], new TestParam().setName("nameTest").setAge(22));
-  }
-
-  @Test
-  public void mapArgumentOnRecursiveParam() {
-    final HashMap<String, Integer> swaggerParamIndexMap = new HashMap<>();
-    swaggerParamIndexMap.put("num", 0);
-    swaggerParamIndexMap.put("str", 1);
-    swaggerParamIndexMap.put("date", 2);
-    ArgumentMapper argumentMapper = new ProducerSpringMVCQueryObjectMapper(swaggerParamIndexMap, 1,
-        RecursiveParam.class);
-    SwaggerInvocation swaggerInvocation = new SwaggerInvocation();
-    final Date testDate = new Date();
-    swaggerInvocation.setSwaggerArguments(new Object[] {2, "str0_0", testDate});
-
-    final Object[] producerArguments = new Object[2];
-    argumentMapper.mapArgument(swaggerInvocation, producerArguments);
-    Assert.assertNull(producerArguments[0]);
-    Assert.assertEquals(producerArguments[1], new RecursiveParam().setNum(2).setStr("str0_0").setDate(testDate));
-  }
-
-  static class TestParam {
-    private String name;
-
-    private int age;
-
-    public String getName() {
-      return name;
-    }
-
-    public TestParam setName(String name) {
-      this.name = name;
-      return this;
-    }
-
-    public int getAge() {
-      return age;
-    }
-
-    public TestParam setAge(int age) {
-      this.age = age;
-      return this;
-    }
-
-    @Override
-    public boolean equals(Object o) {
-      if (this == o) {
-        return true;
-      }
-      if (o == null || getClass() != o.getClass()) {
-        return false;
-      }
-      TestParam testParam = (TestParam) o;
-      return age == testParam.age &&
-          Objects.equals(name, testParam.name);
-    }
-
-    @Override
-    public int hashCode() {
-      return Objects.hash(name, age);
-    }
-  }
-
-  static class RecursiveParam {
-
-    private int num;
-
-    private String str;
-
-    private Date date;
-
-    private RecursiveParam recursiveParam;
-
-    public int getNum() {
-      return num;
-    }
-
-    public RecursiveParam setNum(int num) {
-      this.num = num;
-      return this;
-    }
-
-    public String getStr() {
-      return str;
-    }
-
-    public RecursiveParam setStr(String str) {
-      this.str = str;
-      return this;
-    }
-
-    public Date getDate() {
-      return date;
-    }
-
-    public RecursiveParam setDate(Date date) {
-      this.date = date;
-      return this;
-    }
-
-    public RecursiveParam getRecursiveParam() {
-      return recursiveParam;
-    }
-
-    public RecursiveParam setRecursiveParam(
-        RecursiveParam recursiveParam) {
-      this.recursiveParam = recursiveParam;
-      return this;
-    }
-
-    @Override
-    public String toString() {
-      final StringBuilder sb = new StringBuilder("RecursiveParam{");
-      sb.append("num=").append(num);
-      sb.append(", str='").append(str).append('\'');
-      sb.append(", date=").append(date);
-      sb.append(", recursiveParam=").append(recursiveParam);
-      sb.append('}');
-      return sb.toString();
-    }
-
-    @Override
-    public boolean equals(Object o) {
-      if (this == o) {
-        return true;
-      }
-      if (o == null || getClass() != o.getClass()) {
-        return false;
-      }
-      RecursiveParam that = (RecursiveParam) o;
-      return num == that.num &&
-          Objects.equals(str, that.str) &&
-          Objects.equals(date, that.date) &&
-          Objects.equals(recursiveParam, that.recursiveParam);
-    }
-
-    @Override
-    public int hashCode() {
-      return Objects.hash(num, str, date, recursiveParam);
-    }
-  }
-}
\ No newline at end of file
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/TestJaxrs.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/TestJaxrs.java
new file mode 100644
index 0000000..0559101
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/TestJaxrs.java
@@ -0,0 +1,76 @@
+/*
+ * 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 org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
+import org.apache.servicecomb.swagger.engine.SwaggerProducer;
+import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
+import org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddBeanParamV1;
+import org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddBodyV1;
+import org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddV1;
+import org.apache.servicecomb.swagger.invocation.schemas.models.AddBeanParamV1;
+import org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV1;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestJaxrs {
+  @Test
+  public void add() {
+    SwaggerProducer swaggerProducer = new SwaggerEnvironment().createProducer(new JaxrsAddV1(), null);
+    ProducerArgumentsMapper mapper = swaggerProducer.findOperation("add").getArgumentsMapper();
+
+    SwaggerInvocation invocation = new SwaggerInvocation();
+    invocation.setSwaggerArguments(new Object[] {1, 2});
+
+    Object[] arguments = mapper.toProducerArgs(invocation);
+
+    Assert.assertEquals(2, arguments.length);
+    Assert.assertEquals(1, arguments[0]);
+    Assert.assertEquals(2, arguments[1]);
+  }
+
+  @Test
+  public void addBeanParam() {
+    SwaggerProducer swaggerProducer = new SwaggerEnvironment().createProducer(new JaxrsAddBeanParamV1(), null);
+    ProducerArgumentsMapper mapper = swaggerProducer.findOperation("add").getArgumentsMapper();
+
+    SwaggerInvocation invocation = new SwaggerInvocation();
+    invocation.setSwaggerArguments(new Object[] {1, 2});
+
+    Object[] arguments = mapper.toProducerArgs(invocation);
+
+    Assert.assertEquals(1, arguments.length);
+    AddBeanParamV1 paramV1 = (AddBeanParamV1) arguments[0];
+    Assert.assertEquals(1, paramV1.getX());
+    Assert.assertEquals(2, paramV1.y);
+  }
+
+  @Test
+  public void addBody() {
+    SwaggerProducer swaggerProducer = new SwaggerEnvironment().createProducer(new JaxrsAddBodyV1(), null);
+    ProducerArgumentsMapper mapper = swaggerProducer.findOperation("add").getArgumentsMapper();
+
+    AddWrapperV1 addBody = new AddWrapperV1();
+    SwaggerInvocation invocation = new SwaggerInvocation();
+    invocation.setSwaggerArguments(new Object[] {addBody});
+
+    Object[] arguments = mapper.toProducerArgs(invocation);
+
+    Assert.assertEquals(1, arguments.length);
+    Assert.assertSame(addBody, arguments[0]);
+  }
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/TestPojo.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/TestPojo.java
new file mode 100644
index 0000000..6ec4af5
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/TestPojo.java
@@ -0,0 +1,83 @@
+/*
+ * 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.HashMap;
+import java.util.Map;
+
+import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
+import org.apache.servicecomb.swagger.engine.SwaggerProducer;
+import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
+import org.apache.servicecomb.swagger.invocation.schemas.PojoAddBodyV1;
+import org.apache.servicecomb.swagger.invocation.schemas.PojoAddV1;
+import org.apache.servicecomb.swagger.invocation.schemas.PojoAddWithContextV1;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestPojo {
+  static Map<String, Object> addBody = new HashMap<>();
+
+  static {
+    addBody.put("x", 1);
+    addBody.put("y", 2);
+  }
+
+  @Test
+  public void add() {
+    SwaggerProducer swaggerProducer = new SwaggerEnvironment().createProducer(new PojoAddV1(), null);
+    ProducerArgumentsMapper mapper = swaggerProducer.findOperation("add").getArgumentsMapper();
+
+    SwaggerInvocation invocation = new SwaggerInvocation();
+    invocation.setSwaggerArguments(new Object[] {addBody});
+
+    Object[] arguments = mapper.toProducerArgs(invocation);
+
+    Assert.assertEquals(2, arguments.length);
+    Assert.assertEquals(1, arguments[0]);
+    Assert.assertEquals(2, arguments[1]);
+  }
+
+  @Test
+  public void addBody() {
+    SwaggerProducer swaggerProducer = new SwaggerEnvironment().createProducer(new PojoAddBodyV1(), null);
+    ProducerArgumentsMapper mapper = swaggerProducer.findOperation("add").getArgumentsMapper();
+
+    SwaggerInvocation invocation = new SwaggerInvocation();
+    invocation.setSwaggerArguments(new Object[] {addBody});
+
+    Object[] arguments = mapper.toProducerArgs(invocation);
+
+    Assert.assertEquals(1, arguments.length);
+    Assert.assertSame(addBody, arguments[0]);
+  }
+
+  @Test
+  public void addWithContext_add() {
+    SwaggerProducer swaggerProducer = new SwaggerEnvironment().createProducer(new PojoAddWithContextV1(), null);
+    ProducerArgumentsMapper mapper = swaggerProducer.findOperation("add").getArgumentsMapper();
+
+    SwaggerInvocation invocation = new SwaggerInvocation();
+    invocation.setSwaggerArguments(new Object[] {addBody});
+
+    Object[] arguments = mapper.toProducerArgs(invocation);
+
+    Assert.assertEquals(3, arguments.length);
+    Assert.assertSame(invocation, arguments[0]);
+    Assert.assertEquals(1, arguments[1]);
+    Assert.assertEquals(2, arguments[2]);
+  }
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/TestSpringmvc.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/TestSpringmvc.java
new file mode 100644
index 0000000..3991da8
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/TestSpringmvc.java
@@ -0,0 +1,75 @@
+/*
+ * 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 org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
+import org.apache.servicecomb.swagger.engine.SwaggerProducer;
+import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
+import org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddBodyV1;
+import org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddV1;
+import org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddWrapperV1;
+import org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV1;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestSpringmvc {
+  @Test
+  public void add() {
+    SwaggerProducer swaggerProducer = new SwaggerEnvironment().createProducer(new SpringmvcAddV1(), null);
+    ProducerArgumentsMapper mapper = swaggerProducer.findOperation("add").getArgumentsMapper();
+
+    SwaggerInvocation invocation = new SwaggerInvocation();
+    invocation.setSwaggerArguments(new Object[] {1, 2});
+
+    Object[] arguments = mapper.toProducerArgs(invocation);
+
+    Assert.assertEquals(2, arguments.length);
+    Assert.assertEquals(1, arguments[0]);
+    Assert.assertEquals(2, arguments[1]);
+  }
+
+  @Test
+  public void addWrapper() {
+    SwaggerProducer swaggerProducer = new SwaggerEnvironment().createProducer(new SpringmvcAddWrapperV1(), null);
+    ProducerArgumentsMapper mapper = swaggerProducer.findOperation("add").getArgumentsMapper();
+
+    SwaggerInvocation invocation = new SwaggerInvocation();
+    invocation.setSwaggerArguments(new Object[] {1, 2});
+
+    Object[] arguments = mapper.toProducerArgs(invocation);
+
+    Assert.assertEquals(1, arguments.length);
+    AddWrapperV1 paramV1 = (AddWrapperV1) arguments[0];
+    Assert.assertEquals(1, paramV1.getX());
+    Assert.assertEquals(2, paramV1.y);
+  }
+
+  @Test
+  public void addBody() {
+    SwaggerProducer swaggerProducer = new SwaggerEnvironment().createProducer(new SpringmvcAddBodyV1(), null);
+    ProducerArgumentsMapper mapper = swaggerProducer.findOperation("add").getArgumentsMapper();
+
+    AddWrapperV1 addBody = new AddWrapperV1();
+    SwaggerInvocation invocation = new SwaggerInvocation();
+    invocation.setSwaggerArguments(new Object[] {addBody});
+
+    Object[] arguments = mapper.toProducerArgs(invocation);
+
+    Assert.assertEquals(1, arguments.length);
+    Assert.assertSame(addBody, arguments[0]);
+  }
+}


[servicecomb-java-chassis] 01/03: [SCB-1269][WIP][WEAK] swaggerProducer arguments not depend on swagger interface

Posted by li...@apache.org.
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 8bc9ed5bb3236eda8b8aeee0c757151ad235fec3
Author: wujimin <wu...@huawei.com>
AuthorDate: Thu Apr 25 10:55:20 2019 +0800

    [SCB-1269][WIP][WEAK] swaggerProducer arguments not depend on swagger interface
---
 .../swagger/engine/SwaggerEnvironment.java         | 67 +++++++--------
 .../swagger/engine/SwaggerProducer.java            | 17 +---
 .../swagger/engine/SwaggerProducerOperation.java   | 21 ++---
 .../swagger/invocation/SwaggerInvocation.java      |  5 ++
 ...pper.java => ContextArgumentMapperFactory.java} | 16 +---
 .../arguments/producer/ProducerArgumentSame.java   |  9 +--
 .../producer/ProducerArgumentsMapper.java          |  4 +-
 .../producer/ProducerArgumentsMapperCreator.java   | 94 ++++++++++++++++++++++
 .../producer/ProducerBeanParamMapper.java          | 55 +++++++------
 ...a => ProducerContextArgumentMapperFactory.java} | 14 +---
 .../producer/ProducerInvocationContextMapper.java  |  1 -
 .../ProducerInvocationContextMapperFactory.java    |  8 +-
 ...ava => SwaggerBodyFieldToProducerArgument.java} | 24 +++---
 ...s.producer.ProducerContextArgumentMapperFactory | 18 +++++
 14 files changed, 210 insertions(+), 143 deletions(-)

diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerEnvironment.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerEnvironment.java
index 1b6b2b0..03cf6da 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerEnvironment.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerEnvironment.java
@@ -25,6 +25,7 @@ import java.util.stream.Collectors;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.servicecomb.foundation.common.utils.BeanUtils;
 import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
+import org.apache.servicecomb.swagger.generator.SwaggerGenerator;
 import org.apache.servicecomb.swagger.generator.core.model.SwaggerOperation;
 import org.apache.servicecomb.swagger.generator.core.model.SwaggerOperations;
 import org.apache.servicecomb.swagger.invocation.arguments.ContextArgumentMapperFactory;
@@ -32,7 +33,8 @@ import org.apache.servicecomb.swagger.invocation.arguments.consumer.ConsumerArgu
 import org.apache.servicecomb.swagger.invocation.arguments.consumer.ConsumerArgumentsMapperCreator;
 import org.apache.servicecomb.swagger.invocation.arguments.consumer.ConsumerContextArgumentMapperFactory;
 import org.apache.servicecomb.swagger.invocation.arguments.producer.ProducerArgumentsMapper;
-import org.apache.servicecomb.swagger.invocation.arguments.producer.ProducerArgumentsMapperFactory;
+import org.apache.servicecomb.swagger.invocation.arguments.producer.ProducerArgumentsMapperCreator;
+import org.apache.servicecomb.swagger.invocation.arguments.producer.ProducerContextArgumentMapperFactory;
 import org.apache.servicecomb.swagger.invocation.response.ResponseMapperFactorys;
 import org.apache.servicecomb.swagger.invocation.response.consumer.ConsumerResponseMapper;
 import org.apache.servicecomb.swagger.invocation.response.consumer.ConsumerResponseMapperFactory;
@@ -107,43 +109,50 @@ public class SwaggerEnvironment {
     return apiOperationAnnotation.nickname();
   }
 
-  public SwaggerProducer createProducer(Object producerInstance, Class<?> swaggerIntf,
-      Map<String, Operation> swaggerOperationMap) {
+  public SwaggerProducer createProducer(Object producerInstance, Swagger swagger) {
+    if (swagger == null) {
+      Class<?> producerCls = BeanUtils.getImplClassFromBean(producerInstance);
+      swagger = SwaggerGenerator.generate(producerCls);
+    }
+
+    Map<Class<?>, ContextArgumentMapperFactory> contextFactorys = SPIServiceUtils
+        .getOrLoadSortedService(ProducerContextArgumentMapperFactory.class)
+        .stream()
+        .collect(Collectors.toMap(ProducerContextArgumentMapperFactory::getContextClass, Function.identity()));
+    SwaggerOperations swaggerOperations = new SwaggerOperations(swagger);
+
     Class<?> producerCls = BeanUtils.getImplClassFromBean(producerInstance);
     Map<String, Method> visibleProducerMethods = retrieveVisibleMethods(producerCls);
 
     SwaggerProducer producer = new SwaggerProducer();
     producer.setProducerCls(producerCls);
-    producer.setSwaggerIntf(swaggerIntf);
-    for (Method swaggerMethod : swaggerIntf.getMethods()) {
-      String methodName = swaggerMethod.getName();
+    for (SwaggerOperation swaggerOperation : swaggerOperations.getOperations().values()) {
+      String operationId = swaggerOperation.getOperationId();
       // producer参数不一定等于swagger参数
-      Method producerMethod = visibleProducerMethods.getOrDefault(methodName, null);
+      Method producerMethod = visibleProducerMethods.getOrDefault(operationId, null);
       if (producerMethod == null) {
         // producer未实现契约,非法
-        String msg = String.format("swagger method %s not exist in producer %s.",
-            methodName,
+        String msg = String.format("operationId %s not exist in producer %s.",
+            operationId,
             producerInstance.getClass().getName());
-        throw new Error(msg);
+        throw new IllegalStateException(msg);
       }
 
-      ArgumentsMapperConfig config = new ArgumentsMapperConfig();
-      config.setSwaggerMethod(swaggerMethod);
-      config.setProviderMethod(producerMethod);
-      config.setSwaggerOperation(swaggerOperationMap.get(methodName));
-
-      ProducerArgumentsMapperFactory argumentsMapperFactory = selectProducerArgumentsMapperFactory(config);
-      ProducerArgumentsMapper argsMapper = argumentsMapperFactory.createArgumentsMapper(config);
+      ProducerArgumentsMapperCreator creator = new ProducerArgumentsMapperCreator(
+          Json.mapper().getSerializationConfig(),
+          contextFactorys,
+          producerMethod,
+          swaggerOperation);
+      ProducerArgumentsMapper argsMapper = creator.createArgumentsMapper();
       ProducerResponseMapper responseMapper = producerResponseMapperFactorys.createResponseMapper(
           swaggerMethod.getGenericReturnType(),
           producerMethod.getGenericReturnType());
 
       SwaggerProducerOperation op = new SwaggerProducerOperation();
-      op.setName(methodName);
       op.setProducerClass(producerCls);
       op.setProducerInstance(producerInstance);
       op.setProducerMethod(producerMethod);
-      op.setSwaggerMethod(swaggerMethod);
+      op.setSwaggerOperation(swaggerOperation);
       op.setArgumentsMapper(argsMapper);
       op.setResponseMapper(responseMapper);
 
@@ -153,24 +162,10 @@ public class SwaggerEnvironment {
     return producer;
   }
 
-  ProducerArgumentsMapperFactory selectProducerArgumentsMapperFactory(ArgumentsMapperConfig config) {
-    ProducerArgumentsMapperFactory argumentsMapperFactory = null;
-    for (ProducerArgumentsMapperFactory producerArgumentsMapperFactory : this.producerArgumentsMapperFactoryList) {
-      if (producerArgumentsMapperFactory.canProcess(config)) {
-        argumentsMapperFactory = producerArgumentsMapperFactory;
-        break;
-      }
-    }
-    if (null == argumentsMapperFactory) {
-      argumentsMapperFactory = this.producerArgumentsFactory;
-    }
-    return argumentsMapperFactory;
-  }
-
   private Map<String, Method> retrieveVisibleMethods(Class<?> clazz) {
     Map<String, Method> visibleMethods = new HashMap<>();
     for (Method method : clazz.getMethods()) {
-      String methodName = method.getName();
+      String operationId = method.getName();
       ApiOperation apiOperationAnnotation = method.getAnnotation(ApiOperation.class);
       if (apiOperationAnnotation != null) {
         if (apiOperationAnnotation.hidden()) {
@@ -178,11 +173,11 @@ public class SwaggerEnvironment {
         }
 
         if (StringUtils.isNotEmpty(apiOperationAnnotation.nickname())) {
-          methodName = apiOperationAnnotation.nickname();
+          operationId = apiOperationAnnotation.nickname();
         }
       }
 
-      visibleMethods.put(methodName, method);
+      visibleMethods.put(operationId, method);
     }
     return visibleMethods;
   }
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerProducer.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerProducer.java
index d1e9eef..32968f2 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerProducer.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerProducer.java
@@ -23,8 +23,7 @@ import java.util.Map;
 public class SwaggerProducer {
   private Class<?> producerCls;
 
-  private Class<?> swaggerIntf;
-
+  // key is operationId
   private Map<String, SwaggerProducerOperation> opMap = new HashMap<>();
 
   public Class<?> getProducerCls() {
@@ -35,20 +34,12 @@ public class SwaggerProducer {
     this.producerCls = producerCls;
   }
 
-  public Class<?> getSwaggerIntf() {
-    return swaggerIntf;
-  }
-
-  public void setSwaggerIntf(Class<?> swaggerIntf) {
-    this.swaggerIntf = swaggerIntf;
-  }
-
   public void addOperation(SwaggerProducerOperation op) {
-    opMap.put(op.getName(), op);
+    opMap.put(op.getOperationId(), op);
   }
 
-  public SwaggerProducerOperation findOperation(String name) {
-    return opMap.get(name);
+  public SwaggerProducerOperation findOperation(String operationId) {
+    return opMap.get(operationId);
   }
 
   public Collection<SwaggerProducerOperation> getAllOperations() {
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerProducerOperation.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerProducerOperation.java
index cca21c5..f174415 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerProducerOperation.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerProducerOperation.java
@@ -24,6 +24,7 @@ import java.util.concurrent.CompletableFuture;
 import javax.ws.rs.core.Response.Status;
 
 import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
+import org.apache.servicecomb.swagger.generator.core.model.SwaggerOperation;
 import org.apache.servicecomb.swagger.invocation.AsyncResponse;
 import org.apache.servicecomb.swagger.invocation.Response;
 import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
@@ -36,8 +37,6 @@ import org.apache.servicecomb.swagger.invocation.extension.ProducerInvokeExtensi
 import org.apache.servicecomb.swagger.invocation.response.producer.ProducerResponseMapper;
 
 public class SwaggerProducerOperation {
-  private String name;
-
   // 因为存在aop场景,所以,producerClass不一定等于producerInstance.getClass()
   private Class<?> producerClass;
 
@@ -45,7 +44,7 @@ public class SwaggerProducerOperation {
 
   private Method producerMethod;
 
-  private Method swaggerMethod;
+  private SwaggerOperation swaggerOperation;
 
   private ProducerArgumentsMapper argumentsMapper;
 
@@ -54,12 +53,8 @@ public class SwaggerProducerOperation {
   private List<ProducerInvokeExtension> producerInvokeExtenstionList =
       SPIServiceUtils.getSortedService(ProducerInvokeExtension.class);
 
-  public String getName() {
-    return name;
-  }
-
-  public void setName(String name) {
-    this.name = name;
+  public String getOperationId() {
+    return swaggerOperation.getOperationId();
   }
 
   public Class<?> getProducerClass() {
@@ -86,12 +81,8 @@ public class SwaggerProducerOperation {
     this.producerMethod = producerMethod;
   }
 
-  public Method getSwaggerMethod() {
-    return swaggerMethod;
-  }
-
-  public void setSwaggerMethod(Method swaggerMethod) {
-    this.swaggerMethod = swaggerMethod;
+  public void setSwaggerOperation(SwaggerOperation swaggerOperation) {
+    this.swaggerOperation = swaggerOperation;
   }
 
   public ProducerArgumentsMapper getArgumentsMapper() {
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/SwaggerInvocation.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/SwaggerInvocation.java
index e4c4cb6..5301868 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/SwaggerInvocation.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/SwaggerInvocation.java
@@ -24,6 +24,11 @@ public class SwaggerInvocation extends InvocationContext {
   // 本实例是在consumer端,还是在provider端
   protected InvocationType invocationType;
 
+  // highway consumer and all producer need arguments
+  // only springmvc consumer no arguments
+  //
+  // so only adapt springmvc consumer to arguments mode
+  // not adapt all to http mode
   protected Object[] swaggerArguments;
 
   protected InvocationContext parentContext;
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerInvocationContextMapper.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/ContextArgumentMapperFactory.java
similarity index 65%
copy from swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerInvocationContextMapper.java
copy to swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/ContextArgumentMapperFactory.java
index 251e994..a0a33b1 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerInvocationContextMapper.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/ContextArgumentMapperFactory.java
@@ -15,18 +15,10 @@
  * limitations under the License.
  */
 
-package org.apache.servicecomb.swagger.invocation.arguments.producer;
+package org.apache.servicecomb.swagger.invocation.arguments;
 
-import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
+public interface ContextArgumentMapperFactory {
+  Class<?> getContextClass();
 
-public class ProducerInvocationContextMapper extends AbstractProducerContextArgMapper {
-
-  public ProducerInvocationContextMapper(int producerIdx) {
-    super(producerIdx);
-  }
-
-  @Override
-  public Object createContextArg(SwaggerInvocation invocation) {
-    return invocation;
-  }
+  ArgumentMapper create(int argumentIdx);
 }
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerArgumentSame.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerArgumentSame.java
index 84c6466..4d07b2e 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerArgumentSame.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerArgumentSame.java
@@ -19,25 +19,20 @@ package org.apache.servicecomb.swagger.invocation.arguments.producer;
 
 import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
 import org.apache.servicecomb.swagger.invocation.arguments.ArgumentMapper;
-import org.apache.servicecomb.swagger.invocation.converter.Converter;
 
 public class ProducerArgumentSame implements ArgumentMapper {
   private int swaggerIdx;
 
   private int producerIdx;
 
-  private Converter converter;
-
-  public ProducerArgumentSame(int swaggerIdx, int producerIdx, Converter converter) {
+  public ProducerArgumentSame(int swaggerIdx, int producerIdx) {
     this.swaggerIdx = swaggerIdx;
     this.producerIdx = producerIdx;
-    this.converter = converter;
   }
 
   @Override
   public void mapArgument(SwaggerInvocation invocation, Object[] producerArguments) {
     Object swaggerParam = invocation.getSwaggerArgument(swaggerIdx);
-    Object producerParam = converter.convert(swaggerParam);
-    producerArguments[producerIdx] = producerParam;
+    producerArguments[producerIdx] = swaggerParam;
   }
 }
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerArgumentsMapper.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerArgumentsMapper.java
index 0a2eb1a..1ca2971 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerArgumentsMapper.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerArgumentsMapper.java
@@ -23,9 +23,7 @@ import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
 import org.apache.servicecomb.swagger.invocation.arguments.ArgumentMapper;
 
 /**
- * 将契约参数转为producer原型
- * 比如契约原型是         int add(int x, int y)
- * 而producer原型是int add(HttpRequest request, int x, int y)
+ * map swagger arguments to producer arguments
  */
 public class ProducerArgumentsMapper {
   private List<ArgumentMapper> producerArgMapperList;
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerArgumentsMapperCreator.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerArgumentsMapperCreator.java
new file mode 100644
index 0000000..b964a39
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerArgumentsMapperCreator.java
@@ -0,0 +1,94 @@
+/*
+ * 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.SwaggerGeneratorUtils.collectParameterName;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Parameter;
+import java.util.Map;
+
+import org.apache.servicecomb.foundation.common.utils.LambdaMetafactoryUtils;
+import org.apache.servicecomb.foundation.common.utils.bean.Setter;
+import org.apache.servicecomb.swagger.generator.core.model.SwaggerOperation;
+import org.apache.servicecomb.swagger.invocation.arguments.AbstractArgumentsMapperCreator;
+import org.apache.servicecomb.swagger.invocation.arguments.ArgumentMapper;
+import org.apache.servicecomb.swagger.invocation.arguments.ContextArgumentMapperFactory;
+
+import com.fasterxml.jackson.databind.JavaType;
+import com.fasterxml.jackson.databind.SerializationConfig;
+import com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition;
+import com.fasterxml.jackson.databind.type.TypeFactory;
+
+public class ProducerArgumentsMapperCreator extends AbstractArgumentsMapperCreator {
+  public ProducerArgumentsMapperCreator(SerializationConfig serializationConfig,
+      Map<Class<?>, ContextArgumentMapperFactory> contextFactorys,
+      Method producerMethod, SwaggerOperation swaggerOperation) {
+    super(serializationConfig, contextFactorys, producerMethod, swaggerOperation);
+  }
+
+  public ProducerArgumentsMapper createArgumentsMapper() {
+    doCreateArgumentsMapper();
+
+    return new ProducerArgumentsMapper(mappers, providerMethod.getParameterCount());
+  }
+
+  @Override
+  protected void processUnknownParameter(String parameterName) {
+    throw new IllegalStateException(String
+        .format("failed to find producer parameter in contract, method=%s:%s, parameter name=%s.",
+            providerMethod.getDeclaringClass().getName(), providerMethod.getName(), parameterName));
+  }
+
+  @Override
+  protected ArgumentMapper createKnownParameterMapper(int producerParamIdx, Integer swaggerIdx) {
+    return new ProducerArgumentSame(producerParamIdx, swaggerIdx);
+  }
+
+  @Override
+  protected ArgumentMapper createSwaggerBodyFieldMapper(int producerParamIdx, String parameterName,
+      int swaggerBodyIdx) {
+    return new SwaggerBodyFieldToProducerArgument(producerParamIdx, parameterName, swaggerBodyIdx);
+  }
+
+  @Override
+  protected void processBeanParameter(int producerParamIdx, Parameter producerParameter) {
+    ProducerBeanParamMapper mapper = new ProducerBeanParamMapper(producerParamIdx, producerParameter.getType());
+    JavaType producerType = TypeFactory.defaultInstance().constructType(producerParameter.getParameterizedType());
+    for (BeanPropertyDefinition propertyDefinition : serializationConfig.introspect(producerType)
+        .findProperties()) {
+      String parameterName = collectParameterName(providerMethod, propertyDefinition);
+      Integer swaggerIdx = findAndClearSwaggerParameterIndex(parameterName);
+      if (swaggerIdx == null) {
+        throw new IllegalStateException(String
+            .format("failed to find producer parameter in contract, method=%s:%s, bean parameter name=%s.",
+                providerMethod.getDeclaringClass().getName(), providerMethod.getName(), parameterName));
+      }
+
+      Setter<Object, Object> setter;
+      if (propertyDefinition.hasSetter()) {
+        setter = LambdaMetafactoryUtils.createLambda(propertyDefinition.getSetter().getAnnotated(), Setter.class);
+      } else {
+        setter = LambdaMetafactoryUtils.createSetter(propertyDefinition.getField().getAnnotated());
+      }
+
+      mapper.addField(swaggerIdx, setter);
+    }
+    mappers.add(mapper);
+  }
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerBeanParamMapper.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerBeanParamMapper.java
index b5c404b..bf92549 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerBeanParamMapper.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerBeanParamMapper.java
@@ -17,47 +17,52 @@
 
 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 java.util.ArrayList;
+import java.util.List;
 
+import org.apache.servicecomb.foundation.common.utils.bean.Setter;
 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;
 
 public class ProducerBeanParamMapper implements ArgumentMapper {
+  private class FieldMeta {
+    int swaggerIdx;
+
+    Setter<Object, Object> setter;
+
+    public FieldMeta(int swaggerIdx, Setter<Object, Object> setter) {
+      this.swaggerIdx = swaggerIdx;
+      this.setter = setter;
+    }
+  }
 
   private int producerIdx;
 
-  private Map<String, Integer> swaggerParamIndexMap;
+  private final Class<?> producerParamType;
 
-  private Converter converter;
+  private List<FieldMeta> fields = new ArrayList<>();
 
-  /**
-   * @param producerNameToSwaggerIndexMap name of the fields and setters defined in @BeanParam parameter to swagger
-   * param index
-   * @param producerIdx index of producer param
-   * @param producerParamType type of producer param
-   */
-  public ProducerBeanParamMapper(Map<String, Integer> producerNameToSwaggerIndexMap, int producerIdx,
-      Type producerParamType) {
+  public ProducerBeanParamMapper(int producerIdx, Class<?> producerParamType) {
     this.producerIdx = producerIdx;
-    this.swaggerParamIndexMap = new HashMap<>();
-    this.swaggerParamIndexMap.putAll(producerNameToSwaggerIndexMap);
-    converter = new ConverterCommon(producerParamType);
+    this.producerParamType = producerParamType;
+  }
+
+  public void addField(int swaggerIdx, Setter<Object, Object> setter) {
+    fields.add(new FieldMeta(swaggerIdx, setter));
   }
 
   @Override
   public void mapArgument(SwaggerInvocation invocation, Object[] producerArguments) {
-    Map<String, Object> jsonMap = new HashMap<>(swaggerParamIndexMap.size());
+    try {
+      Object paramInstance = producerParamType.newInstance();
+      producerArguments[producerIdx] = paramInstance;
 
-    for (Entry<String, Integer> swaggerIndexEntry : swaggerParamIndexMap.entrySet()) {
-      jsonMap.put(swaggerIndexEntry.getKey(), invocation.getSwaggerArgument(swaggerIndexEntry.getValue()));
+      for (FieldMeta fieldMeta : fields) {
+        Object value = invocation.getSwaggerArgument(fieldMeta.swaggerIdx);
+        fieldMeta.setter.set(paramInstance, value);
+      }
+    } catch (Throwable e) {
+      throw new IllegalStateException("failed to map bean param.", e);
     }
-
-    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/ProducerInvocationContextMapper.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerContextArgumentMapperFactory.java
similarity index 71%
copy from swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerInvocationContextMapper.java
copy to swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerContextArgumentMapperFactory.java
index 251e994..64e569f 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerInvocationContextMapper.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerContextArgumentMapperFactory.java
@@ -14,19 +14,9 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.servicecomb.swagger.invocation.arguments.producer;
 
-import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-
-public class ProducerInvocationContextMapper extends AbstractProducerContextArgMapper {
-
-  public ProducerInvocationContextMapper(int producerIdx) {
-    super(producerIdx);
-  }
+import org.apache.servicecomb.swagger.invocation.arguments.ContextArgumentMapperFactory;
 
-  @Override
-  public Object createContextArg(SwaggerInvocation invocation) {
-    return invocation;
-  }
+public interface ProducerContextArgumentMapperFactory extends ContextArgumentMapperFactory {
 }
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerInvocationContextMapper.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerInvocationContextMapper.java
index 251e994..658cda0 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerInvocationContextMapper.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerInvocationContextMapper.java
@@ -20,7 +20,6 @@ package org.apache.servicecomb.swagger.invocation.arguments.producer;
 import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
 
 public class ProducerInvocationContextMapper extends AbstractProducerContextArgMapper {
-
   public ProducerInvocationContextMapper(int producerIdx) {
     super(producerIdx);
   }
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerInvocationContextMapperFactory.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerInvocationContextMapperFactory.java
index d370627..258ce65 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerInvocationContextMapperFactory.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerInvocationContextMapperFactory.java
@@ -18,15 +18,9 @@
 package org.apache.servicecomb.swagger.invocation.arguments.producer;
 
 import org.apache.servicecomb.swagger.invocation.arguments.ArgumentMapper;
-import org.apache.servicecomb.swagger.invocation.arguments.ContextArgumentMapperFactory;
 import org.apache.servicecomb.swagger.invocation.context.InvocationContext;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.stereotype.Component;
-
-@Component
-@Qualifier("producer")
-public class ProducerInvocationContextMapperFactory implements ContextArgumentMapperFactory {
 
+public class ProducerInvocationContextMapperFactory implements ProducerContextArgumentMapperFactory {
   @Override
   public Class<?> getContextClass() {
     return InvocationContext.class;
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerArgumentSame.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/SwaggerBodyFieldToProducerArgument.java
similarity index 65%
copy from swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerArgumentSame.java
copy to swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/SwaggerBodyFieldToProducerArgument.java
index 84c6466..474de65 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerArgumentSame.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/SwaggerBodyFieldToProducerArgument.java
@@ -17,27 +17,27 @@
 
 package org.apache.servicecomb.swagger.invocation.arguments.producer;
 
+import java.util.Map;
+
 import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
 import org.apache.servicecomb.swagger.invocation.arguments.ArgumentMapper;
-import org.apache.servicecomb.swagger.invocation.converter.Converter;
 
-public class ProducerArgumentSame implements ArgumentMapper {
-  private int swaggerIdx;
+public class SwaggerBodyFieldToProducerArgument implements ArgumentMapper {
+  private final int producerParamIdx;
 
-  private int producerIdx;
+  private final String parameterName;
 
-  private Converter converter;
+  private final int swaggerBodyIdx;
 
-  public ProducerArgumentSame(int swaggerIdx, int producerIdx, Converter converter) {
-    this.swaggerIdx = swaggerIdx;
-    this.producerIdx = producerIdx;
-    this.converter = converter;
+  public SwaggerBodyFieldToProducerArgument(int producerParamIdx, String parameterName, int swaggerBodyIdx) {
+    this.producerParamIdx = producerParamIdx;
+    this.parameterName = parameterName;
+    this.swaggerBodyIdx = swaggerBodyIdx;
   }
 
   @Override
   public void mapArgument(SwaggerInvocation invocation, Object[] producerArguments) {
-    Object swaggerParam = invocation.getSwaggerArgument(swaggerIdx);
-    Object producerParam = converter.convert(swaggerParam);
-    producerArguments[producerIdx] = producerParam;
+    Map<String, Object> body = invocation.getSwaggerArgument(swaggerBodyIdx);
+    producerArguments[producerParamIdx] = body.get(parameterName);
   }
 }
diff --git a/swagger/swagger-invocation/invocation-core/src/main/resources/META-INF/services/org.apache.servicecomb.swagger.invocation.arguments.producer.ProducerContextArgumentMapperFactory b/swagger/swagger-invocation/invocation-core/src/main/resources/META-INF/services/org.apache.servicecomb.swagger.invocation.arguments.producer.ProducerContextArgumentMapperFactory
new file mode 100644
index 0000000..f1b9e50
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/main/resources/META-INF/services/org.apache.servicecomb.swagger.invocation.arguments.producer.ProducerContextArgumentMapperFactory
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.servicecomb.swagger.invocation.arguments.producer.ProducerInvocationContextMapperFactory
\ No newline at end of file