Search in sources :

Example 1 with WrapSchema

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

the class TestOperationProtobuf method testOperationProtobuf.

@Test
public void testOperationProtobuf() throws Exception {
    UnitTestMeta meta = new UnitTestMeta();
    SchemaMeta schemaMeta = meta.getOrCreateSchemaMeta(Impl.class);
    OperationMeta operationMeta = schemaMeta.findOperation("test");
    OperationProtobuf operationProtobuf = ProtobufManager.getOrCreateOperation(operationMeta);
    Assert.assertEquals(operationMeta, operationProtobuf.getOperationMeta());
    Assert.assertEquals(ArgsNotWrapSchema.class, operationProtobuf.getRequestSchema().getClass());
    Assert.assertEquals(NormalWrapSchema.class, operationProtobuf.getResponseSchema().getClass());
    WrapSchema responseSchema = operationProtobuf.findResponseSchema(200);
    Assert.assertEquals(operationProtobuf.getResponseSchema(), responseSchema);
    responseSchema = operationProtobuf.findResponseSchema(300);
    Assert.assertNotNull(responseSchema);
    Assert.assertNotEquals(operationProtobuf.getResponseSchema(), responseSchema);
}
Also used : UnitTestMeta(org.apache.servicecomb.core.unittest.UnitTestMeta) SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) ArgsNotWrapSchema(org.apache.servicecomb.codec.protobuf.utils.schema.ArgsNotWrapSchema) NormalWrapSchema(org.apache.servicecomb.codec.protobuf.utils.schema.NormalWrapSchema) WrapSchema(org.apache.servicecomb.codec.protobuf.utils.WrapSchema) Test(org.junit.Test)

Example 2 with WrapSchema

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

the class HighwayCodec method decodeResponse.

public static Response decodeResponse(Invocation invocation, OperationProtobuf operationProtobuf, TcpData tcpData, ProtobufFeature protobufFeature) throws Exception {
    ResponseHeader header = ResponseHeader.readObject(tcpData.getHeaderBuffer(), protobufFeature);
    if (header.getContext() != null) {
        invocation.getContext().putAll(header.getContext());
    }
    WrapSchema bodySchema = operationProtobuf.findResponseSchema(header.getStatusCode());
    Object body = bodySchema.readObject(tcpData.getBodyBuffer(), protobufFeature);
    Response response = Response.create(header.getStatusCode(), header.getReasonPhrase(), body);
    response.setHeaders(header.getHeaders());
    return response;
}
Also used : Response(org.apache.servicecomb.swagger.invocation.Response) ResponseHeader(org.apache.servicecomb.transport.highway.message.ResponseHeader) WrapSchema(org.apache.servicecomb.codec.protobuf.utils.WrapSchema)

Example 3 with WrapSchema

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

the class HighwayCodec method decodeRequest.

public static void decodeRequest(Invocation invocation, RequestHeader header, OperationProtobuf operationProtobuf, Buffer bodyBuffer, ProtobufFeature protobufFeature) throws Exception {
    WrapSchema schema = operationProtobuf.getRequestSchema();
    Object[] args = schema.readObject(bodyBuffer, protobufFeature);
    invocation.setSwaggerArguments(args);
    invocation.setContext(header.getContext());
}
Also used : WrapSchema(org.apache.servicecomb.codec.protobuf.utils.WrapSchema)

Example 4 with WrapSchema

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

the class TestHighwayTransport method commonHighwayMock.

private void commonHighwayMock(Invocation invocation) {
    OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
    Mockito.when(invocation.getOperationMeta()).thenReturn(operationMeta);
    OperationProtobuf operationProtobuf = Mockito.mock(OperationProtobuf.class);
    Mockito.when(operationMeta.getExtData("protobuf")).thenReturn(operationProtobuf);
    Endpoint lEndpoint = Mockito.mock(Endpoint.class);
    Mockito.when(invocation.getEndpoint()).thenReturn(lEndpoint);
    WrapSchema lWrapSchema = Mockito.mock(WrapSchema.class);
    Mockito.when(operationProtobuf.getRequestSchema()).thenReturn(lWrapSchema);
    URIEndpointObject ep = Mockito.mock(URIEndpointObject.class);
    Mockito.when(lEndpoint.getAddress()).thenReturn(ep);
    Mockito.when(ep.getHostOrIp()).thenReturn("127.0.0.1");
    Mockito.when(ep.getPort()).thenReturn(80);
}
Also used : Endpoint(org.apache.servicecomb.core.Endpoint) OperationProtobuf(org.apache.servicecomb.codec.protobuf.definition.OperationProtobuf) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) WrapSchema(org.apache.servicecomb.codec.protobuf.utils.WrapSchema) URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject)

Example 5 with WrapSchema

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

the class TestHighwayCodec method testEncodeResponse.

@Test
public void testEncodeResponse() {
    boolean status = true;
    WrapSchema bodySchema = Mockito.mock(WrapSchema.class);
    try {
        commonMock();
        HighwayCodec.encodeResponse(23432142, null, bodySchema, new Object(), new ProtobufFeature());
    } catch (Exception e) {
        status = false;
    }
    Assert.assertTrue(status);
}
Also used : NotWrapSchema(org.apache.servicecomb.codec.protobuf.utils.schema.NotWrapSchema) WrapSchema(org.apache.servicecomb.codec.protobuf.utils.WrapSchema) IOException(java.io.IOException) ProtobufFeature(io.protostuff.runtime.ProtobufFeature) Test(org.junit.Test)

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