use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.
the class TestJaxrsProducerResponseMapper method mapResponse_withHeaders.
@Test
public void mapResponse_withHeaders() {
MultivaluedMap<String, Object> headers = new MultivaluedHashMap<>();
headers.add("h", "v");
new Expectations() {
{
jaxrsResponse.getStatusInfo();
result = Status.OK;
jaxrsResponse.getEntity();
result = "result";
jaxrsResponse.getHeaders();
result = headers;
}
};
Response response = mapper.mapResponse(null, jaxrsResponse);
Assert.assertEquals(Status.OK, response.getStatus());
Assert.assertEquals("result", response.getResult());
Assert.assertEquals(1, response.getHeaders().getHeaderMap().size());
Assert.assertThat(response.getHeaders().getHeader("h"), Matchers.contains("v"));
}
use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.
the class CodeFirstSpringmvc method cseResponse.
@ApiResponse(code = 200, response = User.class, message = "")
@ResponseHeaders({ @ResponseHeader(name = "h1", response = String.class), @ResponseHeader(name = "h2", response = String.class) })
@RequestMapping(path = "/cseResponse", method = RequestMethod.GET)
public Response cseResponse(InvocationContext c1) {
Response response = Response.createSuccess(Status.ACCEPTED, new User());
Headers headers = response.getHeaders();
headers.addHeader("h1", "h1v " + c1.getContext().get(Const.SRC_MICROSERVICE).toString());
InvocationContext c2 = ContextUtils.getInvocationContext();
headers.addHeader("h2", "h2v " + c2.getContext().get(Const.SRC_MICROSERVICE).toString());
return response;
}
use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.
the class CseClientHttpRequest method invoke.
private CseClientHttpResponse invoke(Object[] args) {
Invocation invocation = InvocationFactory.forConsumer(requestMeta.getReferenceConfig(), requestMeta.getOperationMeta(), args);
invocation.getHandlerContext().put(RestConst.REST_CLIENT_REQUEST_PATH, path + "?" + this.uri.getRawQuery());
if (context != null) {
invocation.addContext(context);
}
invocation.getHandlerContext().put(RestConst.CONSUMER_HEADER, httpHeaders);
Response response = doInvoke(invocation);
if (response.isSuccessed()) {
return new CseClientHttpResponse(response);
}
throw ExceptionFactory.convertConsumerException((Throwable) response.getResult());
}
use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.
the class TestInvoker method completableFutureInvoke_failed.
@Test
public void completableFutureInvoke_failed(@Mocked Invocation invocation, @Mocked SwaggerConsumerOperation consumerOperation, @Mocked ConsumerResponseMapper mapper) {
Throwable error = new Error("failed");
Response response = Response.createConsumerFail(error);
new MockUp<InvokerUtils>() {
@Mock
void reactiveInvoke(Invocation invocation, AsyncResponse asyncResp) {
asyncResp.handle(response);
;
}
};
Invoker invoker = new Invoker("test", null, IPerson.class);
CompletableFuture<Object> future = invoker.completableFutureInvoke(invocation, consumerOperation);
future.whenComplete((result, ex) -> {
Assert.assertEquals(null, result);
Assert.assertSame(error, ex);
});
}
use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.
the class TestHighwayClient method doTestSend.
private Object doTestSend(Vertx vertx, HighwayClientConnectionPool pool, HighwayClientConnection tcpClient, Object decodedResponse) throws Exception {
new MockUp<VertxUtils>() {
@Mock
<VERTICLE extends AbstractVerticle> boolean blockDeploy(Vertx vertx, Class<VERTICLE> cls, DeploymentOptions options) throws InterruptedException {
return true;
}
};
new MockUp<ClientPoolManager<HighwayClientConnectionPool>>() {
@Mock
public HighwayClientConnectionPool findClientPool(boolean sync) {
return pool;
}
};
new MockUp<ProtobufManager>() {
@Mock
public OperationProtobuf getOrCreateOperation(OperationMeta operationMeta) throws Exception {
return operationProtobuf;
}
};
new MockUp<HighwayClientConnectionPool>() {
@Mock
HighwayClientConnection findOrCreateClient(String endpoint) {
return tcpClient;
}
};
new MockUp<HighwayCodec>() {
@Mock
public Buffer encodeRequest(Invocation invocation, OperationProtobuf operationProtobuf, long msgId) throws Exception {
return null;
}
@Mock
Response decodeResponse(Invocation invocation, OperationProtobuf operationProtobuf, TcpData tcpData, ProtobufFeature protobufFeature) throws Throwable {
if (Response.class.isInstance(decodedResponse)) {
return (Response) decodedResponse;
}
throw (Throwable) decodedResponse;
}
};
client.init(vertx);
Mockito.when(invocation.getOperationMeta()).thenReturn(operationMeta);
Mockito.when(invocation.getEndpoint()).thenReturn(endpoint);
Mockito.when(invocation.getEndpoint().getEndpoint()).thenReturn("endpoint");
Mockito.when(invocation.getResponseExecutor()).thenReturn(new ReactiveExecutor());
Holder<Object> result = new Holder<>();
client.send(invocation, ar -> {
result.value = ar.getResult();
});
return result.value;
}
Aggregations