use of org.apache.servicecomb.swagger.invocation.response.ResponseMeta in project incubator-servicecomb-java-chassis by apache.
the class DefaultHttpClientFilter method afterReceiveResponse.
@Override
public Response afterReceiveResponse(Invocation invocation, HttpServletResponseEx responseEx) {
OperationMeta operationMeta = invocation.getOperationMeta();
ResponseMeta responseMeta = operationMeta.findResponseMeta(responseEx.getStatus());
RestOperationMeta swaggerRestOperation = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
ProduceProcessor produceProcessor = findProduceProcessor(swaggerRestOperation, responseEx);
if (produceProcessor == null) {
String msg = String.format("method %s, path %s, statusCode %d, reasonPhrase %s, response content-type %s is not supported", swaggerRestOperation.getHttpMethod(), swaggerRestOperation.getAbsolutePath(), responseEx.getStatus(), responseEx.getStatusType().getReasonPhrase(), responseEx.getHeader(HttpHeaders.CONTENT_TYPE));
Exception exception = ExceptionFactory.createConsumerException(new CommonExceptionData(msg));
return Response.consumerFailResp(exception);
}
Object result = null;
try {
result = produceProcessor.decodeResponse(responseEx.getBodyBuffer(), responseMeta.getJavaType());
} catch (Exception e) {
return Response.consumerFailResp(e);
}
Response response = Response.create(responseEx.getStatusType(), result);
for (String headerName : responseEx.getHeaderNames()) {
Collection<String> headerValues = responseEx.getHeaders(headerName);
for (String headerValue : headerValues) {
response.getHeaders().addHeader(headerName, headerValue);
}
}
return response;
}
use of org.apache.servicecomb.swagger.invocation.response.ResponseMeta in project incubator-servicecomb-java-chassis by apache.
the class TestOperationMeta method testOperationMeta.
@Test
public void testOperationMeta() {
UnitTestMeta meta = new UnitTestMeta();
SchemaMeta schemaMeta = meta.getOrCreateSchemaMeta(Impl.class);
OperationMeta operationMeta = schemaMeta.findOperation("test");
Assert.assertEquals("POST", operationMeta.getHttpMethod());
Assert.assertEquals("/test", operationMeta.getOperationPath());
Assert.assertEquals(schemaMeta, operationMeta.getSchemaMeta());
Assert.assertEquals(Impl.class.getName() + ".test", operationMeta.getSchemaQualifiedName());
Assert.assertEquals("app:test." + Impl.class.getName() + ".test", operationMeta.getMicroserviceQualifiedName());
Assert.assertEquals("app:test", operationMeta.getMicroserviceName());
Assert.assertEquals("test", operationMeta.getOperationId());
Assert.assertEquals("x", operationMeta.getParamName(0));
operationMeta.putExtData("ext", 1);
Assert.assertEquals(1, (int) operationMeta.getExtData("ext"));
ResponseMeta responseMeta = operationMeta.findResponseMeta(200);
Assert.assertEquals("Ljava/lang/Integer;", responseMeta.getJavaType().getGenericSignature());
Assert.assertEquals("Ljava/lang/Integer;", responseMeta.getHeaders().get("h1").getGenericSignature());
Assert.assertEquals("Ljava/util/List<Ljava/lang/String;>;", responseMeta.getHeaders().get("h2").getGenericSignature());
Assert.assertEquals(null, responseMeta.getHeaders().get("h3"));
responseMeta = operationMeta.findResponseMeta(300);
Assert.assertEquals("Ljava/lang/String;", responseMeta.getJavaType().getGenericSignature());
Assert.assertEquals("Ljava/lang/Integer;", responseMeta.getHeaders().get("h1").getGenericSignature());
Assert.assertEquals("Ljava/util/List<Ljava/lang/String;>;", responseMeta.getHeaders().get("h2").getGenericSignature());
Assert.assertEquals("Ljava/lang/Integer;", responseMeta.getHeaders().get("h3").getGenericSignature());
}
Aggregations