use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.
the class CodeFirstSpringmvcBase method cseResponse.
public Response cseResponse(InvocationContext c1) {
Response response = Response.createSuccess(Status.ACCEPTED, new User());
Headers headers = response.getHeaders();
headers.addHeader("h1", "h1v " + c1.getContext().toString());
InvocationContext c2 = ContextUtils.getInvocationContext();
headers.addHeader("h2", "h2v " + c2.getContext().toString());
return response;
}
use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.
the class ServerRestArgsFilter method beforeSendResponse.
@Override
public void beforeSendResponse(Invocation invocation, HttpServletResponseEx responseEx) {
Response response = (Response) responseEx.getAttribute(RestConst.INVOCATION_HANDLER_RESPONSE);
ProduceProcessor produceProcessor = (ProduceProcessor) responseEx.getAttribute(RestConst.INVOCATION_HANDLER_PROCESSOR);
Object body = response.getResult();
if (response.isFailed()) {
body = ((InvocationException) body).getErrorData();
}
try (BufferOutputStream output = new BufferOutputStream(Unpooled.compositeBuffer())) {
produceProcessor.encodeResponse(output, body);
responseEx.setBodyBuffer(output.getBuffer());
} catch (Throwable e) {
throw ExceptionFactory.convertProducerException(e);
}
}
use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.
the class TestInvoker method syncInvoke_normal.
@Test
public void syncInvoke_normal(@Mocked Invocation invocation, @Mocked SwaggerConsumerOperation consumerOperation, @Mocked ConsumerResponseMapper mapper) {
Response response = Response.ok("1");
new MockUp<InvokerUtils>() {
@Mock
Response innerSyncInvoke(Invocation invocation) {
return response;
}
};
new Expectations() {
{
consumerOperation.getResponseMapper();
result = mapper;
mapper.mapResponse(response);
result = 1;
}
};
Invoker invoker = new Invoker("test", null, IPerson.class);
Object result = invoker.syncInvoke(invocation, consumerOperation);
Assert.assertEquals(1, result);
}
use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.
the class TestInvoker method syncInvoke_failed.
@Test
public void syncInvoke_failed(@Mocked Invocation invocation, @Mocked SwaggerConsumerOperation consumerOperation, @Mocked ConsumerResponseMapper mapper) {
Throwable error = new Error("failed");
Response response = Response.createConsumerFail(error);
new MockUp<InvokerUtils>() {
@Mock
Response innerSyncInvoke(Invocation invocation) {
return response;
}
};
expectedException.expect(InvocationException.class);
expectedException.expectCause(Matchers.sameInstance(error));
Invoker invoker = new Invoker("test", null, IPerson.class);
invoker.syncInvoke(invocation, consumerOperation);
}
use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.
the class TestInvoker method completableFutureInvoke_normal.
@Test
public void completableFutureInvoke_normal(@Mocked Invocation invocation, @Mocked SwaggerConsumerOperation consumerOperation, @Mocked ConsumerResponseMapper mapper) {
Response response = Response.ok("1");
new MockUp<InvokerUtils>() {
@Mock
void reactiveInvoke(Invocation invocation, AsyncResponse asyncResp) {
asyncResp.handle(response);
;
}
};
new Expectations() {
{
consumerOperation.getResponseMapper();
result = mapper;
mapper.mapResponse(response);
result = 1;
}
};
Invoker invoker = new Invoker("test", null, IPerson.class);
CompletableFuture<Object> future = invoker.completableFutureInvoke(invocation, consumerOperation);
future.whenComplete((result, ex) -> {
Assert.assertEquals(1, result);
Assert.assertEquals(null, ex);
});
}
Aggregations