Search in sources :

Example 21 with THttpClient

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);
}
Also used : TestService(net.morimekta.test.providence.service.TestService) THttpClient(org.apache.thrift.transport.THttpClient) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) PServiceCall(net.morimekta.providence.PServiceCall) ApacheHttpTransport(com.google.api.client.http.apache.ApacheHttpTransport) THttpClient(org.apache.thrift.transport.THttpClient) Test(org.junit.Test)

Example 22 with THttpClient

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);
    }
}
Also used : TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) HonuCollector(org.honu.thrift.HonuCollector) THttpClient(org.apache.thrift.transport.THttpClient)

Example 23 with THttpClient

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);
    }
}
Also used : TServiceClient(org.apache.thrift.TServiceClient) Trace(com.navercorp.pinpoint.bootstrap.context.Trace) InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) TProtocol(org.apache.thrift.protocol.TProtocol) ThriftRequestProperty(com.navercorp.pinpoint.plugin.thrift.ThriftRequestProperty) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) THttpClient(org.apache.thrift.transport.THttpClient) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId) TTransport(org.apache.thrift.transport.TTransport)

Example 24 with THttpClient

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();
}
Also used : ColumnDescriptor(org.apache.hadoop.hbase.thrift.generated.ColumnDescriptor) ArrayList(java.util.ArrayList) THttpClient(org.apache.thrift.transport.THttpClient) ByteBuffer(java.nio.ByteBuffer) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TTransport(org.apache.thrift.transport.TTransport) THttpClient(org.apache.thrift.transport.THttpClient) AlreadyExists(org.apache.hadoop.hbase.thrift.generated.AlreadyExists) Hbase(org.apache.hadoop.hbase.thrift.generated.Hbase) TSocket(org.apache.thrift.transport.TSocket)

Example 25 with THttpClient

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();
    }
}
Also used : TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) THttpClient(org.apache.thrift.transport.THttpClient) THttpClient(org.apache.thrift.transport.THttpClient) Hbase(org.apache.hadoop.hbase.thrift.generated.Hbase)

Aggregations

THttpClient (org.apache.thrift.transport.THttpClient)51 TProtocol (org.apache.thrift.protocol.TProtocol)34 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)18 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)12 TJSONProtocol (org.apache.thrift.protocol.TJSONProtocol)9 Test (org.junit.Test)9 TTransport (org.apache.thrift.transport.TTransport)8 Hbase (org.apache.hadoop.hbase.thrift.generated.Hbase)5 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)5 RequestData (org.simbasecurity.api.service.thrift.RequestData)5 ApacheHttpTransport (com.google.api.client.http.apache.ApacheHttpTransport)4 IOException (java.io.IOException)4 PServiceCall (net.morimekta.providence.PServiceCall)4 TestService (net.morimekta.test.providence.service.TestService)4 Client (org.simbasecurity.api.service.thrift.AuthenticationFilterService.Client)4 HashMap (java.util.HashMap)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 TCLIService (org.apache.hive.service.rpc.thrift.TCLIService)3 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)3 ActionDescriptor (org.simbasecurity.api.service.thrift.ActionDescriptor)3