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;
}
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);
}
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);
}
}
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;
}
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.");
}
}
Aggregations