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);
});
}
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);
}
}
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);
}
Aggregations