use of org.apache.thrift.transport.THttpClient in project providence by morimekta.
the class ProvidenceServlet_ThriftClientTest method testThriftClient_void.
@Test
public void testThriftClient_void() throws TException, IOException, Failure {
ApacheHttpTransport transport = new ApacheHttpTransport();
THttpClient httpClient = new THttpClient(endpoint().toString(), transport.getHttpClient());
TBinaryProtocol protocol = new TBinaryProtocol(httpClient);
net.morimekta.test.thrift.service.TestService.Iface client = new net.morimekta.test.thrift.service.TestService.Client(protocol);
AtomicBoolean called = new AtomicBoolean();
doAnswer(i -> {
called.set(true);
return null;
}).when(impl).voidMethod(55);
client.voidMethod(55);
waitAtMost(Duration.ONE_HUNDRED_MILLISECONDS).untilTrue(called);
verify(impl).voidMethod(55);
verify(instrumentation).onComplete(anyDouble(), any(PServiceCall.class), any(PServiceCall.class));
verifyNoMoreInteractions(impl, instrumentation);
}
use of org.apache.thrift.transport.THttpClient in project Honu by jboulon.
the class HTTPMessageSender method openConnection.
protected void openConnection() throws CommunicationException {
try {
if (httpClient != null) {
try {
httpClient.close();
} catch (Exception ignored) {
}
httpClient = null;
}
if (protocol != null) {
protocol = null;
}
if (collector != null) {
collector = null;
}
currentCollectorInfo = CollectorRegistry.getInstance().getCollector();
if (currentCollectorInfo == null) {
throw new CommunicationException("collector is null");
}
httpClient = new THttpClient(currentCollectorInfo.getHost() + ":" + currentCollectorInfo.getPort());
httpClient.setConnectTimeout(SENDER_TIMEOUT);
protocol = new TBinaryProtocol(httpClient);
collector = new HonuCollector.Client(protocol);
int status = collector.getStatus();
if (status != ServiceStatus.ALIVE) {
throw new RuntimeException("Collector is not alive! -- status:" + status);
}
} catch (Throwable e) {
collector = null;
throw new CommunicationException(e);
}
}
use of org.apache.thrift.transport.THttpClient in project pinpoint by naver.
the class TServiceClientSendBaseInterceptor method before.
@Override
public void before(Object target, Object[] args) {
if (isDebug) {
logger.beforeInterceptor(target, args);
}
if (target instanceof TServiceClient) {
TServiceClient client = (TServiceClient) target;
TProtocol oprot = client.getOutputProtocol();
TTransport transport = oprot.getTransport();
final Trace trace = traceContext.currentRawTraceObject();
if (trace == null) {
return;
}
final boolean shouldSample = trace.canSampled();
if (!shouldSample) {
if (transport instanceof THttpClient) {
return;
}
ThriftRequestProperty parentTraceInfo = new ThriftRequestProperty();
if (isDebug) {
logger.debug("set Sampling flag=false");
}
parentTraceInfo.setShouldSample(false);
InterceptorScopeInvocation currentTransaction = this.scope.getCurrentInvocation();
currentTransaction.setAttachment(parentTraceInfo);
return;
}
SpanEventRecorder recorder = trace.traceBlockBegin();
String remoteAddress = ThriftConstants.UNKNOWN_ADDRESS;
// We simply record as basic method.
if (transport instanceof THttpClient) {
recorder.recordServiceType(ThriftConstants.THRIFT_CLIENT_INTERNAL);
remoteAddress = getRemoteAddressForTHttpClient((THttpClient) transport);
} else {
recorder.recordServiceType(ThriftConstants.THRIFT_CLIENT);
remoteAddress = getRemoteAddress(transport);
recorder.recordDestinationId(remoteAddress);
TraceId nextId = trace.getTraceId().getNextTraceId();
recorder.recordNextSpanId(nextId.getSpanId());
ThriftRequestProperty parentTraceInfo = new ThriftRequestProperty();
parentTraceInfo.setTraceId(nextId.getTransactionId());
parentTraceInfo.setSpanId(nextId.getSpanId());
parentTraceInfo.setParentSpanId(nextId.getParentSpanId());
parentTraceInfo.setFlags(nextId.getFlags());
parentTraceInfo.setParentApplicationName(traceContext.getApplicationName());
parentTraceInfo.setParentApplicationType(traceContext.getServerTypeCode());
parentTraceInfo.setAcceptorHost(remoteAddress);
InterceptorScopeInvocation currentTransaction = this.scope.getCurrentInvocation();
currentTransaction.setAttachment(parentTraceInfo);
}
String methodName = ThriftConstants.UNKNOWN_METHOD_NAME;
if (args[0] instanceof String) {
methodName = (String) args[0];
}
String serviceName = ThriftUtils.getClientServiceName(client);
String thriftUrl = getServiceUrl(remoteAddress, serviceName, methodName);
recorder.recordAttribute(ThriftConstants.THRIFT_URL, thriftUrl);
}
}
use of org.apache.thrift.transport.THttpClient in project hbase by apache.
the class HttpDoAsClient method run.
private void run() throws Exception {
TTransport transport = new TSocket(host, port);
transport.open();
String url = "http://" + host + ":" + port;
THttpClient httpClient = new THttpClient(url);
httpClient.open();
TProtocol protocol = new TBinaryProtocol(httpClient);
Hbase.Client client = new Hbase.Client(protocol);
byte[] t = bytes("demo_table");
//
// Scan all tables, look for the demo table and delete it.
//
System.out.println("scanning tables...");
for (ByteBuffer name : refresh(client, httpClient).getTableNames()) {
System.out.println(" found: " + ClientUtils.utf8(name.array()));
if (ClientUtils.utf8(name.array()).equals(ClientUtils.utf8(t))) {
if (refresh(client, httpClient).isTableEnabled(name)) {
System.out.println(" disabling table: " + ClientUtils.utf8(name.array()));
refresh(client, httpClient).disableTable(name);
}
System.out.println(" deleting table: " + ClientUtils.utf8(name.array()));
refresh(client, httpClient).deleteTable(name);
}
}
//
// Create the demo table with two column families, entry: and unused:
//
ArrayList<ColumnDescriptor> columns = new ArrayList<>(2);
ColumnDescriptor col;
col = new ColumnDescriptor();
col.name = ByteBuffer.wrap(bytes("entry:"));
col.timeToLive = Integer.MAX_VALUE;
col.maxVersions = 10;
columns.add(col);
col = new ColumnDescriptor();
col.name = ByteBuffer.wrap(bytes("unused:"));
col.timeToLive = Integer.MAX_VALUE;
columns.add(col);
System.out.println("creating table: " + ClientUtils.utf8(t));
try {
refresh(client, httpClient).createTable(ByteBuffer.wrap(t), columns);
} catch (AlreadyExists ae) {
System.out.println("WARN: " + ae.message);
}
System.out.println("column families in " + ClientUtils.utf8(t) + ": ");
Map<ByteBuffer, ColumnDescriptor> columnMap = refresh(client, httpClient).getColumnDescriptors(ByteBuffer.wrap(t));
for (ColumnDescriptor col2 : columnMap.values()) {
System.out.println(" column: " + ClientUtils.utf8(col2.name.array()) + ", maxVer: " + col2.maxVersions);
}
transport.close();
httpClient.close();
}
use of org.apache.thrift.transport.THttpClient in project hbase by apache.
the class TestThriftHttpServer method talkToThriftServer.
protected void talkToThriftServer(String url, int customHeaderSize) throws Exception {
THttpClient httpClient = new THttpClient(url);
httpClient.open();
if (customHeaderSize > 0) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < customHeaderSize; i++) {
sb.append("a");
}
httpClient.setCustomHeader("User-Agent", sb.toString());
}
try {
TProtocol prot;
prot = new TBinaryProtocol(httpClient);
Hbase.Client client = new Hbase.Client(prot);
if (!tableCreated) {
TestThriftServer.createTestTables(client);
tableCreated = true;
}
TestThriftServer.checkTableList(client);
} finally {
httpClient.close();
}
}
Aggregations