Example usage for org.apache.thrift.transport THttpClient THttpClient

List of usage examples for org.apache.thrift.transport THttpClient THttpClient

Introduction

In this page you can find the example usage for org.apache.thrift.transport THttpClient THttpClient.

Prototype

public THttpClient(String url, HttpClient client) throws TTransportException 

Source Link

Usage

From source file:com.funtl.framework.rpc.thrift.spring.ThriftClientInterceptor.java

License:Apache License

protected TTransport getTransport() throws TTransportException {
    return new THttpClient(getServiceUrl(), httpClientUtil.getHttpClient());
}

From source file:com.linecorp.armeria.server.thrift.ThriftOverHttp1Test.java

License:Apache License

@Override
protected TTransport newTransport(String uri) throws TTransportException {
    return new THttpClient(uri, httpClient);
}

From source file:com.udps.hive.jdbc.HiveConnection.java

License:Apache License

private TTransport createHttpTransport() throws SQLException {
    DefaultHttpClient httpClient;/* w  ww.j a  va2 s  . c  o m*/

    boolean useSsl = isSslConnection();

    // Create an http client from the configs
    try {
        httpClient = getHttpClient(useSsl);
    } catch (Exception e) {
        String msg = "Could not create http connection to " + jdbcURI + ". " + e.getMessage();
        throw new SQLException(msg, " 08S01", e);
    }

    try {
        transport = new THttpClient(getServerHttpUrl(useSsl), httpClient);
    } catch (TTransportException e) {
        String msg = "Could not create http connection to " + jdbcURI + ". " + e.getMessage();
        throw new SQLException(msg, " 08S01", e);
    }
    return transport;
}

From source file:org.apache.aurora.scheduler.http.api.security.ApiSecurityIT.java

License:Apache License

private AuroraAdmin.Client getClient(HttpClient httpClient) throws TTransportException {
    final TTransport httpClientTransport = new THttpClient(
            "http://" + httpServer.getHostText() + ":" + httpServer.getPort() + API_PATH, httpClient);
    addTearDown(new TearDown() {
        @Override/*from   w  w w.j a va 2 s.  c o m*/
        public void tearDown() throws Exception {
            httpClientTransport.close();
        }
    });
    return new AuroraAdmin.Client(new TJSONProtocol(httpClientTransport));
}

From source file:org.apache.aurora.scheduler.http.api.security.HttpSecurityIT.java

License:Apache License

private AuroraAdmin.Client getClient(HttpClient httpClient) throws TTransportException {
    final TTransport httpClientTransport = new THttpClient(formatUrl(API_PATH), httpClient);
    addTearDown(httpClientTransport::close);
    return new AuroraAdmin.Client(new TJSONProtocol(httpClientTransport));
}

From source file:org.apache.hadoop.hbase.thrift.TestThriftSpnegoHttpServer.java

License:Apache License

@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();/* www.  j a v a2  s . co m*/
        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);
        if (!tableCreated) {
            TestThriftServer.createTestTables(client);
            tableCreated = true;
        }
        TestThriftServer.checkTableList(client);
    }
}

From source file:org.apache.hive.jdbc.HiveConnection.java

License:Apache License

private TTransport createHttpTransport() throws SQLException, TTransportException {
    CloseableHttpClient httpClient;//from  w  ww  .j  a v  a2  s .c o  m
    boolean useSsl = isSslConnection();
    // Create an http client from the configs
    httpClient = getHttpClient(useSsl);
    try {
        transport = new THttpClient(getServerHttpUrl(useSsl), httpClient);
        // We'll call an open/close here to send a test HTTP message to the server. Any
        // TTransportException caused by trying to connect to a non-available peer are thrown here.
        // Bubbling them up the call hierarchy so that a retry can happen in openTransport,
        // if dynamic service discovery is configured.
        TCLIService.Iface client = new TCLIService.Client(new TBinaryProtocol(transport));
        TOpenSessionResp openResp = client.OpenSession(new TOpenSessionReq());
        if (openResp != null) {
            client.CloseSession(new TCloseSessionReq(openResp.getSessionHandle()));
        }
    } catch (TException e) {
        String msg = "Could not create http connection to " + jdbcUriString + ". " + e.getMessage();
        throw new TTransportException(msg, e);
    }
    return transport;
}

From source file:org.apache.hive.jdbc.miniHS2.TestHs2ConnectionMetricsHttp.java

License:Apache License

private TCLIService.Client getHttpClient() throws Exception {
    DefaultHttpClient httpClient = new DefaultHttpClient();

    Map<String, String> headers = new HashMap<>();
    headers.put("Connection", "close");
    httpClient.addRequestInterceptor(//from www .  j ava2s . c o m
            new BasicHttpRequestInterceptor(USERNAME, PASSWORD, null, null, false, headers));

    TTransport transport = new THttpClient(getHttpUrl(), httpClient);
    TProtocol protocol = new TBinaryProtocol(transport);
    return new TCLIService.Client(protocol);
}

From source file:org.apache.hive.service.cli.thrift.TestThriftHttpCLIService.java

License:Apache License

private static TTransport getHttpTransport() throws Exception {
    DefaultHttpClient httpClient = new DefaultHttpClient();
    String httpUrl = transportMode + "://" + host + ":" + port + "/" + thriftHttpPath + "/";
    httpClient.addRequestInterceptor(new HttpBasicAuthInterceptor(USERNAME, PASSWORD, null, null, false, null));
    return new THttpClient(httpUrl, httpClient);
}

From source file:org.apache.hive.service.cli.thrift.TestThriftHttpCLIService.java

License:Apache License

/**
 * Test additional http headers passed to request interceptor.
 * @throws Exception//from w  ww  .jav a  2 s  . c o m
 */
@Test
public void testAdditionalHttpHeaders() throws Exception {
    TTransport transport;
    DefaultHttpClient hClient = new DefaultHttpClient();
    String httpUrl = transportMode + "://" + host + ":" + port + "/" + thriftHttpPath + "/";
    Map<String, String> additionalHeaders = new HashMap<String, String>();
    additionalHeaders.put("key1", "value1");
    additionalHeaders.put("key2", "value2");
    HttpBasicAuthInterceptorWithLogging authInt = new HttpBasicAuthInterceptorWithLogging(USERNAME, PASSWORD,
            null, null, false, additionalHeaders);
    hClient.addRequestInterceptor(authInt);
    transport = new THttpClient(httpUrl, hClient);
    TCLIService.Client httpClient = getClient(transport);

    // Create a new open session request object
    TOpenSessionReq openReq = new TOpenSessionReq();
    httpClient.OpenSession(openReq).getSessionHandle();
    ArrayList<String> headers = authInt.getRequestHeaders();

    for (String h : headers) {
        assertTrue(h.contains("key1:value1"));
        assertTrue(h.contains("key2:value2"));
    }
}