Search in sources :

Example 1 with RequestHeader

use of org.apache.servicecomb.transport.highway.message.RequestHeader in project incubator-servicecomb-java-chassis by apache.

the class HighwayClientConnection method createLogin.

@Override
protected TcpOutputStream createLogin() {
    try {
        RequestHeader header = new RequestHeader();
        header.setMsgType(MsgType.LOGIN);
        LoginRequest login = new LoginRequest();
        login.setProtocol(HighwayTransport.NAME);
        login.setUseProtobufMapCodec(true);
        HighwayOutputStream os = new HighwayOutputStream(AbstractTcpClientPackage.getAndIncRequestId(), null);
        os.write(header, LoginRequest.getLoginRequestSchema(), login);
        return os;
    } catch (Throwable e) {
        throw new Error("impossible.", e);
    }
}
Also used : RequestHeader(org.apache.servicecomb.transport.highway.message.RequestHeader) LoginRequest(org.apache.servicecomb.transport.highway.message.LoginRequest)

Example 2 with RequestHeader

use of org.apache.servicecomb.transport.highway.message.RequestHeader in project incubator-servicecomb-java-chassis by apache.

the class TestHighwayServerConnection method testRequestError.

@Test
public void testRequestError() throws Exception {
    header.setMsgType(MsgType.REQUEST);
    Buffer headerBuffer = createBuffer(requestHeaderSchema, header);
    Buffer bodyBuffer = Buffer.buffer();
    Holder<Boolean> holder = new Holder<>(false);
    new MockUp<HighwayServerInvoke>() {

        @Mock
        public boolean init(NetSocket netSocket, long msgId, RequestHeader header, Buffer bodyBuffer) {
            return false;
        }
    };
    connection.handle(0, headerBuffer, bodyBuffer);
    Assert.assertEquals(null, connection.getProtocol());
    Assert.assertEquals(null, connection.getZipName());
    Assert.assertEquals(false, holder.value);
}
Also used : LinkedBuffer(io.protostuff.LinkedBuffer) Buffer(io.vertx.core.buffer.Buffer) NetSocket(io.vertx.core.net.NetSocket) Holder(javax.xml.ws.Holder) RequestHeader(org.apache.servicecomb.transport.highway.message.RequestHeader) MockUp(mockit.MockUp) Test(org.junit.Test)

Example 3 with RequestHeader

use of org.apache.servicecomb.transport.highway.message.RequestHeader in project incubator-servicecomb-java-chassis by apache.

the class TestHighwayServerConnection method init.

@Before
public void init() {
    new Expectations(CseContext.getInstance()) {

        {
            netSocket.remoteAddress();
            result = new SocketAddressImpl(new InetSocketAddress("127.0.0.1", 80));
        }
    };
    connection = new HighwayServerConnection(endpoint);
    connection.init(netSocket);
    header = new RequestHeader();
}
Also used : Expectations(mockit.Expectations) InetSocketAddress(java.net.InetSocketAddress) RequestHeader(org.apache.servicecomb.transport.highway.message.RequestHeader) SocketAddressImpl(io.vertx.core.net.impl.SocketAddressImpl) Before(org.junit.Before)

Example 4 with RequestHeader

use of org.apache.servicecomb.transport.highway.message.RequestHeader in project java-chassis by ServiceComb.

the class HighwayCodec method encodeRequest.

public static TcpOutputStream encodeRequest(long msgId, Invocation invocation, OperationProtobuf operationProtobuf) throws Exception {
    // 写header
    RequestHeader header = new RequestHeader();
    header.setMsgType(MsgType.REQUEST);
    header.setFlags(0);
    header.setDestMicroservice(invocation.getMicroserviceName());
    header.setSchemaId(invocation.getSchemaId());
    header.setOperationName(invocation.getOperationName());
    header.setContext(invocation.getContext());
    HighwayOutputStream os = new HighwayOutputStream(msgId);
    os.write(header, operationProtobuf.getRequestRootSerializer(), invocation.getSwaggerArguments());
    return os;
}
Also used : RequestHeader(org.apache.servicecomb.transport.highway.message.RequestHeader)

Example 5 with RequestHeader

use of org.apache.servicecomb.transport.highway.message.RequestHeader in project java-chassis by ServiceComb.

the class HighwayClientConnection method createLogin.

@Override
protected TcpOutputStream createLogin() {
    try {
        RequestHeader header = new RequestHeader();
        header.setMsgType(MsgType.LOGIN);
        LoginRequest login = new LoginRequest();
        login.setProtocol(Const.HIGHWAY);
        HighwayOutputStream os = new HighwayOutputStream(AbstractTcpClientPackage.getAndIncRequestId());
        os.write(header, LoginRequest.getRootSerializer(), login);
        return os;
    } catch (Throwable e) {
        throw new Error("impossible.", e);
    }
}
Also used : RequestHeader(org.apache.servicecomb.transport.highway.message.RequestHeader) LoginRequest(org.apache.servicecomb.transport.highway.message.LoginRequest)

Aggregations

RequestHeader (org.apache.servicecomb.transport.highway.message.RequestHeader)11 Test (org.junit.Test)6 Buffer (io.vertx.core.buffer.Buffer)3 Holder (javax.xml.ws.Holder)3 MockUp (mockit.MockUp)3 LoginRequest (org.apache.servicecomb.transport.highway.message.LoginRequest)3 LinkedBuffer (io.protostuff.LinkedBuffer)2 NetSocket (io.vertx.core.net.NetSocket)2 Expectations (mockit.Expectations)2 ByteBuf (io.netty.buffer.ByteBuf)1 Input (io.protostuff.Input)1 SocketAddressImpl (io.vertx.core.net.impl.SocketAddressImpl)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 HashMap (java.util.HashMap)1 Endpoint (org.apache.servicecomb.core.Endpoint)1 Invocation (org.apache.servicecomb.core.Invocation)1 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)1 SchemaMeta (org.apache.servicecomb.core.definition.SchemaMeta)1 InvocationFinishEvent (org.apache.servicecomb.core.event.InvocationFinishEvent)1