Search in sources :

Example 1 with RestParam

use of io.servicecomb.common.rest.definition.RestParam in project java-chassis by ServiceComb.

the class GenericServletMockRequest method getParameterMap.

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

Example 2 with RestParam

use of io.servicecomb.common.rest.definition.RestParam in project java-chassis by ServiceComb.

the class TestRestCodec method beforeClass.

@BeforeClass
public static void beforeClass() {
    restOperation = Mockito.mock(RestOperationMeta.class);
    //        clientRequest = Mockito.mock(RestClientRequest.class);
    paramList = new ArrayList<>();
    Parameter hp = new HeaderParameter();
    hp.setName("header");
    paramList.add(new RestParam(0, hp, int.class));
    when(restOperation.getParamList()).thenReturn(paramList);
}
Also used : RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) Parameter(io.swagger.models.parameters.Parameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) RestParam(io.servicecomb.common.rest.definition.RestParam) BeforeClass(org.junit.BeforeClass)

Example 3 with RestParam

use of io.servicecomb.common.rest.definition.RestParam in project java-chassis by ServiceComb.

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(io.servicecomb.common.rest.definition.RestParam)

Example 4 with RestParam

use of io.servicecomb.common.rest.definition.RestParam in project java-chassis by ServiceComb.

the class CseClientHttpRequest method collectArguments.

private Object[] collectArguments(RequestMeta requestMeta, Map<String, List<String>> queryParams) {
    RestServerRequest mockRequest = new LocalRestServerRequest(requestMeta.getPathParams(), queryParams, httpHeaders, requestBody);
    List<RestParam> paramList = requestMeta.getSwaggerRestOperation().getParamList();
    Object[] args = new Object[paramList.size()];
    for (int idx = 0; idx < paramList.size(); idx++) {
        RestParam param = paramList.get(idx);
        try {
            args[idx] = param.getParamProcessor().getValue(mockRequest);
        } catch (Exception e) {
            LOGGER.error("error arguments for operation " + requestMeta.getOperationMeta().getMicroserviceQualifiedName(), e);
            throw new Error(e);
        }
    }
    return args;
}
Also used : LocalRestServerRequest(io.servicecomb.common.rest.codec.LocalRestServerRequest) LocalRestServerRequest(io.servicecomb.common.rest.codec.LocalRestServerRequest) RestServerRequest(io.servicecomb.common.rest.codec.RestServerRequest) IOException(java.io.IOException) RestParam(io.servicecomb.common.rest.definition.RestParam)

Example 5 with RestParam

use of io.servicecomb.common.rest.definition.RestParam in project java-chassis by ServiceComb.

the class RestCodec method restToArgs.

public static Object[] restToArgs(RestServerRequest 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, cause " + e.getMessage());
        throw ExceptionFactory.convertProducerException(e, "Parameter is not valid.");
    }
}
Also used : InvocationException(io.servicecomb.core.exception.InvocationException) RestParam(io.servicecomb.common.rest.definition.RestParam)

Aggregations

RestParam (io.servicecomb.common.rest.definition.RestParam)10 InvocationException (io.servicecomb.core.exception.InvocationException)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 RestOperationMeta (io.servicecomb.common.rest.definition.RestOperationMeta)2 HashMap (java.util.HashMap)2 Expectations (mockit.Expectations)2 LocalRestServerRequest (io.servicecomb.common.rest.codec.LocalRestServerRequest)1 RestServerRequest (io.servicecomb.common.rest.codec.RestServerRequest)1 URLPathBuilder (io.servicecomb.common.rest.definition.path.URLPathBuilder)1 Invocation (io.servicecomb.core.Invocation)1 OperationMeta (io.servicecomb.core.definition.OperationMeta)1 CommonExceptionData (io.servicecomb.core.exception.CommonExceptionData)1 HeaderParameter (io.swagger.models.parameters.HeaderParameter)1 Parameter (io.swagger.models.parameters.Parameter)1 IOException (java.io.IOException)1 BeforeClass (org.junit.BeforeClass)1