use of org.apache.servicecomb.common.rest.definition.RestOperationMeta in project java-chassis by ServiceComb.
the class TestDefaultHttpClientFilter method extractResult_decodeError200.
@Test
public void extractResult_decodeError200(@Mocked Invocation invocation, @Mocked ReadStreamPart part, @Mocked OperationMeta operationMeta, @Mocked RestOperationMeta swaggerRestOperation, @Mocked HttpServletResponseEx responseEx) {
Map<String, Object> handlerContext = new HashMap<>();
new Expectations() {
{
invocation.getHandlerContext();
result = handlerContext;
invocation.getOperationMeta();
result = operationMeta;
invocation.findResponseType(200);
result = SimpleType.constructUnsafe(Date.class);
operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
result = swaggerRestOperation;
responseEx.getStatus();
result = 200;
responseEx.getBodyBuffer();
result = new BufferImpl().appendString("abc");
}
};
new MockUp<DefaultHttpClientFilter>() {
@Mock
ProduceProcessor findProduceProcessor(RestOperationMeta restOperation, HttpServletResponseEx responseEx) {
return new ProduceJsonProcessor();
}
};
Response response = filter.extractResponse(invocation, responseEx);
Assert.assertEquals(400, response.getStatusCode());
Assert.assertEquals(InvocationException.class, response.<InvocationException>getResult().getClass());
InvocationException invocationException = response.getResult();
Assert.assertEquals("InvocationException: code=400;msg=CommonExceptionData [message=method null, path null, statusCode 200, reasonPhrase null, response content-type null is not supported]", invocationException.getMessage());
Assert.assertEquals("Unrecognized token 'abc': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')\n" + " at [Source: (org.apache.servicecomb.foundation.vertx.stream.BufferInputStream); line: 1, column: 4]", invocationException.getCause().getMessage());
Assert.assertEquals(CommonExceptionData.class, invocationException.getErrorData().getClass());
CommonExceptionData commonExceptionData = (CommonExceptionData) invocationException.getErrorData();
Assert.assertEquals("method null, path null, statusCode 200, reasonPhrase null, response content-type null is not supported", commonExceptionData.getMessage());
}
use of org.apache.servicecomb.common.rest.definition.RestOperationMeta in project java-chassis by ServiceComb.
the class RestServerCodecFilter method decodeRequest.
protected Void decodeRequest(Invocation invocation) {
HttpServletRequestEx requestEx = invocation.getRequestEx();
OperationMeta operationMeta = invocation.getOperationMeta();
RestOperationMeta restOperationMeta = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
Map<String, Object> swaggerArguments = RestCodec.restToArgs(requestEx, restOperationMeta);
invocation.setSwaggerArguments(swaggerArguments);
return null;
}
use of org.apache.servicecomb.common.rest.definition.RestOperationMeta in project incubator-servicecomb-java-chassis by apache.
the class ServerRestArgsFilter method afterReceiveRequest.
@Override
public Response afterReceiveRequest(Invocation invocation, HttpServletRequestEx requestEx) {
OperationMeta operationMeta = invocation.getOperationMeta();
RestOperationMeta restOperationMeta = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
Map<String, Object> swaggerArguments = RestCodec.restToArgs(requestEx, restOperationMeta);
invocation.setSwaggerArguments(swaggerArguments);
return null;
}
use of org.apache.servicecomb.common.rest.definition.RestOperationMeta in project incubator-servicecomb-java-chassis by apache.
the class ServicePathManager method addSchema.
private void addSchema(SchemaMeta schemaMeta) {
for (OperationMeta operationMeta : schemaMeta.getOperations().values()) {
RestOperationMeta restOperationMeta = new RestOperationMeta();
restOperationMeta.init(operationMeta);
operationMeta.putExtData(RestConst.SWAGGER_REST_OPERATION, restOperationMeta);
addResource(restOperationMeta);
}
LOGGER.info("add schema to service paths. {}:{}:{}.", schemaMeta.getAppId(), schemaMeta.getMicroserviceName(), schemaMeta.getSchemaId());
}
use of org.apache.servicecomb.common.rest.definition.RestOperationMeta in project incubator-servicecomb-java-chassis by apache.
the class RestServerCodecFilter method decodeRequest.
protected Void decodeRequest(Invocation invocation) {
HttpServletRequestEx requestEx = invocation.getRequestEx();
OperationMeta operationMeta = invocation.getOperationMeta();
RestOperationMeta restOperationMeta = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
Map<String, Object> swaggerArguments = RestCodec.restToArgs(requestEx, restOperationMeta);
invocation.setSwaggerArguments(swaggerArguments);
return null;
}
Aggregations