Search in sources :

Example 6 with HttpClientWithContext

use of io.servicecomb.foundation.vertx.client.http.HttpClientWithContext in project java-chassis by ServiceComb.

the class WebsocketUtils method open.

public static void open(IpPort ipPort, String url, Handler<Void> onOpen, Handler<Void> onClose, Handler<Buffer> onMessage, Handler<Throwable> onException, Handler<Throwable> onConnectFailed) {
    HttpClientWithContext vertxHttpClient = WebsocketClientPool.INSTANCE.getClient();
    vertxHttpClient.runOnContext(client -> {
        client.websocket(ipPort.getPort(), ipPort.getHostOrIp(), url, RestUtils.getDefaultHeaders(), ws -> {
            onOpen.handle(null);
            ws.exceptionHandler(onException);
            ws.closeHandler(v -> {
                onClose.handle(v);
                try {
                    ws.close();
                } catch (Exception err) {
                }
            });
            ws.handler(onMessage);
        }, onConnectFailed);
    });
}
Also used : HttpClientWithContext(io.servicecomb.foundation.vertx.client.http.HttpClientWithContext)

Example 7 with HttpClientWithContext

use of io.servicecomb.foundation.vertx.client.http.HttpClientWithContext in project java-chassis by ServiceComb.

the class RestTransportClient method send.

public void send(Invocation invocation, AsyncResponse asyncResp) throws Exception {
    HttpClientWithContext httpClientWithContext = clientMgr.findThreadBindClientPool();
    OperationMeta operationMeta = invocation.getOperationMeta();
    RestOperationMeta swaggerRestOperation = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
    String method = swaggerRestOperation.getHttpMethod();
    try {
        VertxHttpMethod httpMethod = HttpMethodFactory.findHttpMethodInstance(method);
        httpMethod.doMethod(httpClientWithContext, invocation, asyncResp);
    } catch (Exception e) {
        asyncResp.fail(invocation.getInvocationType(), e);
        LOGGER.error("vertx rest transport send error.", e);
    }
}
Also used : RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) VertxHttpMethod(io.servicecomb.transport.rest.client.http.VertxHttpMethod) HttpClientWithContext(io.servicecomb.foundation.vertx.client.http.HttpClientWithContext) OperationMeta(io.servicecomb.core.definition.OperationMeta) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta)

Example 8 with HttpClientWithContext

use of io.servicecomb.foundation.vertx.client.http.HttpClientWithContext in project java-chassis by ServiceComb.

the class TestClientPoolManager method testAddNetThread.

@Test
public void testAddNetThread() {
    @SuppressWarnings("unchecked") NetThreadData<HttpClientWithContext> netThread = Mockito.mock(NetThreadData.class);
    instance.addNetThread(netThread);
    HttpClientWithContext context = Mockito.mock(HttpClientWithContext.class);
    Mockito.when(netThread.selectClientPool()).thenReturn(context);
    HttpClientWithContext netThreadValue = instance.findThreadBindClientPool();
    Assert.assertNotNull(netThreadValue);
}
Also used : HttpClientWithContext(io.servicecomb.foundation.vertx.client.http.HttpClientWithContext) Test(org.junit.Test)

Aggregations

HttpClientWithContext (io.servicecomb.foundation.vertx.client.http.HttpClientWithContext)8 OperationMeta (io.servicecomb.core.definition.OperationMeta)4 Test (org.junit.Test)4 AsyncResponse (io.servicecomb.core.AsyncResponse)3 Invocation (io.servicecomb.core.Invocation)3 IpPort (io.servicecomb.foundation.common.net.IpPort)3 OperationProtobuf (io.servicecomb.codec.protobuf.definition.OperationProtobuf)2 RestOperationMeta (io.servicecomb.common.rest.definition.RestOperationMeta)2 Endpoint (io.servicecomb.core.Endpoint)2 HttpClientRequest (io.vertx.core.http.HttpClientRequest)2 ProtobufManager (io.servicecomb.codec.protobuf.definition.ProtobufManager)1 WrapSchema (io.servicecomb.codec.protobuf.utils.WrapSchema)1 URLPathBuilder (io.servicecomb.common.rest.definition.path.URLPathBuilder)1 Const (io.servicecomb.core.Const)1 Response (io.servicecomb.core.Response)1 AbstractTransport (io.servicecomb.core.transport.AbstractTransport)1 JsonUtils (io.servicecomb.foundation.common.utils.JsonUtils)1 VertxUtils (io.servicecomb.foundation.vertx.VertxUtils)1 ClientPoolManager (io.servicecomb.foundation.vertx.client.ClientPoolManager)1 HttpClientVerticle (io.servicecomb.foundation.vertx.client.http.HttpClientVerticle)1