Search in sources :

Example 6 with BufferOutputStream

use of org.apache.servicecomb.foundation.vertx.stream.BufferOutputStream 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);
    }
}
Also used : Response(org.apache.servicecomb.swagger.invocation.Response) ProduceProcessor(org.apache.servicecomb.common.rest.codec.produce.ProduceProcessor) BufferOutputStream(org.apache.servicecomb.foundation.vertx.stream.BufferOutputStream)

Example 7 with BufferOutputStream

use of org.apache.servicecomb.foundation.vertx.stream.BufferOutputStream in project incubator-servicecomb-java-chassis by apache.

the class TestResultSerializer method setUp.

@Before
public void setUp() throws Exception {
    resultSerializer = new ResultSerializer();
    outputStream = new BufferOutputStream();
}
Also used : BufferOutputStream(org.apache.servicecomb.foundation.vertx.stream.BufferOutputStream) Before(org.junit.Before)

Aggregations

BufferOutputStream (org.apache.servicecomb.foundation.vertx.stream.BufferOutputStream)7 Before (org.junit.Before)2 LinkedBuffer (io.protostuff.LinkedBuffer)1 ProtobufOutput (io.protostuff.ProtobufOutput)1 Buffer (io.vertx.core.buffer.Buffer)1 IOException (java.io.IOException)1 ProduceProcessor (org.apache.servicecomb.common.rest.codec.produce.ProduceProcessor)1 Response (org.apache.servicecomb.swagger.invocation.Response)1 Test (org.junit.Test)1