use of org.apache.servicecomb.common.rest.codec.produce.ProduceProcessor in project incubator-servicecomb-java-chassis by apache.
the class TestRestOperationMeta method testCreateProduceProcessorsNull.
@Test
public void testCreateProduceProcessorsNull() {
operationMeta.createProduceProcessors();
Assert.assertSame(ProduceProcessorManager.DEFAULT_PROCESSOR, operationMeta.ensureFindProduceProcessor((String) null));
Assert.assertSame(ProduceProcessorManager.DEFAULT_PROCESSOR, operationMeta.ensureFindProduceProcessor("*/*"));
Assert.assertSame(ProduceProcessorManager.DEFAULT_PROCESSOR, operationMeta.ensureFindProduceProcessor(ProduceProcessorManager.DEFAULT_TYPE));
for (String produce : ProduceProcessorManager.INSTANCE.keys()) {
ProduceProcessor expected = ProduceProcessorManager.INSTANCE.findValue(produce);
Assert.assertSame(expected, operationMeta.findProduceProcessor(produce));
}
}
use of org.apache.servicecomb.common.rest.codec.produce.ProduceProcessor 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.common.rest.codec.produce.ProduceProcessor in project incubator-servicecomb-java-chassis by apache.
the class TestVertxHttpMethod method testHandleResponse.
@Test
public void testHandleResponse() {
boolean status = false;
try {
Invocation invocation = mock(Invocation.class);
AsyncResponse asyncResp = mock(AsyncResponse.class);
HttpClientResponse httpResponse = mock(HttpClientResponse.class);
OperationMeta operationMeta = mock(OperationMeta.class);
RestOperationMeta swaggerRestOperation = mock(RestOperationMeta.class);
Endpoint endpoint = mock(Endpoint.class);
when(invocation.getOperationMeta()).thenReturn(operationMeta);
URLPathBuilder urlPathBuilder = mock(URLPathBuilder.class);
when(swaggerRestOperation.getPathBuilder()).thenReturn(urlPathBuilder);
operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
when(operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION)).thenReturn(swaggerRestOperation);
when(invocation.getEndpoint()).thenReturn(endpoint);
String contentType = httpResponse.getHeader("Content-Type");
ProduceProcessor produceProcessor = mock(ProduceProcessor.class);
when(swaggerRestOperation.findProduceProcessor(contentType)).thenReturn(produceProcessor);
this.handleResponse(invocation, httpResponse, asyncResp);
} catch (Exception ex) {
status = true;
}
Assert.assertFalse(status);
}
use of org.apache.servicecomb.common.rest.codec.produce.ProduceProcessor in project incubator-servicecomb-java-chassis by apache.
the class TestVertxHttpMethod method testSetCseContext.
@Test
public void testSetCseContext() {
boolean status = false;
try {
Invocation invocation = mock(Invocation.class);
HttpClientResponse httpResponse = mock(HttpClientResponse.class);
OperationMeta operationMeta = mock(OperationMeta.class);
RestOperationMeta swaggerRestOperation = mock(RestOperationMeta.class);
HttpClientRequest request = mock(HttpClientRequest.class);
Endpoint endpoint = mock(Endpoint.class);
when(invocation.getOperationMeta()).thenReturn(operationMeta);
URLPathBuilder urlPathBuilder = mock(URLPathBuilder.class);
when(swaggerRestOperation.getPathBuilder()).thenReturn(urlPathBuilder);
operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
when(operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION)).thenReturn(swaggerRestOperation);
when(invocation.getEndpoint()).thenReturn(endpoint);
String contentType = httpResponse.getHeader("Content-Type");
ProduceProcessor produceProcessor = mock(ProduceProcessor.class);
when(swaggerRestOperation.findProduceProcessor(contentType)).thenReturn(produceProcessor);
this.setCseContext(invocation, request);
} catch (Exception ex) {
status = true;
}
Assert.assertFalse(status);
}
use of org.apache.servicecomb.common.rest.codec.produce.ProduceProcessor in project incubator-servicecomb-java-chassis by apache.
the class TestRestOperationMeta method testCreateProduceProcessorsEmpty.
@Test
public void testCreateProduceProcessorsEmpty() {
operationMeta.produces = Arrays.asList();
operationMeta.createProduceProcessors();
Assert.assertSame(ProduceProcessorManager.DEFAULT_PROCESSOR, operationMeta.ensureFindProduceProcessor((String) null));
Assert.assertSame(ProduceProcessorManager.DEFAULT_PROCESSOR, operationMeta.ensureFindProduceProcessor("*/*"));
Assert.assertSame(ProduceProcessorManager.DEFAULT_PROCESSOR, operationMeta.ensureFindProduceProcessor(ProduceProcessorManager.DEFAULT_TYPE));
for (String produce : ProduceProcessorManager.INSTANCE.keys()) {
ProduceProcessor expected = ProduceProcessorManager.INSTANCE.findValue(produce);
Assert.assertSame(expected, operationMeta.findProduceProcessor(produce));
}
}
Aggregations