Search in sources :

Example 6 with RestParam

use of org.apache.servicecomb.common.rest.definition.RestParam in project incubator-servicecomb-java-chassis by apache.

the class URLPathBuilder method initQueryWriterList.

private void initQueryWriterList(Map<String, RestParam> paramMap) {
    for (RestParam param : paramMap.values()) {
        if (!QueryProcessorCreator.PARAMTYPE.equals(param.getParamProcessor().getProcessorType())) {
            continue;
        }
        char prefix = '&';
        if (queryParamWriterList.isEmpty()) {
            prefix = '?';
        }
        UrlParamWriter dynamicWriter = new QueryVarParamWriter(prefix, param);
        queryParamWriterList.add(dynamicWriter);
    }
}
Also used : RestParam(org.apache.servicecomb.common.rest.definition.RestParam)

Example 7 with RestParam

use of org.apache.servicecomb.common.rest.definition.RestParam in project incubator-servicecomb-java-chassis by apache.

the class InvocationToHttpServletRequest method getParameterMap.

@Override
public Map<String, String[]> getParameterMap() {
    Map<String, String[]> paramMap = new HashMap<>();
    for (RestParam param : swaggerOperation.getParamList()) {
        String[] value = param.getValueAsStrings(args);
        paramMap.put(param.getParamName(), value);
    }
    return paramMap;
}
Also used : HashMap(java.util.HashMap) RestParam(org.apache.servicecomb.common.rest.definition.RestParam)

Example 8 with RestParam

use of org.apache.servicecomb.common.rest.definition.RestParam in project incubator-servicecomb-java-chassis by apache.

the class RestCodec method restToArgs.

public static Object[] restToArgs(HttpServletRequest request, RestOperationMeta restOperation) throws InvocationException {
    List<RestParam> paramList = restOperation.getParamList();
    try {
        Object[] paramValues = new Object[paramList.size()];
        for (int idx = 0; idx < paramList.size(); idx++) {
            RestParam param = paramList.get(idx);
            paramValues[idx] = param.getParamProcessor().getValue(request);
        }
        return paramValues;
    } catch (Exception e) {
        LOG.error("Parameter is not valid for operation {}. ", restOperation.getOperationMeta().getMicroserviceQualifiedName(), e);
        throw ExceptionFactory.convertProducerException(e, "Parameter is not valid.");
    }
}
Also used : InvocationException(org.apache.servicecomb.swagger.invocation.exception.InvocationException) RestParam(org.apache.servicecomb.common.rest.definition.RestParam)

Aggregations

RestParam (org.apache.servicecomb.common.rest.definition.RestParam)8 InvocationException (org.apache.servicecomb.swagger.invocation.exception.InvocationException)4 ArrayList (java.util.ArrayList)2 Expectations (mockit.Expectations)2 Test (org.junit.Test)2 HeaderParameter (io.swagger.models.parameters.HeaderParameter)1 Parameter (io.swagger.models.parameters.Parameter)1 HashMap (java.util.HashMap)1 RestOperationMeta (org.apache.servicecomb.common.rest.definition.RestOperationMeta)1 CommonExceptionData (org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData)1 BeforeClass (org.junit.BeforeClass)1