Search in sources :

Example 6 with WrapSchema

use of org.apache.servicecomb.codec.protobuf.utils.WrapSchema in project incubator-servicecomb-java-chassis by apache.

the class HighwayServerInvoke method sendResponse.

private void sendResponse(Map<String, String> context, Response response) {
    ResponseHeader header = new ResponseHeader();
    header.setStatusCode(response.getStatusCode());
    header.setReasonPhrase(response.getReasonPhrase());
    header.setContext(context);
    header.setHeaders(response.getHeaders());
    WrapSchema bodySchema = operationProtobuf.findResponseSchema(response.getStatusCode());
    Object body = response.getResult();
    if (response.isFailed()) {
        body = ((InvocationException) body).getErrorData();
    }
    try {
        Buffer respBuffer = HighwayCodec.encodeResponse(msgId, header, bodySchema, body, protobufFeature);
        connection.write(respBuffer.getByteBuf());
    } catch (Exception e) {
        // 没招了,直接打日志
        String msg = String.format("encode response failed, %s, msgId=%d", operationProtobuf.getOperationMeta().getMicroserviceQualifiedName(), msgId);
        LOGGER.error(msg, e);
    } finally {
        invocation.onFinish(response);
    }
}
Also used : Buffer(io.vertx.core.buffer.Buffer) ResponseHeader(org.apache.servicecomb.transport.highway.message.ResponseHeader) WrapSchema(org.apache.servicecomb.codec.protobuf.utils.WrapSchema) InvocationException(org.apache.servicecomb.swagger.invocation.exception.InvocationException)

Aggregations

WrapSchema (org.apache.servicecomb.codec.protobuf.utils.WrapSchema)6 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)2 ResponseHeader (org.apache.servicecomb.transport.highway.message.ResponseHeader)2 Test (org.junit.Test)2 ProtobufFeature (io.protostuff.runtime.ProtobufFeature)1 Buffer (io.vertx.core.buffer.Buffer)1 IOException (java.io.IOException)1 OperationProtobuf (org.apache.servicecomb.codec.protobuf.definition.OperationProtobuf)1 ArgsNotWrapSchema (org.apache.servicecomb.codec.protobuf.utils.schema.ArgsNotWrapSchema)1 NormalWrapSchema (org.apache.servicecomb.codec.protobuf.utils.schema.NormalWrapSchema)1 NotWrapSchema (org.apache.servicecomb.codec.protobuf.utils.schema.NotWrapSchema)1 Endpoint (org.apache.servicecomb.core.Endpoint)1 SchemaMeta (org.apache.servicecomb.core.definition.SchemaMeta)1 UnitTestMeta (org.apache.servicecomb.core.unittest.UnitTestMeta)1 URIEndpointObject (org.apache.servicecomb.foundation.common.net.URIEndpointObject)1 Response (org.apache.servicecomb.swagger.invocation.Response)1 InvocationException (org.apache.servicecomb.swagger.invocation.exception.InvocationException)1