Search in sources :

Example 41 with THttpClient

use of org.apache.thrift.transport.THttpClient in project airavata by apache.

the class AuroraSchedulerClientFactory method getTProtocol.

/**
 * Gets the t protocol.
 *
 * @param connectionUrl the connection url
 * @param connectionTimeout the connection timeout
 * @return the t protocol
 * @throws Exception the exception
 */
private static TProtocol getTProtocol(String connectionUrl, int connectionTimeout) throws Exception {
    try {
        THttpClient client = new THttpClient(connectionUrl);
        client.setConnectTimeout(connectionTimeout);
        TTransport transport = client;
        transport.open();
        TProtocol protocol = new TJSONProtocol(transport);
        return protocol;
    } catch (Exception ex) {
        logger.error(ex.getMessage(), ex);
        throw ex;
    }
}
Also used : TJSONProtocol(org.apache.thrift.protocol.TJSONProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) THttpClient(org.apache.thrift.transport.THttpClient) TTransport(org.apache.thrift.transport.TTransport)

Example 42 with THttpClient

use of org.apache.thrift.transport.THttpClient in project providence by morimekta.

the class ProvidenceServlet_ThriftClientTest method testThriftClient_oneway.

@Test
public void testThriftClient_oneway() 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).ping();
    client.ping();
    waitAtMost(Duration.ONE_HUNDRED_MILLISECONDS).untilTrue(called);
    verify(impl).ping();
    verify(instrumentation).onComplete(anyDouble(), any(PServiceCall.class), isNull());
    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 43 with THttpClient

use of org.apache.thrift.transport.THttpClient in project providence by morimekta.

the class ProvidenceServlet_ThriftClientTest method testThriftClient_failure.

@Test
public void testThriftClient_failure() 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);
        throw new Failure("test");
    }).when(impl).voidMethod(55);
    try {
        client.voidMethod(55);
    } catch (net.morimekta.test.thrift.service.Failure e) {
        assertEquals("test", e.getText());
    }
    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) Failure(net.morimekta.test.providence.service.Failure) Test(org.junit.Test)

Example 44 with THttpClient

use of org.apache.thrift.transport.THttpClient in project hbase by apache.

the class TestThriftSpnegoHttpFallbackServer method talkToThriftServer.

@Override
protected void talkToThriftServer(String url, int customHeaderSize) throws Exception {
    // Close httpClient and THttpClient automatically on any failures
    try (CloseableHttpClient httpClient = createHttpClient();
        THttpClient tHttpClient = new THttpClient(url, httpClient)) {
        tHttpClient.open();
        if (customHeaderSize > 0) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < customHeaderSize; i++) {
                sb.append("a");
            }
            tHttpClient.setCustomHeader(HttpHeaders.USER_AGENT, sb.toString());
        }
        TProtocol prot = new TBinaryProtocol(tHttpClient);
        Hbase.Client client = new Hbase.Client(prot);
        TestThriftServer.createTestTables(client);
        TestThriftServer.checkTableList(client);
        TestThriftServer.dropTestTables(client);
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) THttpClient(org.apache.thrift.transport.THttpClient) THttpClient(org.apache.thrift.transport.THttpClient) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) Hbase(org.apache.hadoop.hbase.thrift.generated.Hbase)

Example 45 with THttpClient

use of org.apache.thrift.transport.THttpClient in project hbase by apache.

the class TestThriftSpnegoHttpServer method talkToThriftServer.

@Override
protected void talkToThriftServer(String url, int customHeaderSize) throws Exception {
    // Close httpClient and THttpClient automatically on any failures
    try (CloseableHttpClient httpClient = createHttpClient();
        THttpClient tHttpClient = new THttpClient(url, httpClient)) {
        tHttpClient.open();
        if (customHeaderSize > 0) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < customHeaderSize; i++) {
                sb.append("a");
            }
            tHttpClient.setCustomHeader(HttpHeaders.USER_AGENT, sb.toString());
        }
        TProtocol prot = new TBinaryProtocol(tHttpClient);
        Hbase.Client client = new Hbase.Client(prot);
        List<ByteBuffer> bbs = client.getTableNames();
        LOG.info("PRE-EXISTING {}", bbs.stream().map(b -> Bytes.toString(b.array())).collect(Collectors.joining(",")));
        if (!bbs.isEmpty()) {
            for (ByteBuffer bb : bbs) {
                client.disableTable(bb);
                client.deleteTable(bb);
            }
        }
        TestThriftServer.createTestTables(client);
        TestThriftServer.checkTableList(client);
        TestThriftServer.dropTestTables(client);
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) THttpClient(org.apache.thrift.transport.THttpClient) THttpClient(org.apache.thrift.transport.THttpClient) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) Hbase(org.apache.hadoop.hbase.thrift.generated.Hbase) ByteBuffer(java.nio.ByteBuffer)

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